Skip to content

Improve accuracy of computed metrics for FT fonts

Vincent Lefevre requested to merge vinc17/cairo:ft-font-accuracy-new into master

In particular, with bitmap fonts, a floating-point error was affecting y_bearing, yielding a value close to an integer instead of the integer exactly. The change consists in replacing some operations of the form A * (1/B) by A/B. Details of the issue in #503.

This new code will not always avoid rounding errors in final values when these values could be exact, but it makes some of these errors disappear.

The changes in the src/cairo-ft-font.c code consists of:

  • Define the SCALE() macro (with some explanations in a comment).
  • Remove the declarations and definitions of x_factor and y_factor.
  • Update the code to use SCALE() instead of x_factor and y_factor.
  perl -pi -e 's{(DOUBLE_\w+) ?(\(.*\)) \* ([xy])_factor}
                {SCALE (\1 \2, unscaled->\3_scale)}' \
    src/cairo-ft-font.c
  • Replace the remaining 0 * x_factor and 0 * y_factor by 0.

This replaces the obsolete merge request !232 (closed).

Merge request reports