[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / text-rotate.c
blob71d9cc366c72cfffd8a00edc40cc2cf30a96f9c7
1 /*
2 * Copyright © 2004 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 /* Bug history
28 * 2004-11-03 Steve Chaplin <stevech1097@yahoo.com.au>
30 * Reported bug on mailing list:
32 * From: Steve Chaplin <stevech1097@yahoo.com.au>
33 * To: cairo@cairographics.org
34 * Date: Thu, 04 Nov 2004 00:00:17 +0800
35 * Subject: [cairo] Rotated text bug on drawable target
37 * The attached file draws text rotated 90 degrees first to a PNG file and
38 * then to a drawable. The PNG file looks fine, the text on the drawable is
39 * unreadable.
41 * Steve
43 * 2004-11-03 Carl Worth <cworth@cworth.org>
45 * Looks like the major problems with this bug appeared in the great
46 * font rework between 0.1.23 and 0.2.0. And it looks like we need
47 * to fix the regression test suite to test the xlib target (since
48 * the bug does not show up in the png backend).
50 * Hmm... Actually, things don't look perfect even in the PNG
51 * output. Look at how that 'o' moves around. It's particularly off
52 * in the case where it's rotated by PI.
54 * And I'm still not sure about what to do for test cases with
55 * text--a new version of freetype will change everything. We may
56 * need to add a simple backend for stroked fonts and add a simple
57 * builtin font to cairo for pixel-perfect tests with text.
59 * 2005-08-23
61 * It appears that the worst placement and glyph selection problems
62 * have now been resolved. In the past some letters were noticeably
63 * of a different size at some rotations, and there was a lot of
64 * drift away from the baseline. These problems do not appear
65 * anymore.
67 * Another thing that helps is that we now have font options which
68 * we can use to disable hinting in order to get more repeatable
69 * results. I'm doing that in this test now.
71 * There are still some subtle positioning problems which I'm
72 * assuming are due to the lack of finer-than-whole-pixel glyph
73 * positioning. I'm generating a reference image now by replacing
74 * cairo_show_text with cairo_text_path; cairo_fill. This will let
75 * us look more closely at the remaining positioning problems. (In
76 * particular, I want to make sure we're rounding as well as
77 * possible).
79 * 2007-02-21
81 * Seems like all the "bugs" have been fixed and all remainint is
82 * missing support for subpixel glyph positioning. Removing from
83 * XFAIL now.
86 #include "cairo-test.h"
88 #define WIDTH 150
89 #define HEIGHT 150
90 #define NUM_TEXT 20
91 #define TEXT_SIZE 12
93 static cairo_test_draw_function_t draw;
95 cairo_test_t test = {
96 "text-rotate",
97 "Tests show_text under various rotations",
98 WIDTH, HEIGHT,
99 draw
102 /* Draw the word cairo at NUM_TEXT different angles */
103 static cairo_test_status_t
104 draw (cairo_t *cr, int width, int height)
106 int i, x_off, y_off;
107 cairo_text_extents_t extents;
108 cairo_font_options_t *font_options;
109 static char text[] = "cairo";
111 /* paint white so we don't need separate ref images for
112 * RGB24 and ARGB32 */
113 cairo_set_source_rgb (cr, 1., 1., 1.);
114 cairo_paint (cr);
116 cairo_select_font_face (cr, "Bitstream Vera Sans",
117 CAIRO_FONT_SLANT_NORMAL,
118 CAIRO_FONT_WEIGHT_NORMAL);
119 cairo_set_font_size (cr, TEXT_SIZE);
121 font_options = cairo_font_options_create ();
123 cairo_get_font_options (cr, font_options);
124 cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
126 cairo_set_font_options (cr, font_options);
127 cairo_font_options_destroy (font_options);
129 cairo_set_source_rgb (cr, 0, 0, 0);
131 cairo_translate (cr, WIDTH/2.0, HEIGHT/2.0);
133 cairo_text_extents (cr, text, &extents);
135 if (NUM_TEXT == 1) {
136 x_off = y_off = 0;
137 } else {
138 y_off = - floor (0.5 + extents.height / 2.0);
139 x_off = floor (0.5 + (extents.height+1) / (2 * tan (M_PI/NUM_TEXT)));
142 for (i=0; i < NUM_TEXT; i++) {
143 cairo_save (cr);
144 cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
145 cairo_set_line_width (cr, 1.0);
146 cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents.width + 1, extents.height + 1);
147 cairo_set_source_rgb (cr, 1, 0, 0);
148 cairo_stroke (cr);
149 cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing);
150 cairo_set_source_rgb (cr, 0, 0, 0);
151 #if CAIRO_TEST_GENERATE_REFERENCE_IMAGE
152 cairo_text_path (cr, text);
153 cairo_fill (cr);
154 #else
155 cairo_show_text (cr, text);
156 #endif
157 cairo_restore (cr);
160 return CAIRO_TEST_SUCCESS;
164 main (void)
166 return cairo_test (&test);