From: <md...@us...> - 2008-05-08 16:50:02
|
Revision: 5131 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5131&view=rev Author: mdboom Date: 2008-05-08 09:49:50 -0700 (Thu, 08 May 2008) Log Message: ----------- A number of SVG improvements: Clipping in markers, collections and text. Text kerning with embedded fonts. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-05-08 16:45:55 UTC (rev 5130) +++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-05-08 16:49:50 UTC (rev 5131) @@ -193,11 +193,20 @@ write('<defs><path id="%s" d="%s"/></defs>\n' % (name, key)) self._markers[key] = name + clipid = self._get_gc_clip_svg(gc) + if clipid is None: + clippath = '' + else: + clippath = 'clip-path="url(#%s)"' % clipid + + write('<g %s>' % clippath) trans_and_flip = self._make_flip_transform(trans) tpath = trans_and_flip.transform_path(path) for x, y in tpath.vertices: details = 'xlink:href="#%s" x="%f" y="%f"' % (name, x, y) - self._draw_svg_element('use', details, gc, rgbFace) + style = self._get_style(gc, rgbFace) + self._svgwriter.write ('<use style="%s" %s/>\n' % (style, details)) + write('</g>') def draw_path_collection(self, master_transform, cliprect, clippath, clippath_trans, paths, all_transforms, offsets, @@ -221,8 +230,14 @@ path_codes, cliprect, clippath, clippath_trans, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds): + clipid = self._get_gc_clip_svg(gc) + if clipid is not None: + write('<g clip-path="url(#%s)">' % clipid) details = 'xlink:href="#%s" x="%f" y="%f"' % (path_id, xo, self.height - yo) - self._draw_svg_element('use', details, gc, rgbFace) + style = self._get_style(gc, rgbFace) + self._svgwriter.write ('<use style="%s" %s/>\n' % (style, details)) + if clipid is not None: + write('</g>') self._path_collection_id += 1 @@ -309,7 +324,12 @@ write(path) write('</defs>\n') - svg = ['<g style="fill: %s; opacity: %s" transform="' % (color, gc.get_alpha())] + svg = [] + clipid = self._get_gc_clip_svg(gc) + if clipid is not None: + svg.append('<g clip-path="url(#%s)">\n' % clipid) + + svg.append('<g style="fill: %s; opacity: %s" transform="' % (color, gc.get_alpha())) if angle != 0: svg.append('translate(%s,%s)rotate(%1.1f)' % (x,y,-angle)) elif x != 0 or y != 0: @@ -332,16 +352,19 @@ kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT) else: kern = 0 - lastgind = gind - currx += kern/64.0 + currx += (kern / 64.0) / (self.FONT_SCALE / fontsize) svg.append('<use xlink:href="#%s"' % charnum) if currx != 0: svg.append(' x="%s"' % (currx * (self.FONT_SCALE / fontsize))) svg.append('/>\n') + currx += (glyph.linearHoriAdvance / 65536.0) / (self.FONT_SCALE / fontsize) + lastgind = gind svg.append('</g>\n') + if clipid is not None: + svg.append('</g>\n') svg = ''.join(svg) else: thetext = escape_xml_text(s) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |