[cairo-commit] src/cairo-ft-font.c
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Feb 20 17:55:27 PST 2008
src/cairo-ft-font.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
New commits:
commit 70bb2abed04ed25abccbb2d6a5bdc58136701b0a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Feb 20 20:54:01 2008 -0500
[cairo-ft] Handle font sizes smaller than 1px correctly
The FT_Set_Char_Size() docs say it replaces sizes smaller than 1.0 with 1.0.
So, we can't use x_scale and y_scale values less than one. The fix is easy thouh,
cap them to 1.0 and let the FT transform do the scaling down.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index f570fdc..85ebce5 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -594,6 +594,7 @@ _compute_transform (cairo_ft_font_transform_t *sf,
cairo_matrix_t *scale)
{
cairo_status_t status;
+ double x_scale, y_scale;
cairo_matrix_t normalized = *scale;
/* The font matrix has x and y "scale" components which we extract and
@@ -603,23 +604,30 @@ _compute_transform (cairo_ft_font_transform_t *sf,
* freetype's transformation.
*/
- status = _cairo_matrix_compute_scale_factors (&normalized,
- &sf->x_scale, &sf->y_scale,
+ status = _cairo_matrix_compute_scale_factors (scale,
+ &x_scale, &y_scale,
/* XXX */ 1);
if (status)
return status;
- if (sf->x_scale != 0 && sf->y_scale != 0) {
- cairo_matrix_scale (&normalized, 1.0 / sf->x_scale, 1.0 / sf->y_scale);
+ /* FreeType docs say this about x_scale and y_scale:
+ * "A character width or height smaller than 1pt is set to 1pt;"
+ * So, we cap them from below at 1.0 and let the FT transform
+ * take care of sub-1.0 scaling. */
+ if (x_scale < 1.0)
+ x_scale = 1.0;
+ if (y_scale < 1.0)
+ y_scale = 1.0;
- _cairo_matrix_get_affine (&normalized,
- &sf->shape[0][0], &sf->shape[0][1],
- &sf->shape[1][0], &sf->shape[1][1],
- NULL, NULL);
- } else {
- sf->shape[0][0] = sf->shape[1][1] = 1.0;
- sf->shape[0][1] = sf->shape[1][0] = 0.0;
- }
+ sf->x_scale = x_scale;
+ sf->y_scale = y_scale;
+
+ cairo_matrix_scale (&normalized, 1.0 / x_scale, 1.0 / y_scale);
+
+ _cairo_matrix_get_affine (&normalized,
+ &sf->shape[0][0], &sf->shape[0][1],
+ &sf->shape[1][0], &sf->shape[1][1],
+ NULL, NULL);
return CAIRO_STATUS_SUCCESS;
}
@@ -675,8 +683,8 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
if ((unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) != 0) {
error = FT_Set_Char_Size (unscaled->face,
- sf.x_scale * 64.0,
- sf.y_scale * 64.0,
+ sf.x_scale * 64.0 + .5,
+ sf.y_scale * 64.0 + .5,
0, 0);
if (error)
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
More information about the cairo-commit
mailing list