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

Skip to content

Commit a892892

Browse files
committed
Remove used_characters tracking in mathtext.
Backends that need to track what characters have been used (pdf/ps, for subsetting purposes) already have their own logic to do so, so don't do it in mathtext as well. Changes in Fonts are only touching private API. Changes in the call signature of MathtextBackendAgg/MathtextBackendPath look like they are touching public API, but it is in fact impossible for an external user to construct a valid `box` parameter (this requires classes defined in `_mathtext`), so `get_results` is effectively private API from a caller PoV. It is also impossible to register new MathtextBackends without touching private API. Thus, the only difference is in the tuple returned by MathtextBackendAgg, which now has one fewer element. Because the return value is a tuple which is unpacked at the call site, it is not possible to emit a proper deprecation warning (one would need to know whether the result is being unpacked to 6 or 7 values). Callers can work around this by e.g. unpacking the last item into `*_`. Note that because this is only for MathtextBackendAgg (i.e., a raster backend), it is unlikely that callers actually care about the used_characters info at all.
1 parent 4df33d2 commit a892892

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``MathtextBackendAgg.get_results`` no longer returns ``used_characters``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The last item (``used_characters``) in the tuple returned by
4+
``MathtextBackendAgg.get_results`` has been removed. In order to unpack this
5+
tuple in a backward and forward-compatible way, use e.g.
6+
``ox, oy, width, height, descent, image, *_ = parse(...)``,
7+
which will ignore ``used_characters`` if it was present.

lib/matplotlib/_mathtext.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def __init__(self, default_font_prop, mathtext_backend):
8989
"""
9090
self.default_font_prop = default_font_prop
9191
self.mathtext_backend = mathtext_backend
92-
self.used_characters = {}
9392

9493
def get_kern(self, font1, fontclass1, sym1, fontsize1,
9594
font2, fontclass2, sym2, fontsize2, dpi):
@@ -157,7 +156,6 @@ def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi):
157156
parameters (see `get_metrics` for their detailed description).
158157
"""
159158
info = self._get_info(font, font_class, sym, fontsize, dpi)
160-
self.used_characters.setdefault(info.font.fname, set()).add(info.num)
161159
self.mathtext_backend.render_glyph(ox, oy, info)
162160

163161
def render_rect_filled(self, x1, y1, x2, y2):

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
211211

212212
def draw_mathtext(self, gc, x, y, s, prop, angle):
213213
"""Draw mathtext using :mod:`matplotlib.mathtext`."""
214-
ox, oy, width, height, descent, font_image, used_characters = \
214+
ox, oy, width, height, descent, font_image = \
215215
self.mathtext_parser.parse(s, self.dpi, prop)
216216

217217
xd = descent * sin(radians(angle))
@@ -254,7 +254,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
254254
return w, h, d
255255

256256
if ismath:
257-
ox, oy, width, height, descent, fonts, used_characters = \
257+
ox, oy, width, height, descent, font_image = \
258258
self.mathtext_parser.parse(s, self.dpi, prop)
259259
return width, height, descent
260260

lib/matplotlib/mathtext.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
134134
y = int(y1)
135135
self.image.draw_rect_filled(int(x1), y, np.ceil(x2), y + height)
136136

137-
def get_results(self, box, used_characters):
137+
def get_results(self, box):
138138
self.mode = 'bbox'
139139
orig_height = box.height
140140
orig_depth = box.depth
@@ -152,8 +152,7 @@ def get_results(self, box, used_characters):
152152
self.width,
153153
self.height + self.depth,
154154
self.depth,
155-
self.image,
156-
used_characters)
155+
self.image)
157156
self.image = None
158157
return result
159158

@@ -182,7 +181,7 @@ def render_glyph(self, ox, oy, info):
182181
def render_rect_filled(self, x1, y1, x2, y2):
183182
self.rects.append((x1, self.height - y2, x2 - x1, y2 - y1))
184183

185-
def get_results(self, box, used_characters):
184+
def get_results(self, box):
186185
_mathtext.ship(0, 0, box)
187186
return self._Result(self.width,
188187
self.height + self.depth,

0 commit comments

Comments
 (0)