diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2013-03-08 06:21:59 -0500 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2013-03-08 06:22:59 -0500 |
commit | a8f1b456db744e33a10b2301df03528787e5b1ca (patch) | |
tree | 0213cc49738ea2d78a0df626d85df1b71031c9d6 | |
parent | 4f00d2344c84a1017a1e7d76ccb2fa552c80a969 (diff) |
[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.
-rw-r--r-- | src/cairo-ft-font.c | 15 |
1 files 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; |