src/reportlab/graphics/renderbase.py
changeset 3326 ce725978d11c
parent 3233 9408fec15198
child 3368 afa025c34493
equal deleted inserted replaced
3325:64eb1b787d02 3326:ce725978d11c
    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