@@ -76,7 +76,10 @@ class Label(LabelBase):
7676 This is helpful when two or more labels need to be aligned to the same baseline
7777 :param (int,str) tab_replacement: tuple with tab character replace information. When
7878 (4, " ") will indicate a tab replacement of 4 spaces, defaults to 4 spaces by
79- tab character"""
79+ tab character
80+ :param str label_direction: string defining the label text orientation. There are 5
81+ configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left
82+ ``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``"""
8083
8184 # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
8285 # pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -103,6 +106,13 @@ def __init__(self, font, **kwargs) -> None:
103106
104107 self .color = kwargs .get ("color" , 0xFFFFFF )
105108 self .background_color = kwargs .get ("background_color" , None )
109+ self ._label_direction = kwargs .get ("label_direction" , "LTR" )
110+
111+ if self ._label_direction not in ["LTR" , "RTL" , "UPD" , "UPR" , "DWR" ]:
112+ raise RuntimeError ("Please provide a valid text direction" )
113+
114+ if self ._label_direction == "RTL" :
115+ self ._text = "" .join (reversed (self ._text ))
106116
107117 self .base_alignment = kwargs .get ("base_alignment" , False )
108118
@@ -124,6 +134,7 @@ def __init__(self, font, **kwargs) -> None:
124134 scale = kwargs .get ("scale" , 1 ),
125135 base_alignment = kwargs .get ("base_alignment" , False ),
126136 tab_replacement = kwargs .get ("tab_replacement" , (4 , " " )),
137+ label_direction = kwargs .get ("label_direction" , "LTR" ),
127138 )
128139
129140 def _reset_text (
@@ -144,6 +155,7 @@ def _reset_text(
144155 scale : int = None ,
145156 base_alignment : bool = None ,
146157 tab_replacement : Tuple [int , str ] = None ,
158+ label_direction : str = "LTR" ,
147159 ) -> None :
148160
149161 # Store all the instance variables
@@ -175,13 +187,17 @@ def _reset_text(
175187 self .base_alignment = base_alignment
176188 if tab_replacement is not None :
177189 self ._tab_replacement = tab_replacement
190+ if label_direction is not None :
191+ self ._label_direction = label_direction
178192
179193 # if text is not provided as a parameter (text is None), use the previous value.
180194 if (text is None ) and self ._save_text :
181195 text = self ._text
182196
183197 if self ._save_text : # text string will be saved
184198 self ._text = self ._tab_text .join (text .split ("\t " ))
199+ if self ._label_direction == "RTL" :
200+ self ._text = "" .join (reversed (self ._text ))
185201 else :
186202 self ._text = None # save a None value since text string is not saved
187203
@@ -263,6 +279,16 @@ def _reset_text(
263279 y = label_position_yoffset - y_offset - self ._padding_top ,
264280 )
265281
282+ if self ._label_direction == "UPR" :
283+ self .tilegrid .transpose_xy = True
284+ self .tilegrid .flip_x = True
285+ if self ._label_direction == "DWR" :
286+ self .tilegrid .transpose_xy = True
287+ self .tilegrid .flip_y = True
288+ if self ._label_direction == "UPD" :
289+ self .tilegrid .flip_x = True
290+ self .tilegrid .flip_y = True
291+
266292 # Clear out any items in the local_group Group, in case this is an update to
267293 # the bitmap_label
268294 for _ in self .local_group :
0 commit comments