fontations icon indicating copy to clipboard operation
fontations copied to clipboard

[skrifa] move to floating point

Open dfrg opened this issue 2 years ago • 1 comments

We currently aim to match FreeType exactly for metrics and outlines. This requires a great deal of complicated fixed point math and leads to various issues with loss of precision due to rounding and truncation at seemingly arbitrary places in loading/scaling code.

It would be nice to both simplify code and return more precise results by moving internal calculations to floating point.

I propose a gradual approach:

  1. Process COLR in full floating point. This functionality is still relatively new so users are likely not dependent on the current state making it a good place to experiment. The current situation with FT is already problematic and in flux (see https://gitlab.freedesktop.org/freetype/freetype/-/issues/1257) so we’re unlikely to cause a disturbance here.

  2. Scale glyph metrics in float. We were doing this previously but changed recently to match FT. Our global metrics already use floating point because they were deemed less sensitive to diffs.

  3. Consider scaling outlines in floating point. This one is more controversial and may have complications with hinting. If we do this, it would make sense to start with CFF first because the conversion is simpler and it would improve the case where intermediate values can overflow the internal 16.16 representation at high ppem.

As a first step, code should contain // FTCOMPAT: comments to make it easy to find code where we drop precision for compatibility. We can make some of these changes behind a feature gate.

dfrg avatar Nov 07 '23 17:11 dfrg

  1. is done.

drott avatar Jan 23 '24 15:01 drott