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>
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
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.
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
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
81 * Seems like all the "bugs" have been fixed and all remaining is
82 * missing support for subpixel glyph positioning. Removing from
86 #include "cairo-test.h"
93 /* Draw the word cairo at NUM_TEXT different angles.
94 * We separate the circle into quadrants to reduce
95 * numerical errors i.e. so each quarter is pixel-aligned.
98 draw_quadrant (cairo_t *cr,
100 const cairo_text_extents_t *extents,
101 const cairo_matrix_t *transform,
102 int x_off, int y_off)
106 for (i = 0; i < NUM_TEXT/4; i++) {
108 cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
109 cairo_transform (cr, transform);
110 cairo_set_line_width (cr, 1.0);
111 cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents->width + 1, extents->height + 1);
112 cairo_set_source_rgb (cr, 1, 0, 0);
114 cairo_move_to (cr, x_off - extents->x_bearing, y_off - extents->y_bearing);
115 cairo_set_source_rgb (cr, 0, 0, 0);
116 #if CAIRO_TEST_GENERATE_REFERENCE_IMAGE
117 cairo_text_path (cr, text);
120 cairo_show_text (cr, text);
126 static cairo_test_status_t
127 draw (cairo_t *cr, int width, int height)
129 cairo_text_extents_t extents;
130 cairo_font_options_t *font_options;
131 const char text[] = "cairo";
135 /* paint white so we don't need separate ref images for
136 * RGB24 and ARGB32 */
137 cairo_set_source_rgb (cr, 1., 1., 1.);
140 cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
141 CAIRO_FONT_SLANT_NORMAL,
142 CAIRO_FONT_WEIGHT_NORMAL);
143 cairo_set_font_size (cr, TEXT_SIZE);
145 font_options = cairo_font_options_create ();
147 cairo_get_font_options (cr, font_options);
148 cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
150 cairo_set_font_options (cr, font_options);
151 cairo_font_options_destroy (font_options);
153 cairo_set_source_rgb (cr, 0, 0, 0);
155 cairo_translate (cr, WIDTH/2.0, HEIGHT/2.0);
157 cairo_text_extents (cr, text, &extents);
162 y_off = - floor (0.5 + extents.height / 2.0);
163 x_off = floor (0.5 + (extents.height+1) / (2 * tan (M_PI/NUM_TEXT)));
167 cairo_matrix_init_identity (&m);
168 draw_quadrant (cr, text, &extents, &m, x_off, y_off);
169 cairo_matrix_init (&m, 0, 1, -1, 0, 0, 0);
170 draw_quadrant (cr, text, &extents, &m, x_off, y_off);
174 cairo_scale (cr, -1, -1);
175 cairo_matrix_init_identity (&m);
176 draw_quadrant (cr, text, &extents, &m, x_off, y_off);
177 cairo_matrix_init (&m, 0, 1, -1, 0, 0, 0);
178 draw_quadrant (cr, text, &extents, &m, x_off, y_off);
181 return CAIRO_TEST_SUCCESS;
184 CAIRO_TEST (text_rotate,
185 "Tests show_text under various rotations",
186 "text, transform", /* keywords */
187 NULL, /* requirements */