88
88
# * the alpha channel of images
89
89
# * image compression could be improved (PDF supports png-like compression)
90
90
# * encoding of fonts, including mathtext fonts and unicode support
91
- # * Type 1 font support (i.e., "pdf.use_afm")
92
91
# * TTF support has lots of small TODOs, e.g. how do you know if a font
93
92
# is serif/sans-serif, or symbolic/non-symbolic?
94
93
# * draw_markers, draw_line_collection, etc.
95
- # * use_tex
96
94
97
95
def fill (strings , linelen = 75 ):
98
96
"""Make one string from sequence of strings, with whitespace
@@ -518,7 +516,7 @@ def writeFonts(self):
518
516
elif self .dviFontInfo .has_key (filename ):
519
517
# a Type 1 font from a dvi file; the filename is really the TeX name
520
518
matplotlib .verbose .report ('Writing Type-1 font' , 'debug' )
521
- fontdictObject = self .embedType1 (filename , self .dviFontInfo [filename ])
519
+ fontdictObject = self .embedTeXFont (filename , self .dviFontInfo [filename ])
522
520
else :
523
521
# a normal TrueType font
524
522
matplotlib .verbose .report ('Writing TrueType font' , 'debug' )
@@ -542,53 +540,62 @@ def _write_afm_font(self, filename):
542
540
self .writeObject (fontdictObject , fontdict )
543
541
return fontdictObject
544
542
545
- def embedType1 (self , texname , fontinfo ):
543
+ def embedTeXFont (self , texname , fontinfo ):
546
544
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__` ,
551
546
'debug' )
552
547
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
-
566
548
# Widths
567
549
widthsObject = self .reserveObject ('font widths' )
568
- self .writeObject (widthsObject , fontinfo .widths )
550
+ self .writeObject (widthsObject , fontinfo .dvifont . widths )
569
551
570
552
# Font dictionary
571
553
fontdictObject = self .reserveObject ('font dictionary' )
572
554
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
+ }
581
561
582
562
# Encoding (if needed)
583
563
if fontinfo .encodingfile is not None :
584
564
enc = dviread .Encoding (fontinfo .encodingfile )
585
565
differencesArray = [ Name (ch ) for ch in enc ]
586
566
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
591
582
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
+
592
599
self .writeObject (fontdictObject , fontdict )
593
600
return fontdictObject
594
601
@@ -1389,11 +1396,12 @@ def draw_tex(self, gc, x, y, s, prop, angle):
1389
1396
pdfname = self .file .fontName (dvifont .texname )
1390
1397
if not self .file .dviFontInfo .has_key (dvifont .texname ):
1391
1398
psfont = self .tex_font_mapping (dvifont .texname )
1399
+ fontfile = psfont .filename
1392
1400
self .file .dviFontInfo [dvifont .texname ] = Bunch (
1393
1401
fontfile = psfont .filename ,
1402
+ basefont = psfont .psname ,
1394
1403
encodingfile = psfont .encoding ,
1395
1404
effects = psfont .effects ,
1396
- widths = dvifont .widths ,
1397
1405
dvifont = dvifont )
1398
1406
seq += [['font' , pdfname , dvifont .size ]]
1399
1407
oldfont = dvifont
0 commit comments