[cairo] Text rotation bugs

Carl Worth cworth at cworth.org
Tue Nov 9 14:34:25 PST 2004


I've been playing a bit more with text rotation.

The recent patches fixed some of the gross errors in the Xlib backend,
but even with the image backend there are still errors.

Here's a bit of code to draw the word "cairo" and its bounding box,
rotated some number of times:

    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_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);
    }

Note that all of the drawing commands are loop-invariant. The only thing
changing here is the rotation. A complete program containing this code
can be found in cairo/test/text_rotate.c, and the attached image shows
the result with NUM_TEXT set to 20.

Looking at the results, it's plain to see that while at an angle of 0
the text is precisely contained within its bounding box, at other angles
it is not. Also, the relative position of the letters is not consistent,
(compare "r" and "o"). Finally, at some rotation the scale of the
letters is inconsistent, (compare iteration 1 with N-1 for a dramatic
example).

I've been working on the test so far, and haven't looked closely at the
implementation yet.

-Carl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: text_rotate-out.png
Type: image/png
Size: 11756 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041109/e3df4a79/text_rotate-out.png


More information about the cairo mailing list