@@ -141,64 +141,80 @@ class MathtextBackendAgg(MathtextBackend):
141
141
"""
142
142
def __init__ (self ):
143
143
MathtextBackend .__init__ (self )
144
- self .bbox = [0 ,0 ,0 ,0 ]
144
+ self ._xmin = self ._ymin = np .inf
145
+ self ._xmax = self ._ymax = - np .inf
145
146
self ._glyphs = []
146
147
self ._rects = []
147
148
148
- ox = property (cbook .deprecated ("3.2" )(lambda self :0 ))
149
- oy = property (cbook .deprecated ("3.2" )(lambda self :0 ))
150
- image = property (cbook .deprecated ("3.2" )(lambda self :None ))
151
- mode = property (cbook .deprecated ("3.2" )(lambda self :"bbox" ))
149
+ @cbook .deprecated ("3.2" )
150
+ @property
151
+ def ox (self ):
152
+ return 0
153
+
154
+ @cbook .deprecated ("3.2" )
155
+ @property
156
+ def oy (self ):
157
+ return 0
158
+
159
+ @cbook .deprecated ("3.2" )
160
+ @property
161
+ def bbox (self ):
162
+ return [self ._xmin ,self ._ymin ,self ._xmax ,self ._ymax ]
163
+
164
+ @cbook .deprecated ("3.2" )
165
+ @property
166
+ def mode (self ):
167
+ return "bbox"
152
168
153
- def _update_bbox (self ,x1 ,y1 ,x2 ,y2 ):
154
- self .bbox = [min (self .bbox [0 ],x1 ),
155
- min (self .bbox [1 ],y1 ),
156
- max (self .bbox [2 ],x2 ),
157
- max (self .bbox [3 ],y2 )]
169
+ @cbook .deprecated ("3.2" )
170
+ @property
171
+ def image (self ):
172
+ return None
158
173
159
174
def render_glyph (self ,ox ,oy ,info ):
160
175
self ._glyphs .append ((ox ,oy ,info ))
161
- self ._update_bbox (ox + info .metrics .xmin ,
162
- oy - info .metrics .ymax ,
163
- ox + info .metrics .xmax ,
164
- oy - info .metrics .ymin )
176
+ metrics = info .metrics
177
+ self ._xmin = min (self ._xmin ,ox + metrics .xmin )
178
+ self ._ymin = min (self ._ymin ,self .height - oy + metrics .ymin )
179
+ self ._xmax = max (self ._xmax ,ox + metrics .xmax )
180
+ self ._ymax = max (self ._ymax ,self .height - oy + metrics .ymax )
165
181
166
182
def render_rect_filled (self ,x1 ,y1 ,x2 ,y2 ):
167
183
self ._rects .append ((x1 ,y1 ,x2 ,y2 ))
168
- self ._update_bbox (x1 ,y1 ,x2 ,y2 )
184
+ self ._xmin = min (self ._xmin ,x1 )
185
+ self ._xmax = max (self ._xmax ,x2 )
186
+ self ._ymin = min (self ._ymin ,y1 )
187
+ self ._ymax = max (self ._ymax ,y2 )
169
188
170
189
def get_results (self ,box ,used_characters ):
171
190
orig_height = box .height
172
- orig_depth = box .depth
191
+ orig_depth = box .depth
173
192
ship (0 ,0 ,box )
174
- bbox = xmin ,ymin ,xmax ,ymax = [self .bbox [0 ]- 1 ,self .bbox [1 ]- 1 ,
175
- self .bbox [2 ]+ 1 ,self .bbox [3 ]+ 1 ]
176
- self .set_canvas_size (
177
- xmax - xmin ,
178
- ymax - ymin - orig_depth ,
179
- ymax - ymin - orig_height )
180
- image = FT2Image (
181
- np .ceil (self .width ),np .ceil (self .height + max (self .depth ,0 )))
193
+ xmin = self ._xmin - 1
194
+ xmax = self ._xmax + 1
195
+ ymin = self ._ymin - 1
196
+ ymax = self ._ymax + 1
197
+ image = FT2Image (np .ceil (xmax - xmin ),np .ceil (ymax - ymin ))
182
198
183
199
for ox ,oy ,info in self ._glyphs :
184
200
info .font .draw_glyph_to_bitmap (
185
- image ,ox - xmin ,oy - info .metrics .iceberg - ymin ,
201
+ image ,ox + 1 ,oy - info .metrics .iceberg + 1 ,
186
202
info .glyph ,antialiased = rcParams ['text.antialiased' ])
187
203
for x1 ,y1 ,x2 ,y2 in self ._rects :
188
- x1 -= xmin
189
- x2 -= xmin
190
- y1 -= ymin
191
- y2 -= ymin
204
+ x1 += 1
205
+ x2 += 1
206
+ y1 += 1
207
+ y2 += 1
192
208
height = max (int (y2 - y1 )- 1 ,0 )
193
209
if height == 0 :
194
- center = (y2 + y1 )/ 2.0
195
- y = int (center - (height + 1 )/ 2.0 )
210
+ center = (y2 + y1 )/ 2
211
+ y = int (center - (height + 1 )/ 2 )
196
212
else :
197
213
y = int (y1 )
198
214
image .draw_rect_filled (int (x1 ),y ,np .ceil (x2 ),y + height )
199
215
200
216
return (0 ,0 ,
201
- self . width , self . height + self . depth , self . depth ,
217
+ np . ceil ( xmax - xmin ), np . ceil ( ymax - ymin ), - ymin ,
202
218
image ,
203
219
used_characters )
204
220