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

Skip to content

Commit ed0066f

Browse files
committed
Fix a bug in pdf usetex: allow using non-embedded fonts
svn path=/trunk/matplotlib/; revision=6737
1 parent a174502 commit ed0066f

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2009-01-05 Fix a bug in pdf usetex: allow using non-embedded fonts. - JKS
2+
13
2009-01-05 optional use of preview.sty in usetex mode. - JJL
24

35
2009-01-02 Allow multipage pdf files. - JKS

lib/matplotlib/backends/backend_pdf.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@
8888
# * the alpha channel of images
8989
# * image compression could be improved (PDF supports png-like compression)
9090
# * encoding of fonts, including mathtext fonts and unicode support
91-
# * Type 1 font support (i.e., "pdf.use_afm")
9291
# * TTF support has lots of small TODOs, e.g. how do you know if a font
9392
# is serif/sans-serif, or symbolic/non-symbolic?
9493
# * draw_markers, draw_line_collection, etc.
95-
# * use_tex
9694

9795
def fill(strings, linelen=75):
9896
"""Make one string from sequence of strings, with whitespace
@@ -518,7 +516,7 @@ def writeFonts(self):
518516
elif self.dviFontInfo.has_key(filename):
519517
# a Type 1 font from a dvi file; the filename is really the TeX name
520518
matplotlib.verbose.report('Writing Type-1 font', 'debug')
521-
fontdictObject = self.embedType1(filename, self.dviFontInfo[filename])
519+
fontdictObject = self.embedTeXFont(filename, self.dviFontInfo[filename])
522520
else:
523521
# a normal TrueType font
524522
matplotlib.verbose.report('Writing TrueType font', 'debug')
@@ -542,53 +540,62 @@ def _write_afm_font(self, filename):
542540
self.writeObject(fontdictObject, fontdict)
543541
return fontdictObject
544542

545-
def embedType1(self, texname, fontinfo):
543+
def embedTeXFont(self, texname, fontinfo):
546544
matplotlib.verbose.report(
547-
'Embedding ' + texname +
548-
' which is the Type 1 font ' + (fontinfo.fontfile or '(none)') +
549-
' with encoding ' + (fontinfo.encodingfile or '(none)') +
550-
' and effects ' + `fontinfo.effects`,
545+
'Embedding TeX font ' + texname + ' - fontinfo=' + `fontinfo.__dict__`,
551546
'debug')
552547

553-
t1font = type1font.Type1Font(fontinfo.fontfile)
554-
if fontinfo.effects:
555-
t1font = t1font.transform(fontinfo.effects)
556-
557-
# Font descriptors may be shared between differently encoded
558-
# Type-1 fonts, so only create a new descriptor if there is no
559-
# existing descriptor for this font.
560-
effects = (fontinfo.effects.get('slant', 0.0), fontinfo.effects.get('extend', 1.0))
561-
fontdesc = self.type1Descriptors.get((fontinfo.fontfile, effects))
562-
if fontdesc is None:
563-
fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
564-
self.type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
565-
566548
# Widths
567549
widthsObject = self.reserveObject('font widths')
568-
self.writeObject(widthsObject, fontinfo.widths)
550+
self.writeObject(widthsObject, fontinfo.dvifont.widths)
569551

570552
# Font dictionary
571553
fontdictObject = self.reserveObject('font dictionary')
572554
fontdict = {
573-
'Type': Name('Font'),
574-
'Subtype': Name('Type1'),
575-
'BaseFont': Name(t1font.prop['FontName']),
576-
'FirstChar': 0,
577-
'LastChar': len(fontinfo.widths) - 1,
578-
'Widths': widthsObject,
579-
'FontDescriptor': fontdesc,
580-
}
555+
'Type': Name('Font'),
556+
'Subtype': Name('Type1'),
557+
'FirstChar': 0,
558+
'LastChar': len(fontinfo.dvifont.widths) - 1,
559+
'Widths': widthsObject,
560+
}
581561

582562
# Encoding (if needed)
583563
if fontinfo.encodingfile is not None:
584564
enc = dviread.Encoding(fontinfo.encodingfile)
585565
differencesArray = [ Name(ch) for ch in enc ]
586566
differencesArray = [ 0 ] + differencesArray
587-
fontdict.update({
588-
'Encoding': { 'Type': Name('Encoding'),
589-
'Differences': differencesArray },
590-
})
567+
fontdict['Encoding'] = \
568+
{ 'Type': Name('Encoding'),
569+
'Differences': differencesArray }
570+
571+
# If no file is specified, stop short
572+
if fontinfo.fontfile is None:
573+
warnings.warn(
574+
'Because of TeX configuration (pdftex.map, see updmap ' +
575+
'option pdftexDownloadBase14) the font %s ' % fontinfo.basefont +
576+
'is not embedded. This is deprecated as of PDF 1.5 ' +
577+
'and it may cause the consumer application to show something ' +
578+
'that was not intended.')
579+
fontdict['BaseFont'] = Name(fontinfo.basefont)
580+
self.writeObject(fontdictObject, fontdict)
581+
return fontdictObject
591582

583+
# We have a font file to embed - read it in and apply any effects
584+
t1font = type1font.Type1Font(fontinfo.fontfile)
585+
if fontinfo.effects:
586+
t1font = t1font.transform(fontinfo.effects)
587+
fontdict['BaseFont'] = Name(t1font.prop['FontName'])
588+
589+
# Font descriptors may be shared between differently encoded
590+
# Type-1 fonts, so only create a new descriptor if there is no
591+
# existing descriptor for this font.
592+
effects = (fontinfo.effects.get('slant', 0.0), fontinfo.effects.get('extend', 1.0))
593+
fontdesc = self.type1Descriptors.get((fontinfo.fontfile, effects))
594+
if fontdesc is None:
595+
fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
596+
self.type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
597+
fontdict['FontDescriptor'] = fontdesc
598+
592599
self.writeObject(fontdictObject, fontdict)
593600
return fontdictObject
594601

@@ -1389,11 +1396,12 @@ def draw_tex(self, gc, x, y, s, prop, angle):
13891396
pdfname = self.file.fontName(dvifont.texname)
13901397
if not self.file.dviFontInfo.has_key(dvifont.texname):
13911398
psfont = self.tex_font_mapping(dvifont.texname)
1399+
fontfile = psfont.filename
13921400
self.file.dviFontInfo[dvifont.texname] = Bunch(
13931401
fontfile=psfont.filename,
1402+
basefont=psfont.psname,
13941403
encodingfile=psfont.encoding,
13951404
effects=psfont.effects,
1396-
widths=dvifont.widths,
13971405
dvifont=dvifont)
13981406
seq += [['font', pdfname, dvifont.size]]
13991407
oldfont = dvifont

0 commit comments

Comments
 (0)