Revision: 8068
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8068&view=rev
Author:   mdboom
Date:     2010-01-04 14:14:38 +0000 (Mon, 04 Jan 2010)

Log Message:
-----------
Fix bug in PDF, PS, SVG and OS-X backends: do not simplify filled paths.

Modified Paths:
--------------
    branches/v0_99_maint/lib/matplotlib/backends/backend_pdf.py
    branches/v0_99_maint/lib/matplotlib/backends/backend_ps.py
    branches/v0_99_maint/lib/matplotlib/backends/backend_svg.py
    branches/v0_99_maint/src/_macosx.m

Modified: branches/v0_99_maint/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- branches/v0_99_maint/lib/matplotlib/backends/backend_pdf.py 2010-01-04 
04:30:24 UTC (rev 8067)
+++ branches/v0_99_maint/lib/matplotlib/backends/backend_pdf.py 2010-01-04 
14:14:38 UTC (rev 8068)
@@ -1043,7 +1043,8 @@
             # an API change
             self.output(*self.pathOperations(
                     Path.hatch(hatch_style[2]),
-                    Affine2D().scale(sidelen)))
+                    Affine2D().scale(sidelen),
+                    simplify=False))
             self.output(Op.stroke)
 
             self.endStream()
@@ -1124,7 +1125,7 @@
 
     def markerObject(self, path, trans, fillp, lw):
         """Return name of a marker XObject representing the given path."""
-        pathops = self.pathOperations(path, trans)
+        pathops = self.pathOperations(path, trans, simplify=False)
         key = (tuple(pathops), bool(fillp))
         result = self.markers.get(key)
         if result is None:
@@ -1153,10 +1154,11 @@
             self.endStream()
 
     @staticmethod
-    def pathOperations(path, transform, clip=None):
+    def pathOperations(path, transform, clip=None, simplify=None):
         cmds = []
         last_points = None
-        for points, code in path.iter_segments(transform, clip=clip):
+        for points, code in path.iter_segments(transform, clip=clip,
+                                               simplify=simplify):
             if code == Path.MOVETO:
                 cmds.extend(points)
                 cmds.append(Op.moveto)
@@ -1178,9 +1180,11 @@
     def writePath(self, path, transform, clip=False):
         if clip:
             clip = (0.0, 0.0, self.width * 72, self.height * 72)
+            simplify = path.should_simplify
         else:
             clip = None
-        cmds = self.pathOperations(path, transform, clip)
+            simplify = False
+        cmds = self.pathOperations(path, transform, clip, simplify=simplify)
         self.output(*cmds)
 
     def reserveObject(self, name=''):
@@ -1852,7 +1856,7 @@
             if self._clippath != clippath:
                 path, affine = clippath.get_transformed_path_and_affine()
                 cmds.extend(
-                    PdfFile.pathOperations(path, affine) +
+                    PdfFile.pathOperations(path, affine, simplify=False) +
                     [Op.clip, Op.endpath])
         return cmds
 

Modified: branches/v0_99_maint/lib/matplotlib/backends/backend_ps.py
===================================================================
--- branches/v0_99_maint/lib/matplotlib/backends/backend_ps.py  2010-01-04 
04:30:24 UTC (rev 8067)
+++ branches/v0_99_maint/lib/matplotlib/backends/backend_ps.py  2010-01-04 
14:14:38 UTC (rev 8068)
@@ -248,7 +248,8 @@
         0 setlinewidth
 """ % locals())
         self._pswriter.write(
-            self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0)))
+            self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0),
+                               simplify=False))
         self._pswriter.write("""\
           stroke
      } bind
@@ -427,7 +428,7 @@
         # unflip
         im.flipud_out()
 
-    def _convert_path(self, path, transform, clip=False):
+    def _convert_path(self, path, transform, clip=False, simplify=None):
         ps = []
         last_points = None
         if clip:
@@ -435,7 +436,8 @@
                     self.height * 72.0)
         else:
             clip = None
-        for points, code in path.iter_segments(transform, clip=clip):
+        for points, code in path.iter_segments(transform, clip=clip,
+                                               simplify=simplify):
             if code == Path.MOVETO:
                 ps.append("%g %g m" % tuple(points))
             elif code == Path.LINETO:
@@ -458,7 +460,8 @@
         if id is None:
             id = 'c%x' % len(self._clip_paths)
             ps_cmd = ['/%s {' % id]
-            ps_cmd.append(self._convert_path(clippath, clippath_transform))
+            ps_cmd.append(self._convert_path(clippath, clippath_transform,
+                                             simplify=False))
             ps_cmd.extend(['clip', 'newpath', '} bind def\n'])
             self._pswriter.write('\n'.join(ps_cmd))
             self._clip_paths[(clippath, clippath_transform)] = id
@@ -468,9 +471,10 @@
         """
         Draws a Path instance using the given affine transform.
         """
+        clip = (rgbFace is None and gc.get_hatch_path() is None)
+        simplify = path.should_simplify and clip
         ps = self._convert_path(
-            path, transform,
-            clip=(rgbFace is None and gc.get_hatch_path() is None))
+            path, transform, clip=clip, simplify=simplify)
         self._draw_ps(ps, gc, rgbFace)
 
     def draw_markers(self, gc, marker_path, marker_trans, path, trans, 
rgbFace=None):
@@ -491,7 +495,8 @@
 
         # construct the generic marker command:
         ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # dont want the 
translate to be global
-        ps_cmd.append(self._convert_path(marker_path, marker_trans))
+        ps_cmd.append(self._convert_path(marker_path, marker_trans,
+                                         simplify=False))
 
         if rgbFace:
             ps_cmd.extend(['gsave', ps_color, 'fill', 'grestore'])
@@ -518,7 +523,7 @@
             name = 'p%x_%x' % (self._path_collection_id, i)
             ps_cmd = ['/%s {' % name,
                       'newpath', 'translate']
-            ps_cmd.append(self._convert_path(path, transform))
+            ps_cmd.append(self._convert_path(path, transform, simplify=False))
             ps_cmd.extend(['} bind def\n'])
             write('\n'.join(ps_cmd))
             path_codes.append(name)

Modified: branches/v0_99_maint/lib/matplotlib/backends/backend_svg.py
===================================================================
--- branches/v0_99_maint/lib/matplotlib/backends/backend_svg.py 2010-01-04 
04:30:24 UTC (rev 8067)
+++ branches/v0_99_maint/lib/matplotlib/backends/backend_svg.py 2010-01-04 
14:14:38 UTC (rev 8068)
@@ -101,7 +101,8 @@
             self._svgwriter.write(' width="%d" height="%d" >\n' % (HATCH_SIZE, 
HATCH_SIZE))
             path_data = self._convert_path(
                 gc.get_hatch_path(),
-                Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, 
HATCH_SIZE))
+                Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, 
HATCH_SIZE),
+                simplify=False)
             if rgbFace is None:
                 fill = 'none'
             else:
@@ -159,7 +160,7 @@
         clippath, clippath_trans = gc.get_clip_path()
         if clippath is not None:
             clippath_trans = self._make_flip_transform(clippath_trans)
-            path_data = self._convert_path(clippath, clippath_trans)
+            path_data = self._convert_path(clippath, clippath_trans, 
simplify=False)
             path = '<path d="%s"/>' % path_data
         elif cliprect is not None:
             x, y, w, h = cliprect.bounds
@@ -210,7 +211,7 @@
                 .scale(1.0, -1.0)
                 .translate(0.0, self.height))
 
-    def _convert_path(self, path, transform, clip=False):
+    def _convert_path(self, path, transform, clip=False, simplify=None):
         path_data = []
         appender = path_data.append
         path_commands = self._path_commands
@@ -219,7 +220,8 @@
             clip = (0.0, 0.0, self.width, self.height)
         else:
             clip = None
-        for points, code in path.iter_segments(transform, clip=clip):
+        for points, code in path.iter_segments(transform, clip=clip,
+                                               simplify=simplify):
             if code == Path.CLOSEPOLY:
                 segment = 'z'
             else:
@@ -234,15 +236,18 @@
 
     def draw_path(self, gc, path, transform, rgbFace=None):
         trans_and_flip = self._make_flip_transform(transform)
+        clip = (rgbFace is None and gc.get_hatch_path() is None)
+        simplify = path.should_simplify and clip
         path_data = self._convert_path(
-            path, trans_and_flip,
-            clip=(rgbFace is None and gc.get_hatch_path() is None))
+            path, trans_and_flip, clip=clip, simplify=simplify)
         self._draw_svg_element('path', 'd="%s"' % path_data, gc, rgbFace)
 
     def draw_markers(self, gc, marker_path, marker_trans, path, trans, 
rgbFace=None):
         write = self._svgwriter.write
 
-        key = self._convert_path(marker_path, marker_trans + 
Affine2D().scale(1.0, -1.0))
+        key = self._convert_path(marker_path,
+                                 marker_trans + Affine2D().scale(1.0, -1.0),
+                                 simplify=False)
         name = self._markers.get(key)
         if name is None:
             name = 'm%s' % md5(key).hexdigest()
@@ -276,7 +281,7 @@
         for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
             master_transform, paths, all_transforms)):
             transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
-            d = self._convert_path(path, transform)
+            d = self._convert_path(path, transform, simplify=False)
             name = 'coll%x_%x_%s' % (self._path_collection_id, i,
                                      md5(d).hexdigest())
             write('<path id="%s" d="%s"/>\n' % (name, d))

Modified: branches/v0_99_maint/src/_macosx.m
===================================================================
--- branches/v0_99_maint/src/_macosx.m  2010-01-04 04:30:24 UTC (rev 8067)
+++ branches/v0_99_maint/src/_macosx.m  2010-01-04 14:14:38 UTC (rev 8068)
@@ -536,7 +536,7 @@
         return NULL;
     }
     CGContextSetAlpha(cr, alpha);
- 
+
     self->color[3] = alpha;
 
     Py_INCREF(Py_None);
@@ -881,7 +881,7 @@
                                   0,
                                   rect,
                                   QUANTIZE_AUTO,
-                                  1);
+                                  rgbFace == NULL);
     if (!iterator)
     {
         PyErr_SetString(PyExc_RuntimeError,
@@ -958,7 +958,7 @@
                                           0,
                                           rect,
                                           QUANTIZE_AUTO,
-                                          1);
+                                          0);
             if (!iterator)
             {
                 Py_DECREF(hatchpath);
@@ -1143,14 +1143,14 @@
         Py_DECREF(translation);
         PyErr_SetString(PyExc_ValueError,
             "transform_point did not return a NumPy array");
-        return false; 
+        return false;
     }
     if (PyArray_NDIM(translation)!=1 || PyArray_DIM(translation, 0)!=2)
     {
         Py_DECREF(translation);
         PyErr_SetString(PyExc_ValueError,
             "transform_point did not return an approriate array");
-        return false; 
+        return false;
     }
     tx = (CGFloat)(*(double*)PyArray_GETPTR1(translation, 0));
     ty = (CGFloat)(*(double*)PyArray_GETPTR1(translation, 1));
@@ -1261,7 +1261,7 @@
         master.c = c;
         master.d = d;
         master.tx = tx;
-       master.ty = ty;
+        master.ty = ty;
         if (!ok) goto exit;
         CGContextConcatCTM(cr, master);
     }
@@ -1429,7 +1429,7 @@
     Py_ssize_t Nlinestyles = PySequence_Size(linestyles);
     Py_ssize_t Naa         = PySequence_Size(antialiaseds);
     if (N < Nlinestyles) Nlinestyles = N;
-    if ((Nfacecolors == 0 && Nedgecolors == 0) || Np == 0) goto exit; 
+    if ((Nfacecolors == 0 && Nedgecolors == 0) || Np == 0) goto exit;
 
     /* Preset graphics context properties if possible */
     if (Naa==1)
@@ -1674,7 +1674,7 @@
         master.c = c;
         master.d = d;
         master.tx = tx;
-       master.ty = ty;
+        master.ty = ty;
     }
     else
     {
@@ -2288,7 +2288,7 @@
 
     width = CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
     rect = CTLineGetImageBounds(line, cr);
- 
+
     CFRelease(line);
 
     return Py_BuildValue("fff", width, rect.size.height, descent);
@@ -3044,7 +3044,7 @@
     }
     /* NSSize contains CGFloat; cannot use size directly */
     if(!PyArg_ParseTuple(args, "u#dd",
-                               &characters, &n, &width, &height)) return NULL;
+                                &characters, &n, &width, &height)) return NULL;
     size.width = width;
     size.height = height;
 
@@ -3058,7 +3058,7 @@
     NSRect rect = [view bounds];
 
     NSString* filename = [NSString stringWithCharacters: characters
-                                                length: (unsigned)n];
+                                                 length: (unsigned)n];
     NSString* extension = [filename pathExtension];
 
     /* Calling dataWithPDFInsideRect on the view causes its update status
@@ -3077,23 +3077,23 @@
     if (! [extension isEqualToString: @"tiff"] &&
         ! [extension isEqualToString: @"tif"])
     {
-       NSBitmapImageFileType filetype;
-       NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData: data];
-       if ([extension isEqualToString: @"bmp"])
-           filetype = NSBMPFileType;
-       else if ([extension isEqualToString: @"gif"])
-           filetype = NSGIFFileType;
-       else if ([extension isEqualToString: @"jpg"] ||
-                [extension isEqualToString: @"jpeg"])
-           filetype = NSJPEGFileType;
-       else if ([extension isEqualToString: @"png"])
-           filetype = NSPNGFileType;
-       else
-       {   PyErr_SetString(PyExc_ValueError, "Unknown file type");
-           return NULL;
-       }
+        NSBitmapImageFileType filetype;
+        NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData: 
data];
+        if ([extension isEqualToString: @"bmp"])
+            filetype = NSBMPFileType;
+        else if ([extension isEqualToString: @"gif"])
+            filetype = NSGIFFileType;
+        else if ([extension isEqualToString: @"jpg"] ||
+                 [extension isEqualToString: @"jpeg"])
+            filetype = NSJPEGFileType;
+        else if ([extension isEqualToString: @"png"])
+            filetype = NSPNGFileType;
+        else
+        {   PyErr_SetString(PyExc_ValueError, "Unknown file type");
+            return NULL;
+        }
 
-       data = [bitmapRep representationUsingType:filetype properties:nil];
+        data = [bitmapRep representationUsingType:filetype properties:nil];
     }
 
     [data writeToFile: filename atomically: YES];


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

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to