From: <md...@us...> - 2008-05-29 13:01:45
|
Revision: 5298 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5298&view=rev Author: mdboom Date: 2008-05-29 06:01:40 -0700 (Thu, 29 May 2008) Log Message: ----------- Implement path clipping in SVG backend. Modified Paths: -------------- branches/v0_91_maint/CHANGELOG branches/v0_91_maint/lib/matplotlib/backends/backend_svg.py Modified: branches/v0_91_maint/CHANGELOG =================================================================== --- branches/v0_91_maint/CHANGELOG 2008-05-29 11:47:44 UTC (rev 5297) +++ branches/v0_91_maint/CHANGELOG 2008-05-29 13:01:40 UTC (rev 5298) @@ -1,3 +1,5 @@ +2008-05-29 Implement path clipping in SVG backend - MGD + 2008-05-28 Fix crashing of PDFs in xpdf and ghostscript when two-byte characters are used with Type 3 fonts - MGD Modified: branches/v0_91_maint/lib/matplotlib/backends/backend_svg.py =================================================================== --- branches/v0_91_maint/lib/matplotlib/backends/backend_svg.py 2008-05-29 11:47:44 UTC (rev 5297) +++ branches/v0_91_maint/lib/matplotlib/backends/backend_svg.py 2008-05-29 13:01:40 UTC (rev 5298) @@ -56,6 +56,37 @@ self._svgwriter.write ('%s<%s style="%s" %s %s/>\n' % ( cliprect, element, style, clippath, details)) + def _path_commands(self, path): + cmd = [] + while 1: + code, xp, yp = path.vertex() + yp = self.height - yp + + if code == agg.path_cmd_stop: + cmd.append('z') # Hack, path_cmd_end_poly not found + break + elif code == agg.path_cmd_move_to: + cmd.append('M%g %g' % (xp, yp)) + elif code == agg.path_cmd_line_to: + cmd.append('L%g %g' % (xp, yp)) + elif code == agg.path_cmd_curve3: + verts = [xp, yp] + verts.extent(path.vertex()[1:]) + verts[-1] = self.height - verts[-1] + cmd.append('Q%g %g %g %g' % tuple(verts)) + elif code == agg.path_cmd_curve4: + verts = [xp, yp] + verts.extend(path.vertex()[1:]) + verts[-1] = self.height - verts[-1] + verts.extend(path.vertex()[1:]) + verts[-1] = self.height - verts[-1] + cmd.append('C%g %g %g %g %g %g'%tuple(verts)) + elif code == agg.path_cmd_end_poly: + cmd.append('z') + + path_data = "".join(cmd) + return path_data + def _get_font(self, prop): key = hash(prop) font = self.fontd.get(key) @@ -108,10 +139,28 @@ def _get_gc_clip_svg(self, gc): cliprect = gc.get_clip_rectangle() - if cliprect is None: + clippath = gc.get_clip_path() + if cliprect is None and clippath is None: return '', None - else: + elif clippath is not None: # See if we've already seen this clip rectangle + key = hash(clippath) + if self._clipd.get(key) is None: # If not, store a new clipPath + self._clipd[key] = clippath + style = "stroke: gray; fill: none;" + path_data = self._path_commands(clippath) + path = """\ +<defs> + <clipPath id="%(key)s"> + <path d="%(path_data)s"/> + </clipPath> +</defs> +""" % locals() + return path, key + else: + return '', key + elif cliprect is not None: + # See if we've already seen this clip rectangle key = hash(cliprect) if self._clipd.get(key) is None: # If not, store a new clipPath self._clipd[key] = cliprect @@ -139,35 +188,7 @@ self._svgwriter.write('</g>\n') def draw_path(self, gc, rgbFace, path): - cmd = [] - - while 1: - code, xp, yp = path.vertex() - yp = self.height - yp - - if code == agg.path_cmd_stop: - cmd.append('z') # Hack, path_cmd_end_poly not found - break - elif code == agg.path_cmd_move_to: - cmd.append('M%g %g' % (xp, yp)) - elif code == agg.path_cmd_line_to: - cmd.append('L%g %g' % (xp, yp)) - elif code == agg.path_cmd_curve3: - verts = [xp, yp] - verts.extent(path.vertex()[1:]) - verts[-1] = self.height - verts[-1] - cmd.append('Q%g %g %g %g' % tuple(verts)) - elif code == agg.path_cmd_curve4: - verts = [xp, yp] - verts.extend(path.vertex()[1:]) - verts[-1] = self.height - verts[-1] - verts.extend(path.vertex()[1:]) - verts[-1] = self.height - verts[-1] - cmd.append('C%g %g %g %g %g %g'%tuple(verts)) - elif code == agg.path_cmd_end_poly: - cmd.append('z') - - path_data = "".join(cmd) + path_data = self._path_commands(path) self._draw_svg_element("path", 'd="%s"' % path_data, gc, rgbFace) def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2, rotation): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |