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

Skip to content

Commit 22a6682

Browse files
committed
finetune stix and stixsans
1 parent 8007cd1 commit 22a6682

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

lib/matplotlib/mathtext.py

Lines changed: 38 additions & 18 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.03,
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.3}
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+
# superscript is present
1207+
SUB2 = {'cm': 0.3,
1208+
'stix': 0.6,
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
@@ -2696,6 +2711,11 @@ def subsuper(self, s, loc, toks):
26962711
xHeight = state.font_output.get_xheight(
26972712
state.font, state.fontsize, state.dpi)
26982713

2714+
fs = rcParams['mathtext.fontset']
2715+
# If a custom fontset is used, use CM parameters
2716+
if fs == 'custom':
2717+
fs = 'cm'
2718+
26992719
if napostrophes:
27002720
if super is None:
27012721
super = Hlist([])
@@ -2732,35 +2752,35 @@ def subsuper(self, s, loc, toks):
27322752
return [result]
27332753

27342754
# Handle regular sub/superscripts
2735-
shift_up = nucleus.height - SUBDROP * xHeight
2755+
shift_up = nucleus.height - SUBDROP[fs] * xHeight
27362756
if self.is_dropsub(nucleus):
2737-
shift_down = nucleus.depth + SUBDROP * xHeight
2757+
shift_down = nucleus.depth + SUBDROP[fs] * xHeight
27382758
else:
2739-
shift_down = SUBDROP * xHeight
2759+
shift_down = SUBDROP[fs] * xHeight
27402760
if super is None:
27412761
# node757
27422762
x = Hlist([sub])
27432763
x.shrink()
2744-
x.width += SCRIPT_SPACE * xHeight
2745-
shift_down = max(shift_down, SUB1)
2746-
clr = x.height - (abs(xHeight * 4.0) / 5.0)
2747-
shift_down = max(shift_down, clr)
2764+
x.width += SCRIPT_SPACE[fs] * xHeight
2765+
shift_down = max(shift_down, SUB1[fs] * xHeight)
2766+
#clr = x.height - (abs(xHeight * 4.0) / 5.0)
2767+
#shift_down = max(shift_down, clr)
27482768
x.shift_amount = shift_down / 2.
27492769
else:
27502770
if self.is_slanted(last_char):
2751-
x = Hlist([Kern(DELTA * super.height),super])
2771+
x = Hlist([Kern(DELTA[fs] * super.height),super])
27522772
else:
27532773
x = Hlist([super])
27542774
x.shrink()
2755-
x.width += SCRIPT_SPACE * xHeight
2756-
shift_up = SUP1 * xHeight
2775+
x.width += SCRIPT_SPACE[fs] * xHeight
2776+
shift_up = SUP1[fs] * xHeight
27572777
if sub is None:
27582778
x.shift_amount = -shift_up
27592779
else: # Both sub and superscript
27602780
y = Hlist([sub])
27612781
y.shrink()
2762-
y.width += SCRIPT_SPACE * xHeight
2763-
shift_down = max(shift_down, SUB1 * xHeight)
2782+
y.width += SCRIPT_SPACE[fs] * xHeight
2783+
shift_down = max(shift_down, SUB2[fs] * xHeight)
27642784
# If sub and superscript collide, move sup up
27652785
clr = (2.0 * rule_thickness -
27662786
((shift_up - x.depth) - (y.height - shift_down)))

0 commit comments

Comments
 (0)