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

Skip to content

Commit b1c141e

Browse files
committed
Minor PDF filesize improvement.
svn path=/trunk/matplotlib/; revision=3695
1 parent f2309d8 commit b1c141e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ def embedTTFType3(font, characters, descriptor):
508508
charprocsObject = self.reserveObject('character procs')
509509
differencesArray = []
510510
firstchar, lastchar = 0, 255
511+
bbox = [cvt(x, nearest=False) for x in font.bbox]
511512

512513
fontdict = {
513514
'Type' : Name('Font'),
@@ -517,7 +518,7 @@ def embedTTFType3(font, characters, descriptor):
517518
'FontDescriptor' : fontdescObject,
518519
'Subtype' : Name('Type3'),
519520
'Name' : descriptor['FontName'],
520-
'FontBBox' : [cvt(x, nearest=False) for x in font.bbox],
521+
'FontBBox' : bbox,
521522
'FontMatrix' : [ .001, 0, 0, .001, 0, 0 ],
522523
'CharProcs' : charprocsObject,
523524
'Encoding' : {
@@ -575,15 +576,18 @@ def get_char_width(charcode):
575576
charprocs = {}
576577
charprocsRef = {}
577578
for charname, stream in rawcharprocs.items():
579+
charprocDict = { 'Length': len(stream) }
580+
# The 2-byte characters are used as XObjects, so they
581+
# need extra info in their dictionary
582+
if charname in two_byte_chars:
583+
charprocDict['Type'] = Name('XObject')
584+
charprocDict['Subtype'] = Name('Form')
585+
charprocDict['BBox'] = bbox
578586
charprocObject = self.reserveObject('charProc for %s' % name)
579-
self.beginStream(charprocObject.id,
580-
None,
581-
{'Length': len(stream),
582-
'Type': Name('XObject'),
583-
'Subtype': Name('Form'),
584-
'BBox': [cvt(x, nearest=False) for x in font.bbox]})
587+
self.beginStream(charprocObject.id, None, charprocDict)
585588
self.currentstream.write(stream)
586589
self.endStream()
590+
587591
# Send the glyphs with ccode > 255 to the XObject dictionary,
588592
# and the others to the font itself
589593
if charname in two_byte_chars:

0 commit comments

Comments
 (0)