@@ -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
686693class 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' )
23052321math_parse_s_ps = math_parse_s_ft2font_common ('PS' )
23062322math_parse_s_pdf = math_parse_s_ft2font_common ('PDF' )
0 commit comments