@@ -906,38 +906,43 @@ def _register(self, words):
906906 assert isinstance (word , bytes )
907907
908908 texname , psname = words [:2 ]
909+ words = words [2 :]
909910 effects , encoding , filename = b'' , None , None
910- for word in words [2 :]:
911- if not word .startswith (b'<' ):
912- effects = word
913- else :
914- word = word .lstrip (b'<' )
915- if word .startswith (b'[' ) or word .endswith (b'.enc' ):
916- if encoding is not None :
917- matplotlib .verbose .report (
918- 'Multiple encodings for %s = %s'
919- % (texname , psname ), 'debug' )
920- if word .startswith (b'[' ):
921- encoding = word [1 :]
922- else :
923- encoding = word
924- else :
925- assert filename is None
926- filename = word
927911
928- eff = effects .split ()
929- effects = {}
930- try :
931- effects ['slant' ] = float (eff [eff .index (b'SlantFont' )- 1 ])
932- except ValueError :
933- pass
934- try :
935- effects ['extend' ] = float (eff [eff .index (b'ExtendFont' )- 1 ])
936- except ValueError :
937- pass
912+ # pick the last non-filename word for effects
913+ effects_words = [word for word in words if not word .startswith (b'<' )]
914+ if effects_words :
915+ effects = effects_words [- 1 ]
916+
917+ encoding_re = br'<<?(\[.*|.*\.enc)'
918+ encoding_files = [word .lstrip (b'<' ).lstrip (b'[' )
919+ for word in words
920+ if re .match (encoding_re , word )]
921+ if len (encoding_files ) > 1 :
922+ matplotlib .verbose .report (
923+ 'Multiple encodings for %s = %s' % (texname , psname ), 'debug' )
924+ if encoding_files :
925+ encoding = encoding_files [- 1 ]
926+
927+ font_files = [word .lstrip (b'<' )
928+ for word in words
929+ if word .startswith (b'<' )
930+ and not re .match (encoding_re , word )]
931+ if font_files :
932+ filename = font_files [- 1 ]
933+
934+ eff = {}
935+ for psword , keyword in ((b'SlantFont' , 'slant' ),
936+ (b'ExtendFont' , 'extend' )):
937+ match = re .search (b'([^ ]+) +' + psword , effects )
938+ if match :
939+ try :
940+ eff [keyword ] = float (match .group (1 ))
941+ except ValueError :
942+ pass
938943
939944 self ._font [texname ] = PsFont (
940- texname = texname , psname = psname , effects = effects ,
945+ texname = texname , psname = psname , effects = eff ,
941946 encoding = encoding , filename = filename )
942947
943948
0 commit comments