[cairo-commit] 3 commits - configure.ac src/cairo-ft-font.c src/cairoint.h src/cairo-xlib-render-compositor.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Fri Dec 21 15:47:51 PST 2012


 configure.ac                       |    7 ---
 src/cairo-ft-font.c                |   75 ++++++++++++++++---------------------
 src/cairo-xlib-render-compositor.c |    2 
 src/cairoint.h                     |    2 
 4 files changed, 37 insertions(+), 49 deletions(-)

New commits:
commit b94a519aad3d5b50aa6de47ee16ee6a099de9791
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Dec 21 18:40:08 2012 -0500

    [ft] Fix resizing of bitmap fonts
    
    Say, you were asking cairo for a font at 200px.  For bitmap-only fonts,
    cairo was finding the closes strike size and using it.  If the strike
    was at 20px, well, that's what you were getting.  We now scale that 20px
    strike by a factor of 10 to get the correct size rendering.
    
    Note that by itself this patch doesn't change much on the Linux desktop.
    The reason is that the size you are interested in (eg. 200px) is lost by
    fontconfig.  When you request a font at 200px, fontconfig returns a font
    pattern that says 20px, and so the next layers thing you want a font at
    20px.  To address that, one also needs a piece of fontconfig config that
    puts the 200 back into the pixelsize.  Something like this:
    
    <match target="font">
      <test name="scalable" mode="eq">
        <bool>false</bool>
      </test>
      <edit name="pixelsize" mode="assign">
        <times>
          <name>size</name>
          <name>dpi</name>
          <double>0.0138888888888</double> <!--1/72.-->
        </times>
      </edit>
    </match>
    
    I'm going to try to upstream this config so it will be enabled by
    default.  The config can be a bit smarter.  For example, if
    metricshinting is enabled and the size difference is small, we may as
    well not scale.
    
    The nice thing about this is that the configuration of whether and when
    to scale bitmaps will be done in fontconfig, not cairo / Qt / ... code.

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 0580fac..8ebadb4 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -708,7 +708,8 @@ _cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled)
 
 static cairo_status_t
 _compute_transform (cairo_ft_font_transform_t *sf,
-		    cairo_matrix_t      *scale)
+		    cairo_matrix_t      *scale,
+		    cairo_ft_unscaled_font_t *unscaled)
 {
     cairo_status_t status;
     double x_scale, y_scale;
@@ -736,6 +737,30 @@ _compute_transform (cairo_ft_font_transform_t *sf,
     if (y_scale < 1.0)
       y_scale = 1.0;
 
+    if (unscaled && (unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) {
+	double min_distance = DBL_MAX;
+	int i;
+	int best_i = 0;
+	double best_x_size = 0;
+	double best_y_size = 0;
+
+	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);
+
+	    if (distance <= min_distance) {
+		min_distance = distance;
+		best_i = i;
+		best_x_size = x_size;
+		best_y_size = y_size;
+	    }
+	}
+
+	x_scale = best_x_size;
+	y_scale = best_y_size;
+    }
+
     sf->x_scale = x_scale;
     sf->y_scale = y_scale;
 
@@ -773,7 +798,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
     unscaled->have_scale = TRUE;
     unscaled->current_scale = *scale;
 
-    status = _compute_transform (&sf, scale);
+    status = _compute_transform (&sf, scale, unscaled);
     if (unlikely (status))
 	return status;
 
@@ -798,35 +823,12 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 
     FT_Set_Transform(unscaled->face, &mat, NULL);
 
-    if ((unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) != 0) {
-	error = FT_Set_Char_Size (unscaled->face,
-				  sf.x_scale * 64.0 + .5,
-				  sf.y_scale * 64.0 + .5,
-				  0, 0);
-	if (error)
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    } else {
-	double min_distance = DBL_MAX;
-	int i;
-	int best_i = 0;
-
-	for (i = 0; i < unscaled->face->num_fixed_sizes; i++) {
-	    double size = unscaled->face->available_sizes[i].y_ppem / 64.;
-	    double distance = fabs (size - sf.y_scale);
-
-	    if (distance <= min_distance) {
-		min_distance = distance;
-		best_i = i;
-	    }
-	}
-	error = FT_Set_Char_Size (unscaled->face,
-				  unscaled->face->available_sizes[best_i].x_ppem,
-				  unscaled->face->available_sizes[best_i].y_ppem,
-				  0, 0);
-
-	if (error)
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
+    error = FT_Set_Char_Size (unscaled->face,
+			      sf.x_scale * 64.0 + .5,
+			      sf.y_scale * 64.0 + .5,
+			      0, 0);
+    if (error)
+      return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -3079,7 +3081,7 @@ _cairo_ft_resolve_pattern (FcPattern		      *pattern,
                            font_matrix,
                            &scale);
 
-    status = _compute_transform (&sf, &scale);
+    status = _compute_transform (&sf, &scale, NULL);
     if (unlikely (status))
 	return (cairo_font_face_t *)&_cairo_font_face_nil;
 
commit 1404ed9692af1958b4090c46d1a27e0fe4a5616e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Dec 21 18:35:41 2012 -0500

    [ft] Remove ancient check for FT_Bitmap_Size.y_ppem
    
    That member is available in the version of FreeType we require.

diff --git a/configure.ac b/configure.ac
index f523284..fc8d3b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -522,13 +522,6 @@ if test "x$use_ft" = "xyes"; then
   _save_cflags="$CFLAGS"
   LIBS="$LIBS $ft_LIBS"
   CFLAGS="$CFLAGS $ft_CFLAGS"
-  AC_CHECK_MEMBER(FT_Bitmap_Size.y_ppem,
-                  HAVE_FT_BITMAP_SIZE_Y_PPEM=1,
-                  HAVE_FT_BITMAP_SIZE_Y_PPEM=0,
-                  [#include <ft2build.h>
-                   #include FT_FREETYPE_H])
-  AC_DEFINE_UNQUOTED(HAVE_FT_BITMAP_SIZE_Y_PPEM,$HAVE_FT_BITMAP_SIZE_Y_PPEM,
-                     [FT_Bitmap_Size structure includes y_ppem field])
 
   AC_CHECK_FUNCS(FT_Get_X11_Font_Format FT_GlyphSlot_Embolden FT_GlyphSlot_Oblique FT_Load_Sfnt_Table FT_Library_SetLcdFilter)
 
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 75cc132..0580fac 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -811,11 +811,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 	int best_i = 0;
 
 	for (i = 0; i < unscaled->face->num_fixed_sizes; i++) {
-#if HAVE_FT_BITMAP_SIZE_Y_PPEM
 	    double size = unscaled->face->available_sizes[i].y_ppem / 64.;
-#else
-	    double size = unscaled->face->available_sizes[i].height;
-#endif
 	    double distance = fabs (size - sf.y_scale);
 
 	    if (distance <= min_distance) {
@@ -823,16 +819,11 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 		best_i = i;
 	    }
 	}
-#if HAVE_FT_BITMAP_SIZE_Y_PPEM
 	error = FT_Set_Char_Size (unscaled->face,
 				  unscaled->face->available_sizes[best_i].x_ppem,
 				  unscaled->face->available_sizes[best_i].y_ppem,
 				  0, 0);
-	if (error)
-#endif
-	    error = FT_Set_Pixel_Sizes (unscaled->face,
-					unscaled->face->available_sizes[best_i].width,
-					unscaled->face->available_sizes[best_i].height);
+
 	if (error)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
commit 867c876b0e7ce3dcc8afc7227ef6317701a6dda0
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Nov 7 14:30:35 2012 -0800

    [Minor] Improve logging

diff --git a/src/cairo-xlib-render-compositor.c b/src/cairo-xlib-render-compositor.c
index 74c43e9..e7d7f79 100644
--- a/src/cairo-xlib-render-compositor.c
+++ b/src/cairo-xlib-render-compositor.c
@@ -1485,6 +1485,8 @@ check_composite_glyphs (const cairo_composite_rectangles_t *extents,
 			cairo_glyph_t *glyphs,
 			int *num_glyphs)
 {
+    TRACE ((stderr, "%s\n", __FUNCTION__));
+
     cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)extents->surface;
     cairo_xlib_display_t *display = dst->display;
     int max_request_size, size;
diff --git a/src/cairoint.h b/src/cairoint.h
index 7463595..0a925d1 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2032,7 +2032,7 @@ cairo_private void
 _cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip);
 
 #if 0
-#define TRACE(x) fprintf x
+#define TRACE(x) fprintf (stderr, "%s: ", __FILE__), fprintf x
 #define TRACE_(x) x
 #else
 #define TRACE(x)


More information about the cairo-commit mailing list