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

Skip to content

Commit 30d6161

Browse files
authored
Merge pull request #22467 from anntzer/gaf
Small cleanup to font handling in agg.
2 parents 98184f4 + 50252d2 commit 30d6161

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,12 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
222222

223223
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
224224
# docstring inherited
225-
226225
if ismath:
227226
return self.draw_mathtext(gc, x, y, s, prop, angle)
228-
229-
flags = get_hinting_flag()
230-
font = self._get_agg_font(prop)
231-
232-
if font is None:
233-
return None
227+
font = self._prepare_font(prop)
234228
# We pass '0' for angle here, since it will be rotated (in raster
235229
# space) in the following call to draw_text_image).
236-
font.set_text(s, 0, flags=flags)
230+
font.set_text(s, 0, flags=get_hinting_flag())
237231
font.draw_glyphs_to_bitmap(
238232
antialiased=mpl.rcParams['text.antialiased'])
239233
d = font.get_descent() / 64.0
@@ -264,9 +258,8 @@ def get_text_width_height_descent(self, s, prop, ismath):
264258
self.mathtext_parser.parse(s, self.dpi, prop)
265259
return width, height, descent
266260

267-
flags = get_hinting_flag()
268-
font = self._get_agg_font(prop)
269-
font.set_text(s, 0.0, flags=flags)
261+
font = self._prepare_font(prop)
262+
font.set_text(s, 0.0, flags=get_hinting_flag())
270263
w, h = font.get_width_height() # width and height of unrotated string
271264
d = font.get_descent()
272265
w /= 64.0 # convert from subpixels
@@ -295,17 +288,14 @@ def get_canvas_width_height(self):
295288
# docstring inherited
296289
return self.width, self.height
297290

298-
def _get_agg_font(self, prop):
291+
def _prepare_font(self, font_prop):
299292
"""
300-
Get the font for text instance t, caching for efficiency
293+
Get the `.FT2Font` for *font_prop*, clear its buffer, and set its size.
301294
"""
302-
fname = findfont(prop)
303-
font = get_font(fname)
304-
295+
font = get_font(findfont(font_prop))
305296
font.clear()
306-
size = prop.get_size_in_points()
297+
size = font_prop.get_size_in_points()
307298
font.set_size(size, self.dpi)
308-
309299
return font
310300

311301
def points_to_pixels(self, points):

0 commit comments

Comments
 (0)