[cairo] [PATCH] ft: correct abs(distance) to fabs(distance)

Matt Sealey matt at genesi-usa.com
Wed Mar 20 12:12:19 PDT 2013


Previous commit a8f1b45 ([FT] Prefer downscaling bitmap glyphs to upscaling)
modified the behavior of Cairo's FT font backend but it seems accidentally
used abs() with a 'double' type argument. The compiler almost silently
converts the double to signed integer and then we get the absolute value
of that signed integer as a signed integer result cast into a double.

The net effect is that min_distance loses precision (fractional part is
discarded by the compiler's conversion of double -> int) and in some cases
observed here some fonts do not render correctly if there was any scaling
involved that actually had a fractional value.

Signed-off-by: Matt Sealey <matt at genesi-usa.com>
---
 src/cairo-ft-font.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 90f410c..1ab56be 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -759,7 +759,7 @@ _compute_transform (cairo_ft_font_transform_t *sf,
 
 	    if ((magnify && distance >= 0) || fabs (distance) <= min_distance) {
 		magnify = distance < 0;
-		min_distance = abs (distance);
+		min_distance = fabs (distance);
 		best_i = i;
 		best_x_size = x_size;
 		best_y_size = y_size;
-- 
1.7.10.4



More information about the cairo mailing list