@@ -532,7 +532,7 @@ def _get_info (self, fontname, sym, fontsize, dpi, mark_as_used=True):
532532 slanted = slanted
533533 )
534534
535- self .glyphd [key ] = Bunch (
535+ result = self .glyphd [key ] = Bunch (
536536 font = font ,
537537 fontsize = fontsize ,
538538 postscript_name = font .postscript_name ,
@@ -542,7 +542,7 @@ def _get_info (self, fontname, sym, fontsize, dpi, mark_as_used=True):
542542 glyph = glyph ,
543543 offset = offset
544544 )
545- return self . glyphd [ key ]
545+ return result
546546
547547 def get_xheight (self , font , fontsize , dpi ):
548548 cached_font = self ._get_font (font )
@@ -2343,7 +2343,7 @@ def auto_sized_delimiter(self, s, loc, toks):
23432343##############################################################################
23442344# MAIN
23452345
2346- class math_parse_s_ft2font_common :
2346+ class MathTextParser :
23472347 """
23482348 Parse the math expression s, return the (bbox, fonts) tuple needed
23492349 to render it.
@@ -2352,40 +2352,38 @@ class math_parse_s_ft2font_common:
23522352
23532353 return is width, height, fonts
23542354 """
2355- major , minor1 , minor2 , tmp , tmp = sys .version_info
2356- if major == 2 and minor1 == 2 :
2357- raise SystemExit ('mathtext broken on python2.2. We hope to get this fixed soon' )
2358-
23592355 _parser = None
2360-
2356+
23612357 _backend_mapping = {
23622358 'Agg' : MathtextBackendAgg ,
23632359 'PS' : MathtextBackendPs ,
2364- 'PDF ' : MathtextBackendPdf ,
2360+ 'Pdf ' : MathtextBackendPdf ,
23652361 'SVG' : MathtextBackendSvg ,
23662362 'Cairo' : MathtextBackendCairo
23672363 }
23682364
23692365 def __init__ (self , output ):
2370- self .output = output
2371- self .cache = {}
2366+ self ._output = output
2367+ self ._cache = {}
23722368
2373- def __call__ (self , s , dpi , prop ):
2369+ def parse (self , s , dpi , prop ):
23742370 cacheKey = (s , dpi , hash (prop ))
2375- if self .cache . has_key (cacheKey ):
2376- result = self . cache [ cacheKey ]
2371+ result = self ._cache . get (cacheKey )
2372+ if result is not None :
23772373 return result
23782374
2379- if self .output == 'PS' and rcParams ['ps.useafm' ]:
2375+ if self ._output == 'PS' and rcParams ['ps.useafm' ]:
23802376 font_output = StandardPsFonts (prop )
23812377 else :
2382- backend = self ._backend_mapping [self .output ]()
2378+ backend = self ._backend_mapping [self ._output ]()
23832379 if rcParams ['mathtext.use_cm' ]:
23842380 font_output = BakomaFonts (prop , backend )
23852381 else :
23862382 font_output = UnicodeFonts (prop , backend )
23872383
23882384 fontsize = prop .get_size_in_points ()
2385+ # This is a class variable so we don't rebuild the parser
2386+ # with each request.
23892387 if self ._parser is None :
23902388 self .__class__ ._parser = Parser ()
23912389 box = self ._parser .parse (s , font_output , fontsize , dpi )
@@ -2395,16 +2393,16 @@ def __call__(self, s, dpi, prop):
23952393 font_output .set_canvas_size (w , h )
23962394 ship (2 , 2 , box )
23972395 result = font_output .get_results ()
2398- self .cache [cacheKey ] = result
2396+ self ._cache [cacheKey ] = result
23992397 # Free up the transient data structures
24002398 self ._parser .clear ()
24012399 # Remove a cyclical reference
24022400 font_output .mathtext_backend .fonts_object = None
24032401
24042402 return result
24052403
2406- math_parse_s_ft2font = math_parse_s_ft2font_common ('Agg' )
2407- math_parse_s_ft2font_svg = math_parse_s_ft2font_common ('SVG' )
2408- math_parse_s_ps = math_parse_s_ft2font_common ('PS' )
2409- math_parse_s_pdf = math_parse_s_ft2font_common ('PDF' )
2410- math_parse_s_cairo = math_parse_s_ft2font_common ('Cairo' )
2404+ # math_parse_s_ft2font = math_parse_s_ft2font_common('Agg')
2405+ # math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
2406+ # math_parse_s_ps = math_parse_s_ft2font_common('PS')
2407+ # math_parse_s_pdf = math_parse_s_ft2font_common('PDF')
2408+ # math_parse_s_cairo = math_parse_s_ft2font_common('Cairo')
0 commit comments