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

Skip to content

Commit 24cc7a7

Browse files
committed
Reduce number of marker objects in pdf output
svn path=/trunk/matplotlib/; revision=6868
1 parent 21e0bfd commit 24cc7a7

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2009-02-02 Reduce number of marker XObjects in pdf output - JKS
2+
13
2009-02-02 Change default resolution on polar plot to 1 - MGD
24

35
2009-02-02 Avoid malloc errors in ttconv for fonts that don't have

lib/matplotlib/backends/backend_pdf.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,26 +1109,28 @@ def writeImages(self):
11091109

11101110
def markerObject(self, path, trans, fillp, lw):
11111111
"""Return name of a marker XObject representing the given path."""
1112-
key = (path, trans, fillp is not None, lw)
1112+
pathops = self.pathOperations(path, trans)
1113+
key = (tuple(pathops), bool(fillp))
11131114
result = self.markers.get(key)
11141115
if result is None:
11151116
name = Name('M%d' % len(self.markers))
11161117
ob = self.reserveObject('marker %d' % len(self.markers))
1117-
self.markers[key] = (name, ob, path, trans, fillp, lw)
1118+
bbox = path.get_extents(trans)
1119+
self.markers[key] = [name, ob, bbox, lw]
11181120
else:
1121+
if result[-1] < lw:
1122+
result[-1] = lw
11191123
name = result[0]
11201124
return name
11211125

11221126
def writeMarkers(self):
1123-
for tup in self.markers.values():
1124-
name, object, path, trans, fillp, lw = tup
1125-
bbox = path.get_extents(trans)
1127+
for (pathops, fillp),(name, ob, bbox, lw) in self.markers.iteritems():
11261128
bbox = bbox.padded(lw * 0.5)
11271129
self.beginStream(
1128-
object.id, None,
1130+
ob.id, None,
11291131
{'Type': Name('XObject'), 'Subtype': Name('Form'),
11301132
'BBox': list(bbox.extents) })
1131-
self.writePath(path, trans)
1133+
self.output(*pathops)
11321134
if fillp:
11331135
self.output(Op.fill_stroke)
11341136
else:
@@ -1280,10 +1282,17 @@ def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
12801282

12811283
def draw_path(self, gc, path, transform, rgbFace=None):
12821284
self.check_gc(gc, rgbFace)
1283-
stream = self.file.writePath(path, transform, rgbFace is None)
1285+
self.file.writePath(path, transform, rgbFace is None)
12841286
self.file.output(self.gc.paint())
12851287

12861288
def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
1289+
# For simple paths or small numbers of markers, don't bother
1290+
# making an XObject
1291+
if len(path) * len(marker_path) <= 10:
1292+
RendererBase.draw_markers(self, gc, marker_path, marker_trans,
1293+
path, trans, rgbFace)
1294+
return
1295+
12871296
self.check_gc(gc, rgbFace)
12881297
fillp = rgbFace is not None
12891298

0 commit comments

Comments
 (0)