@@ -769,10 +769,11 @@ def draw(self, renderer):
769
769
770
770
class TextArea (OffsetBox ):
771
771
"""
772
- The TextArea is contains a single Text instance. The text is
773
- placed at (0, 0) with baseline+left alignment. The width and height
774
- of the TextArea instance is the width and height of the its child
775
- text.
772
+ The TextArea is a container artist for a single Text instance.
773
+
774
+ The text is placed at (0, 0) with baseline+left alignment, by default. The
775
+ width and height of the TextArea instance is the width and height of its
776
+ child text.
776
777
"""
777
778
def __init__ (self , s ,
778
779
textprops = None ,
@@ -876,37 +877,43 @@ def get_offset(self):
876
877
def get_window_extent (self , renderer ):
877
878
"""Return the bounding box in display space."""
878
879
w , h , xd , yd = self .get_extent (renderer )
879
- ox , oy = self .get_offset () # w, h, xd, yd)
880
+ ox , oy = self .get_offset ()
880
881
return mtransforms .Bbox .from_bounds (ox - xd , oy - yd , w , h )
881
882
882
883
def get_extent (self , renderer ):
883
884
_ , h_ , d_ = renderer .get_text_width_height_descent (
884
885
"lp" , self ._text ._fontproperties , ismath = False )
885
886
886
- bbox , info , d = self ._text ._get_layout (renderer )
887
+ bbox , info , yd = self ._text ._get_layout (renderer )
887
888
w , h = bbox .width , bbox .height
888
889
889
890
self ._baseline_transform .clear ()
890
891
891
892
if len (info ) > 1 and self ._multilinebaseline :
892
- d_new = 0.5 * h - 0.5 * (h_ - d_ )
893
- self ._baseline_transform .translate (0 , d - d_new )
894
- d = d_new
893
+ yd_new = 0.5 * h - 0.5 * (h_ - d_ )
894
+ self ._baseline_transform .translate (0 , yd - yd_new )
895
+ yd = yd_new
895
896
896
897
else : # single line
897
898
898
- h_d = max (h_ - d_ , h - d )
899
+ h_d = max (h_ - d_ , h - yd )
899
900
900
901
if self .get_minimumdescent ():
901
- ## to have a minimum descent, #i.e., "l" and "p" have same
902
- ## descents.
903
- d = max (d , d_ )
904
- #else:
905
- # d = d
902
+ # To have a minimum descent, i.e., "l" and "p" have same
903
+ # descents.
904
+ yd = max (yd , d_ )
906
905
907
- h = h_d + d
906
+ h = h_d + yd
908
907
909
- return w , h , 0. , d
908
+ ha = self ._text .get_horizontalalignment ()
909
+ if ha == 'left' :
910
+ xd = 0
911
+ elif ha == 'center' :
912
+ xd = w / 2
913
+ elif ha == 'right' :
914
+ xd = w
915
+
916
+ return w , h , xd , yd
910
917
911
918
def draw (self , renderer ):
912
919
# docstring inherited
@@ -1288,11 +1295,10 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
1288
1295
1289
1296
if prop is None :
1290
1297
prop = {}
1291
- badkwargs = {'ha' , 'horizontalalignment' , ' va' , 'verticalalignment' }
1298
+ badkwargs = {'va' , 'verticalalignment' }
1292
1299
if badkwargs & set (prop ):
1293
1300
raise ValueError (
1294
- "Mixing horizontalalignment or verticalalignment with "
1295
- "AnchoredText is not supported." )
1301
+ 'Mixing verticalalignment with AnchoredText is not supported.' )
1296
1302
1297
1303
self .txt = TextArea (s , textprops = prop , minimumdescent = False )
1298
1304
fp = self .txt ._text .get_fontproperties ()
0 commit comments