@@ -450,21 +450,59 @@ def _place_text(
450
450
) # for type BuiltinFont, this creates the x-offset in the glyph bitmap.
451
451
# for BDF loaded fonts, this should equal 0
452
452
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
463
496
464
497
xposition = xposition + my_glyph .shift_x
465
498
466
499
return (left , top , right - left , bottom - top ) # bounding_box
467
500
501
+
502
+
503
+
504
+
505
+
468
506
@property
469
507
def bounding_box (self ):
470
508
"""An (x, y, w, h) tuple that completely covers all glyphs. The
0 commit comments