From a8f1b456db744e33a10b2301df03528787e5b1ca Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 8 Mar 2013 06:21:59 -0500 Subject: [FT] Prefer downscaling bitmap glyphs to upscaling Say, you have bitmap strikes for sizes 50ppem and 100ppem. To render at 60ppem, it's much better to downscale the 100ppem bitmap than upscale 50ppem one. Prefer downscaling. --- src/cairo-ft-font.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index 8ebadb43..90f410c7 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -739,6 +739,7 @@ _compute_transform (cairo_ft_font_transform_t *sf, if (unscaled && (unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) { double min_distance = DBL_MAX; + cairo_bool_t magnify = TRUE; int i; int best_i = 0; double best_x_size = 0; @@ -747,10 +748,18 @@ _compute_transform (cairo_ft_font_transform_t *sf, for (i = 0; i < unscaled->face->num_fixed_sizes; i++) { double x_size = unscaled->face->available_sizes[i].y_ppem / 64.; double y_size = unscaled->face->available_sizes[i].y_ppem / 64.; - double distance = fabs (y_size - y_scale); + double distance = y_size - y_scale; - if (distance <= min_distance) { - min_distance = distance; + /* + * distance is positive if current strike is larger than desired + * size, and negative if smaller. + * + * We like to prefer down-scaling to upscaling. + */ + + if ((magnify && distance >= 0) || fabs (distance) <= min_distance) { + magnify = distance < 0; + min_distance = abs (distance); best_i = i; best_x_size = x_size; best_y_size = y_size; -- cgit v1.2.3