src/reportlab/graphics/renderbase.py
branchrtl-support
changeset 3467 4f25b3a34c5f
parent 3233 9408fec15198
equal deleted inserted replaced
3267:c2db88548c0a 3467:4f25b3a34c5f
    36     For example, if we have two adjacent red shapes we don't need
    36     For example, if we have two adjacent red shapes we don't need
    37     to set the pen color to red in between. Returns the effect
    37     to set the pen color to red in between. Returns the effect
    38     the given shape would have on the graphics state"""
    38     the given shape would have on the graphics state"""
    39     delta = {}
    39     delta = {}
    40     for (prop, value) in shape.getProperties().items():
    40     for (prop, value) in shape.getProperties().items():
    41         if STATE_DEFAULTS.has_key(prop):
    41         if prop in STATE_DEFAULTS:
    42             delta[prop] = value
    42             delta[prop] = value
    43     return delta
    43     return delta
    44 
    44 
    45 
    45 
    46 class StateTracker:
    46 class StateTracker:
    60         # loops below.
    60         # loops below.
    61         self._combined = []
    61         self._combined = []
    62         if defaults is None:
    62         if defaults is None:
    63             defaults = STATE_DEFAULTS.copy()
    63             defaults = STATE_DEFAULTS.copy()
    64         #ensure  that if we have a transform, we have a CTM
    64         #ensure  that if we have a transform, we have a CTM
    65         if defaults.has_key('transform'):
    65         if 'transform' in defaults:
    66             defaults['ctm'] = defaults['transform']
    66             defaults['ctm'] = defaults['transform']
    67         self._combined.append(defaults)
    67         self._combined.append(defaults)
    68 
    68 
    69     def push(self,delta):
    69     def push(self,delta):
    70         """Take a new state dictionary of changes and push it onto
    70         """Take a new state dictionary of changes and push it onto
    98         reverseDelta = {}
    98         reverseDelta = {}
    99         #print 'pop()...'
    99         #print 'pop()...'
   100         for key, curValue in lastDelta.items():
   100         for key, curValue in lastDelta.items():
   101             #print '   key=%s, value=%s' % (key, curValue)
   101             #print '   key=%s, value=%s' % (key, curValue)
   102             prevValue = newState[key]
   102             prevValue = newState[key]
   103             if prevValue <> curValue:
   103             if prevValue != curValue:
   104                 #print '    state popping "%s"="%s"' % (key, curValue)
   104                 #print '    state popping "%s"="%s"' % (key, curValue)
   105                 if key == 'transform':
   105                 if key == 'transform':
   106                     reverseDelta[key] = inverse(lastDelta['transform'])
   106                     reverseDelta[key] = inverse(lastDelta['transform'])
   107                 else:  #just return to previous state
   107                 else:  #just return to previous state
   108                     reverseDelta[key] = prevValue
   108                     reverseDelta[key] = prevValue
   125         self._combined[-1][key] = value
   125         self._combined[-1][key] = value
   126 
   126 
   127 def testStateTracker():
   127 def testStateTracker():
   128     print 'Testing state tracker'
   128     print 'Testing state tracker'
   129     defaults = {'fillColor':None, 'strokeColor':None,'fontName':None, 'transform':[1,0,0,1,0,0]}
   129     defaults = {'fillColor':None, 'strokeColor':None,'fontName':None, 'transform':[1,0,0,1,0,0]}
       
   130     from reportlab.graphics.shapes import _baseGFontName
   130     deltas = [
   131     deltas = [
   131         {'fillColor':'red'},
   132         {'fillColor':'red'},
   132         {'fillColor':'green', 'strokeColor':'blue','fontName':'Times-Roman'},
   133         {'fillColor':'green', 'strokeColor':'blue','fontName':_baseGFontName},
   133         {'transform':[0.5,0,0,0.5,0,0]},
   134         {'transform':[0.5,0,0,0.5,0,0]},
   134         {'transform':[0.5,0,0,0.5,2,3]},
   135         {'transform':[0.5,0,0,0.5,2,3]},
   135         {'strokeColor':'red'}
   136         {'strokeColor':'red'}
   136         ]
   137         ]
   137 
   138 
   251             else:
   252             else:
   252                 node._canvas = canvas
   253                 node._canvas = canvas
   253                 ocanvas = None
   254                 ocanvas = None
   254 
   255 
   255             self.fillDerivedValues(node)
   256             self.fillDerivedValues(node)
       
   257             dtcb = getattr(node,'_drawTimeCallback',None)
       
   258             if dtcb:
       
   259                 dtcb(node,canvas=canvas,renderer=self)
   256             #draw the object, or recurse
   260             #draw the object, or recurse
   257             if isinstance(node, Line):
   261             if isinstance(node, Line):
   258                 self.drawLine(node)
   262                 self.drawLine(node)
   259             elif isinstance(node, Image):
   263             elif isinstance(node, Image):
   260                 self.drawImage(node)
   264                 self.drawImage(node)