@@ -172,68 +172,58 @@ def update_from(self, other):
172172 self ._linespacing = other ._linespacing
173173
174174 def _get_layout (self , renderer ):
175- # layout the xylocs in display coords as if angle = zero and
176- # then rotate them around self._x, self._y
177- #return _unit_box
178175 key = self .get_prop_tup ()
179176 if self .cached .has_key (key ): return self .cached [key ]
180- horizLayout = []
181- transform = self .get_transform ()
182- x , y = self .get_position ()
183- thisx , thisy = transform .transform_point ((x , y ))
184- tx , ty = thisx , thisy
185177
186- width = 0
187- height = 0
178+ horizLayout = []
188179
189- xmin , ymin = thisx , thisy
180+ thisx , thisy = 0.0 , 0.0
181+ xmin , ymin = 0.0 , 0.0
182+ width , height = 0.0 , 0.0
190183 lines = self ._text .split ('\n ' )
191184
192- whs = []
185+ whs = npy .zeros ((len (lines ), 2 ))
186+ horizLayout = npy .zeros ((len (lines ), 4 ))
193187 # Find full vertical extent of font,
194188 # including ascenders and descenders:
195189 tmp , heightt , bl = renderer .get_text_width_height_descent (
196190 'lp' , self ._fontproperties , ismath = False )
197191 offsety = heightt * self ._linespacing
198192
199193 baseline = None
200- for line in lines :
194+ for i , line in enumerate ( lines ) :
201195 w , h , d = renderer .get_text_width_height_descent (
202196 line , self ._fontproperties , ismath = self .is_math_text (line ))
203197 if baseline is None :
204198 baseline = h - d
205- whs . append ( ( w , h ) )
206- horizLayout . append (( line , thisx , thisy , w , h ))
199+ whs [ i ] = w , h
200+ horizLayout [ i ] = thisx , thisy , w , h
207201 thisy -= offsety
208202 width = max (width , w )
209203
210- ymin = horizLayout [- 1 ][2 ]
211- ymax = horizLayout [0 ][2 ] + horizLayout [0 ][- 1 ]
204+ ymin = horizLayout [- 1 ][1 ]
205+ ymax = horizLayout [0 ][1 ] + horizLayout [0 ][3 ]
212206 height = ymax - ymin
213-
214207 xmax = xmin + width
208+
215209 # get the rotation matrix
216- M = self .get_rotation_matrix ( xmin , ymin )
210+ M = Affine2D (). rotate_deg ( self .get_rotation () )
217211
218- # the corners of the unrotated bounding box
219- cornersHoriz = npy .array (
220- [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )],
221- npy .float_ )
222212 offsetLayout = npy .zeros ((len (lines ), 2 ))
213+ offsetLayout [:] = horizLayout [:, 0 :2 ]
223214 # now offset the individual text lines within the box
224215 if len (lines )> 1 : # do the multiline aligment
225216 malign = self ._get_multialignment ()
226- for i , (line , thisx , thisy , w , h ) in enumerate (horizLayout ):
227- if malign == 'center' : offsetx = width / 2.0 - w / 2.0
228- elif malign == 'right' : offsetx = width - w
229- else : offsetx = 0
230- thisx += offsetx
231- offsetLayout [i ] = (thisx , thisy )
232- else : # no additional layout needed
233- offsetLayout [0 ] = horizLayout [0 ][1 :3 ]
217+ if malign == 'center' :
218+ offsetLayout [:, 0 ] += width / 2.0 - horizLayout [:, 2 ] / 2.0
219+ elif malign == 'right' :
220+ offsetLayout [:, 0 ] += width - horizLayout [:, 2 ]
234221
222+ # the corners of the unrotated bounding box
223+ cornersHoriz = npy .array (
224+ [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )],
225+ npy .float_ )
235226 # now rotate the bbox
236-
237227 cornersRotated = M .transform (cornersHoriz )
238228
239229 txs = cornersRotated [:, 0 ]
@@ -251,37 +241,30 @@ def _get_layout(self, renderer):
251241
252242 # compute the text location in display coords and the offsets
253243 # necessary to align the bbox with that location
254- tx , ty = self ._get_xy_display ()
255-
256- if halign == 'center' : offsetx = tx - (xmin + width / 2.0 )
257- elif halign == 'right' : offsetx = tx - (xmin + width )
258- else : offsetx = tx - xmin
244+ if halign == 'center' : offsetx = (xmin + width / 2.0 )
245+ elif halign == 'right' : offsetx = (xmin + width )
246+ else : offsetx = xmin
259247
260- if valign == 'center' : offsety = ty - (ymin + height / 2.0 )
261- elif valign == 'top' : offsety = ty - (ymin + height )
262- elif valign == 'baseline' : offsety = ty - (ymin + height ) + baseline
263- else : offsety = ty - ymin
248+ if valign == 'center' : offsety = (ymin + height / 2.0 )
249+ elif valign == 'top' : offsety = (ymin + height )
250+ elif valign == 'baseline' : offsety = (ymin + height ) + baseline
251+ else : offsety = ymin
264252
265- xmin + = offsetx
266- ymin + = offsety
253+ xmin - = offsetx
254+ ymin - = offsety
267255
268256 bbox = Bbox .from_lbwh (xmin , ymin , width , height )
269257
270258 # now rotate the positions around the first x,y position
271259 xys = M .transform (offsetLayout )
272- xys += (offsetx , offsety )
273-
274- # now inverse transform back to data coords
275- inverse_transform = transform .inverted ()
276- xys = inverse_transform .transform (xys )
260+ xys -= (offsetx , offsety )
277261
278262 xs , ys = xys [:, 0 ], xys [:, 1 ]
279263
280264 ret = bbox , zip (lines , whs , xs , ys )
281265 self .cached [key ] = ret
282266 return ret
283267
284-
285268 def set_bbox (self , rectprops ):
286269 """
287270 Draw a bounding box around self. rect props are any settable
@@ -307,28 +290,30 @@ def draw(self, renderer):
307290 if self .get_clip_on ():
308291 gc .set_clip_rectangle (self .clipbox )
309292
310-
311-
312293 if self ._bbox :
313294 bbox_artist (self , renderer , self ._bbox )
314295 angle = self .get_rotation ()
315296
316297 bbox , info = self ._get_layout (renderer )
317298 trans = self .get_transform ()
299+ posx , posy = self .get_position ()
300+ posx , posy = trans .transform_point ((posx , posy ))
301+ canvasw , canvash = renderer .get_canvas_width_height ()
302+
318303 if rcParams ['text.usetex' ]:
319- canvasw , canvash = renderer .get_canvas_width_height ()
320304 for line , wh , x , y in info :
321- x , y = trans .transform_point ((x , y ))
305+ x = x + posx
306+ y = y + posy
322307 if renderer .flipy ():
323308 y = canvash - y
324309
325310 renderer .draw_tex (gc , x , y , line ,
326311 self ._fontproperties , angle )
327312 return
328313
329- canvasw , canvash = renderer .get_canvas_width_height ()
330314 for line , wh , x , y in info :
331- x , y = trans .transform_point ((x , y ))
315+ x = x + posx
316+ y = y + posy
332317 if renderer .flipy ():
333318 y = canvash - y
334319
@@ -402,8 +387,7 @@ def get_prop_tup(self):
402387 x , y = self .get_position ()
403388 return (x , y , self ._text , self ._color ,
404389 self ._verticalalignment , self ._horizontalalignment ,
405- hash (self ._fontproperties ), self ._rotation ,
406- self .get_transform ().id
390+ hash (self ._fontproperties ), self ._rotation
407391 )
408392
409393 def get_text (self ):
@@ -432,11 +416,11 @@ def get_window_extent(self, renderer=None):
432416
433417 angle = self .get_rotation ()
434418 bbox , info = self ._get_layout (self ._renderer )
419+ x , y = self .get_position ()
420+ x , y = self .get_transform ().transform_point ((x , y ))
421+ bbox = bbox .translated (x , y )
435422 return bbox
436423
437- def get_rotation_matrix (self , x0 , y0 ):
438- return Affine2D ().rotate_deg_around (x0 , y0 , self .get_rotation ())
439-
440424 def set_backgroundcolor (self , color ):
441425 """
442426 Set the background color of the text by updating the bbox (see set_bbox for more info)
0 commit comments