@@ -1027,39 +1027,24 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
1027
1027
1028
1028
return fontname , uniindex
1029
1029
1030
- _size_alternatives = {}
1030
+ @ functools . lru_cache ()
1031
1031
def get_sized_alternatives_for_symbol (self , fontname , sym ):
1032
- fixes = {'\\ {' : '{' , '\\ }' : '}' , '\\ [' : '[' , '\\ ]' : ']' }
1032
+ fixes = {
1033
+ '\\ {' : '{' , '\\ }' : '}' , '\\ [' : '[' , '\\ ]' : ']' ,
1034
+ '<' : '\N{MATHEMATICAL LEFT ANGLE BRACKET} ' ,
1035
+ '>' : '\N{MATHEMATICAL RIGHT ANGLE BRACKET} ' ,
1036
+ }
1033
1037
sym = fixes .get (sym , sym )
1034
-
1035
- alternatives = self ._size_alternatives .get (sym )
1036
- if alternatives :
1037
- return alternatives
1038
-
1039
- alternatives = []
1040
1038
try :
1041
1039
uniindex = get_unicode_index (sym )
1042
1040
except ValueError :
1043
1041
return [(fontname , sym )]
1044
-
1045
- fix_ups = {
1046
- ord ('<' ): 0x27e8 ,
1047
- ord ('>' ): 0x27e9 }
1048
-
1049
- uniindex = fix_ups .get (uniindex , uniindex )
1050
-
1051
- for i in range (6 ):
1052
- font = self ._get_font (i )
1053
- glyphindex = font .get_char_index (uniindex )
1054
- if glyphindex != 0 :
1055
- alternatives .append ((i , chr (uniindex )))
1056
-
1042
+ alternatives = [(i , chr (uniindex )) for i in range (6 )
1043
+ if self ._get_font (i ).get_char_index (uniindex ) != 0 ]
1057
1044
# The largest size of the radical symbol in STIX has incorrect
1058
1045
# metrics that cause it to be disconnected from the stem.
1059
1046
if sym == r'\__sqrt__' :
1060
1047
alternatives = alternatives [:- 1 ]
1061
-
1062
- self ._size_alternatives [sym ] = alternatives
1063
1048
return alternatives
1064
1049
1065
1050
0 commit comments