[cairo-commit] 3 commits - src/cairo-gstate.c test/user-font.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue May 27 18:16:39 PDT 2008


 src/cairo-gstate.c |   23 +++++++++++++-----
 test/user-font.c   |   67 ++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 60 insertions(+), 30 deletions(-)

New commits:
commit 8c4f4a758bf4c1138f313d9cafa5564ac827b61d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 27 20:27:18 2008 -0400

    [cairo-gstate] Use clip, not surface, extents to drop invisible glyphs

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index b67125d..c738669 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1697,7 +1697,7 @@ _cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t      *gstate,
 
 	drop = TRUE;
 
-	if (_cairo_surface_get_extents (gstate->target, &surface_extents))
+	if (_cairo_gstate_int_clip_extents (gstate, &surface_extents))
 	    drop = FALSE; /* unbounded surface */
 	else {
 	    /* XXX We currently drop any glyphs that has its position outside
commit c752bd665ae707edf207653f183b6d132dd0384e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 27 20:27:07 2008 -0400

    [cairo-gstate] Add _cairo_gstate_int_clip_extents()

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 8751285..b67125d 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1175,6 +1175,21 @@ _cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
 			     gstate->antialias, gstate->target);
 }
 
+static cairo_status_t
+_cairo_gstate_int_clip_extents (cairo_gstate_t        *gstate,
+				cairo_rectangle_int_t *extents)
+{
+    cairo_status_t status;
+
+    status = _cairo_surface_get_extents (gstate->target, extents);
+    if (status)
+        return status;
+
+    status = _cairo_clip_intersect_to_rectangle (&gstate->clip, extents);
+
+    return status;
+}
+
 cairo_status_t
 _cairo_gstate_clip_extents (cairo_gstate_t *gstate,
 		            double         *x1,
@@ -1185,11 +1200,7 @@ _cairo_gstate_clip_extents (cairo_gstate_t *gstate,
     cairo_rectangle_int_t extents;
     cairo_status_t status;
     
-    status = _cairo_surface_get_extents (gstate->target, &extents);
-    if (status)
-        return status;
-
-    status = _cairo_clip_intersect_to_rectangle (&gstate->clip, &extents);
+    status = _cairo_gstate_int_clip_extents (gstate, &extents);
     if (status)
         return status;
 
commit 0f07c45fa30279cb1aba6092bc84a859dd479054
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 27 17:53:35 2008 -0400

    [test/user-font] Use user_data to access glyphs array
    
    This way the same callback code can be used to render multiple different
    glyph arrays.  Change done for education purposes, otherwise doesn't
    make any difference in the test.

diff --git a/test/user-font.c b/test/user-font.c
index 81871a5..5cddfed 100644
--- a/test/user-font.c
+++ b/test/user-font.c
@@ -64,33 +64,13 @@ cairo_test_t test = {
  * ----10 11 12----(baseline)
  *     13 14 15
  */
-
-static const struct {
+typedef struct {
     unsigned long ucs4;
     int width;
     char data[16];
-} glyphs [] = {
-    { '\0', 0, { END_GLYPH } },
-    { ' ',  1, { END_GLYPH } },
-    { '-',  2, { 7, 8, STROKE, END_GLYPH } },
-    { '.',  1, { 10, 10, STROKE, END_GLYPH } },
-    { 'a',  3, { 4, 6, 12, 10, 7, 9, STROKE, END_GLYPH } },
-    { 'c',  3, { 6, 4, 10, 12, STROKE, END_GLYPH } },
-    { 'e',  3, { 12, 10, 4, 6, 9, 7, STROKE, END_GLYPH } },
-    { 'f',  3, { 3, 2, 11, STROKE, 4, 6, STROKE, END_GLYPH } },
-    { 'g',  3, { 12, 10, 4, 6, 15, 13, STROKE, END_GLYPH } },
-    { 'h',  3, { 1, 10, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
-    { 'i',  1, { 1, 1, STROKE, 4, 10, STROKE, END_GLYPH } },
-    { 'l',  1, { 1, 10, STROKE, END_GLYPH } },
-    { 'n',  3, { 10, 4, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
-    { 'o',  3, { 4, 10, 12, 6, CLOSE, END_GLYPH } },
-    { 'r',  3, { 4, 10, STROKE, 7, 5, 6, STROKE, END_GLYPH } },
-    { 's',  3, { 6, 4, 7, 9, 12, 10, STROKE, END_GLYPH } },
-    { 't',  3, { 2, 11, 12, STROKE, 4, 6, STROKE, END_GLYPH } },
-    { 'u',  3, { 4, 10, 12, 6, STROKE, END_GLYPH } },
-    { 'z',  3, { 4, 6, 10, 12, STROKE, END_GLYPH } },
-    {  -1,  0, { END_GLYPH } },
-};
+} test_scaled_font_glyph_t;
+
+static cairo_user_data_key_t test_font_face_glyphs_key;
 
 static cairo_status_t
 test_scaled_font_init (cairo_scaled_font_t  *scaled_font,
@@ -106,6 +86,8 @@ test_scaled_font_unicode_to_glyph (cairo_scaled_font_t *scaled_font,
 				   unsigned long        unicode,
 				   unsigned long       *glyph)
 {
+    test_scaled_font_glyph_t *glyphs = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
+								      &test_font_face_glyphs_key);
     int i;
 
     for (i = 0; glyphs[i].ucs4 != -1; i++)
@@ -124,6 +106,8 @@ test_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
 			       cairo_t              *cr,
 			       cairo_text_extents_t *metrics)
 {
+    test_scaled_font_glyph_t *glyphs = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
+								      &test_font_face_glyphs_key);
     int i;
     const char *data;
     div_t d;
@@ -164,10 +148,45 @@ get_user_font_face (void)
     static cairo_font_face_t *user_font_face = NULL;
 
     if (!user_font_face) {
+
+	/* Simple glyph definition: 1 - 15 means lineto (or moveto for first
+	 * point) for one of the points on this grid:
+	 *
+	 *      1  2  3
+	 *      4  5  6
+	 *      7  8  9
+	 * ----10 11 12----(baseline)
+	 *     13 14 15
+	 */
+	static const test_scaled_font_glyph_t glyphs [] = {
+	    { '\0', 0, { END_GLYPH } },
+	    { ' ',  1, { END_GLYPH } },
+	    { '-',  2, { 7, 8, STROKE, END_GLYPH } },
+	    { '.',  1, { 10, 10, STROKE, END_GLYPH } },
+	    { 'a',  3, { 4, 6, 12, 10, 7, 9, STROKE, END_GLYPH } },
+	    { 'c',  3, { 6, 4, 10, 12, STROKE, END_GLYPH } },
+	    { 'e',  3, { 12, 10, 4, 6, 9, 7, STROKE, END_GLYPH } },
+	    { 'f',  3, { 3, 2, 11, STROKE, 4, 6, STROKE, END_GLYPH } },
+	    { 'g',  3, { 12, 10, 4, 6, 15, 13, STROKE, END_GLYPH } },
+	    { 'h',  3, { 1, 10, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
+	    { 'i',  1, { 1, 1, STROKE, 4, 10, STROKE, END_GLYPH } },
+	    { 'l',  1, { 1, 10, STROKE, END_GLYPH } },
+	    { 'n',  3, { 10, 4, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
+	    { 'o',  3, { 4, 10, 12, 6, CLOSE, END_GLYPH } },
+	    { 'r',  3, { 4, 10, STROKE, 7, 5, 6, STROKE, END_GLYPH } },
+	    { 's',  3, { 6, 4, 7, 9, 12, 10, STROKE, END_GLYPH } },
+	    { 't',  3, { 2, 11, 12, STROKE, 4, 6, STROKE, END_GLYPH } },
+	    { 'u',  3, { 4, 10, 12, 6, STROKE, END_GLYPH } },
+	    { 'z',  3, { 4, 6, 10, 12, STROKE, END_GLYPH } },
+	    {  -1,  0, { END_GLYPH } },
+	};
+
 	user_font_face = cairo_user_font_face_create ();
 	cairo_user_font_face_set_init_func             (user_font_face, test_scaled_font_init);
 	cairo_user_font_face_set_render_glyph_func     (user_font_face, test_scaled_font_render_glyph);
 	cairo_user_font_face_set_unicode_to_glyph_func (user_font_face, test_scaled_font_unicode_to_glyph);
+
+	cairo_font_face_set_user_data (user_font_face, &test_font_face_glyphs_key, glyphs, NULL);
     }
 
     return user_font_face;


More information about the cairo-commit mailing list