8000 remove kerning between nucleus and sub or super · matplotlib/matplotlib@4d7d377 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d7d377

Browse files
committed
remove kerning between nucleus and sub or super
1 parent 2b050ec commit 4d7d377

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

lib/matplotlib/mathtext.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,8 @@ 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 = {'cm': 0.05,
1191-
'stix': 0.10,
1190+
SCRIPT_SPACE = {'cm': 0.025,
1191+
'stix': 0.20,
11921192
'stixsans': 0.10,
11931193
'arevsans': 0.10}
11941194
## Percentage of x-height that sub/superscripts drop below the baseline
@@ -1212,12 +1212,18 @@ def get_underline_thickness(self, font, fontsize, dpi):
12121212
'stix': 0.6,
12131213
'stixsans': 0.5,
12141214
'arevsans': 0.8}
1215-
# Percentage of x-height that supercripts are offset relative to the subscript
1216-
# for slanted nuclei
1215+
# Percentage of x-height that sub/supercripts are offset relative to the
1216+
# nucleus end
12171217
DELTA = {'cm': 0.10,
1218-
'stix': 0.15,
1218+
'stix': 0.10,
12191219
'stixsans': 0.25,
12201220
'arevsans': 0.12}
1221+
# Additional percentage of last character height that supercripts are offset
1222+
# relative to the subscript for slanted nuclei
1223+
DELTASLANTED = {'cm': 0.05,
1224+
'stix': 0.05,
1225+
'stixsans': 0.05,
1226+
'arevsans': 0.12}
12211227
# Percentage of x-height that supercripts are offset relative to the subscript
12221228
# for integrals
12231229
DELTAINTEGRAL = {'cm': 0.5,
@@ -2714,8 +2720,16 @@ def subsuper(self, s, loc, toks):
27142720

27152721
last_char = nucleus
27162722
if isinstance(nucleus,Hlist):
2717-
if len(nucleus.children) >= 2:
2718-
last_char = nucleus.children[-2]
2723+
# remove kerns
2724+
new_children = []
2725+
for child in nucleus.children:
2726+
if not isinstance(child, Kern):
2727+
new_children.append(child)
2728+
nucleus = Hlist(new_children, do_kern=False)
2729+
if len(new_children):
2730+
last_char = new_children[-1]
2731+
else:
2732+
nucleus = Hlist([nucleus],do_kern=False)
27192733

27202734
state = self.get_state()
27212735
rule_thickness = state.font_output.get_underline_thickness(
@@ -2733,7 +2747,6 @@ def subsuper(self, s, loc, toks):
27332747
else:
27342748
fs = 'cm'
27352749

2736-
27372750
if napostrophes:
27382751
if super is None:
27392752
super = Hlist([])
@@ -2774,50 +2787,43 @@ def subsuper(self, s, loc, toks):
27742787
lc_baseline = 0
27752788
if self.is_dropsub(last_char):
27762789
lc_baseline = last_char.depth
2777-
if super is None:
2778-
# node757
2790+
2791+
# Compute kerning for sub and super
2792+
superkern = DELTA[fs] * xHeight
2793+
subkern = DELTA[fs] * xHeight
2794+
if self.is_slanted(last_char):
2795+
superkern += DELTASLANTED[fs] * xHeight
27792796
if self.is_dropsub(last_char):
2780-
x = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
2797+
subkern = -DELTAINTEGRAL[fs] * lc_height
27812798
else:
2782-
x = Hlist([sub])
2799+
subkern = 0.25 * DELTA[fs] * lc_height
2800+
2801+
if super is None:
2802+
# node757
2803+
x = Hlist([Kern(subkern), sub])
27832804
x.shrink()
2784-
x.width += SCRIPT_SPACE[fs] * xHeight
27852805
shift_down = max(lc_baseline + SUBDROP[fs] * xHeight,
27862806
SUB1[fs] * xHeight)
27872807
if not self.is_dropsub(last_char):
27882808
shift_down /= 2
27892809
x.shift_amount = shift_down
27902810
else:
2791-
if self.is_dropsub(last_char):
2792-
delta = DELTAINTEGRAL[fs]
2793-
else:
2794-
delta = DELTA[fs]
2795-
2796-
if self.is_slanted(last_char):
2797-
x = Hlist([Kern(delta * last_char.height),super])
2798-
else:
2799-
x = Hlist([super])
2811+
x = Hlist([Kern(superkern), super])
28002812
x.shrink()
2801-
x.width += SCRIPT_SPACE[fs] * xHeight
28022813
if self.is_dropsub(last_char):
28032814
shift_up = lc_height - SUBDROP[fs] * xHeight
28042815
else:
28052816
shift_up = SUP1[fs] * xHeight
28062817
if sub is None:
28072818
x.shift_amount = -shift_up
28082819
else: # Both sub and superscript
2809-
if self.is_dropsub(last_char):
2810-
y = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
2811-
else:
2812-
y = Hlist([sub])
2813-
#y = Hlist([sub])
2820+
y = Hlist([Kern(subkern),sub])
28142821
y.shrink()
2815-
y.width += SCRIPT_SPACE[fs] * xHeight
28162822
if self.is_dropsub(last_char):
28172823
shift_down = lc_baseline + SUBDROP[fs] * xHeight
28182824
else:
28192825
shift_down = SUB2[fs] * xHeight
2820-
# If sub and superscript collide, move sup up
2826+
# If sub and superscript collide, move super up
28212827
clr = (2.0 * rule_thickness -
28222828
((shift_up - x.depth) - (y.height - shift_down)))
28232829
if clr > 0.:
@@ -2827,7 +2833,8 @@ def subsuper(self, s, loc, toks):
28272833
y])
28282834
x.shift_amount = shift_down
28292835

2830-
result = Hlist([nucleus, x])
2836+
x.width += SCRIPT_SPACE[fs] * xHeight
2837+
result = Hlist([nucleus, x], do_kern=False)
28312838
return [result]
28322839

28332840
def _genfrac(self, ldelim, rdelim, rule, style, num, den):

0 commit comments

Comments
 (0)
0