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

Skip to content

Commit 2c51662

Browse files
committed
finetune stix and stixsans
1 parent 9e211f3 commit 2c51662

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

lib/matplotlib/mathtext.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,16 +1187,31 @@ def get_underline_thickness(self, font, fontsize, dpi):
11871187
# get any smaller
11881188
NUM_SIZE_LEVELS = 6
11891189
# Percentage of x-height of additional horiz. space after sub/superscripts
1190-
SCRIPT_SPACE = 0.00
1191-
# Percentage of x-height that sub/superscripts drop below the baseline
1192-
SUBDROP = 0.3
1190+
SCRIPT_SPACE = {'cm': 0.00,
1191+
'stix': 0.10,
1192+
'stixsans': 0.10}
1193+
## Percentage of x-height that sub/superscripts drop below the baseline
1194+
#SUBDROP = {'cm': 0.3,
1195+
#'stix': 0.3,
1196+
#'stixsans': 0.00}
11931197
# Percentage of x-height that superscripts drop below the baseline
1194-
SUP1 = 0.4
1198+
SUP1 = {'cm': 0.4,
1199+
'stix': 0.8,
1200+
'stixsans': 0.8}
11951201
# Percentage of x-height that subscripts drop below the baseline
1196-
SUB1 = 0.0
1202+
SUB1 = {'cm': 0.4,
1203+
'stix': 0.6,
1204+
'stixsans': 0.6}
1205+
# Percentage of x-height that subscripts drop below the baseline when a
1206+
# subscript is present
1207+
SUB2 = {'cm': 0.3,
1208+
'stix': 0.8,
1209+
'stixsans': 0.5}
11971210
# Percentage of x-height that supercripts are offset relative to the subscript
11981211
# for slanted nuclei
1199-
DELTA = 0.10
1212+
DELTA = {'cm': 0.10,
1213+
'stix': 0.15,
1214+
'stixsans': 0.25}
12001215

12011216
class MathTextWarning(Warning):
12021217
pass
@@ -2693,6 +2708,15 @@ def subsuper(self, s, loc, toks):
26932708
xHeight = state.font_output.get_xheight(
26942709
state.font, state.fontsize, state.dpi)
26952710

2711+
fs = rcParams['mathtext.fontset']
2712+
# If a custom fontset is used, try to infer what sort of font is being
2713+
# used. If serif use stix parameters, if sans use stixsans.
2714+
if fs == 'custom':
2715+
if 'sans' in rcParams['mathtext.rm']:
2716+
fs = 'stixsans'
2717+
else:
2718+
fs = 'stix'
2719+
26962720
if napostrophes:
26972721
if super is None:
26982722
super = Hlist([])
@@ -2729,35 +2753,36 @@ def subsuper(self, s, loc, toks):
27292753
return [result]
27302754

27312755
# Handle regular sub/superscripts
2732-
shift_up = nucleus.height - SUBDROP * xHeight
2733-
if self.is_dropsub(nucleus):
2734-
shift_down = nucleus.depth + SUBDROP * xHeight
2735-
else:
2736-
shift_down = SUBDROP * xHeight
2756+
#shift_up = nucleus.height - SUBDROP[fs] * xHeight
2757+
#if self.is_dropsub(nucleus):
2758+
#shift_down = nucleus.depth + SUBDROP[fs] * xHeight
2759+
#else:
2760+
#shift_down = SUBDROP[fs] * xHeight
2761+
shift_down, shift_up = 0,0
27372762
if super is None:
27382763
# node757
27392764
x = Hlist([sub])
27402765
x.shrink()
2741-
x.width += SCRIPT_SPACE * xHeight
2742-
shift_down = max(shift_down, SUB1)
2743-
clr = x.height - (abs(xHeight * 4.0) / 5.0)
2744-
shift_down = max(shift_down, clr)
2766+
x.width += SCRIPT_SPACE[fs] * xHeight
2767+
shift_down = max(shift_down, SUB1[fs] * xHeight)
2768+
#clr = x.height - (abs(xHeight * 4.0) / 5.0)
2769+
#shift_down = max(shift_down, clr)
27452770
x.shift_amount = shift_down / 2.
27462771
else:
27472772
if self.is_slanted(last_char):
2748-
x = Hlist([Kern(DELTA * super.height),super])
2773+
x = Hlist([Kern(DELTA[fs] * super.height),super])
27492774
else:
27502775
x = Hlist([super])
27512776
x.shrink()
2752-
x.width += SCRIPT_SPACE * xHeight
2753-
shift_up = SUP1 * xHeight
2777+
x.width += SCRIPT_SPACE[fs] * xHeight
2778+
shift_up = SUP1[fs] * xHeight
27542779
if sub is None:
27552780
x.shift_amount = -shift_up
27562781
else: # Both sub and superscript
27572782
y = Hlist([sub])
27582783
y.shrink()
2759-
y.width += SCRIPT_SPACE * xHeight
2760-
shift_down = max(shift_down, SUB1 * xHeight)
2784+
y.width += SCRIPT_SPACE[fs] * xHeight
2785+
shift_down = max(shift_down, SUB2[fs] * xHeight)
27612786
# If sub and superscript collide, move sup up
27622787
clr = (2.0 * rule_thickness -
27632788
((shift_up - x.depth) - (y.height - shift_down)))

0 commit comments

Comments
 (0)