@@ -721,7 +721,7 @@ def __init__(self, filename, metadata=None):
721
721
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
- self ._dviFontInfo = {}# mapsdvi font names toembedding information
724
+ self ._dviFontInfo = {}# mapspdf names todvifonts
725
725
self ._character_tracker = _backend_pdf_ps .CharacterTracker ()
726
726
727
727
self .alphaStates = {}# maps alpha values to graphics state objects
@@ -764,9 +764,30 @@ def __init__(self, filename, metadata=None):
764
764
self .writeObject (self .resourceObject ,resources )
765
765
766
766
fontNames = _api .deprecated ("3.11" )(property (lambda self :self ._fontNames ))
767
- dviFontInfo = _api .deprecated ("3.11" )(property (lambda self :self ._dviFontInfo ))
768
767
type1Descriptors = _api .deprecated ("3.11" )(property (lambda _ : {}))
769
768
769
+ @_api .deprecated ("3.11" )
770
+ @property
771
+ def dviFontInfo (self ):
772
+ d = {}
773
+ tex_font_map = dviread .PsfontsMap (dviread .find_tex_file ('pdftex.map' ))
774
+ for pdfname ,dvifont in self ._dviFontInfo .items ():
775
+ psfont = tex_font_map [dvifont .texname ]
776
+ if psfont .filename is None :
777
+ raise ValueError (
778
+ "No usable font file found for {} (TeX: {}); "
779
+ "the font may lack a Type-1 version"
780
+ .format (psfont .psname ,dvifont .texname ))
781
+ d [dvifont .texname ]= types .SimpleNamespace (
782
+ dvifont = dvifont ,
783
+ pdfname = pdfname ,
784
+ fontfile = psfont .filename ,
785
+ basefont = psfont .psname ,
786
+ encodingfile = psfont .encoding ,
787
+ effects = psfont .effects ,
788
+ )
789
+ return d
790
+
770
791
def newPage (self ,width ,height ):
771
792
self .endStream ()
772
793
@@ -938,39 +959,19 @@ def fontName(self, fontprop):
938
959
def dviFontName (self ,dvifont ):
939
960
"""
940
961
Given a dvi font object, return a name suitable for Op.selectfont.
941
- This registers the font information internally (in ``_dviFontInfo``) if
942
- not yet registered.
943
- """
944
-
945
- dvi_info = self ._dviFontInfo .get (dvifont .texname )
946
- if dvi_info is not None :
947
- return dvi_info .pdfname
948
-
949
- tex_font_map = dviread .PsfontsMap (dviread .find_tex_file ('pdftex.map' ))
950
- psfont = tex_font_map [dvifont .texname ]
951
- if psfont .filename is None :
952
- raise ValueError (
953
- "No usable font file found for {} (TeX: {}); "
954
- "the font may lack a Type-1 version"
955
- .format (psfont .psname ,dvifont .texname ))
956
962
957
- pdfname = next (self ._internal_font_seq )
963
+ Register the font internally (in ``_dviFontInfo``) if not yet registered.
964
+ """
965
+ pdfname = Name (f"F-{ dvifont .texname .decode ('ascii' )} " )
958
966
_log .debug ('Assigning font %s = %s (dvi)' ,pdfname ,dvifont .texname )
959
- self ._dviFontInfo [dvifont .texname ]= types .SimpleNamespace (
960
- dvifont = dvifont ,
961
- pdfname = pdfname ,
962
- fontfile = psfont .filename ,
963
- basefont = psfont .psname ,
964
- encodingfile = psfont .encoding ,
965
- effects = psfont .effects )
966
- return pdfname
967
+ self ._dviFontInfo [pdfname ]= dvifont
968
+ return Name (pdfname )
967
969
968
970
def writeFonts (self ):
969
971
fonts = {}
970
- for dviname ,info in sorted (self ._dviFontInfo .items ()):
971
- Fx = info .pdfname
972
- _log .debug ('Embedding Type-1 font %s from dvi.' ,dviname )
973
- fonts [Fx ]= self ._embedTeXFont (info )
972
+ for pdfname ,dvifont in sorted (self ._dviFontInfo .items ()):
973
+ _log .debug ('Embedding Type-1 font %s from dvi.' ,dvifont .texname )
974
+ fonts [pdfname ]= self ._embedTeXFont (dvifont )
974
975
for filename in sorted (self ._fontNames ):
975
976
Fx = self ._fontNames [filename ]
976
977
_log .debug ('Embedding font %s.' ,filename )
@@ -998,9 +999,14 @@ def _write_afm_font(self, filename):
998
999
self .writeObject (fontdictObject ,fontdict )
999
1000
return fontdictObject
1000
1001
1001
- def _embedTeXFont (self ,fontinfo ):
1002
- _log .debug ('Embedding TeX font %s - fontinfo=%s' ,
1003
- fontinfo .dvifont .texname ,fontinfo .__dict__ )
1002
+ def _embedTeXFont (self ,dvifont ):
1003
+ tex_font_map = dviread .PsfontsMap (dviread .find_tex_file ('pdftex.map' ))
1004
+ psfont = tex_font_map [dvifont .texname ]
1005
+ if psfont .filename is None :
1006
+ raise ValueError (
1007
+ "No usable font file found for {} (TeX: {}); "
1008
+ "the font may lack a Type-1 version"
1009
+ .format (psfont .psname ,dvifont .texname ))
1004
1010
1005
1011
# The font dictionary is the top-level object describing a font
1006
1012
fontdictObject = self .reserveObject ('font dictionary' )
@@ -1010,17 +1016,17 @@ def _embedTeXFont(self, fontinfo):
1010
1016
}
1011
1017
1012
1018
# Read the font file and apply any encoding changes and effects
1013
- t1font = _type1font .Type1Font (fontinfo . fontfile )
1014
- if fontinfo . encodingfile is not None :
1019
+ t1font = _type1font .Type1Font (psfont . filename )
1020
+ if psfont . encoding is not None :
1015
1021
t1font = t1font .with_encoding (
1016
- {i :c for i ,c in enumerate (dviread ._parse_enc (fontinfo . encodingfile ))}
1022
+ {i :c for i ,c in enumerate (dviread ._parse_enc (psfont . encoding ))}
1017
1023
)
1018
- if fontinfo .effects :
1019
- t1font = t1font .transform (fontinfo .effects )
1024
+ if psfont .effects :
1025
+ t1font = t1font .transform (psfont .effects )
1020
1026
1021
1027
# Reduce the font to only the glyphs used in the document, get the encoding
1022
1028
# for that subset, and compute various properties based on the encoding.
1023
- chars = frozenset (self ._character_tracker .used [fontinfo . dvifont .fname ])
1029
+ chars = frozenset (self ._character_tracker .used [dvifont .fname ])
1024
1030
t1font = t1font .subset (chars ,self ._get_subset_prefix (chars ))
1025
1031
fontdict ['BaseFont' ]= Name (t1font .prop ['FontName' ])
1026
1032
# createType1Descriptor writes the font data as a side effect
@@ -1031,17 +1037,15 @@ def _embedTeXFont(self, fontinfo):
1031
1037
lc = fontdict ['LastChar' ]= max (encoding .keys (),default = 255 )
1032
1038
1033
1039
# Convert glyph widths from TeX 12.20 fixed point to 1/1000 text space units
1034
- tfm = fontinfo . dvifont ._tfm
1040
+ tfm = dvifont ._tfm
1035
1041
widths = [(1000 * metrics .tex_width )>> 20
1036
1042
if (metrics := tfm .get_metrics (char ))else 0
1037
1043
for char in range (fc ,lc + 1 )]
1038
1044
fontdict ['Widths' ]= widthsObject = self .reserveObject ('glyph widths' )
1039
1045
self .writeObject (widthsObject ,widths )
1040
-
1041
1046
self .writeObject (fontdictObject ,fontdict )
1042
1047
return fontdictObject
1043
1048
1044
-
1045
1049
def _generate_encoding (self ,encoding ):
1046
1050
prev = - 2
1047
1051
result = []
@@ -1055,7 +1059,6 @@ def _generate_encoding(self, encoding):
1055
1059
'Differences' :result
1056
1060
}
1057
1061
1058
-
1059
1062
@_api .delete_parameter ("3.11" ,"fontfile" )
1060
1063
def createType1Descriptor (self ,t1font ,fontfile = None ):
1061
1064
# Create and write the font descriptor and the font file