1
0
Fork 0

draw565: Fix bounding box calculations

wasp-os uses an drawing optimization technique to automatically place
a single pixel line on the right of glyphs when rendering them. This
results in a change to the bounding box for a rendered string (by adding
a single pixel on the right of the final character). Fix the bounding box
calculations accordingly. Among other things this eliminates graphical
artifacts when rendering labels in 2048.

Fixes: #203
Fixes: 58b5c0378e ("draw565: Optimize the string drawing")
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
master
Daniel Thompson 2021-06-04 10:46:25 +01:00
parent 1115ac2fff
commit 4ad8273902
2 changed files with 2 additions and 2 deletions

View File

@ -53,7 +53,7 @@ def test_font_width(draw):
for f in (fonts.sans24, fonts.sans28, fonts.sans36):
draw.set_font(f)
assert 3 == draw.bounding_box('0000')[0] % 4
assert 0 == draw.bounding_box('0000')[0] % 4
if f.max_ch() >= 90:
assert draw.bounding_box('IIII')[0] < draw.bounding_box('WWWW')[0]

View File

@ -75,7 +75,7 @@ def _bounding_box(s, font):
return (0, font.height())
get_ch = font.get_ch
w = len(s) - 1
w = len(s)
for ch in s:
(_, h, wc) = get_ch(ch)
w += wc