-
Notifications
You must be signed in to change notification settings - Fork 480
[varLib.mutator] Improve CharString rounding #3481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Because CharString commands are relative, rounding point coordinates can result in accumulating round errors causing the last point in the contour to not match the first point, leaning to rendering artifacts. This test demonstrates this.
Since CharString point coordinates are relative, rounding each point independently can accumulate rounding errors causing to the last point to not match the first one, which leads to rendering artifacts. This is a hack to round the absolute point coordinates, but using pens to convert the relative coordinates to absolute ones and back. This is a hack since it drops hinting operators, and it can’t preserve the original operators, in addition to being slower. There is probably a more clever way to doing this.
Smells like a variant of this: #2838 |
Use AFDKO’s tx for instancing CFF2 table, to work around issues with FontTools instancer (fonttools/fonttools#3481).
I think so (here at the instancing not merging side, though). Not rounding at all works as well, but it gives larger file size and can expose bugs in implementations not prepared to handle fractional CFF coordinates. |
|
thanks for spotting this Khaled
would be nice to find out how tx manages to do this while, if I understand correctly, also preserving hinting and other operators. Maybe @skef could help undestand this? |
Note that the hints are represented with absolute positions and are (currently) in "hint substitution" style rather than "hintmask" style (for CFF variants they're translated back into hintmask style after processing). |
Random thing: if the test is CFF2, why does it have |
It would be nice to have a fix for this in varLib.instancer. I was under the impression we are discouraged from using varLib.mutator? |
yeah, it's sort of deprecated in favour of varLib.instancer. I think this PR predates CFF2 support in varLib.instancer which was added around May 2024. |
Ah, that makes sense. I can confirm that the same issue exists in varLib.instancer, though. |
We should try converting all coordinates to absolute, do the instantiation, then revert. |
In the form of a charstring still I mean. |
Since CharString point coordinates are relative, rounding each point independently can accumulate rounding errors causing to the last point to not match the first one, which leads to rendering artifacts.
This is a hack to round the absolute point coordinates, but using pens to convert the relative coordinates to absolute ones and back.
This is a hack since it drops hinting operators, and it can’t preserve the original operators, in addition to being slower.
There is probably a more clever way to doing this.