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

Skip to content

Commit fe60db5

Browse files
committed
Fixes bounding box bug with Agg backend.
Fixes spacing bug when using standard Ps fonts. Reduces memory usage by not caching mathtext expressions for too long. svn path=/trunk/matplotlib/; revision=3755
1 parent a0e0656 commit fe60db5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ def _update_bbox(self, x1, y1, x2, y2):
253253

254254
def render_glyph(self, ox, oy, info):
255255
self._update_bbox(ox + info.metrics.xmin,
256-
oy + info.metrics.ymin,
256+
oy - info.metrics.ymax,
257257
ox + info.metrics.xmax,
258-
oy + info.metrics.ymax)
258+
oy - info.metrics.ymin)
259259

260260
def render_rect_filled(self, x1, y1, x2, y2):
261261
self._update_bbox(x1, y1, x2, y2)
@@ -265,7 +265,8 @@ def get_results(self, box):
265265
bbox = self.bbox
266266
bbox = [bbox[0] - 2, bbox[1] - 2, bbox[2] + 2, bbox[3] + 2]
267267
self._switch_to_real_backend()
268-
self.fonts_object.set_canvas_size(bbox[2] - bbox[0], bbox[3] - bbox[1])
268+
self.fonts_object.set_canvas_size(
269+
bbox[2] - bbox[0], bbox[3] - bbox[1])
269270
ship(-bbox[0], -bbox[1], box)
270271
return self.fonts_object.get_results(box)
271272

@@ -321,6 +322,8 @@ def render_glyph(self, ox, oy, info):
321322
fontsize = info.fontsize
322323
symbol_name = info.symbol_name
323324

325+
# TODO: Optimize out the font changes
326+
324327
ps = """/%(postscript_name)s findfont
325328
%(fontsize)s scalefont
326329
setfont
@@ -928,7 +931,7 @@ def _get_info (self, fontname, sym, fontsize, dpi):
928931
xmin, ymin, xmax, ymax = [val * scale
929932
for val in font.get_bbox_char(glyph)]
930933
metrics = Bunch(
931-
advance = (xmax-xmin),
934+
advance = font.get_width_char(glyph) * scale,
932935
width = font.get_width_char(glyph) * scale,
933936
height = font.get_height_char(glyph) * scale,
934937
xmin = xmin,
@@ -2439,6 +2442,7 @@ def parse(self, s, dpi, prop):
24392442
cacheKey = (s, dpi, hash(prop))
24402443
result = self._cache.get(cacheKey)
24412444
if result is not None:
2445+
del self._cache[cacheKey]
24422446
return result
24432447

24442448
if self._output == 'PS' and rcParams['ps.useafm']:

0 commit comments

Comments
 (0)