[cairo-commit] src/cairo-ft-font.c

Chris Wilson ickle at kemper.freedesktop.org
Sun Aug 19 04:43:48 PDT 2012


 src/cairo-ft-font.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 43c5387d1b251938eeba458a95d63e2dc7178c2d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Aug 19 12:41:15 2012 +0100

    ft: Only use a specified font filename if its accessible
    
    If we try to use a non-existent path, FT_New_Face returns an error.
    Instead, just use fontconfig to generate a fallback pattern.
    
    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 f9fcfae..98a5583 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -64,6 +64,12 @@
 #include FT_LCD_FILTER_H
 #endif
 
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#else
+#define access(p, m) 0
+#endif
+
 /* Fontconfig version older than 2.6 didn't have these options */
 #ifndef FC_LCD_FILTER
 #define FC_LCD_FILTER	"lcdfilter"
@@ -551,12 +557,14 @@ _cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern,
     if (ret == FcResultOutOfMemory)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     if (ret == FcResultMatch) {
-	/* If FC_INDEX is not set, we just use 0 */
-	ret = FcPatternGetInteger (pattern, FC_INDEX, 0, &id);
-	if (ret == FcResultOutOfMemory)
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	if (access (filename, R_OK) == 0) {
+	    /* If FC_INDEX is not set, we just use 0 */
+	    ret = FcPatternGetInteger (pattern, FC_INDEX, 0, &id);
+	    if (ret == FcResultOutOfMemory)
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-	goto DONE;
+	    goto DONE;
+	}
     }
 
     /* The pattern contains neither a face nor a filename, resolve it later. */


More information about the cairo-commit mailing list