mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 00:04:28 +01:00
[GH-ISSUE #144] TTF font rendering not perfect for some fonts #2830
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @B0rax on GitHub (Oct 13, 2023).
Original GitHub issue: https://github.com/OpenEPaperLink/OpenEPaperLink/issues/144
Describe the bug
If fonts are rendered very big, smooth curves may be rendered incorrectly
To Reproduce
Steps to reproduce the behavior:
Expected behavior

This is how it looks rendered on macOS:
As you can see, the corners are rounded incorrectly on the OEPL image.

Here is an overlay of both images:
OEPL AP used
@nlimper commented on GitHub (Oct 13, 2023):
The truetype rendering is not perfect yet, that's right.
For smaller sizes, there are rounding issues because I didn't put in the 'hinting' part of the rendering (if you want to have a headache, try to read https://developer.apple.com/fonts/TrueType-Reference-Manual/RM03/Chap3.html and https://googlefonts.github.io/how-to-hint-variable-fonts/). But that shouldn't affect the rendering of the bigger font sizes. It indeed looks like there's something wrong with calculating the curves.
You can have a look at https://fontdrop.info/ to see detailed info about the coordinates and curves of individual characters of a font, it helped me a lot. Also, quality of rendering can vary from font to font, so maybe you have more success if you choose a similar but different font.
It's on my list to dive into it some day, but because of the complexity, I have to be in the mood for it. It will come eventually, but if somebody else want to dive into it, I would also be happy.
Pointers:
generateOutline-function in /src/truetype.cppreference manual: https://developer.apple.com/fonts/TrueType-Reference-Manual/
@B0rax commented on GitHub (Oct 14, 2023):
Thanks for the pointers! Don't get me wrong, I think you did an amazing job with the truetype rendering. I just wanted a place to document my findings.
I used the analysing page you linked (font drop) to look how the characters of this particular font are made. For example, here is the top of the "0" character that shows the artefacts:

This shows me that for this character, we have very long curves.
I looked into the
generateOutlinefunction. The calculation of the points on the spline is done here:c4beaa51c8/ESP32_AP-Flasher/src/truetype.cpp (L768-L769)The calculations looked fine to me, but I plotted them in Geogebra to look at them. (maybe that is not the most efficient way to do it, but it works). This is the result and it looks like the spline is correctly calculated:

So the calculations of the intermediate points are fine. I will look into it more.
@nlimper commented on GitHub (Oct 15, 2023):
Thanks for checking. It's nice to investigate the cause together.
Is suspect there might be some amplified rounding issues somewhere, however I cannot pinpoint them yet.
The outline is generated in the
generateOutlinefunction, but it is not actually drawn. If you activate the commented out parts of theaddLinefunction, the outline is actually drawn. If you then comment out call to thefillGlyphfunction in line 953, only the outline is generated, without a fill, which maybe give a bit clearer view. Next step I would do is to Serial.print the actual coordinates passed to the addLine function to see if they would make sense.@nlimper commented on GitHub (Oct 22, 2023):
Found it!
you were very close... It doesn't help to change the starting point during the drawing of the curve... x0 and y0 are needed to draw the line between the intermediate points on the curve, but of course it should not be used in the bezier formula as they change with every line segment.
Changed it to
pointsOfCurve[0].xandpointsOfCurve[0].y-> fixed.Will be soon in a commit in the repo, somewhere in the coming days. Thanks for diving in to this together.
@B0rax commented on GitHub (Oct 22, 2023):
Nice! Thank you!
@nlimper commented on GitHub (Oct 22, 2023):
before and after :-)
Fixes in commit
a4e19b19ab