[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / ft-font-create-for-ft-face.c
blob35cb77d487156c57ce64a073b70eae610f76a399
1 /*
2 * Copyright © 2005 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Carl D. Worth <cworth@cworth.org>
26 #include "cairo-test.h"
27 #include <cairo-ft.h>
29 static cairo_test_draw_function_t draw;
31 cairo_test_t test = {
32 "ft-font-create-for-ft-face",
33 "Simple test to verify that cairo_ft_font_create_for_ft_face doesn't crash.",
34 0, 0,
35 draw
38 static cairo_test_status_t
39 draw (cairo_t *cr, int width, int height)
41 FcPattern *pattern, *resolved;
42 FcResult result;
43 cairo_font_face_t *font_face;
44 cairo_scaled_font_t *scaled_font;
45 cairo_font_options_t *font_options;
46 cairo_font_extents_t font_extents;
47 cairo_matrix_t font_matrix, ctm;
48 FT_Face ft_face;
50 /* We're trying here to get our hands on _some_ FT_Face but we do
51 * not at all care which one. So we start with an empty pattern
52 * and do the minimal substitution on it in order to get a valid
53 * pattern.
55 * Do not use this in production code! */
56 pattern = FcPatternCreate ();
57 if (! pattern) {
58 cairo_test_log ("FcPatternCreate failed.\n");
59 return CAIRO_TEST_FAILURE;
62 FcConfigSubstitute (NULL, pattern, FcMatchPattern);
63 FcDefaultSubstitute (pattern);
64 resolved = FcFontMatch (NULL, pattern, &result);
65 if (! resolved) {
66 cairo_test_log ("FcFontMatch failed.\n");
67 return CAIRO_TEST_FAILURE;
70 font_face = cairo_ft_font_face_create_for_pattern (resolved);
72 if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
73 cairo_test_log ("Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
74 cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
75 cairo_font_face_destroy (font_face);
76 return CAIRO_TEST_FAILURE;
79 cairo_matrix_init_identity (&font_matrix);
81 cairo_get_matrix (cr, &ctm);
83 font_options = cairo_font_options_create ();
85 cairo_get_font_options (cr, font_options);
87 scaled_font = cairo_scaled_font_create (font_face,
88 &font_matrix,
89 &ctm,
90 font_options);
92 ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
94 cairo_font_options_destroy (font_options);
95 cairo_font_face_destroy (font_face);
96 FcPatternDestroy (pattern);
97 FcPatternDestroy (resolved);
99 if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_FT) {
100 cairo_test_log ("Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n",
101 cairo_scaled_font_get_type (scaled_font), CAIRO_FONT_TYPE_FT);
102 cairo_scaled_font_destroy (scaled_font);
103 return CAIRO_TEST_FAILURE;
106 if (!ft_face) {
107 cairo_test_log ("Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n");
108 cairo_scaled_font_destroy (scaled_font);
109 return CAIRO_TEST_FAILURE;
112 /* phew, that was a lot of work. But at least we didn't ever have
113 * to call freetype directly, nor did we have to make many (any?)
114 * assumptions about the current system.
116 * Now, on to the simple thing we actually want to test.
118 font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
120 /* Set the font_face and force cairo to actually use it for
121 * something. */
122 cairo_save (cr);
123 cairo_set_font_face (cr, font_face);
124 cairo_font_extents (cr, &font_extents);
125 cairo_restore (cr);
127 /* Finally, even more cleanup */
128 cairo_font_face_destroy (font_face);
129 cairo_ft_scaled_font_unlock_face (scaled_font);
130 cairo_scaled_font_destroy (scaled_font);
132 return CAIRO_TEST_SUCCESS;
136 main (void)
138 return cairo_test (&test);