Back to index

lightning-sunbird  0.9+nobinonly
text_rotate.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2004 Red Hat, Inc.
00003  *
00004  * Permission to use, copy, modify, distribute, and sell this software
00005  * and its documentation for any purpose is hereby granted without
00006  * fee, provided that the above copyright notice appear in all copies
00007  * and that both that copyright notice and this permission notice
00008  * appear in supporting documentation, and that the name of
00009  * Red Hat, Inc. not be used in advertising or publicity pertaining to
00010  * distribution of the software without specific, written prior
00011  * permission. Red Hat, Inc. makes no representations about the
00012  * suitability of this software for any purpose.  It is provided "as
00013  * is" without express or implied warranty.
00014  *
00015  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
00016  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00017  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
00018  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00019  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00020  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
00021  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  *
00023  * Author: Carl D. Worth <cworth@cworth.org>
00024  */
00025 
00026 /* Bug history
00027  *
00028  * 2004-11-03 Steve Chaplin <stevech1097@yahoo.com.au>
00029  *
00030  *   Reported bug on mailing list:
00031  *
00032  *     From: Steve Chaplin <stevech1097@yahoo.com.au>
00033  *     To: cairo@cairographics.org
00034  *     Date: Thu, 04 Nov 2004 00:00:17 +0800
00035  *     Subject: [cairo] Rotated text bug on drawable target
00036  *
00037  *     The attached file draws text rotated 90 degrees first to a PNG file and
00038  *     then to a drawable. The PNG file looks fine, the text on the drawable is
00039  *     unreadable.
00040  *
00041  *     Steve
00042  *
00043  * 2004-11-03 Carl Worth <cworth@cworth.org>
00044  *
00045  *   Looks like the major problems with this bg appeared in the great
00046  *   font rework between 0.1.23 and 0.2.0. And it looks like we need
00047  *   to fix the regression test suite to test the xlib target (since
00048  *   the bug does not show up in the png backend).
00049  *
00050  *   Hmm... Actually, things don't look perfect even in the PNG
00051  *   output. Look at how that 'o' moves around. It's particularly off
00052  *   in the case where it's rotated by PI.
00053  *
00054  *   And I'm still not sure about what to do for test cases with
00055  *   text--a new version of freetype will change everything. We may
00056  *   need to add a simple backend for stroked fonts and add a simple
00057  *   builtin font to cairo for pixel-perfect tests with text.
00058  */
00059 
00060 #include "cairo_test.h"
00061 
00062 #define WIDTH  150
00063 #define HEIGHT 150
00064 #define NUM_TEXT 20
00065 #define TEXT_SIZE 12
00066 
00067 cairo_test_t test = {
00068     "text_rotate",
00069     "Tests show_text under various rotations",
00070     WIDTH, HEIGHT
00071 };
00072 
00073 /* Draw the word cairo at NUM_TEXT different angles */
00074 static void
00075 draw (cairo_t *cr, int width, int height)
00076 {
00077     int i, x_off, y_off;
00078     cairo_text_extents_t extents;
00079     static char text[] = "cairo";
00080 
00081     cairo_select_font (cr, "Bitstream Vera Sans",
00082                      CAIRO_FONT_SLANT_NORMAL,
00083                      CAIRO_FONT_WEIGHT_NORMAL);
00084     cairo_scale_font (cr, TEXT_SIZE);
00085 
00086     cairo_set_rgb_color (cr, 0,0,0);
00087 
00088     cairo_translate (cr, WIDTH/2.0, HEIGHT/2.0);
00089 
00090     cairo_text_extents (cr, text, &extents);
00091 
00092     if (NUM_TEXT == 1) {
00093        x_off = y_off = 0;
00094     } else {
00095        y_off = - round (extents.height / 2.0);
00096        x_off = round ((extents.height+1) / (2 * tan (M_PI/NUM_TEXT)));
00097     }
00098   
00099     for (i=0; i < NUM_TEXT; i++) {
00100        cairo_save (cr);
00101        cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
00102        cairo_set_line_width (cr, 1.0);
00103        cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents.width + 1, extents.height + 1);
00104        cairo_set_rgb_color (cr, 1, 0, 0);
00105        cairo_stroke (cr);
00106        cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing);
00107        cairo_set_rgb_color (cr, 0, 0, 0);
00108        cairo_show_text (cr, "cairo");
00109        cairo_restore (cr);
00110     }
00111 }
00112 
00113 int
00114 main (void)
00115 {
00116     return cairo_test (&test, draw);
00117 }