@@ -722,8 +722,6 @@ def __init__(self, filename, metadata=None):
722
722
self ._internal_font_seq = (Name (f'F{ i } ' ) for i in itertools .count (1 ))
723
723
self ._fontNames = {} # maps filenames to internal font names
724
724
self ._dviFontInfo = {} # maps dvi font names to embedding information
725
- # differently encoded Type-1 fonts may share the same descriptor
726
- self ._type1Descriptors = {}
727
725
self ._character_tracker = _backend_pdf_ps .CharacterTracker ()
728
726
729
727
self .alphaStates = {} # maps alpha values to graphics state objects
@@ -767,8 +765,6 @@ def __init__(self, filename, metadata=None):
767
765
768
766
fontNames = _api .deprecated ("3.11" )(property (lambda self : self ._fontNames ))
769
767
dviFontInfo = _api .deprecated ("3.11" )(property (lambda self : self ._dviFontInfo ))
770
- type1Descriptors = _api .deprecated ("3.11" )(
771
- property (lambda self : self ._type1Descriptors ))
772
768
773
769
def newPage (self , width , height ):
774
770
self .endStream ()
@@ -1005,48 +1001,42 @@ def _embedTeXFont(self, fontinfo):
1005
1001
_log .debug ('Embedding TeX font %s - fontinfo=%s' ,
1006
1002
fontinfo .dvifont .texname , fontinfo .__dict__ )
1007
1003
1008
- # Font dictionary
1004
+ # The font dictionary is the top-level object describing a font
1009
1005
fontdictObject = self .reserveObject ('font dictionary' )
1010
1006
fontdict = {
1011
1007
'Type' : Name ('Font' ),
1012
1008
'Subtype' : Name ('Type1' ),
1013
1009
}
1014
1010
1015
- # We have a font file to embed - read it in and apply any effects
1011
+ # Read the font file and apply any encoding changes and effects
1016
1012
t1font = _type1font .Type1Font (fontinfo .fontfile )
1017
1013
if fontinfo .encodingfile is not None :
1018
1014
t1font = t1font .with_encoding (
1019
1015
{i : c for i , c in enumerate (dviread ._parse_enc (fontinfo .encodingfile ))}
1020
1016
)
1021
-
1022
1017
if fontinfo .effects :
1023
1018
t1font = t1font .transform (fontinfo .effects )
1019
+
1020
+ # Reduce the font to only the glyphs used in the document, get the encoding
1021
+ # for that subset, and compute various properties based on the encoding.
1024
1022
chars = frozenset (self ._character_tracker .used [fontinfo .dvifont .fname ])
1025
1023
t1font = t1font .subset (chars , self ._get_subset_prefix (chars ))
1026
1024
fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
1025
+ # createType1Descriptor writes the font data as a side effect
1026
+ fontdict ['FontDescriptor' ] = self .createType1Descriptor (t1font )
1027
1027
encoding = t1font .prop ['Encoding' ]
1028
+ fontdict ['Encoding' ] = self ._generate_encoding (encoding )
1028
1029
fc = fontdict ['FirstChar' ] = min (encoding .keys (), default = 0 )
1029
1030
lc = fontdict ['LastChar' ] = max (encoding .keys (), default = 255 )
1030
- fontdict ['Encoding' ] = self ._generate_encoding (encoding )
1031
- # Font descriptors may be shared between differently encoded
1032
- # Type-1 fonts, so only create a new descriptor if there is no
1033
- # existing descriptor for this font.
1034
- effects = (fontinfo .effects .get ('slant' , 0.0 ),
1035
- fontinfo .effects .get ('extend' , 1.0 ))
1036
- fontdesc = self ._type1Descriptors .get ((fontinfo .fontfile , effects ))
1037
- if fontdesc is None :
1038
- fontdesc = self .createType1Descriptor (t1font )
1039
- self ._type1Descriptors [(fontinfo .fontfile , effects )] = fontdesc
1040
- fontdict ['FontDescriptor' ] = fontdesc
1041
-
1042
- # Use TeX Font Metrics file to get glyph widths (TeX uses its 12.20 fixed point
1043
- # representation and we want 1/1000 text space units)
1031
+
1032
+ # Convert glyph widths from TeX 12.20 fixed point to 1/1000 text space units
1044
1033
tfm = fontinfo .dvifont ._tfm
1045
1034
widths = [(1000 * metrics .tex_width ) >> 20
1046
1035
if (metrics := tfm .get_metrics (char )) else 0
1047
1036
for char in range (fc , lc + 1 )]
1048
1037
fontdict ['Widths' ] = widthsObject = self .reserveObject ('glyph widths' )
1049
1038
self .writeObject (widthsObject , widths )
1039
+
1050
1040
self .writeObject (fontdictObject , fontdict )
1051
1041
return fontdictObject
1052
1042
0 commit comments