[reportlab-users] problem with renderSVG (patch)

Robin Becker reportlab-users@reportlab.com
Sat, 4 Oct 2003 23:22:39 +0100


In article <3F7F2ED5.452E85CF@rasselstein-hoesch.de>, Dirk Datzert
<dirk.datzert@tks-rasselstein.thyssenkrupp.com> writes
>Hi all,
>
>!!! refering to my mail sent earlier !!!
>
>I have a strange problem with renderSVG. I detected this in use with
>polyLines, but I think that it is a general problem in renderSVG.
>
>I would say that the StateTracker Code in renderSVG is not working as 
>expected to work and that polyLine should set fillColor to none.
>
>Regards,

Dirk can you indicate what you think is the problem?

Dinu as the author can you comment on Dirk's patch?

>Dirk--- renderSVG.py.orig      Fri Sep 26 20:59:52 2003
>+++ renderSVG.py       Sat Oct  4 22:27:10 2003
>@@ -515,6 +515,7 @@
> 
>         if self._strokeColor != None:
>             self.setColor(self._strokeColor)
>+            self.setFillColor(None)
>             pairs = []
>             for i in xrange(len(points)):
>                 pairs.append("%f %f" % (points[i]))
>@@ -585,7 +586,11 @@
>     def closePath(self):
>         self.path = self.path + 'Z '
> 
>+    def saveState(self):
>+        '''do nothing for compatibility'''
>+        pass
> 
>+    restoreState = saveState
> 
> 
> class _SVGRenderer(Renderer):
>@@ -596,6 +601,26 @@
>         self._tracker = StateTracker()
>         self.verbose = 0
> 
>+    def pop(self):
>+        self._tracker.pop()
>+        self.applyState()
>+
>+    def push(self,node):
>+        deltas = getStateDelta(node)
>+        self._tracker.push(deltas)
>+        self.applyState()
>+
>+    def applyState(self):
>+        s = self._tracker.getState()
>+        self._canvas.setLineWidth(s['strokeWidth'])
>+        self._canvas.setStrokeColor(s['strokeColor'])
>+        self._canvas.setLineCap(s['strokeLineCap'])
>+        self._canvas.setLineJoin(s['strokeLineJoin'])
>+        da = s['strokeDashArray']
>+        da = da and (0,da) or None
>+        self._canvas.setDash(da)
>+        self._canvas.setFillColor(s['fillColor'])
>+        self._canvas.setFont(s['fontName'], s['fontSize'])
> 
>     def draw(self, drawing, canvas, x, y, showBoundary=rl_config.showBoundary):
>         """This is the top level function, which draws the drawing at the given
>@@ -610,13 +635,14 @@
>             #bounding box
>             if showBoundary:
>                 canvas.rect(x, y, drawing.width, drawing.height)
>-
>+            canvas.saveState()
>             deltas = STATE_DEFAULTS.copy()
>             deltas['transform'] = [1,0,0,1,x,y]
>             self._tracker.push(deltas)
>-            self.applyStateChanges(deltas, {})
>+            self.applyState()
>             self.drawNode(drawing)
>-            self._tracker.pop()
>+            self.pop()
>+            canvas.restoreState()
>         finally:
>             del self._canvas, self._drawing, canvas._drawing
> 
>@@ -629,29 +655,20 @@
> 
>         if self.verbose: print "### begin _SVGRenderer.drawNode"
> 
>+        #begin node
>         self._canvas.comment('begin node %s'%`node`)
>-        color = self._canvas._color
>-        if not (isinstance(node, Path) and node.isClipPath):
>-            pass # self._canvas.saveState()
> 
>         #apply state changes
>-        deltas = getStateDelta(node)
>-        self._tracker.push(deltas)
>-        self.applyStateChanges(deltas, {})
>+        self.push(node)
> 
>         #draw the object, or recurse
>         self.drawNodeDispatcher(node)
> 
>-        rDeltas = self._tracker.pop()
>-        if not (isinstance(node, Path) and node.isClipPath):
>-            pass # self._canvas.restoreState()
>-        self._canvas.comment('end node %s'%`node`)
>-        self._canvas._color = color
>+        # restore the state
>+        self.pop()
> 
>-        #restore things we might have lost (without actually doing anything).
>-        for k, v in rDeltas.items():
>-            if self._restores.has_key(k):
>-                setattr(self._canvas,self._restores[k],v)
>+        #end node
>+        self._canvas.comment('end node %s'%`node`)
> 
>         if self.verbose: print "### end _SVGRenderer.drawNode"
> 

-- 
Robin Becker