@@ -70,7 +70,7 @@ def __init__(self, width, height, dpi):
70
70
self ._filter_renderers = []
71
71
72
72
self ._update_methods ()
73
- self .mathtext_parser = MathTextParser ('agg ' )
73
+ self .mathtext_parser = MathTextParser ('path ' )
74
74
75
75
self .bbox = Bbox .from_bounds (0 , 0 , self .width , self .height )
76
76
@@ -172,36 +172,35 @@ def draw_path(self, gc, path, transform, rgbFace=None):
172
172
173
173
def draw_mathtext (self , gc , x , y , s , prop , angle ):
174
174
"""Draw mathtext using :mod:`matplotlib.mathtext`."""
175
- ox , oy , width , height , descent , font_image = \
176
- self .mathtext_parser .parse (s , self .dpi , prop ,
177
- antialiased = gc .get_antialiased ())
178
-
179
- xd = descent * sin (radians (angle ))
180
- yd = descent * cos (radians (angle ))
181
- x = round (x + ox + xd )
182
- y = round (y - oy + yd )
183
- self ._renderer .draw_text_image (font_image , x , y + 1 , angle , gc )
175
+ parse = self .mathtext_parser .parse (
176
+ s , self .dpi , prop , antialiased = gc .get_antialiased ())
177
+ c = cos (radians (angle ))
178
+ s = sin (radians (angle ))
179
+ for font , size , char , dx , dy in parse .glyphs :
180
+ font .set_size (size , self .dpi )
181
+ bitmap = font ._render_glyph (
182
+ font .get_char_index (char ),
183
+ x + dx * c - dy * s , self .height - y + dx * s + dy * c , angle ,
184
+ get_hinting_flag ())
185
+ self ._renderer .draw_text_image (
186
+ bitmap ["buffer" ],
187
+ bitmap ["left" ],
188
+ int (self .height ) - bitmap ["top" ] + bitmap ["buffer" ].shape [0 ],
189
+ 0 , gc )
190
+ # TODO: Also draw rects (fraction bars, etc.) with draw_path().
184
191
185
192
def draw_text (self , gc , x , y , s , prop , angle , ismath = False , mtext = None ):
186
193
# docstring inherited
187
194
if ismath :
188
195
return self .draw_mathtext (gc , x , y , s , prop , angle )
189
196
font = self ._prepare_font (prop )
190
- # We pass '0' for angle here, since it will be rotated (in raster
191
- # space) in the following call to draw_text_image).
192
- font .set_text (s , 0 , flags = get_hinting_flag ())
193
- font .draw_glyphs_to_bitmap (
194
- antialiased = gc .get_antialiased ())
195
- d = font .get_descent () / 64.0
196
- # The descent needs to be adjusted for the angle.
197
- xo , yo = font .get_bitmap_offset ()
198
- xo /= 64.0
199
- yo /= 64.0
200
- xd = d * sin (radians (angle ))
201
- yd = d * cos (radians (angle ))
202
- x = round (x + xo + xd )
203
- y = round (y + yo + yd )
204
- self ._renderer .draw_text_image (font , x , y + 1 , angle , gc )
197
+ font .set_text (s , angle , flags = get_hinting_flag ())
198
+ for bitmap in font ._render_glyphs (x , self .height - y ):
199
+ self ._renderer .draw_text_image (
200
+ bitmap ["buffer" ],
201
+ bitmap ["left" ],
202
+ int (self .height ) - bitmap ["top" ] + bitmap ["buffer" ].shape [0 ],
203
+ 0 , gc )
205
204
206
205
def get_text_width_height_descent (self , s , prop , ismath ):
207
206
# docstring inherited
@@ -211,9 +210,8 @@ def get_text_width_height_descent(self, s, prop, ismath):
211
210
return super ().get_text_width_height_descent (s , prop , ismath )
212
211
213
212
if ismath :
214
- ox , oy , width , height , descent , font_image = \
215
- self .mathtext_parser .parse (s , self .dpi , prop )
216
- return width , height , descent
213
+ parse = self .mathtext_parser .parse (s , self .dpi , prop )
214
+ return parse .width , parse .height , parse .depth
217
215
218
216
font = self ._prepare_font (prop )
219
217
font .set_text (s , 0.0 , flags = get_hinting_flag ())
0 commit comments