[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / ft-text-vertical-layout-type3.c
blob4d1394aedd08ab97fb80069792d39bdc0c9e059e
1 /*
2 * Copyright © 2006 Jinghua Luo
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 * JINGHUA LUO 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: Jinghua Luo <sunmoon1997@gmail.com>
24 * Derived from:
25 * text-antialias-none.c,
26 * ft-font-create-for-ft-face.c.
27 * Original Author: Carl D. Worth <cworth@cworth.org>
29 #include "cairo-test.h"
30 #include <cairo-ft.h>
32 #define WIDTH 80
33 #define HEIGHT 200
34 #define TEXT_SIZE 30
36 static cairo_test_draw_function_t draw;
38 cairo_test_t test = {
39 "ft-text-vertical-layout-type3",
40 "Tests text rendering for vertical layout with TrueType fonts",
41 WIDTH, HEIGHT,
42 draw
45 static cairo_scaled_font_t *
46 create_scaled_font (cairo_t * cr)
48 FcPattern *pattern, *resolved;
49 FcResult result;
50 cairo_font_face_t *font_face;
51 cairo_scaled_font_t *scaled_font;
52 cairo_font_options_t *font_options;
53 cairo_matrix_t font_matrix, ctm;
54 double pixel_size;
56 font_options = cairo_font_options_create ();
58 cairo_get_font_options (cr, font_options);
60 pattern = FcPatternCreate ();
62 FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *)"Bitstream Vera Sans");
63 FcPatternAddDouble (pattern, FC_PIXEL_SIZE, TEXT_SIZE);
64 FcConfigSubstitute (NULL, pattern, FcMatchPattern);
66 cairo_ft_font_options_substitute (font_options, pattern);
68 FcDefaultSubstitute (pattern);
69 resolved = FcFontMatch (NULL, pattern, &result);
71 /* set layout to vertical */
72 FcPatternDel (resolved, FC_VERTICAL_LAYOUT);
73 FcPatternAddBool (resolved, FC_VERTICAL_LAYOUT, FcTrue);
75 FcPatternGetDouble (resolved, FC_PIXEL_SIZE, 0, &pixel_size);
77 font_face = cairo_ft_font_face_create_for_pattern (resolved);
79 cairo_matrix_init_translate (&font_matrix, 10, 30);
80 cairo_matrix_rotate (&font_matrix, M_PI_2/3);
81 cairo_matrix_scale (&font_matrix, pixel_size, pixel_size);
83 cairo_get_matrix (cr, &ctm);
85 scaled_font = cairo_scaled_font_create (font_face,
86 &font_matrix,
87 &ctm,
88 font_options);
90 cairo_font_options_destroy (font_options);
91 cairo_font_face_destroy (font_face);
92 FcPatternDestroy (pattern);
93 FcPatternDestroy (resolved);
95 return scaled_font;
98 static cairo_test_status_t
99 draw (cairo_t *cr, int width, int height)
101 cairo_text_extents_t extents;
102 cairo_scaled_font_t * scaled_font;
103 static char text[] = "i-W";
104 double line_width, x, y;
106 line_width = cairo_get_line_width (cr);
108 /* We draw in the default black, so paint white first. */
109 cairo_save (cr);
110 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
111 cairo_paint (cr);
112 cairo_restore (cr);
114 scaled_font = create_scaled_font (cr);
115 cairo_set_scaled_font (cr, scaled_font);
117 cairo_set_line_width (cr, 1.0);
118 cairo_set_source_rgb (cr, 0, 0, 0); /* black */
119 cairo_text_extents (cr, text, &extents);
120 x = width - (extents.width + extents.x_bearing) - 5;
121 y = height - (extents.height + extents.y_bearing) - 5;
122 cairo_move_to (cr, x, y);
123 cairo_show_text (cr, text);
124 cairo_rectangle (cr,
125 x + extents.x_bearing - line_width / 2,
126 y + extents.y_bearing - line_width / 2,
127 extents.width + line_width,
128 extents.height + line_width);
129 cairo_stroke (cr);
131 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
132 cairo_text_extents (cr, text, &extents);
133 x = -extents.x_bearing + 5;
134 y = -extents.y_bearing + 5;
135 cairo_move_to (cr, x, y);
136 cairo_text_path (cr, text);
137 cairo_fill (cr);
138 cairo_rectangle (cr,
139 x + extents.x_bearing - line_width / 2,
140 y + extents.y_bearing - line_width / 2,
141 extents.width + line_width,
142 extents.height + line_width);
143 cairo_stroke (cr);
145 cairo_scaled_font_destroy (scaled_font);
147 return CAIRO_TEST_SUCCESS;
151 main (void)
153 return cairo_test (&test);