Back to index

lightning-sunbird  0.9+nobinonly
fill_rule.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-10-27  Carl Worth  <cworth@cworth.org>
00029  *
00030  *   There's currently a regression bug in the tessellation code. This
00031  *   causes each of these simple star shapes to be filled incorrectly.
00032  *
00033  *   It looks like right now we can get this test to pass by doing:
00034  *
00035  *       cvs update -r 1.16 src/cairo_traps.c
00036  *
00037  *   But we don't want to revert that change permanently since it
00038  *   really does correct some bugs. It must be that the old version of
00039  *   the code is masking some other bugs in the tessellation code. My
00040  *   current plan is to back this revision up for the next snapshot,
00041  *   but not to list the test as an expected failure since I'm
00042  *   planning on doing the new tessellator which should fix this
00043  *   problem.
00044  *
00045  * 2005-01-11 Carl Worth <cworth@cworth.org>
00046  *
00047  *   Keith committed some fixes that fix the original size-20
00048  *   star_path:
00049  *
00050  *     * src/cairo_wideint.c: (_cairo_int32x32_64_mul),
00051  *     (_cairo_int64x64_128_mul):
00052  *     * src/cairo_wideint.h:
00053  *     int32x32_64_mul and int64x64_128_mul are different from their
00054  *     unsigned compatriots
00055  *
00056  * 2005-01-12 Carl Worth <cworth@cworth.org>
00057  *
00058  *   Going back to the SVG test suite, however, the original star
00059  *   shape is still broken. Adding both shapes now as little_star_path
00060  *   and big_star_path.
00061  *
00062  */
00063 
00064 #include "cairo_test.h"
00065 
00066 #define LITTLE_STAR_SIZE 20
00067 #define BIG_STAR_SIZE    80
00068 
00069 cairo_test_t test = {
00070     "fill_rule",
00071     "Tests cairo_set_full_rule with some star shapes",
00072     BIG_STAR_SIZE * 2 + 3, BIG_STAR_SIZE + LITTLE_STAR_SIZE + 3
00073 };
00074 
00075 /* The SVG start trimmed down, but still showing the bug (originally) */
00076 static void
00077 little_star_path (cairo_t *cr)
00078 {
00079     cairo_move_to (cr, 10, 0);
00080     cairo_rel_line_to (cr, 6, 20);
00081     cairo_rel_line_to (cr, -16, -12);
00082     cairo_rel_line_to (cr, 20, 0);
00083     cairo_rel_line_to (cr, -16, 12);
00084 }
00085 
00086 /* The star shape from the SVG test suite. This was is still buggy even after
00087    we got little_star_path working. */
00088 static void
00089 big_star_path (cairo_t *cr)
00090 {
00091     cairo_move_to (cr, 40, 0);
00092     cairo_rel_line_to (cr, 25, 80);
00093     cairo_rel_line_to (cr, -65, -50);
00094     cairo_rel_line_to (cr, 80, 0);
00095     cairo_rel_line_to (cr, -65, 50);
00096     cairo_close_path (cr);
00097 }
00098 
00099 /* Fill the same path twice, once with each fill rule */
00100 static void
00101 draw (cairo_t *cr, int width, int height)
00102 {
00103     cairo_set_rgb_color (cr, 1, 0, 0);
00104 
00105     cairo_translate (cr, 1, 1);
00106     little_star_path (cr);
00107     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
00108     cairo_fill (cr);
00109 
00110     cairo_translate (cr, LITTLE_STAR_SIZE + 1, 0);
00111     little_star_path (cr);
00112     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
00113     cairo_fill (cr);
00114 
00115     cairo_translate (cr, -(LITTLE_STAR_SIZE + 1), LITTLE_STAR_SIZE + 1);
00116     big_star_path (cr);
00117     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
00118     cairo_fill (cr);
00119 
00120     cairo_translate (cr, BIG_STAR_SIZE + 1, 0);
00121     big_star_path (cr);
00122     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
00123     cairo_fill (cr);
00124 }
00125 
00126 int
00127 main (void)
00128 {
00129     return cairo_test (&test, draw);
00130 }