summaryrefslogtreecommitdiff
path: root/test/text-rotate.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-01-22 19:02:39 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2010-01-22 23:01:51 +0000
commitf0678fb70ceec5db1b7c3f0eb1c5603039daf307 (patch)
tree41af25ae6b3433bc559b020f20567df776dd33bb /test/text-rotate.c
parent2edd2adafc471f4aa9c417d4bc76cc38466a9ed0 (diff)
downloadcairo-f0678fb70ceec5db1b7c3f0eb1c5603039daf307.tar.gz
test: Tweak aligned of text-rotate
Reset the rotation for every quadrant so that the starting rectangles are pixel-aligned.
Diffstat (limited to 'test/text-rotate.c')
-rw-r--r--test/text-rotate.c68
1 files changed, 49 insertions, 19 deletions
diff --git a/test/text-rotate.c b/test/text-rotate.c
index 2613c88f9..cbc756c09 100644
--- a/test/text-rotate.c
+++ b/test/text-rotate.c
@@ -90,14 +90,47 @@
#define NUM_TEXT 20
#define TEXT_SIZE 12
-/* Draw the word cairo at NUM_TEXT different angles */
+/* Draw the word cairo at NUM_TEXT different angles.
+ * We separate the circle into quadrants to reduce
+ * numerical errors i.e. so each quarter is pixel-aligned.
+ */
+static void
+draw_quadrant (cairo_t *cr,
+ const char *text,
+ const cairo_text_extents_t *extents,
+ const cairo_matrix_t *transform,
+ int x_off, int y_off)
+{
+ int i;
+
+ for (i = 0; i < NUM_TEXT/4; i++) {
+ cairo_save (cr);
+ cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
+ cairo_transform (cr, transform);
+ cairo_set_line_width (cr, 1.0);
+ cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents->width + 1, extents->height + 1);
+ cairo_set_source_rgb (cr, 1, 0, 0);
+ cairo_stroke (cr);
+ cairo_move_to (cr, x_off - extents->x_bearing, y_off - extents->y_bearing);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+#if CAIRO_TEST_GENERATE_REFERENCE_IMAGE
+ cairo_text_path (cr, text);
+ cairo_fill (cr);
+#else
+ cairo_show_text (cr, text);
+#endif
+ cairo_restore (cr);
+ }
+}
+
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
- int i, x_off, y_off;
cairo_text_extents_t extents;
cairo_font_options_t *font_options;
const char text[] = "cairo";
+ int x_off, y_off;
+ cairo_matrix_t m;
/* paint white so we don't need separate ref images for
* RGB24 and ARGB32 */
@@ -130,23 +163,20 @@ draw (cairo_t *cr, int width, int height)
x_off = floor (0.5 + (extents.height+1) / (2 * tan (M_PI/NUM_TEXT)));
}
- for (i=0; i < NUM_TEXT; i++) {
- cairo_save (cr);
- cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
- cairo_set_line_width (cr, 1.0);
- cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents.width + 1, extents.height + 1);
- cairo_set_source_rgb (cr, 1, 0, 0);
- cairo_stroke (cr);
- cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing);
- cairo_set_source_rgb (cr, 0, 0, 0);
-#if CAIRO_TEST_GENERATE_REFERENCE_IMAGE
- cairo_text_path (cr, text);
- cairo_fill (cr);
-#else
- cairo_show_text (cr, text);
-#endif
- cairo_restore (cr);
- }
+ cairo_save (cr);
+ cairo_matrix_init_identity (&m);
+ draw_quadrant (cr, text, &extents, &m, x_off, y_off);
+ cairo_matrix_init (&m, 0, 1, -1, 0, 0, 0);
+ draw_quadrant (cr, text, &extents, &m, x_off, y_off);
+ cairo_restore (cr);
+
+ cairo_save (cr);
+ cairo_scale (cr, -1, -1);
+ cairo_matrix_init_identity (&m);
+ draw_quadrant (cr, text, &extents, &m, x_off, y_off);
+ cairo_matrix_init (&m, 0, 1, -1, 0, 0, 0);
+ draw_quadrant (cr, text, &extents, &m, x_off, y_off);
+ cairo_restore (cr);
return CAIRO_TEST_SUCCESS;
}