From 9dacc32fbc4acd00795805244dd0d2a4faa48818 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 9 Nov 2004 14:22:37 +0000 Subject: [PATCH] Increase size and increase number of different angles drawn. (draw): Fix broken usage of extents (missing bearings), add stroked bounding box (shifted out by 0.5 units to just abut the text), and increase position adjustments to make room for this larger box. --- ChangeLog | 9 +++++++++ test/text-rotate.c | 32 ++++++++++++++++++-------------- test/text_rotate.c | 32 ++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90a911c76..617e3aaad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-11-09 Carl Worth + + * test/text_rotate.c (NUM_TEXT): Increase size and increase number + of different angles drawn. + (draw): Fix broken usage of extents (missing bearings), add + stroked bounding box (shifted out by 0.5 units to just abut the + text), and increase position adjustments to make room for this + larger box. + 2004-11-08 Dave Beckett * configure.in: require libpixman 0.1.2 since diff --git a/test/text-rotate.c b/test/text-rotate.c index 156523974..af62cc64f 100644 --- a/test/text-rotate.c +++ b/test/text-rotate.c @@ -59,10 +59,10 @@ #include "cairo_test.h" -#define WIDTH 100 -#define HEIGHT 100 -#define NUM_TEXT 8 -#define TEXT_SIZE 10 +#define WIDTH 150 +#define HEIGHT 150 +#define NUM_TEXT 20 +#define TEXT_SIZE 12 cairo_test_t test = { "text_rotate", @@ -89,18 +89,22 @@ draw (cairo_t *cr, int width, int height) cairo_text_extents (cr, text, &extents); - for (i=0; i < 8; i++) { + for (i=0; i < NUM_TEXT; i++) { + double x_off, y_off; + if (NUM_TEXT == 1) { + x_off = y_off = 0.0; + } else { + y_off = - round (extents.height / 2.0); + x_off = round ((extents.height+1) / (2 * tan (M_PI/NUM_TEXT))); + } cairo_save (cr); cairo_rotate (cr, 2*M_PI*i/NUM_TEXT); - /* XXX: extents.height / 4.0 gets the right result here, but I - * would think it should be extents.height / 2.0. Perhaps I'm - * using the extents incorrectly, (really need to go write - * that reference on cairo_text_extents with a good - * diagram...). - */ - cairo_move_to (cr, - extents.height / (2 * tan (2*M_PI/NUM_TEXT)), - extents.height / 4.0); + 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_rgb_color (cr, 1, 0, 0); + cairo_stroke (cr); + cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing); + cairo_set_rgb_color (cr, 0, 0, 0); cairo_show_text (cr, "cairo"); cairo_restore (cr); } diff --git a/test/text_rotate.c b/test/text_rotate.c index 156523974..af62cc64f 100644 --- a/test/text_rotate.c +++ b/test/text_rotate.c @@ -59,10 +59,10 @@ #include "cairo_test.h" -#define WIDTH 100 -#define HEIGHT 100 -#define NUM_TEXT 8 -#define TEXT_SIZE 10 +#define WIDTH 150 +#define HEIGHT 150 +#define NUM_TEXT 20 +#define TEXT_SIZE 12 cairo_test_t test = { "text_rotate", @@ -89,18 +89,22 @@ draw (cairo_t *cr, int width, int height) cairo_text_extents (cr, text, &extents); - for (i=0; i < 8; i++) { + for (i=0; i < NUM_TEXT; i++) { + double x_off, y_off; + if (NUM_TEXT == 1) { + x_off = y_off = 0.0; + } else { + y_off = - round (extents.height / 2.0); + x_off = round ((extents.height+1) / (2 * tan (M_PI/NUM_TEXT))); + } cairo_save (cr); cairo_rotate (cr, 2*M_PI*i/NUM_TEXT); - /* XXX: extents.height / 4.0 gets the right result here, but I - * would think it should be extents.height / 2.0. Perhaps I'm - * using the extents incorrectly, (really need to go write - * that reference on cairo_text_extents with a good - * diagram...). - */ - cairo_move_to (cr, - extents.height / (2 * tan (2*M_PI/NUM_TEXT)), - extents.height / 4.0); + 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_rgb_color (cr, 1, 0, 0); + cairo_stroke (cr); + cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing); + cairo_set_rgb_color (cr, 0, 0, 0); cairo_show_text (cr, "cairo"); cairo_restore (cr); }