Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18fa52f

Browse files
committed
Merged revisions 8068 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_99_maint ........ r8068 | mdboom | 2010-01-04 09:14:38 -0500 (Mon, 04 Jan 2010) | 2 lines Fix bug in PDF, PS, SVG and OS-X backends: do not simplify filled paths. ........ svn path=/trunk/matplotlib/; revision=8069
1 parent ca66d11 commit 18fa52f

4 files changed

Lines changed: 66 additions & 52 deletions

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@ def writeHatches(self):
10681068
# an API change
10691069
self.output(*self.pathOperations(
10701070
Path.hatch(hatch_style[2]),
1071-
Affine2D().scale(sidelen)))
1071+
Affine2D().scale(sidelen),
1072+
simplify=False))
10721073
self.output(Op.stroke)
10731074

10741075
self.endStream()
@@ -1192,7 +1193,7 @@ def writeImages(self):
11921193

11931194
def markerObject(self, path, trans, fillp, lw):
11941195
"""Return name of a marker XObject representing the given path."""
1195-
pathops = self.pathOperations(path, trans)
1196+
pathops = self.pathOperations(path, trans, simplify=False)
11961197
key = (tuple(pathops), bool(fillp))
11971198
result = self.markers.get(key)
11981199
if result is None:
@@ -1221,10 +1222,11 @@ def writeMarkers(self):
12211222
self.endStream()
12221223

12231224
@staticmethod
1224-
def pathOperations(path, transform, clip=None):
1225+
def pathOperations(path, transform, clip=None, simplify=None):
12251226
cmds = []
12261227
last_points = None
1227-
for points, code in path.iter_segments(transform, clip=clip):
1228+
for points, code in path.iter_segments(transform, clip=clip,
1229+
simplify=simplify):
12281230
if code == Path.MOVETO:
12291231
# This is allowed anywhere in the path
12301232
cmds.extend(points)
@@ -1250,9 +1252,11 @@ def pathOperations(path, transform, clip=None):
12501252
def writePath(self, path, transform, clip=False):
12511253
if clip:
12521254
clip = (0.0, 0.0, self.width * 72, self.height * 72)
1255+
simplify = path.should_simplify
12531256
else:
12541257
clip = None
1255-
cmds = self.pathOperations(path, transform, clip)
1258+
simplify = False
1259+
cmds = self.pathOperations(path, transform, clip, simplify=simplify)
12561260
self.output(*cmds)
12571261

12581262
def reserveObject(self, name=''):
@@ -1969,7 +1973,7 @@ def clip_cmd(self, cliprect, clippath):
19691973
if self._clippath != clippath:
19701974
path, affine = clippath.get_transformed_path_and_affine()
19711975
cmds.extend(
1972-
PdfFile.pathOperations(path, affine) +
1976+
PdfFile.pathOperations(path, affine, simplify=False) +
19731977
[Op.clip, Op.endpath])
19741978
return cmds
19751979

lib/matplotlib/backends/backend_ps.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def create_hatch(self, hatch):
251251
0 setlinewidth
252252
""" % locals())
253253
self._pswriter.write(
254-
self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0)))
254+
self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0),
255+
simplify=False))
255256
self._pswriter.write("""\
256257
stroke
257258
} bind
@@ -457,15 +458,16 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
457458
# unflip
458459
im.flipud_out()
459460

460-
def _convert_path(self, path, transform, clip=False):
461+
def _convert_path(self, path, transform, clip=False, simplify=None):
461462
ps = []
462463
last_points = None
463464
if clip:
464465
clip = (0.0, 0.0, self.width * 72.0,
465466
self.height * 72.0)
466467
else:
467468
clip = None
468-
for points, code in path.iter_segments(transform, clip=clip):
469+
for points, code in path.iter_segments(transform, clip=clip,
470+
simplify=simplify):
469471
if code == Path.MOVETO:
470472
ps.append("%g %g m" % tuple(points))
471473
elif code == Path.LINETO:
@@ -488,7 +490,8 @@ def _get_clip_path(self, clippath, clippath_transform):
488490
if id is None:
489491
id = 'c%x' % len(self._clip_paths)
490492
ps_cmd = ['/%s {' % id]
491-
ps_cmd.append(self._convert_path(clippath, clippath_transform))
493+
ps_cmd.append(self._convert_path(clippath, clippath_transform,
494+
simplify=False))
492495
ps_cmd.extend(['clip', 'newpath', '} bind def\n'])
493496
self._pswriter.write('\n'.join(ps_cmd))
494497
self._clip_paths[(clippath, clippath_transform)] = id
@@ -498,9 +501,10 @@ def draw_path(self, gc, path, transform, rgbFace=None):
498501
"""
499502
Draws a Path instance using the given affine transform.
500503
"""
504+
clip = (rgbFace is None and gc.get_hatch_path() is None)
505+
simplify = path.should_simplify and clip
501506
ps = self._convert_path(
502-
path, transform,
503-
clip=(rgbFace is None and gc.get_hatch_path() is None))
507+
path, transform, clip=clip, simplify=simplify)
504508
self._draw_ps(ps, gc, rgbFace)
505509

506510
def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
@@ -521,7 +525,8 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
521525

522526
# construct the generic marker command:
523527
ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # dont want the translate to be global
524-
ps_cmd.append(self._convert_path(marker_path, marker_trans))
528+
ps_cmd.append(self._convert_path(marker_path, marker_trans,
529+
simplify=False))
525530

526531
if rgbFace:
527532
ps_cmd.extend(['gsave', ps_color, 'fill', 'grestore'])
@@ -547,7 +552,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
547552
name = 'p%x_%x' % (self._path_collection_id, i)
548553
ps_cmd = ['/%s {' % name,
549554
'newpath', 'translate']
550-
ps_cmd.append(self._convert_path(path, transform))
555+
ps_cmd.append(self._convert_path(path, transform, simplify=False))
551556
ps_cmd.extend(['} bind def\n'])
552557
write('\n'.join(ps_cmd))
553558
path_codes.append(name)

lib/matplotlib/backends/backend_svg.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def _get_hatch(self, gc, rgbFace):
108108
self._svgwriter.write(' width="%d" height="%d" >\n' % (HATCH_SIZE, HATCH_SIZE))
109109
path_data = self._convert_path(
110110
gc.get_hatch_path(),
111-
Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE))
111+
Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE),
112+
simplify=False)
112113
if rgbFace is None:
113114
fill = 'none'
114115
else:
@@ -166,7 +167,7 @@ def _get_gc_clip_svg(self, gc):
166167
clippath, clippath_trans = gc.get_clip_path()
167168
if clippath is not None:
168169
clippath_trans = self._make_flip_transform(clippath_trans)
169-
path_data = self._convert_path(clippath, clippath_trans)
170+
path_data = self._convert_path(clippath, clippath_trans, simplify=False)
170171
path = '<path d="%s"/>' % path_data
171172
elif cliprect is not None:
172173
x, y, w, h = cliprect.bounds
@@ -217,7 +218,7 @@ def _make_flip_transform(self, transform):
217218
.scale(1.0, -1.0)
218219
.translate(0.0, self.height))
219220

220-
def _convert_path(self, path, transform, clip=False):
221+
def _convert_path(self, path, transform, clip=False, simplify=None):
221222
path_data = []
222223
appender = path_data.append
223224
path_commands = self._path_commands
@@ -226,7 +227,8 @@ def _convert_path(self, path, transform, clip=False):
226227
clip = (0.0, 0.0, self.width, self.height)
227228
else:
228229
clip = None
229-
for points, code in path.iter_segments(transform, clip=clip):
230+
for points, code in path.iter_segments(transform, clip=clip,
231+
simplify=simplify):
230232
if code == Path.CLOSEPOLY:
231233
segment = 'z'
232234
else:
@@ -241,15 +243,18 @@ def _convert_path(self, path, transform, clip=False):
241243

242244
def draw_path(self, gc, path, transform, rgbFace=None):
243245
trans_and_flip = self._make_flip_transform(transform)
246+
clip = (rgbFace is None and gc.get_hatch_path() is None)
247+
simplify = path.should_simplify and clip
244248
path_data = self._convert_path(
245-
path, trans_and_flip,
246-
clip=(rgbFace is None and gc.get_hatch_path() is None))
249+
path, trans_and_flip, clip=clip, simplify=simplify)
247250
self._draw_svg_element('path', 'd="%s"' % path_data, gc, rgbFace)
248251

249252
def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
250253
write = self._svgwriter.write
251254

252-
key = self._convert_path(marker_path, marker_trans + Affine2D().scale(1.0, -1.0))
255+
key = self._convert_path(marker_path,
256+
marker_trans + Affine2D().scale(1.0, -1.0),
257+
simplify=False)
253258
name = self._markers.get(key)
254259
if name is None:
255260
name = 'm%s' % md5(key).hexdigest()
@@ -282,7 +287,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
282287
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
283288
master_transform, paths, all_transforms)):
284289
transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
285-
d = self._convert_path(path, transform)
290+
d = self._convert_path(path, transform, simplify=False)
286291
name = 'coll%x_%x_%s' % (self._path_collection_id, i,
287292
md5(d).hexdigest())
288293
write('<path id="%s" d="%s"/>\n' % (name, d))
@@ -456,7 +461,7 @@ def draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
456461
write('<defs>\n')
457462
for char_id, glyph_path in glyph_map_new.iteritems():
458463
path = Path(*glyph_path)
459-
path_data = self._convert_path(path, _flip)
464+
path_data = self._convert_path(path, _flip, simplify=False)
460465
path_element = '<path id="%s" d="%s"/>\n' % (char_id, ''.join(path_data))
461466
write(path_element)
462467
write('</defs>\n')
@@ -504,7 +509,7 @@ def draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
504509
for char_id, glyph_path in glyph_map_new.iteritems():
505510
char_id = self._adjust_char_id(char_id)
506511
path = Path(*glyph_path)
507-
path_data = self._convert_path(path, None) #_flip)
512+
path_data = self._convert_path(path, None, simplify=False) #_flip)
508513
path_element = '<path id="%s" d="%s"/>\n' % (char_id, ''.join(path_data))
509514
write(path_element)
510515
write('</defs>\n')
@@ -535,7 +540,7 @@ def draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
535540

536541
for verts, codes in rects:
537542
path = Path(verts, codes)
538-
path_data = self._convert_path(path, None)
543+
path_data = self._convert_path(path, None, simplify=False)
539544
path_element = '<path d="%s"/>\n' % (''.join(path_data))
540545
svg.append(path_element)
541546

src/_macosx.m

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
539539
return NULL;
540540
}
541541
CGContextSetAlpha(cr, alpha);
542-
542+
543543
self->color[3] = alpha;
544544

545545
Py_INCREF(Py_None);
@@ -884,7 +884,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
884884
0,
885885
rect,
886886
QUANTIZE_AUTO,
887-
1);
887+
rgbFace == NULL);
888888
if (!iterator)
889889
{
890890
PyErr_SetString(PyExc_RuntimeError,
@@ -961,7 +961,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
961961
0,
962962
rect,
963963
QUANTIZE_AUTO,
964-
1);
964+
0);
965965
if (!iterator)
966966
{
967967
Py_DECREF(hatchpath);
@@ -1146,14 +1146,14 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
11461146
Py_DECREF(translation);
11471147
PyErr_SetString(PyExc_ValueError,
11481148
"transform_point did not return a NumPy array");
1149-
return false;
1149+
return false;
11501150
}
11511151
if (PyArray_NDIM(translation)!=1 || PyArray_DIM(translation, 0)!=2)
11521152
{
11531153
Py_DECREF(translation);
11541154
PyErr_SetString(PyExc_ValueError,
11551155
"transform_point did not return an approriate array");
1156-
return false;
1156+
return false;
11571157
}
11581158
tx = (CGFloat)(*(double*)PyArray_GETPTR1(translation, 0));
11591159
ty = (CGFloat)(*(double*)PyArray_GETPTR1(translation, 1));
@@ -1397,7 +1397,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
13971397
Py_ssize_t Nlinestyles = PySequence_Size(linestyles);
13981398
Py_ssize_t Naa = PySequence_Size(antialiaseds);
13991399
if (N < Nlinestyles) Nlinestyles = N;
1400-
if ((Nfacecolors == 0 && Nedgecolors == 0) || Np == 0) goto exit;
1400+
if ((Nfacecolors == 0 && Nedgecolors == 0) || Np == 0) goto exit;
14011401

14021402
/* Preset graphics context properties if possible */
14031403
if (Naa==1)
@@ -1641,7 +1641,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
16411641
master.c = c;
16421642
master.d = d;
16431643
master.tx = tx;
1644-
master.ty = ty;
1644+
master.ty = ty;
16451645
}
16461646
else
16471647
{
@@ -2255,7 +2255,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
22552255

22562256
width = CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
22572257
rect = CTLineGetImageBounds(line, cr);
2258-
2258+
22592259
CFRelease(line);
22602260

22612261
return Py_BuildValue("fff", width, rect.size.height, descent);
@@ -3022,7 +3022,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
30223022
}
30233023
/* NSSize contains CGFloat; cannot use size directly */
30243024
if(!PyArg_ParseTuple(args, "u#dd",
3025-
&characters, &n, &width, &height)) return NULL;
3025+
&characters, &n, &width, &height)) return NULL;
30263026
size.width = width;
30273027
size.height = height;
30283028

@@ -3036,7 +3036,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
30363036
NSRect rect = [view bounds];
30373037

30383038
NSString* filename = [NSString stringWithCharacters: characters
3039-
length: (unsigned)n];
3039+
length: (unsigned)n];
30403040
NSString* extension = [filename pathExtension];
30413041

30423042
/* Calling dataWithPDFInsideRect on the view causes its update status
@@ -3055,23 +3055,23 @@ static void _data_provider_release(void* info, const void* data, size_t size)
30553055
if (! [extension isEqualToString: @"tiff"] &&
30563056
! [extension isEqualToString: @"tif"])
30573057
{
3058-
NSBitmapImageFileType filetype;
3059-
NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData: data];
3060-
if ([extension isEqualToString: @"bmp"])
3061-
filetype = NSBMPFileType;
3062-
else if ([extension isEqualToString: @"gif"])
3063-
filetype = NSGIFFileType;
3064-
else if ([extension isEqualToString: @"jpg"] ||
3065-
[extension isEqualToString: @"jpeg"])
3066-
filetype = NSJPEGFileType;
3067-
else if ([extension isEqualToString: @"png"])
3068-
filetype = NSPNGFileType;
3069-
else
3070-
{ PyErr_SetString(PyExc_ValueError, "Unknown file type");
3071-
return NULL;
3072-
}
3073-
3074-
data = [bitmapRep representationUsingType:filetype properties:nil];
3058+
NSBitmapImageFileType filetype;
3059+
NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData: data];
3060+
if ([extension isEqualToString: @"bmp"])
3061+
filetype = NSBMPFileType;
3062+
else if ([extension isEqualToString: @"gif"])
3063+
filetype = NSGIFFileType;
3064+
else if ([extension isEqualToString: @"jpg"] ||
3065+
[extension isEqualToString: @"jpeg"])
3066+
filetype = NSJPEGFileType;
3067+
else if ([extension isEqualToString: @"png"])
3068+
filetype = NSPNGFileType;
3069+
else
3070+
{ PyErr_SetString(PyExc_ValueError, "Unknown file type");
3071+
return NULL;
3072+
}
3073+
3074+
data = [bitmapRep representationUsingType:filetype properties:nil];
30753075
}
30763076

30773077
[data writeToFile: filename atomically: YES];

0 commit comments

Comments
 (0)