Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccdeeba

Browse files
committed
implement comments by mdboom
1 parent 4d1c494 commit ccdeeba

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/matplotlib/mathtext.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,19 @@ def is_slanted(self, nucleus):
26622662
return nucleus.is_slanted()
26632663
return False
26642664

2665+
def _get_fontset_name(self):
2666+
fs = rcParams['mathtext.fontset']
2667+
# If a custom fontset is used, check if it is Arev Sans, otherwise use
2668+
# CM parameters.
2669+
if fs == 'custom':
2670+
if (rcParams['mathtext.rm'] == 'sans' and
2671+
rcParams['font.sans-serif'][0].lower() == 'Arev Sans'.lower()):
2672+
fs = 'arevsans'
2673+
else:
2674+
fs = 'cm'
2675+
2676+
return fs
2677+
26652678
def subsuper(self, s, loc, toks):
26662679
assert(len(toks)==1)
26672680

@@ -2759,15 +2772,15 @@ def subsuper(self, s, loc, toks):
27592772
result = Hlist([vlist])
27602773
return [result]
27612774

2762-
# We remove kerning for consistency (otherwise it will compute kerning
2763-
# based on non-shrinked characters and may put them very close together
2764-
# when superscripted)
2775+
# We remove kerning on the last character for consistency (otherwise it
2776+
# will compute kerning based on non-shrinked characters and may put them
2777+
# too close together when superscripted)
27652778
# We change the width of the last character to match the advance to
27662779
# consider some fonts with weird metrics: e.g. stix's f has a width of
27672780
# 7.75 and a kerning of -4.0 for an advance of 3.72, and we want to put
27682781
# the superscript at the advance
27692782
last_char = nucleus
2770-
if isinstance(nucleus,Hlist):
2783+
if isinstance(nucleus, Hlist):
27712784
new_children = nucleus.children
27722785
if len(new_children):
27732786
# remove last kern
@@ -2781,17 +2794,10 @@ def subsuper(self, s, loc, toks):
27812794
last_char.width = last_char._metrics.advance
27822795
nucleus = Hlist([nucleus])
27832796

2784-
fs = rcParams['mathtext.fontset']
2785-
# If a custom fontset is used, check if it is Arev Sans, otherwise use
2786-
# CM parameters.
2787-
if fs == 'custom':
2788-
if (rcParams['mathtext.rm'] == 'sans' and
2789-
rcParams['font.sans-serif'][0].lower() == 'Arev Sans'.lower()):
2790-
fs = 'arevsans'
2791-
else:
2792-
fs = 'cm'
2793-
27942797
# Handle regular sub/superscripts
2798+
2799+
fs = self._get_fontset_name()
2800+
27952801
lc_height = last_char.height
27962802
lc_baseline = 0
27972803
if self.is_dropsub(last_char):

0 commit comments

Comments
 (0)