diff options
Diffstat (limited to 'test/cairo-test.c')
-rw-r--r-- | test/cairo-test.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/cairo-test.c b/test/cairo-test.c index cbd4fb1ab..5a2cf1a74 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -1825,3 +1825,70 @@ cairo_test_status_from_status (const cairo_test_context_t *ctx, return CAIRO_TEST_FAILURE; } + +#if CAIRO_HAS_FT_FONT + +#include "cairo-ft.h" + +static void +_free_face (void *face) +{ + FT_Done_Face ((FT_Face) face); +} + +static FT_Library ft_library = NULL; + +#endif + +static const cairo_user_data_key_t ft_font_key; + +cairo_test_status_t +cairo_test_ft_select_font_from_file (cairo_t *cr, + const char *filename) +{ + const cairo_test_context_t *ctx = cairo_test_get_context (cr); +#if CAIRO_HAS_FT_FONT + FT_Face face; + cairo_font_face_t *font_face; + char *srcdir_filename = NULL; + + if (access (filename, F_OK) != 0) { + if (ctx->srcdir) { + xasprintf (&srcdir_filename, "%s/%s", ctx->srcdir, filename); + filename = srcdir_filename; + } + } + + if (access (filename, F_OK) != 0) { + cairo_test_log (ctx, "Could not find font file: %s\n", filename); + return CAIRO_TEST_FAILURE; + } + + if (!ft_library) { + if (FT_Init_FreeType (&ft_library)) + return CAIRO_TEST_FAILURE; + } + + if (FT_New_Face (ft_library, filename, 0, &face)) { + cairo_test_log (ctx, "FT_New_Face failed loading font file: %s\n", filename); + return CAIRO_TEST_FAILURE; + } + + free (srcdir_filename); + font_face = cairo_ft_font_face_create_for_ft_face (face, 0); + if (cairo_font_face_status (font_face)) + return CAIRO_TEST_FAILURE; + + cairo_font_face_set_user_data (font_face, &ft_font_key, face, _free_face); + cairo_set_font_face (cr, font_face); + if (cairo_status (cr)) + return CAIRO_TEST_FAILURE; + + cairo_font_face_destroy (font_face); + + return CAIRO_TEST_SUCCESS; +#else + cairo_test_log (ctx, "cairo_test_ft_select_font_from_file() requires the FreeType backend\n"); + return CAIRO_TEST_FAILURE; +#endif +} |