ft-font-create-for-ft-face.c [plain text]
#include "cairo-test.h"
#include <cairo-ft.h>
static cairo_test_draw_function_t draw;
static const cairo_test_t test = {
"ft-font-create-for-ft-face",
"Simple test to verify that cairo_ft_font_create_for_ft_face doesn't crash.",
0, 0,
draw
};
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
FcPattern *pattern, *resolved;
FcResult result;
cairo_font_face_t *font_face;
cairo_scaled_font_t *scaled_font;
cairo_font_options_t *font_options;
cairo_font_extents_t font_extents;
cairo_matrix_t font_matrix, ctm;
FT_Face ft_face;
pattern = FcPatternCreate ();
if (! pattern) {
cairo_test_log (ctx, "FcPatternCreate failed.\n");
return CAIRO_TEST_FAILURE;
}
FcConfigSubstitute (NULL, pattern, FcMatchPattern);
FcDefaultSubstitute (pattern);
resolved = FcFontMatch (NULL, pattern, &result);
if (! resolved) {
cairo_test_log (ctx, "FcFontMatch failed.\n");
return CAIRO_TEST_FAILURE;
}
font_face = cairo_ft_font_face_create_for_pattern (resolved);
if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
cairo_font_face_destroy (font_face);
return CAIRO_TEST_FAILURE;
}
cairo_matrix_init_identity (&font_matrix);
cairo_get_matrix (cr, &ctm);
font_options = cairo_font_options_create ();
cairo_get_font_options (cr, font_options);
scaled_font = cairo_scaled_font_create (font_face,
&font_matrix,
&ctm,
font_options);
ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
cairo_font_options_destroy (font_options);
cairo_font_face_destroy (font_face);
FcPatternDestroy (pattern);
FcPatternDestroy (resolved);
if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_FT) {
cairo_test_log (ctx, "Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n",
cairo_scaled_font_get_type (scaled_font), CAIRO_FONT_TYPE_FT);
cairo_scaled_font_destroy (scaled_font);
return CAIRO_TEST_FAILURE;
}
if (!ft_face) {
cairo_test_log (ctx, "Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n");
cairo_scaled_font_destroy (scaled_font);
return CAIRO_TEST_FAILURE;
}
font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
cairo_save (cr);
cairo_set_font_face (cr, font_face);
cairo_font_extents (cr, &font_extents);
cairo_restore (cr);
cairo_font_face_destroy (font_face);
cairo_ft_scaled_font_unlock_face (scaled_font);
cairo_scaled_font_destroy (scaled_font);
return CAIRO_TEST_SUCCESS;
}
int
main (void)
{
return cairo_test (&test);
}