2005-08-17 09:51:09 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2005 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-test.h"
|
|
|
|
|
#include <cairo-ft.h>
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
|
|
|
|
draw (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
2008-08-11 21:12:45 +01:00
|
|
|
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
|
2006-01-20 15:15:40 +00:00
|
|
|
FcPattern *pattern, *resolved;
|
|
|
|
|
FcResult result;
|
2005-08-17 09:51:09 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* We're trying here to get our hands on _some_ FT_Face but we do
|
2006-01-20 15:15:40 +00:00
|
|
|
* not at all care which one. So we start with an empty pattern
|
|
|
|
|
* and do the minimal substitution on it in order to get a valid
|
2008-04-29 09:03:00 +01:00
|
|
|
* pattern.
|
|
|
|
|
*
|
|
|
|
|
* Do not use this in production code! */
|
2005-08-17 09:51:09 +00:00
|
|
|
pattern = FcPatternCreate ();
|
2006-01-20 15:15:40 +00:00
|
|
|
if (! pattern) {
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx, "FcPatternCreate failed.\n");
|
2005-08-17 09:51:09 +00:00
|
|
|
return CAIRO_TEST_FAILURE;
|
2006-01-20 15:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcConfigSubstitute (NULL, pattern, FcMatchPattern);
|
|
|
|
|
FcDefaultSubstitute (pattern);
|
|
|
|
|
resolved = FcFontMatch (NULL, pattern, &result);
|
|
|
|
|
if (! resolved) {
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx, "FcFontMatch failed.\n");
|
2006-01-20 15:15:40 +00:00
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
2005-08-17 09:51:09 +00:00
|
|
|
|
2006-01-20 15:15:40 +00:00
|
|
|
font_face = cairo_ft_font_face_create_for_pattern (resolved);
|
2005-08-17 09:51:09 +00:00
|
|
|
|
2006-02-28 02:30:27 -08:00
|
|
|
if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
|
2006-02-28 02:30:27 -08:00
|
|
|
cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
|
|
|
|
|
cairo_font_face_destroy (font_face);
|
|
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-17 09:51:09 +00:00
|
|
|
cairo_matrix_init_identity (&font_matrix);
|
|
|
|
|
|
|
|
|
|
cairo_get_matrix (cr, &ctm);
|
|
|
|
|
|
|
|
|
|
font_options = cairo_font_options_create ();
|
|
|
|
|
|
2006-07-31 15:17:15 -04:00
|
|
|
cairo_get_font_options (cr, font_options);
|
|
|
|
|
|
2005-08-17 09:51:09 +00:00
|
|
|
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);
|
2006-01-20 15:15:40 +00:00
|
|
|
FcPatternDestroy (resolved);
|
2005-08-17 09:51:09 +00:00
|
|
|
|
2006-02-28 02:30:27 -08:00
|
|
|
if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_FT) {
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx, "Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n",
|
2006-02-28 02:30:27 -08:00
|
|
|
cairo_scaled_font_get_type (scaled_font), CAIRO_FONT_TYPE_FT);
|
|
|
|
|
cairo_scaled_font_destroy (scaled_font);
|
|
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-17 09:51:09 +00:00
|
|
|
if (!ft_face) {
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx, "Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n");
|
2005-08-17 09:51:09 +00:00
|
|
|
cairo_scaled_font_destroy (scaled_font);
|
|
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* phew, that was a lot of work. But at least we didn't ever have
|
|
|
|
|
* to call freetype directly, nor did we have to make many (any?)
|
|
|
|
|
* assumptions about the current system.
|
|
|
|
|
*
|
|
|
|
|
* Now, on to the simple thing we actually want to test.
|
|
|
|
|
*/
|
|
|
|
|
font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
|
|
|
|
|
|
|
|
|
|
/* Set the font_face and force cairo to actually use it for
|
|
|
|
|
* something. */
|
2008-04-29 09:03:00 +01:00
|
|
|
cairo_save (cr);
|
2005-08-17 09:51:09 +00:00
|
|
|
cairo_set_font_face (cr, font_face);
|
|
|
|
|
cairo_font_extents (cr, &font_extents);
|
2008-04-29 09:03:00 +01:00
|
|
|
cairo_restore (cr);
|
2005-08-17 09:51:09 +00:00
|
|
|
|
|
|
|
|
/* Finally, even more cleanup */
|
|
|
|
|
cairo_font_face_destroy (font_face);
|
|
|
|
|
cairo_ft_scaled_font_unlock_face (scaled_font);
|
|
|
|
|
cairo_scaled_font_destroy (scaled_font);
|
|
|
|
|
|
|
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
CAIRO_TEST (ft_font_create_for_ft_face,
|
|
|
|
|
"Simple test to verify that cairo_ft_font_create_for_ft_face doesn't crash.",
|
|
|
|
|
"ft, font", /* keywords */
|
|
|
|
|
NULL, /* requirements */
|
|
|
|
|
0, 0,
|
|
|
|
|
NULL, draw)
|
|
|
|
|
|