@@ -344,11 +344,14 @@ class Type1Font:
344344 Subrs - array of byte code subroutines
345345 OtherSubrs - bytes object encoding some PostScript code
346346 """
347- __slots__ = ('parts' , 'decrypted' , 'prop' , '_pos' )
347+ __slots__ = ('parts' , 'decrypted' , 'prop' , '_pos' , '_abbr' )
348348 # the _pos dict contains (begin, end) indices to parts[0] + decrypted
349349 # so that they can be replaced when transforming the font;
350350 # but since sometimes a definition appears in both parts[0] and decrypted,
351351 # _pos[name] is an array of such pairs
352+ #
353+ # _abbr maps three standard abbreviations to their particular names in
354+ # this font (e.g. 'RD' is named '-|' in some fonts)
352355
353356 def __init__ (self , input ):
354357 """
@@ -368,6 +371,7 @@ def __init__(self, input):
368371 self .parts = self ._split (data )
369372
370373 self .decrypted = self ._decrypt (self .parts [1 ], 'eexec' )
374+ self ._abbr = {'RD' : 'RD' , 'ND' : 'ND' , 'NP' : 'NP' }
371375 self ._parse ()
372376
373377 def _read (self , file ):
@@ -552,10 +556,18 @@ def _parse(self):
552556 break
553557
554558 # sometimes noaccess def and readonly def are abbreviated
555- if kw .is_name ( b 'def' , b 'ND', b'RD' , b'|-' ):
559+ if kw .is_keyword ( 'def' , self . _abbr [ 'ND' ], self . _abbr [ 'NP' ] ):
556560 prop [key ] = value
557561 pos .setdefault (key , []).append ((keypos , kw .endpos ()))
558562
563+ # detect the standard abbreviations
564+ if value == '{noaccess def}' :
565+ self ._abbr ['ND' ] = key
566+ elif value == '{noaccess put}' :
567+ self ._abbr ['NP' ] = key
568+ elif value == '{string currentfile exch readstring pop}' :
569+ self ._abbr ['RD' ] = key
570+
559571 # Fill in the various *Name properties
560572 if 'FontName' not in prop :
561573 prop ['FontName' ] = (prop .get ('FullName' ) or
@@ -604,9 +616,14 @@ def _parse_subrs(self, tokens, _data):
604616 "Second token following dup in Subrs definition must "
605617 f"be a number, was { nbytes_token } "
606618 )
607- token = next (tokens ) # usually RD or |- but the font can define this to be anything
608- binary_token = tokens .send (1 + nbytes_token .numeric_value ())
609- array [index_token .numeric_value ()] = binary_token .value [1 :]
619+ token = next (tokens )
620+ if not token .is_keyword (self ._abbr ['RD' ]):
621+ raise RuntimeError (
622+ f"Token preceding subr must be { self ._abbr ['RD' ]} , "
623+ f"was { token } "
624+ )
625+ binary_token = tokens .send (1 + nbytes_token .value ())
626+ array [index_token .value ()] = binary_token .value ()
610627
611628 return array , next (tokens ).endpos ()
612629
0 commit comments