@@ -222,18 +222,12 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
222
222
223
223
def draw_text (self , gc , x , y , s , prop , angle , ismath = False , mtext = None ):
224
224
# docstring inherited
225
-
226
225
if ismath :
227
226
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 )
234
228
# We pass '0' for angle here, since it will be rotated (in raster
235
229
# 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 () )
237
231
font .draw_glyphs_to_bitmap (
238
232
antialiased = mpl .rcParams ['text.antialiased' ])
239
233
d = font .get_descent () / 64.0
@@ -264,9 +258,8 @@ def get_text_width_height_descent(self, s, prop, ismath):
264
258
self .mathtext_parser .parse (s , self .dpi , prop )
265
259
return width , height , descent
266
260
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 ())
270
263
w , h = font .get_width_height () # width and height of unrotated string
271
264
d = font .get_descent ()
272
265
w /= 64.0 # convert from subpixels
@@ -295,17 +288,14 @@ def get_canvas_width_height(self):
295
288
# docstring inherited
296
289
return self .width , self .height
297
290
298
- def _get_agg_font (self , prop ):
291
+ def _prepare_font (self , font_prop ):
299
292
"""
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.
301
294
"""
302
- fname = findfont (prop )
303
- font = get_font (fname )
304
-
295
+ font = get_font (findfont (font_prop ))
305
296
font .clear ()
306
- size = prop .get_size_in_points ()
297
+ size = font_prop .get_size_in_points ()
307
298
font .set_size (size , self .dpi )
308
-
309
299
return font
310
300
311
301
def points_to_pixels (self , points ):
0 commit comments