@@ -189,16 +189,39 @@ def _update_background_color(self, new_color):
189
189
/ 2
190
190
)
191
191
lines = self .text .count ("\n " ) + 1
192
- if not self ._added_background_tilegrid :
193
- # only if we have text or padding
194
- if len (self .text ) + self ._padding_left + self ._padding_right > 0 :
192
+
193
+ if not self ._added_background_tilegrid : # no bitmap is in the self Group
194
+ # add bitmap if text is present and bitmap sizes > 0 pixels
195
+ if (
196
+ (len (self ._text ) > 0 )
197
+ and (
198
+ self ._boundingbox [2 ] + self ._padding_left + self ._padding_right > 0
199
+ )
200
+ and (
201
+ self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
202
+ )
203
+ ):
195
204
if len (self ) > 0 :
196
205
self .insert (0 , self ._create_background_box (lines , y_offset ))
197
206
else :
198
207
self .append (self ._create_background_box (lines , y_offset ))
199
208
self ._added_background_tilegrid = True
200
- else :
201
- self [0 ] = self ._create_background_box (lines , y_offset )
209
+
210
+ else : # a bitmap is present in the self Group
211
+ # update bitmap if text is present and bitmap sizes > 0 pixels
212
+ if (
213
+ (len (self ._text ) > 0 )
214
+ and (
215
+ self ._boundingbox [2 ] + self ._padding_left + self ._padding_right > 0
216
+ )
217
+ and (
218
+ self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
219
+ )
220
+ ):
221
+ self [0 ] = self ._create_background_box (lines , y_offset )
222
+ else : # delete the existing bitmap
223
+ self .pop (0 )
224
+ self ._added_background_tilegrid = False
202
225
203
226
def _update_text (
204
227
self , new_text
@@ -290,20 +313,8 @@ def _update_text(
290
313
self .pop ()
291
314
self ._text = new_text
292
315
self ._boundingbox = (left , top , left + right , bottom - top )
293
- if (
294
- self ._background_color
295
- and len (new_text ) + self ._padding_left + self ._padding_right > 0
296
- ):
297
- if not self ._added_background_tilegrid :
298
- self ._added_background_tilegrid = True
299
- self .insert (0 , self ._create_background_box (lines , y_offset ))
300
- else :
301
- self [0 ] = self ._create_background_box (lines , y_offset )
302
- else :
303
- self ._background_palette .make_transparent (0 )
304
- if self ._added_background_tilegrid :
305
- self .pop (0 )
306
- self ._added_background_tilegrid = False
316
+
317
+ self ._update_background_color (self ._background_color )
307
318
308
319
@property
309
320
def bounding_box (self ):
0 commit comments