Skip to content

Commit

Permalink
Fix off-by-one in bounds of centered text. (#42)
Browse files Browse the repository at this point in the history
The calculation of redraw boxes for centered text
was off by one because of confusion about rounding
when the text has an odd pixel length.

Tests for this are in the version-2 branch.
  • Loading branch information
Erik Corry authored Nov 3, 2023
1 parent 025661b commit 4f97010
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/texture.toit
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ abstract class TextTexture_ extends SizedTexture:
assert: alignment == TEXT_TEXTURE_ALIGN_CENTER
assert: pixel_width_old == (font.pixel_width new)
// Make x relative to the text origin, which is the middle.
unchanged_width := (pixel_width_old >> 1) - (font.pixel_width old[..unchanged_left])
unchanged_width := ((pixel_width_old + 1) >> 1) - (font.pixel_width old[..unchanged_left])
changed_extent_old.x -= unchanged_width + changed_extent_old.displacement
changed_extent_new.x -= unchanged_width + changed_extent_new.displacement
block.call changed_extent_old changed_extent_new
Expand Down

0 comments on commit 4f97010

Please sign in to comment.