@@ -99,6 +99,7 @@ def __init__(self, font: FontProtocol, **kwargs) -> None:
99
99
if text is not None :
100
100
self ._reset_text (str (text ))
101
101
102
+ # pylint: disable=too-many-branches
102
103
def _create_background_box (self , lines : int , y_offset : int ) -> TileGrid :
103
104
"""Private Class function to create a background_box
104
105
:param lines: int number of lines
@@ -114,16 +115,27 @@ def _create_background_box(self, lines: int, y_offset: int) -> TileGrid:
114
115
else : # draw a "loose" bounding box to include any ascenders/descenders.
115
116
ascent , descent = self ._ascent , self ._descent
116
117
117
- if self ._label_direction in ("UPR" , " DWR" , "TTB " ):
118
+ if self ._label_direction in ("DWR" , "UPR " ):
118
119
box_height = (
119
- self ._bounding_box [3 ] + self ._padding_top + self ._padding_bottom
120
+ self ._bounding_box [3 ] + self ._padding_right + self ._padding_left
120
121
)
121
- x_box_offset = - self ._padding_bottom
122
+ x_box_offset = - self ._padding_left
122
123
box_width = (
123
124
(ascent + descent )
124
125
+ int ((lines - 1 ) * self ._width * self ._line_spacing )
125
- + self ._padding_left
126
+ + self ._padding_top
127
+ + self ._padding_bottom
128
+ )
129
+ elif self ._label_direction == "TTB" :
130
+ box_height = (
131
+ self ._bounding_box [3 ] + self ._padding_top + self ._padding_bottom
132
+ )
133
+ x_box_offset = - self ._padding_left
134
+ box_width = (
135
+ (ascent + descent )
136
+ + int ((lines - 1 ) * self ._height * self ._line_spacing )
126
137
+ self ._padding_right
138
+ + self ._padding_left
127
139
)
128
140
else :
129
141
box_width = (
@@ -137,23 +149,33 @@ def _create_background_box(self, lines: int, y_offset: int) -> TileGrid:
137
149
+ self ._padding_bottom
138
150
)
139
151
152
+ if self ._label_direction == "DWR" :
153
+ padding_to_use = self ._padding_bottom
154
+ elif self ._label_direction == "TTB" :
155
+ padding_to_use = self ._padding_top
156
+ y_offset = 0
157
+ ascent = 0
158
+ else :
159
+ padding_to_use = self ._padding_top
160
+
140
161
if self ._base_alignment :
141
- y_box_offset = - ascent - self . _padding_top
162
+ y_box_offset = - ascent - padding_to_use
142
163
else :
143
- y_box_offset = - ascent + y_offset - self ._padding_top
164
+
165
+ y_box_offset = - ascent + y_offset - padding_to_use
144
166
145
167
box_width = max (0 , box_width ) # remove any negative values
146
168
box_height = max (0 , box_height ) # remove any negative values
147
169
148
170
if self ._label_direction == "UPR" :
149
- movx = left + x_box_offset
171
+ movx = y_box_offset
150
172
movy = - box_height - x_box_offset
151
173
elif self ._label_direction == "DWR" :
152
- movx = left + x_box_offset
174
+ movx = y_box_offset
153
175
movy = x_box_offset
154
176
elif self ._label_direction == "TTB" :
155
- movx = left + x_box_offset
156
- movy = x_box_offset
177
+ movx = x_box_offset
178
+ movy = y_box_offset
157
179
else :
158
180
movx = left + x_box_offset
159
181
movy = y_box_offset
@@ -168,6 +190,7 @@ def _create_background_box(self, lines: int, y_offset: int) -> TileGrid:
168
190
169
191
return tile_grid
170
192
193
+ # pylint: enable=too-many-branches
171
194
def _set_background_color (self , new_color : Optional [int ]) -> None :
172
195
"""Private class function that allows updating the font box background color
173
196
0 commit comments