1
/*
2
 * Copyright © 2005,2008 Red Hat, Inc.
3
 *
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.
14
 *
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.
22
 *
23
 * Author: Carl D. Worth <cworth@cworth.org>
24
 *         Behdad Esfahbod <behdad@behdad.org>
25
 */
26

            
27
#include "config.h"
28

            
29
#include "cairo-test.h"
30

            
31
#include <cairo.h>
32
#include <assert.h>
33
#include <string.h>
34

            
35
#if   CAIRO_HAS_WIN32_FONT
36
#define CAIRO_FONT_FAMILY_DEFAULT "Arial"
37
#elif CAIRO_HAS_QUARTZ_FONT
38
#define CAIRO_FONT_FAMILY_DEFAULT "Helvetica"
39
#elif CAIRO_HAS_FT_FONT
40
#define CAIRO_FONT_FAMILY_DEFAULT ""
41
#else
42
#define CAIRO_FONT_FAMILY_DEFAULT "@cairo:"
43
#endif
44

            
45

            
46
static cairo_test_status_t
47
1
preamble (cairo_test_context_t *ctx)
48
{
49
    cairo_t *cr;
50
    cairo_surface_t *surface;
51
    cairo_font_face_t *font_face;
52
    cairo_status_t status;
53

            
54
1
    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
55
1
    cr = cairo_create (surface);
56
1
    cairo_surface_destroy (surface);
57

            
58
1
    font_face = cairo_font_face_reference (cairo_get_font_face (cr));
59
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
60
1
    assert (cairo_toy_font_face_get_family (font_face) != NULL);
61
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
62
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
63
1
    status = cairo_font_face_status(font_face);
64
1
    cairo_font_face_destroy (font_face);
65

            
66
1
    if (status)
67
	return cairo_test_status_from_status (ctx, status);
68

            
69
1
    cairo_select_font_face (cr,
70
			    "bizarre",
71
			    CAIRO_FONT_SLANT_OBLIQUE,
72
			    CAIRO_FONT_WEIGHT_BOLD);
73
1
    font_face = cairo_font_face_reference (cairo_get_font_face (cr));
74
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
75
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bizarre"));
76
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
77
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
78
1
    status = cairo_font_face_status(font_face);
79
1
    cairo_font_face_destroy (font_face);
80

            
81
1
    if (status)
82
	return cairo_test_status_from_status (ctx, status);
83

            
84
1
    font_face = cairo_toy_font_face_create ("bozarre",
85
					    CAIRO_FONT_SLANT_OBLIQUE,
86
					    CAIRO_FONT_WEIGHT_BOLD);
87
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
88
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bozarre"));
89
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
90
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
91
1
    status = cairo_font_face_status(font_face);
92
1
    cairo_font_face_destroy (font_face);
93

            
94
1
    if (status)
95
	return cairo_test_status_from_status (ctx, status);
96

            
97
1
    font_face = cairo_toy_font_face_create (NULL,
98
					    CAIRO_FONT_SLANT_OBLIQUE,
99
					    CAIRO_FONT_WEIGHT_BOLD);
100
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
101
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
102
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
103
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
104
1
    assert (cairo_font_face_status(font_face) == CAIRO_STATUS_NULL_POINTER);
105
1
    cairo_font_face_destroy (font_face);
106

            
107
1
    font_face = cairo_toy_font_face_create ("\xff",
108
					    CAIRO_FONT_SLANT_OBLIQUE,
109
					    CAIRO_FONT_WEIGHT_BOLD);
110
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
111
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
112
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
113
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
114
1
    assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_STRING);
115
1
    cairo_font_face_destroy (font_face);
116

            
117
1
    font_face = cairo_toy_font_face_create ("sans",
118
					    -1,
119
					    CAIRO_FONT_WEIGHT_BOLD);
120
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
121
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
122
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
123
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
124
1
    assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_SLANT);
125
1
    cairo_font_face_destroy (font_face);
126

            
127
1
    font_face = cairo_toy_font_face_create ("sans",
128
					    CAIRO_FONT_SLANT_OBLIQUE,
129
					    -1);
130
1
    assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
131
1
    assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
132
1
    assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
133
1
    assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
134
1
    assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_WEIGHT);
135
1
    cairo_font_face_destroy (font_face);
136

            
137
1
    cairo_destroy (cr);
138

            
139
1
    return CAIRO_TEST_SUCCESS;
140
}
141

            
142
1
CAIRO_TEST (toy_font_face,
143
	    "Check the construction of 'toy' font faces",
144
	    "font, api", /* keywords */
145
	    NULL, /* requirements */
146
	    0, 0,
147
	    preamble, NULL)