@@ -828,14 +828,19 @@ def __new__(cls, filename):
828828 # store the unparsed lines (keyed by the first word, which is the
829829 # texname) and parse them on-demand.
830830 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 )
832835 self ._parsed = {}
833836 return self
834837
835838 def __getitem__ (self , texname ):
836839 assert isinstance (texname , bytes )
837840 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
839844 try :
840845 return self ._parsed [texname ]
841846 except KeyError :
@@ -879,6 +884,7 @@ def _parse_and_cache_line(self, line):
879884 if not line or line .startswith ((b" " , b"%" , b"*" , b";" , b"#" )):
880885 return
881886 tfmname = basename = special = encodingfile = fontfile = None
887+ is_subsetted = is_t1 = is_truetype = False
882888 matches = re .finditer (br'"([^"]*)(?:"|$)|(\S+)' , line )
883889 for match in matches :
884890 quoted , unquoted = match .groups ()
@@ -897,14 +903,13 @@ def _parse_and_cache_line(self, line):
897903 encodingfile = word
898904 else :
899905 fontfile = word
906+ is_subsetted = True
900907 elif tfmname is None :
901908 tfmname = unquoted
902909 elif basename is None :
903910 basename = unquoted
904911 elif quoted :
905912 special = quoted
906- if basename is None :
907- basename = tfmname
908913 effects = {}
909914 if special :
910915 words = reversed (special .split ())
@@ -913,13 +918,35 @@ def _parse_and_cache_line(self, line):
913918 effects ["slant" ] = float (next (words ))
914919 elif word == b"ExtendFont" :
915920 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 :
917943 encodingfile = find_tex_file (encodingfile )
918- if fontfile is not None and not fontfile . startswith ( b"/" ) :
944+ if fontfile is not None :
919945 fontfile = find_tex_file (fontfile )
920946 self ._parsed [tfmname ] = PsFont (
921947 texname = tfmname , psname = basename , effects = effects ,
922948 encoding = encodingfile , filename = fontfile )
949+ return True
923950
924951
925952def _parse_enc (path ):
0 commit comments