@@ -828,14 +828,19 @@ def __new__(cls, filename):
828
828
# store the unparsed lines (keyed by the first word, which is the
829
829
# texname) and parse them on-demand.
830
830
with open (filename , 'rb' ) as file :
831
- self ._unparsed = {line .split (b' ' , 1 )[0 ]: line for line in file }
831
+ self ._unparsed = {}
832
+ for line in file :
833
+ tfmname = line .split (b' ' , 1 )[0 ]
834
+ self ._unparsed .setdefault (tfmname , []).append (line )
832
835
self ._parsed = {}
833
836
return self
834
837
835
838
def __getitem__ (self , texname ):
836
839
assert isinstance (texname , bytes )
837
840
if texname in self ._unparsed :
838
- self ._parse_and_cache_line (self ._unparsed .pop (texname ))
841
+ for line in self ._unparsed .pop (texname ):
842
+ if self ._parse_and_cache_line (line ):
843
+ break
839
844
try :
840
845
return self ._parsed [texname ]
841
846
except KeyError :
@@ -879,6 +884,7 @@ def _parse_and_cache_line(self, line):
879
884
if not line or line .startswith ((b" " , b"%" , b"*" , b";" , b"#" )):
880
885
return
881
886
tfmname = basename = special = encodingfile = fontfile = None
887
+ is_subsetted = is_t1 = is_truetype = False
882
888
matches = re .finditer (br'"([^"]*)(?:"|$)|(\S+)' , line )
883
889
for match in matches :
884
890
quoted , unquoted = match .groups ()
@@ -897,14 +903,13 @@ def _parse_and_cache_line(self, line):
897
903
encodingfile = word
898
904
else :
899
905
fontfile = word
906
+ is_subsetted = True
900
907
elif tfmname is None :
901
908
tfmname = unquoted
902
909
elif basename is None :
903
910
basename = unquoted
904
911
elif quoted :
905
912
special = quoted
906
- if basename is None :
907
- basename = tfmname
908
913
effects = {}
909
914
if special :
910
915
words = reversed (special .split ())
@@ -913,13 +918,35 @@ def _parse_and_cache_line(self, line):
913
918
effects ["slant" ] = float (next (words ))
914
919
elif word == b"ExtendFont" :
915
920
effects ["extend" ] = float (next (words ))
916
- if encodingfile is not None and not encodingfile .startswith (b"/" ):
921
+
922
+ # Verify some properties of the line that would cause it to be ignored
923
+ # otherwise.
924
+ if fontfile is not None :
925
+ if fontfile .endswith ((b".ttf" , b".ttc" )):
926
+ is_truetype = True
927
+ elif not fontfile .endswith (b".otf" ):
928
+ is_t1 = True
929
+ elif basename is not None :
930
+ is_t1 = True
931
+ if is_truetype and is_subsetted and encodingfile is None :
932
+ return
933
+ if not is_t1 and ("slant" in effects or "extend" in effects ):
934
+ return
935
+ if abs (effects .get ("slant" , 0 )) > 1 :
936
+ return
937
+ if abs (effects .get ("extend" , 0 )) > 2 :
938
+ return
939
+
940
+ if basename is None :
941
+ basename = tfmname
942
+ if encodingfile is not None :
917
943
encodingfile = find_tex_file (encodingfile )
918
- if fontfile is not None and not fontfile . startswith ( b"/" ) :
944
+ if fontfile is not None :
919
945
fontfile = find_tex_file (fontfile )
920
946
self ._parsed [tfmname ] = PsFont (
921
947
texname = tfmname , psname = basename , effects = effects ,
922
948
encoding = encodingfile , filename = fontfile )
949
+ return True
923
950
924
951
925
952
def _parse_enc (path ):
0 commit comments