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

Skip to content

Commit 8b557bb

Browse files
committed
finetune stix and stixsans
1 parent 4f05e66 commit 8b557bb

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
@@ -2693,6 +2708,11 @@ 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, use CM parameters
2713+
if fs == 'custom':
2714+
fs = 'cm'
2715+
26962716
if napostrophes:
26972717
if super is None:
26982718
super = Hlist([])
@@ -2729,35 +2749,35 @@ def subsuper(self, s, loc, toks):
27292749
return [result]
27302750

27312751
# Handle regular sub/superscripts
2732-
shift_up = nucleus.height - SUBDROP * xHeight
2752+
shift_up = nucleus.height - SUBDROP[fs] * xHeight
27332753
if self.is_dropsub(nucleus):
2734-
shift_down = nucleus.depth + SUBDROP * xHeight
2754+
shift_down = nucleus.depth + SUBDROP[fs] * xHeight
27352755
else:
2736-
shift_down = SUBDROP * xHeight
2756+
shift_down = SUBDROP[fs] * xHeight
27372757
if super is None:
27382758
# node757
27392759
x = Hlist([sub])
27402760
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)
2761+
x.width += SCRIPT_SPACE[fs] * xHeight
2762+
shift_down = max(shift_down, SUB1[fs] * xHeight)
2763+
#clr = x.height - (abs(xHeight * 4.0) / 5.0)
2764+
#shift_down = max(shift_down, clr)
27452765
x.shift_amount = shift_down / 2.
27462766
else:
27472767
if self.is_slanted(last_char):
2748-
x = Hlist([Kern(DELTA * super.height),super])
2768+
x = Hlist([Kern(DELTA[fs] * super.height),super])
27492769
else:
27502770
x = Hlist([super])
27512771
x.shrink()
2752-
x.width += SCRIPT_SPACE * xHeight
2753-
shift_up = SUP1 * xHeight
2772+
x.width += SCRIPT_SPACE[fs] * xHeight
2773+
shift_up = SUP1[fs] * xHeight
27542774
if sub is None:
27552775
x.shift_amount = -shift_up
27562776
else: # Both sub and superscript
27572777
y = Hlist([sub])
27582778
y.shrink()
2759-
y.width += SCRIPT_SPACE * xHeight
2760-
shift_down = max(shift_down, SUB1 * xHeight)
2779+
y.width += SCRIPT_SPACE[fs] * xHeight
2780+
shift_down = max(shift_down, SUB2[fs] * xHeight)
27612781
# If sub and superscript collide, move sup up
27622782
clr = (2.0 * rule_thickness -
27632783
((shift_up - x.depth) - (y.height - shift_down)))

0 commit comments

Comments
 (0)