Skip to content

Commit a47afc0

Browse files
committed
Add try/except backward compatibility for bitmap.blit function in _place_text
1 parent 3e8f35f commit a47afc0

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,59 @@ def _place_text(
450450
) # for type BuiltinFont, this creates the x-offset in the glyph bitmap.
451451
# for BDF loaded fonts, this should equal 0
452452

453-
bitmap.blit(
454-
xposition + my_glyph.dx,
455-
yposition - my_glyph.height - my_glyph.dy,
456-
my_glyph.bitmap,
457-
x1=glyph_offset_x,
458-
y1=0,
459-
x2=glyph_offset_x + my_glyph.width - 1,
460-
y2=0 + my_glyph.height - 1,
461-
skip_index=0, # do not copy over any 0 background pixels
462-
)
453+
try:
454+
bitmap.blit(
455+
xposition + my_glyph.dx,
456+
yposition - my_glyph.height - my_glyph.dy,
457+
my_glyph.bitmap,
458+
x1=glyph_offset_x,
459+
y1=0,
460+
x2=glyph_offset_x + my_glyph.width - 1,
461+
y2=0 + my_glyph.height - 1,
462+
skip_index=0, # do not copy over any 0 background pixels
463+
)
464+
465+
except:
466+
for y in range(my_glyph.height):
467+
for x in range(my_glyph.width):
468+
x_placement = x + xposition + my_glyph.dx
469+
y_placement = y + yposition - my_glyph.height - my_glyph.dy
470+
471+
if (bitmap_width > x_placement >= 0) and (
472+
bitmap_height > y_placement >= 0
473+
):
474+
475+
# Allows for remapping the bitmap indexes using paletteIndex
476+
# for background and text.
477+
palette_indexes = (
478+
background_palette_index,
479+
text_palette_index,
480+
)
481+
482+
this_pixel_color = palette_indexes[
483+
my_glyph.bitmap[
484+
y * my_glyph.bitmap.width + x + glyph_offset_x
485+
]
486+
]
487+
488+
if not print_only_pixels or this_pixel_color > 0:
489+
# write all characters if printOnlyPixels = False,
490+
# or if thisPixelColor is > 0
491+
bitmap[
492+
y_placement * bitmap_width + x_placement
493+
] = this_pixel_color
494+
elif y_placement > bitmap_height:
495+
break
463496

464497
xposition = xposition + my_glyph.shift_x
465498

466499
return (left, top, right - left, bottom - top) # bounding_box
467500

501+
502+
503+
504+
505+
468506
@property
469507
def bounding_box(self):
470508
"""An (x, y, w, h) tuple that completely covers all glyphs. The

0 commit comments

Comments
 (0)