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

Skip to content

Commit 96f5450

Browse files
committed
Fix superscript offset bug (only offset when nucleus is slanted)
svn path=/trunk/matplotlib/; revision=3673
1 parent 49bd18a commit 96f5450

2 files changed

Lines changed: 40 additions & 24 deletions

File tree

lib/matplotlib/_mathtext_data.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@
6868
r'\imath' : ('cmmi10', 8),
6969
r'\jmath' : ('cmmi10', 65),
7070
r'\wp' : ('cmmi10', 14),
71-
r'\Gamma' : ('cmmi10', 37),
72-
r'\Delta' : ('cmmi10', 11),
73-
r'\Theta' : ('cmmi10', 12),
74-
r'\Lambda' : ('cmmi10', 26),
75-
r'\Xi' : ('cmmi10', 4),
76-
r'\Pi' : ('cmmi10', 33),
77-
r'\Sigma' : ('cmmi10', 16),
78-
r'\Upsilon' : ('cmmi10', 19),
79-
r'\Phi' : ('cmmi10', 15),
80-
r'\Psi' : ('cmmi10', 27),
81-
r'\Omega' : ('cmmi10', 23),
8271
r'\alpha' : ('cmmi10', 13),
8372
r'\beta' : ('cmmi10', 35),
8473
r'\gamma' : ('cmmi10', 24),
@@ -128,6 +117,17 @@
128117
r'%' : ('cmr10', 48),
129118
r'\$' : ('cmr10', 99),
130119
r'@' : ('cmr10', 111),
120+
r'\Gamma' : ('cmr10', 19),
121+
r'\Delta' : ('cmr10', 6),
122+
r'\Theta' : ('cmr10', 7),
123+
r'\Lambda' : ('cmr10', 14),
124+
r'\Xi' : ('cmr10', 3),
125+
r'\Pi' : ('cmr10', 17),
126+
r'\Sigma' : ('cmr10', 10),
127+
r'\Upsilon' : ('cmr10', 11),
128+
r'\Phi' : ('cmr10', 9),
129+
r'\Psi' : ('cmr10', 15),
130+
r'\Omega' : ('cmr10', 12),
131131

132132
# these are mathml names, I think. I'm just using them for the
133133
# tex methods noted

lib/matplotlib/mathtext.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _get_info (self, fontname, sym, fontsize, dpi, mark_as_used=True):
482482
if bunch is not None:
483483
return bunch
484484

485-
cached_font, num, symbol_name, fontsize = \
485+
cached_font, num, symbol_name, fontsize, slanted = \
486486
self._get_glyph(fontname, sym, fontsize)
487487

488488
font = cached_font.font
@@ -500,7 +500,8 @@ def _get_info (self, fontname, sym, fontsize, dpi, mark_as_used=True):
500500
ymin = ymin+offset,
501501
ymax = ymax+offset,
502502
# iceberg is the equivalent of TeX's "height"
503-
iceberg = glyph.horiBearingY/64.0 + offset
503+
iceberg = glyph.horiBearingY/64.0 + offset,
504+
slanted = slanted
504505
)
505506

506507
self.glyphd[key] = Bunch(
@@ -558,21 +559,25 @@ def _get_offset(self, cached_font, glyph, fontsize, dpi):
558559
return glyph.height/64.0/2.0 + 256.0/64.0 * dpi/72.0
559560
return 0.
560561

562+
_slanted_symbols = Set(r"\int \oint".split())
563+
561564
def _get_glyph(self, fontname, sym, fontsize):
562565
if fontname in self.fontmap and latex_to_bakoma.has_key(sym):
563566
basename, num = latex_to_bakoma[sym]
567+
slanted = basename == "cmmi10" or sym in self._slanted_symbols
564568
cached_font = self._get_font(basename)
565569
symbol_name = cached_font.font.get_glyph_name(num)
566570
num = cached_font.glyphmap[num]
567571
elif len(sym) == 1:
572+
slanted = (fontname == "it")
568573
cached_font = self._get_font(fontname)
569574
num = ord(sym)
570575
symbol_name = cached_font.font.get_glyph_name(
571576
cached_font.charmap[num])
572577
else:
573578
raise ValueError('unrecognized symbol "%s"' % sym)
574579

575-
return cached_font, num, symbol_name, fontsize
580+
return cached_font, num, symbol_name, fontsize, slanted
576581

577582
# The Bakoma fonts contain many pre-sized alternatives for the
578583
# delimiters. The AutoSizedChar class will use these alternatives
@@ -666,6 +671,8 @@ def _get_glyph(self, fontname, sym, fontsize):
666671
and not category(unichr(uniindex)).startswith("L")):
667672
fontname = 'rm'
668673

674+
slanted = (fontname == 'it')
675+
669676
cached_font = self._get_font(fontname)
670677
if found_symbol:
671678
try:
@@ -681,7 +688,7 @@ def _get_glyph(self, fontname, sym, fontsize):
681688
glyphindex = cached_font.charmap[uniindex]
682689

683690
symbol_name = cached_font.font.get_glyph_name(glyphindex)
684-
return cached_font, uniindex, symbol_name, fontsize
691+
return cached_font, uniindex, symbol_name, fontsize, slanted
685692

686693
class StandardPsFonts(Fonts):
687694
"""
@@ -759,6 +766,8 @@ def _get_info (self, fontname, sym, fontsize, dpi):
759766
else:
760767
warn("No TeX to built-in Postscript mapping for '%s'" % sym,
761768
MathTextWarning)
769+
770+
slanted = (fontname == 'it')
762771
font = self._get_font(fontname)
763772

764773
if found_symbol:
@@ -772,7 +781,8 @@ def _get_info (self, fontname, sym, fontsize, dpi):
772781

773782
if not found_symbol:
774783
glyph = sym = '?'
775-
symbol_name = font.get_char_name(glyph)
784+
num = ord(glyph)
785+
symbol_name = font.get_name_char(glyph)
776786

777787
offset = 0
778788

@@ -789,7 +799,8 @@ def _get_info (self, fontname, sym, fontsize, dpi):
789799
ymin = ymin+offset,
790800
ymax = ymax+offset,
791801
# iceberg is the equivalent of TeX's "height"
792-
iceberg = ymax + offset
802+
iceberg = ymax + offset,
803+
slanted = slanted
793804
)
794805

795806
self.glyphd[key] = Bunch(
@@ -963,6 +974,9 @@ def _update_metrics(self):
963974
self.width = metrics.width
964975
self.height = metrics.iceberg
965976
self.depth = -(metrics.iceberg - metrics.height)
977+
978+
def is_slanted(self):
979+
return self._metrics.slanted
966980

967981
def get_kerning(self, next):
968982
"""Return the amount of kerning between this and the given
@@ -2019,6 +2033,11 @@ def is_dropsub(self, nucleus):
20192033
if isinstance(nucleus, Char):
20202034
return nucleus.c in self._dropsub_symbols
20212035
return False
2036+
2037+
def is_slanted(self, nucleus):
2038+
if isinstance(nucleus, Char):
2039+
return nucleus.is_slanted()
2040+
return False
20222041

20232042
def subsuperscript(self, s, loc, toks):
20242043
assert(len(toks)==1)
@@ -2126,7 +2145,8 @@ def subsuperscript(self, s, loc, toks):
21262145
if clr > 0.:
21272146
shift_up += clr
21282147
shift_down += clr
2129-
x.shift_amount = DELTA * (shift_up + shift_down)
2148+
if self.is_slanted(nucleus):
2149+
x.shift_amount = DELTA * (shift_up + shift_down)
21302150
x = Vlist([x,
21312151
Kern((shift_up - x.depth) - (y.height - shift_down)),
21322152
y])
@@ -2296,11 +2316,7 @@ def __call__(self, s, dpi, prop, angle=0):
22962316
font_output.mathtext_backend.fonts_object = None
22972317
return self.cache[cacheKey]
22982318

2299-
if rcParams["mathtext.mathtext2"]:
2300-
from matplotlib.mathtext2 import math_parse_s_ft2font
2301-
from matplotlib.mathtext2 import math_parse_s_ft2font_svg
2302-
else:
2303-
math_parse_s_ft2font = math_parse_s_ft2font_common('Agg')
2304-
math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
2319+
math_parse_s_ft2font = math_parse_s_ft2font_common('Agg')
2320+
math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
23052321
math_parse_s_ps = math_parse_s_ft2font_common('PS')
23062322
math_parse_s_pdf = math_parse_s_ft2font_common('PDF')

0 commit comments

Comments
 (0)