@@ -989,24 +989,13 @@ def _embedTeXFont(self, fontinfo):
989
989
_log .debug ('Embedding TeX font %s - fontinfo=%s' ,
990
990
fontinfo .dvifont .texname , fontinfo .__dict__ )
991
991
992
- # Widths
993
- widthsObject = self .reserveObject ('font widths' )
994
- tfm = fontinfo .dvifont ._tfm
995
- # convert from TeX's 12.20 representation to 1/1000 text space units.
996
- widths = [(1000 * metrics .tex_width ) >> 20
997
- if (metrics := tfm .get_metrics (char )) else 0
998
- for char in range (max (tfm ._glyph_metrics , default = - 1 ) + 1 )]
999
- self .writeObject (widthsObject , widths )
1000
-
1001
992
# Font dictionary
1002
993
fontdictObject = self .reserveObject ('font dictionary' )
1003
994
fontdict = {
1004
995
'Type' : Name ('Font' ),
1005
996
'Subtype' : Name ('Type1' ),
1006
- 'FirstChar' : 0 ,
1007
- 'LastChar' : len (widths ) - 1 ,
1008
- 'Widths' : widthsObject ,
1009
- }
997
+ 'Widths' : (widthsObject := self .reserveObject ('glyph widths' )),
998
+ }
1010
999
1011
1000
# Encoding (if needed)
1012
1001
if fontinfo .encodingfile is not None :
@@ -1025,6 +1014,7 @@ def _embedTeXFont(self, fontinfo):
1025
1014
"application to show something that was not intended." ,
1026
1015
fontinfo .basefont )
1027
1016
fontdict ['BaseFont' ] = Name (fontinfo .basefont )
1017
+ del fontdict ['Widths' ]
1028
1018
self .writeObject (fontdictObject , fontdict )
1029
1019
return fontdictObject
1030
1020
@@ -1035,7 +1025,8 @@ def _embedTeXFont(self, fontinfo):
1035
1025
chars = self ._character_tracker .used [fontinfo .dvifont .fname ]
1036
1026
t1font = t1font .subset (chars )
1037
1027
fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
1038
-
1028
+ fc = fontdict ['FirstChar' ] = min (t1font .prop ['Encoding' ].keys (), default = 0 )
1029
+ lc = fontdict ['LastChar' ] = max (t1font .prop ['Encoding' ].keys (), default = 255 )
1039
1030
# Font descriptors may be shared between differently encoded
1040
1031
# Type-1 fonts, so only create a new descriptor if there is no
1041
1032
# existing descriptor for this font.
@@ -1047,7 +1038,14 @@ def _embedTeXFont(self, fontinfo):
1047
1038
self .type1Descriptors [(fontinfo .fontfile , effects )] = fontdesc
1048
1039
fontdict ['FontDescriptor' ] = fontdesc
1049
1040
1041
+ # Use TeX Font Metrics file to get glyph widths (TeX uses its 12.20 fixed point
1042
+ # representation and we want 1/1000 text space units)
1043
+ tfm = fontinfo .dvifont ._tfm
1044
+ widths = [(1000 * metrics .tex_width ) >> 20
1045
+ if (metrics := tfm .get_metrics (char )) else 0
1046
+ for char in range (fc , lc + 1 )]
1050
1047
self .writeObject (fontdictObject , fontdict )
1048
+ self .writeObject (widthsObject , widths )
1051
1049
return fontdictObject
1052
1050
1053
1051
def createType1Descriptor (self , t1font , fontfile ):
@@ -1087,6 +1085,14 @@ def createType1Descriptor(self, t1font, fontfile):
1087
1085
1088
1086
ft2font = get_font (fontfile )
1089
1087
1088
+ encoding = t1font .prop ['Encoding' ]
1089
+ charset = '' .join (
1090
+ sorted (
1091
+ f'/{ c } ' for c in encoding .values ()
1092
+ if c != '.notdef'
1093
+ )
1094
+ )
1095
+
1090
1096
descriptor = {
1091
1097
'Type' : Name ('FontDescriptor' ),
1092
1098
'FontName' : Name (t1font .prop ['FontName' ]),
@@ -1100,6 +1106,7 @@ def createType1Descriptor(self, t1font, fontfile):
1100
1106
'FontFile' : fontfileObject ,
1101
1107
'FontFamily' : t1font .prop ['FamilyName' ],
1102
1108
'StemV' : 50 , # TODO
1109
+ 'CharSet' : charset ,
1103
1110
# (see also revision 3874; but not all TeX distros have AFM files!)
1104
1111
# 'FontWeight': a number where 400 = Regular, 700 = Bold
1105
1112
}
0 commit comments