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

Skip to content

Commit fed68f8

Browse files
committed
Reduce Ps files sizes when using mathtext
svn path=/trunk/matplotlib/; revision=3756
1 parent fe60db5 commit fed68f8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,23 @@ def MathtextBackendAgg():
315315
class MathtextBackendPs(MathtextBackend):
316316
def __init__(self):
317317
self.pswriter = StringIO()
318+
self.lastfont = None
318319

319320
def render_glyph(self, ox, oy, info):
320321
oy = self.height - oy + info.offset
321322
postscript_name = info.postscript_name
322323
fontsize = info.fontsize
323324
symbol_name = info.symbol_name
324325

325-
# TODO: Optimize out the font changes
326-
327-
ps = """/%(postscript_name)s findfont
326+
if (postscript_name, fontsize) != self.lastfont:
327+
ps = """/%(postscript_name)s findfont
328328
%(fontsize)s scalefont
329329
setfont
330-
%(ox)f %(oy)f moveto
330+
""" % locals()
331+
self.lastfont = postscript_name, fontsize
332+
self.pswriter.write(ps)
333+
334+
ps = """%(ox)f %(oy)f moveto
331335
/%(symbol_name)s glyphshow\n
332336
""" % locals()
333337
self.pswriter.write(ps)

0 commit comments

Comments
 (0)