Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac4b31a

Browse filesBrowse files
authored
Merge pull request #14236 from anntzer/stixsizedalternatives
Simplify StixFonts.get_sized_alternatives_for_symbol.
2 parents f899d04 + 4f86365 commit ac4b31a
Copy full SHA for ac4b31a

File tree

Expand file treeCollapse file tree

1 file changed

+8
-23
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-23
lines changed

‎lib/matplotlib/mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+8-23Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,39 +1027,24 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
10271027

10281028
return fontname, uniindex
10291029

1030-
_size_alternatives = {}
1030+
@functools.lru_cache()
10311031
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+
}
10331037
sym = fixes.get(sym, sym)
1034-
1035-
alternatives = self._size_alternatives.get(sym)
1036-
if alternatives:
1037-
return alternatives
1038-
1039-
alternatives = []
10401038
try:
10411039
uniindex = get_unicode_index(sym)
10421040
except ValueError:
10431041
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]
10571044
# The largest size of the radical symbol in STIX has incorrect
10581045
# metrics that cause it to be disconnected from the stem.
10591046
if sym == r'\__sqrt__':
10601047
alternatives = alternatives[:-1]
1061-
1062-
self._size_alternatives[sym] = alternatives
10631048
return alternatives
10641049

10651050

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.