reportlab/graphics/renderbase.py
author andy_robinson
Tue, 06 Feb 2001 00:50:53 +0000
changeset 604 c61e69d2721e
parent 594 ed61db938b7a
child 817 8c3a399effda
permissions -rw-r--r--
Fixes for QIR barchart presentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     1
###############################################################################
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     2
#   $Log $
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     3
#   
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     4
#   
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     5
"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     6
Superclass for renderers to factor out common functionality and default implementations.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     7
"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     8
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
     9
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    10
__version__=''' $Id $ '''
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    11
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    12
from reportlab.graphics.shapes import *
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    13
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    14
def inverse(A):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    15
    "For A affine 2D represented as 6vec return 6vec version of A**(-1)"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    16
    # I checked this RGB
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    17
    det = float(A[0]*A[3] - A[2]*A[1])
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    18
    R = [A[3]/det, -A[1]/det, -A[2]/det, A[0]/det]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    19
    return tuple(R+[-R[0]*A[4]-R[2]*A[5],-R[1]*A[4]-R[3]*A[5]])
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    20
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    21
def mmult(A, B):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    22
    "A postmultiplied by B"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    23
    # I checked this RGB
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    24
    # [a0 a2 a4]    [b0 b2 b4]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    25
    # [a1 a3 a5] *  [b1 b3 b5]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    26
    # [      1 ]    [      1 ]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    27
    #
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    28
    return (A[0]*B[0] + A[2]*B[1],
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    29
            A[1]*B[0] + A[3]*B[1],
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    30
            A[0]*B[2] + A[2]*B[3],
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    31
            A[1]*B[2] + A[3]*B[3],
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    32
            A[0]*B[4] + A[2]*B[5] + A[4],
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    33
            A[1]*B[4] + A[3]*B[5] + A[5])
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    34
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    35
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    36
def getStateDelta(shape):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    37
    """Used to compute when we need to change the graphics state.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    38
    For example, if we have two adjacent red shapes we don't need
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    39
    to set the pen color to red in between. Returns the effect
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    40
    the given shape would have on the graphics state"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    41
    delta = {}
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    42
    for (prop, value) in shape.getProperties().items():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    43
        if STATE_DEFAULTS.has_key(prop):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    44
            delta[prop] = value
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    45
    return delta
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    46
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    47
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    48
class StateTracker:
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    49
    """Keeps a stack of transforms and state
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    50
    properties.  It can contain any properties you
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    51
    want, but the keys 'transform' and 'ctm' have
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    52
    special meanings.  The getCTM()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    53
    method returns the current transformation
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    54
    matrix at any point, without needing to
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    55
    invert matrixes when you pop."""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    56
    def __init__(self, defaults=None):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    57
        # one stack to keep track of what changes...
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    58
        self.__deltas = []
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    59
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    60
        # and another to keep track of cumulative effects.  Last one in
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    61
        # list is the current graphics state.  We put one in to simplify
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    62
        # loops below.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    63
        self.__combined = []
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    64
        if defaults is None:
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    65
            defaults = STATE_DEFAULTS.copy()
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
    66
        #ensure  that if we have a transform, we have a CTM
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
    67
        if defaults.has_key('transform'):
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
    68
            defaults['ctm'] = defaults['transform']
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    69
        self.__combined.append(defaults)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    70
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    71
    def push(self,delta):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    72
        """Take a new state dictionary of changes and push it onto
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    73
        the stack.  After doing this, the combined state is accessible
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    74
        through getState()"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    75
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    76
        newstate = self.__combined[-1].copy()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    77
        for (key, value) in delta.items():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    78
            if key == 'transform':  #do cumulative matrix
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    79
                newstate['transform'] = delta['transform']
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
    80
                newstate['ctm'] = mmult(self.__combined[-1]['ctm'], delta['transform'])
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
    81
                #print 'statetracker transform = (%0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f)' % tuple(newstate['transform'])
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
    82
                #print 'statetracker ctm = (%0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f)' % tuple(newstate['ctm'])
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
    83
                
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    84
            else:  #just overwrite it
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    85
                newstate[key] = value
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    86
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    87
        self.__combined.append(newstate)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    88
        self.__deltas.append(delta)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    89
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    90
    def pop(self):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    91
        """steps back one, and returns a state dictionary with the
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    92
        deltas to reverse out of wherever you are.  Depending
594
ed61db938b7a Continued work on bar charts and support
andy_robinson
parents: 592
diff changeset
    93
        on your back end, you may not need the return value,
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    94
        since you can get the complete state afterwards with getState()"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    95
        del self.__combined[-1]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    96
        newState = self.__combined[-1]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    97
        lastDelta = self.__deltas[-1]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    98
        del  self.__deltas[-1]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
    99
        #need to diff this against the last one in the state
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   100
        reverseDelta = {}
594
ed61db938b7a Continued work on bar charts and support
andy_robinson
parents: 592
diff changeset
   101
        #print 'pop()...'
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   102
        for key, curValue in lastDelta.items():
604
c61e69d2721e Fixes for QIR barchart presentation
andy_robinson
parents: 594
diff changeset
   103
            #print '   key=%s, value=%s' % (key, curValue)
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   104
            prevValue = newState[key]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   105
            if prevValue <> curValue:
594
ed61db938b7a Continued work on bar charts and support
andy_robinson
parents: 592
diff changeset
   106
                #print '    state popping "%s"="%s"' % (key, curValue)
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   107
                if key == 'transform':
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   108
                    reverseDelta[key] = inverse(lastDelta['transform'])
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   109
                else:  #just return to previous state
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   110
                    reverseDelta[key] = prevValue
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   111
        return reverseDelta
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   112
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   113
    def getState(self):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   114
        "returns the complete graphics state at this point"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   115
        return self.__combined[-1]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   116
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   117
    def getCTM(self):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   118
        "returns the current transformation matrix at this point"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   119
        return self.__combined[-1]['ctm']
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   120
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   121
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   122
def testStateTracker():
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   123
    print 'Testing state tracker'
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   124
    defaults = {'fillColor':None, 'strokeColor':None,'fontName':None, 'transform':[1,0,0,1,0,0]}
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   125
    deltas = [
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   126
        {'fillColor':'red'},
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   127
        {'fillColor':'green', 'strokeColor':'blue','fontName':'Times-Roman'},
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   128
        {'transform':[0.5,0,0,0.5,0,0]},
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   129
        {'transform':[0.5,0,0,0.5,2,3]},
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   130
        {'strokeColor':'red'}
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   131
        ]
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   132
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   133
    st = StateTracker(defaults)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   134
    print 'initial:', st.getState()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   135
    print
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   136
    for delta in deltas:
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   137
        print 'pushing:', delta
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   138
        st.push(delta)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   139
        print 'state:  ',st.getState(),'\n'
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   140
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   141
    for delta in deltas:
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   142
        print 'popping:',st.pop()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   143
        print 'state:  ',st.getState(),'\n'
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   144
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   145
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   146
class Renderer:
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 568
diff changeset
   147
    """Virtual superclass for graphics renderers."""
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   148
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   149
    def __init__(self):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   150
        self._tracker = StateTracker()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   151
        
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   152
    def undefined(self, operation):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   153
        raise ValueError, "%s operation not defined at superclass class=%s" %(operation, self.__class__)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   154
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   155
    def draw(self, drawing, canvas, x, y):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   156
        """This is the top level function, which
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   157
        draws the drawing at the given location.
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   158
        The recursive part is handled by drawNode."""
604
c61e69d2721e Fixes for QIR barchart presentation
andy_robinson
parents: 594
diff changeset
   159
        print 'enter Renderer.draw()'
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   160
        self.undefined("draw")
604
c61e69d2721e Fixes for QIR barchart presentation
andy_robinson
parents: 594
diff changeset
   161
        print 'enter Renderer.draw()'
c61e69d2721e Fixes for QIR barchart presentation
andy_robinson
parents: 594
diff changeset
   162
        
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   163
    def drawNode(self, node):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   164
        """This is the recursive method called for each node
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   165
        in the tree"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   166
        # Undefined here, but with closer analysis probably can be handled in superclass
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   167
        self.undefined("drawNode")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   168
        
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   169
    def drawNodeDispatcher(self, node):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   170
        """dispatch on the node's (super) class: shared code"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   171
        #print "drawNodeDispatcher", self, node.__class__
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   172
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   173
        # replace UserNode with its contents
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   174
        if isinstance(node, UserNode):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   175
            node = node.provideNode()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   176
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   177
        #draw the object, or recurse
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   178
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   179
        if isinstance(node, Line):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   180
            self.drawLine(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   181
        elif isinstance(node, Rect):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   182
            self.drawRect(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   183
        elif isinstance(node, Circle):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   184
            self.drawCircle(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   185
        elif isinstance(node, Ellipse):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   186
            self.drawEllipse(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   187
        elif isinstance(node, PolyLine):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   188
            self.drawPolyLine(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   189
        elif isinstance(node, Polygon):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   190
            self.drawPolygon(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   191
        elif isinstance(node, Path):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   192
            self.drawPath(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   193
        elif isinstance(node, String):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   194
            self.drawString(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   195
        elif isinstance(node, Group):
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   196
            self.drawGroup(node)
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   197
        elif isinstance(node, Wedge):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   198
            #print "drawWedge"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   199
            self.drawWedge(node)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   200
        else:
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 568
diff changeset
   201
            print 'DrawingError','Unexpected element %s in drawing!' % str(node)
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   202
        #print "done dispatching"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   203
            
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   204
    _restores = {'stroke':'_stroke','stroke_width': '_lineWidth','stroke_linecap':'_lineCap',
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   205
                'stroke_linejoin':'_lineJoin','fill':'_fill','font_family':'_font',
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   206
                'font_size':'_fontSize'}
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   207
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   208
    def drawGroup(self, group):
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   209
        # just do the contents.  Some renderers might need to override this
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   210
        # if they need a flipped transform
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   211
        for childNode in group.contents:
592
35f70c45f74c Fixed user node rendering bug, added barchart1
andy_robinson
parents: 590
diff changeset
   212
            if isinstance(childNode, UserNode):
35f70c45f74c Fixed user node rendering bug, added barchart1
andy_robinson
parents: 590
diff changeset
   213
                node2 = childNode.provideNode()
35f70c45f74c Fixed user node rendering bug, added barchart1
andy_robinson
parents: 590
diff changeset
   214
            else:
35f70c45f74c Fixed user node rendering bug, added barchart1
andy_robinson
parents: 590
diff changeset
   215
                node2 = childNode
35f70c45f74c Fixed user node rendering bug, added barchart1
andy_robinson
parents: 590
diff changeset
   216
            self.drawNode(node2)
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   217
568
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   218
    def drawWedge(self, wedge):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   219
        # by default ask the wedge to make a polygon of itself and draw that!
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   220
        #print "drawWedge"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   221
        polygon = wedge.asPolygon()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   222
        self.drawPolygon(polygon)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   223
        
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   224
    def drawPath(self, path):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   225
        polygons = path.asPolygons()
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   226
        for polygon in polygons:
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   227
                self.drawPolygon(polygon)
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   228
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   229
    def drawRect(self, rect):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   230
        # could be implemented in terms of polygon
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   231
        self.undefined("drawRect")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   232
        
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   233
    def drawLine(self, line):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   234
        self.undefined("drawLine")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   235
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   236
    def drawCircle(self, circle):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   237
        self.undefined("drawCircle")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   238
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   239
    def drawPolyLine(self, p):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   240
        self.undefined("drawPolyLine")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   241
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   242
    def drawEllipse(self, ellipse):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   243
        self.undefined("drawEllipse")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   244
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   245
    def drawPolygon(self, p):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   246
        self.undefined("drawPolygon")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   247
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   248
    def drawString(self, stringObj):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   249
        self.undefined("drawString")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   250
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   251
    def applyStateChanges(self, delta, newState):
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   252
        """This takes a set of states, and outputs the operators
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   253
        needed to set those properties"""
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   254
        self.undefined("applyStateChanges")
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   255
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   256
if __name__=='__main__':
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   257
    print "this file has no script interpretation"
9cadc5ef53db Added graphics module
andy_robinson
parents:
diff changeset
   258
    print __doc__