Back to index

lightning-sunbird  0.9+nobinonly
pixman_rotate.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <math.h>
00005 
00006 #include <cairo.h>
00007 #include <cairo-png.h>
00008 #include <cairo-pdf.h>
00009 
00010 #include "cairo_test.h"
00011 
00012 #define WIDTH 32
00013 #define HEIGHT       WIDTH
00014 
00015 #define IMAGE_WIDTH  (3 * WIDTH)
00016 #define IMAGE_HEIGHT IMAGE_WIDTH
00017 
00018 cairo_test_t test = {
00019     "pixman_rotate",
00020     "Exposes pixman off-by-one error when rotating",
00021     IMAGE_WIDTH, IMAGE_HEIGHT
00022 };
00023 
00024 /* Draw the word cairo at NUM_TEXT different angles */
00025 static void
00026 draw (cairo_t *cr, int width, int height)
00027 {
00028     cairo_surface_t *target, *stamp;
00029 
00030     target = cairo_current_target_surface (cr);
00031     cairo_surface_reference (target);
00032 
00033     stamp = cairo_surface_create_similar (target, CAIRO_FORMAT_ARGB32,
00034                                      WIDTH, HEIGHT);
00035     cairo_set_target_surface (cr, stamp);
00036     cairo_new_path (cr);
00037     cairo_rectangle (cr, WIDTH / 4, HEIGHT / 4, WIDTH / 2, HEIGHT / 2);
00038     cairo_set_rgb_color (cr, 1, 0, 0);
00039     cairo_set_alpha (cr, 0.8);
00040     cairo_fill (cr);
00041 
00042     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
00043     cairo_set_line_width (cr, 2);
00044     cairo_set_rgb_color (cr, 0, 0, 0);
00045     cairo_set_alpha (cr, 1);
00046     cairo_stroke (cr);
00047 
00048     cairo_set_target_surface (cr, target);
00049 
00050     /* Draw a translucent rectangle for reference where the rotated
00051      * image should be. */
00052     cairo_new_path (cr);
00053     cairo_rectangle (cr, WIDTH, HEIGHT, WIDTH, HEIGHT);
00054     cairo_set_rgb_color (cr, 1, 1, 0);
00055     cairo_set_alpha (cr, 0.3);
00056     cairo_fill (cr);
00057 
00058 #if 1 /* Set to 0 to generate reference image */
00059     cairo_translate (cr, 2 * WIDTH, 2 * HEIGHT);
00060     cairo_rotate (cr, M_PI);
00061 #else
00062     cairo_translate (cr, WIDTH, HEIGHT);
00063 #endif
00064 
00065     cairo_set_alpha (cr, 1);
00066     cairo_show_surface (cr, stamp, WIDTH + 2, HEIGHT + 2);
00067 
00068     cairo_show_page (cr);
00069 
00070     cairo_surface_destroy (stamp);
00071     cairo_surface_destroy (target);
00072 }
00073 
00074 int
00075 main (void)
00076 {
00077     return cairo_test (&test, draw);
00078 }