@@ -76,7 +76,10 @@ class Label(LabelBase):
76
76
This is helpful when two or more labels need to be aligned to the same baseline
77
77
:param (int,str) tab_replacement: tuple with tab character replace information. When
78
78
(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``"""
80
83
81
84
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
82
85
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -103,6 +106,13 @@ def __init__(self, font, **kwargs) -> None:
103
106
104
107
self .color = kwargs .get ("color" , 0xFFFFFF )
105
108
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 ))
106
116
107
117
self .base_alignment = kwargs .get ("base_alignment" , False )
108
118
@@ -124,6 +134,7 @@ def __init__(self, font, **kwargs) -> None:
124
134
scale = kwargs .get ("scale" , 1 ),
125
135
base_alignment = kwargs .get ("base_alignment" , False ),
126
136
tab_replacement = kwargs .get ("tab_replacement" , (4 , " " )),
137
+ label_direction = kwargs .get ("label_direction" , "LTR" ),
127
138
)
128
139
129
140
def _reset_text (
@@ -144,6 +155,7 @@ def _reset_text(
144
155
scale : int = None ,
145
156
base_alignment : bool = None ,
146
157
tab_replacement : Tuple [int , str ] = None ,
158
+ label_direction : str = "LTR" ,
147
159
) -> None :
148
160
149
161
# Store all the instance variables
@@ -175,13 +187,17 @@ def _reset_text(
175
187
self .base_alignment = base_alignment
176
188
if tab_replacement is not None :
177
189
self ._tab_replacement = tab_replacement
190
+ if label_direction is not None :
191
+ self ._label_direction = label_direction
178
192
179
193
# if text is not provided as a parameter (text is None), use the previous value.
180
194
if (text is None ) and self ._save_text :
181
195
text = self ._text
182
196
183
197
if self ._save_text : # text string will be saved
184
198
self ._text = self ._tab_text .join (text .split ("\t " ))
199
+ if self ._label_direction == "RTL" :
200
+ self ._text = "" .join (reversed (self ._text ))
185
201
else :
186
202
self ._text = None # save a None value since text string is not saved
187
203
@@ -263,6 +279,16 @@ def _reset_text(
263
279
y = label_position_yoffset - y_offset - self ._padding_top ,
264
280
)
265
281
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
+
266
292
# Clear out any items in the local_group Group, in case this is an update to
267
293
# the bitmap_label
268
294
for _ in self .local_group :
0 commit comments