[cairo-commit] 2 commits - src/cairo-ft-font.c util/cairo-script

Chris Wilson ickle at kemper.freedesktop.org
Mon Aug 20 09:24:54 PDT 2012


 src/cairo-ft-font.c                        |    3 ++-
 util/cairo-script/cairo-script-operators.c |   19 +++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 30d09cd33a582a2dd3f3a544366892c724f67592
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Aug 20 17:20:08 2012 +0100

    cairo-script: Attempt to fallback for unresolved patterns
    
    If we fail to resolve a particular pattern, try removing a few features
    from the pattern and see if we can resolve that fallback and continue on
    with the trace with a close approximation.
    
    This is then behaves very similar as if the pattern requested a specific
    font that was not available on the system and so was substituted.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c
index 8df03d6..42f5296 100644
--- a/util/cairo-script/cairo-script-operators.c
+++ b/util/cairo-script/cairo-script-operators.c
@@ -1922,6 +1922,7 @@ _ft_create_for_pattern (csi_t *ctx,
     if (bytes != tmpl.bytes)
 	_csi_free (ctx, bytes);
 
+retry:
     resolved = pattern;
     if (cairo_version () < CAIRO_VERSION_ENCODE (1, 9, 0)) {
 	/* prior to 1.9, you needed to pass a resolved pattern */
@@ -1933,9 +1934,23 @@ _ft_create_for_pattern (csi_t *ctx,
     }
 
     font_face = cairo_ft_font_face_create_for_pattern (resolved);
-    FcPatternDestroy (resolved);
     if (resolved != pattern)
-	FcPatternDestroy (pattern);
+	FcPatternDestroy (resolved);
+
+    if (cairo_font_face_status (font_face)) {
+	char *filename = NULL;
+
+	/* Try a manual fallback process by eliminating specific requests */
+
+	if (FcPatternGetString (pattern,
+				FC_FILE, 0,
+				(FcChar8 **) &filename) == FcResultMatch) {
+	    FcPatternDel (pattern, FC_FILE);
+	    goto retry;
+	}
+    }
+
+    FcPatternDestroy (pattern);
 
     data = _csi_slab_alloc (ctx, sizeof (*data));
     ctx->_faces = _csi_list_prepend (ctx->_faces, &data->blob.list);
commit a7d505d40f439208b30762be663f332c60bc0883
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Aug 20 16:43:28 2012 +0100

    ft: Report FILE_NOT_FOUND if creating a font with a specified nonexistent file
    
    If the FcPattern used to create a font specifies an exact file to use
    and it does not exist we will fail much later with an ambiguous
    NO_MEMORY error. As suggested by Behdad Esfahbod we should report this
    back to the user so that they can take the appropriate action rather
    than providing an automatic fallback.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 98a5583..bd616b5 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -564,7 +564,8 @@ _cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern,
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	    goto DONE;
-	}
+	} else
+	    return _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND);
     }
 
     /* The pattern contains neither a face nor a filename, resolve it later. */


More information about the cairo-commit mailing list