File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -418,15 +418,37 @@ def _place_text(
418418 ) # for type BuiltinFont, this creates the x-offset in the glyph bitmap.
419419 # for BDF loaded fonts, this should equal 0
420420
421+ y_blit_target = yposition - my_glyph .height - my_glyph .dy
422+
423+ # Clip glyph y-direction if outside the font ascent/descent metrics.
424+ # Note: bitmap.blit will automatically clip the bottom of the glyph.
425+ y_clip = 0
426+ if (y_blit_target ) < 0 :
427+ y_clip = - (y_blit_target ) # clip this amount from top of bitmap
428+ y_blit_target = 0 # draw the clipped bitmap at y=0
429+
430+ print (
431+ 'Warning: Glyph clipped, exceeds Ascent property: "{}"' .format (
432+ char
433+ )
434+ )
435+
436+ if (y_blit_target + my_glyph .height ) > bitmap .height :
437+ print (
438+ 'Warning: Glyph clipped, exceeds descent property: "{}"' .format (
439+ char
440+ )
441+ )
442+
421443 self ._blit (
422444 bitmap ,
423445 xposition + my_glyph .dx ,
424- yposition - my_glyph . height - my_glyph . dy ,
446+ y_blit_target ,
425447 my_glyph .bitmap ,
426448 x_1 = glyph_offset_x ,
427- y_1 = 0 ,
449+ y_1 = y_clip ,
428450 x_2 = glyph_offset_x + my_glyph .width ,
429- y_2 = 0 + my_glyph .height ,
451+ y_2 = my_glyph .height ,
430452 skip_index = skip_index , # do not copy over any 0 background pixels
431453 )
432454
You can’t perform that action at this time.
0 commit comments