Revision: 4686
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4686&view=rev
Author:   mdboom
Date:     2007-12-10 08:15:30 -0800 (Mon, 10 Dec 2007)

Log Message:
-----------
Support draw_path (importantly for ellipses) in Pdf, Svg and Cairo
backends.
Fix SVG text rendering bug.

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py
    trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
    trunk/matplotlib/lib/matplotlib/backends/backend_svg.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2007-12-10 15:34:29 UTC (rev 4685)
+++ trunk/matplotlib/CHANGELOG  2007-12-10 16:15:30 UTC (rev 4686)
@@ -1,3 +1,9 @@
+2007-12-10 Fix SVG text rendering bug.
+
+2007-12-10 Increase accuracy of circle and ellipse drawing by using an 8-piece
+           bezier approximation, rather than a 4-piece one.  Fix PDF, SVG and
+           Cairo backends so they can draw paths (meaning ellipses as well).
+
 2007-12-07 Issue a warning when drawing an image on a non-linear axis. - MGD
 
 2007-12-06 let widgets.Cursor initialize to the lower x and y bounds

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py   2007-12-10 
15:34:29 UTC (rev 4685)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py   2007-12-10 
16:15:30 UTC (rev 4686)
@@ -34,6 +34,7 @@
 backend_version = cairo.version
 del _version_required
 
+from matplotlib import agg
 from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
      FigureManagerBase, FigureCanvasBase
 from matplotlib.cbook        import enumerate, izip, is_string_like
@@ -124,7 +125,35 @@
 
         #_.ctx.restore() # revert to the default attributes
 
+    def draw_path(self, gc, rgbFace, path):
+        ctx = gc.ctx
+        ctx.new_path()
 
+        while 1:
+            code, xp, yp = path.vertex()
+            yp = self.height - yp
+
+            if code == agg.path_cmd_stop:
+                ctx.close_path()
+                break
+            elif code == agg.path_cmd_move_to:
+                ctx.move_to(xp, yp)
+            elif code == agg.path_cmd_line_to:
+                ctx.line_to(xp, yp)
+            elif code == agg.path_cmd_curve3:
+                _, xp1, yp1 = path.vertex()
+                yp1 = self.height - yp1
+                ctx.curve_to(xp, yp, xp, yp, xp1, yp1)
+            elif code == agg.path_cmd_curve4:
+                _, xp1, yp1 = path.vertex()
+                yp1 = self.height - yp1
+                _, xp2, yp2 = path.vertex()
+                yp2 = self.height - yp2
+                ctx.curve_to(xp, yp, xp1, yp1, xp2, yp2)
+            elif code == agg.path_cmd_end_poly:
+                ctx.close_path()
+        self._fill_and_stroke(ctx, rgbFace)
+
     def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2,
                  rotation):
         if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
@@ -307,11 +336,11 @@
         ctx.translate(x, y)
         if angle:
            ctx.rotate (-angle * npy.pi / 180)
-           
+
         for font, fontsize, s, ox, oy in glyphs:
            ctx.new_path()
            ctx.move_to(ox, oy)
-           
+
            fontProp = ttfFontProperty(font)
            ctx.save()
            ctx.select_font_face (fontProp.name,
@@ -332,7 +361,7 @@
 
         ctx.restore()
 
-        
+
     def flipy(self):
         if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
         return True
@@ -494,7 +523,7 @@
 
         self.figure.draw (renderer)
         surface.write_to_png (fobj)
-    
+
     def print_pdf(self, fobj, *args, **kwargs):
         return self._save(fobj, 'pdf', *args, **kwargs)
 
@@ -506,10 +535,10 @@
 
     def print_svgz(self, fobj, *args, **kwargs):
         return self._save(fobj, 'svgz', *args, **kwargs)
-    
+
     def get_default_filetype(self):
         return rcParams['cairo.format']
-    
+
     def _save (self, fo, format, **kwargs):
         # save PDF/PS/SVG
         orientation = kwargs.get('orientation', 'portrait')

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2007-12-10 
15:34:29 UTC (rev 4685)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2007-12-10 
16:15:30 UTC (rev 4686)
@@ -1249,6 +1249,36 @@
 
         self.file.output(self.gc.close_and_paint())
 
+    def draw_path(self, gc, rgbFace, path):
+        self.check_gc(gc, rgbFace)
+
+        cmds = []
+
+        while 1:
+            code, xp, yp = path.vertex()
+
+            if code == agg.path_cmd_stop:
+                cmds.append(Op.closepath)
+                break
+            elif code == agg.path_cmd_move_to:
+                cmds.extend([xp, yp, Op.moveto])
+            elif code == agg.path_cmd_line_to:
+                cmds.extend([xp, yp, Op.lineto])
+            elif code == agg.path_cmd_curve3:
+                cmds.extend([xp, yp])
+                cmds.extend([xp, yp])
+                cmds.extend(path.vertex()[1:])
+                cmds.append(Op.curveto)
+            elif code == agg.path_cmd_curve4:
+                cmds.extend([xp, yp])
+                cmds.extend(path.vertex()[1:])
+                cmds.extend(path.vertex()[1:])
+                cmds.append(Op.curveto)
+            elif code == agg.path_cmd_end_poly:
+                cmds.append(Op.closepath)
+        self.file.output(*cmds)
+        self.file.output(self.gc.paint())
+
     def get_image_magnification(self):
         return self.image_magnification
 

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py     2007-12-10 
15:34:29 UTC (rev 4685)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py     2007-12-10 
16:15:30 UTC (rev 4686)
@@ -2,6 +2,7 @@
 
 import os, codecs, base64, tempfile, urllib, gzip
 
+from matplotlib import agg
 from matplotlib import verbose, __version__, rcParams
 from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
      FigureManagerBase, FigureCanvasBase
@@ -137,6 +138,38 @@
     def close_group(self, s):
         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)
+        self._draw_svg_element("path", 'd="%s"' % path_data, gc, rgbFace)
+
     def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2, 
rotation):
         """
         Ignores angles for now
@@ -284,7 +317,7 @@
                     svg.append(' transform="translate(%s)"' %
                                (currx * (self.FONT_SCALE / fontsize)))
                 svg.append('/>\n')
-                currx += (glyph.linearHoriAdvance / 65536.0)
+                currx += (glyph.linearHoriAdvance / 65536.0) / 
(self.FONT_SCALE / fontsize)
             svg.append('</g>\n')
             svg = ''.join(svg)
         else:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to