Skip to content

Conversation

andersrein
Copy link

When rendering text by rasterizing one glyph at a time and copying the bitmaps for each glyph onto a larger bitmap it is quite complicate to copy from the source bitmap to the target bitmap at sub-pixel precision. I was able to improve this by adding a dx parameter which allows setting the sub-pixel x offset when rasterizing a glyph. This way the source bitmap can be copied to the target bitmap at exact pixel offsets. Have a look at the result:

fontdue_difference
The top line was rendered using the new sub-pixel offset in order to place the glyph at the exact position of the accumulated horizontal advance. The bottom line shows the best effort rendering of the text by rounding the current x position to the nearest whole pixel. Have a look at the 'd' and 'e' in video on the bottom line. These are too close together. Also the 'u' and 'b' in youtube is too far form each other.

Added dx parameter which allows for controlling the horizontal offset
within the pixel. This allows drawing glyphs at the exact floating point
x position provided by accumulating the horizontal advance_width metric
when drawing text.
@andersrein andersrein force-pushed the feature/sub-pixel-offset-rasterize branch from a470b69 to 7d78496 Compare December 23, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant