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

Skip to content

Commit e3236e9

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 1101b8e commit e3236e9

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
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 & 10 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):
@@ -147,7 +146,6 @@ def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi):
147146
parameters (see `get_metrics` for their detailed description).
148147
"""
149148
info = self._get_info(font, font_class, sym, fontsize, dpi)
150-
self.used_characters.setdefault(info.font.fname, set()).add(info.num)
151149
self.mathtext_backend.render_glyph(ox, oy, info)
152150

153151
def render_rect_filled(self, x1, y1, x2, y2):
@@ -169,14 +167,6 @@ def get_underline_thickness(self, font, fontsize, dpi):
169167
"""
170168
raise NotImplementedError()
171169

172-
def get_used_characters(self):
173-
"""
174-
Get the set of characters that were used in the math
175-
expression. Used by backends that need to subset fonts so
176-
they know which glyphs to include.
177-
"""
178-
return self.used_characters
179-
180170
def get_sized_alternatives_for_symbol(self, fontname, sym):
181171
"""
182172
Override if your font provides multiple sizes of the same

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))
@@ -260,7 +260,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
260260
return w, h, d
261261

262262
if ismath:
263-
ox, oy, width, height, descent, fonts, used_characters = \
263+
ox, oy, width, height, descent, font_image = \
264264
self.mathtext_parser.parse(s, self.dpi, prop)
265265
return width, height, descent
266266

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)