@@ -263,6 +263,41 @@ def test_annotation_negative_coords():
263
263
ax .annotate ("-apx" , (- 25 , - 10 ), xycoords = "axes pixels" )
264
264
265
265
266
+ def test_text_annotation_get_window_extent ():
267
+ from matplotlib .figure import Figure
268
+ from matplotlib .text import Annotation , Text
269
+ from matplotlib .backends .backend_agg import RendererAgg
270
+
271
+ figure = Figure (dpi = 100 )
272
+ renderer = RendererAgg (200 , 200 , 100 )
273
+
274
+
275
+ # Only text annotation
276
+ annotation = Annotation ('test' , xy = (0 , 0 ))
277
+ annotation .set_figure (figure )
278
+
279
+ text = Text (text = 'test' , x = 0 , y = 0 )
280
+ text .set_figure (figure )
281
+
282
+ bbox = annotation .get_window_extent (renderer = renderer )
283
+
284
+ text_bbox = text .get_window_extent (renderer = renderer )
285
+ eq_ (bbox .width , text_bbox .width )
286
+ eq_ (bbox .height , text_bbox .height )
287
+
288
+ _ , _ , d = renderer .get_text_width_height_descent (
289
+ 'text' , annotation ._fontproperties , ismath = False )
290
+ _ , _ , lp_d = renderer .get_text_width_height_descent (
291
+ 'lp' , annotation ._fontproperties , ismath = False )
292
+ below_line = max (d , lp_d )
293
+
294
+ # These numbers are specific to the current implementation of Text
295
+ points = bbox .get_points ()
296
+ eq_ (points [0 , 0 ], 0.0 )
297
+ eq_ (points [1 , 0 ], text_bbox .width )
298
+ eq_ (points [0 , 1 ], - below_line )
299
+ eq_ (points [1 , 1 ], text_bbox .height - below_line )
300
+
266
301
def test_arrow_annotation_get_window_extent ():
267
302
from matplotlib .figure import Figure
268
303
from matplotlib .text import Annotation
0 commit comments