2 * Copyright © 2005 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Owen Taylor <otaylor@redhat.com>
26 #include "cairo-test.h"
31 * A) Horizontal B) 5° C) 45° D) Vertical
32 * 1) Rotated 0° 2) Rotated 45° C) Rotated 90°
43 static const double gradient_angles[] = { 0, 45, 90 };
44 #define N_GRADIENT_ANGLES 3
45 static const double rotate_angles[] = { 0, 45, 90 };
46 #define N_ROTATE_ANGLES 3
47 static const int n_stops[] = { 2, 3 };
54 #define WIDTH N_GRADIENT_ANGLES * UNIT_SIZE + (N_GRADIENT_ANGLES + 1) * PAD
55 #define HEIGHT N_N_STOPS * N_ROTATE_ANGLES * UNIT_SIZE + (N_N_STOPS * N_ROTATE_ANGLES + 1) * PAD
58 draw_unit (cairo_t *cr,
59 double gradient_angle,
63 cairo_pattern_t *pattern;
65 cairo_rectangle (cr, 0, 0, 1, 1);
69 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
70 cairo_rectangle (cr, 0, 0, 1, 1);
73 cairo_translate (cr, 0.5, 0.5);
74 cairo_scale (cr, 1 / 1.5, 1 / 1.5);
75 cairo_rotate (cr, rotate_angle);
77 pattern = cairo_pattern_create_linear (-0.5 * cos (gradient_angle), -0.5 * sin (gradient_angle),
78 0.5 * cos (gradient_angle), 0.5 * sin (gradient_angle));
81 cairo_pattern_add_color_stop_rgb (pattern, 0.2, 0.3, 0.3, 0.3);
82 cairo_pattern_add_color_stop_rgb (pattern, 0.8, 1.0, 1.0, 1.0);
84 cairo_pattern_add_color_stop_rgb (pattern, 0.2, 1.0, 0.0, 0.0);
85 cairo_pattern_add_color_stop_rgb (pattern, 0.5, 1.0, 1.0, 1.0);
86 cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.0, 0.0, 1.0);
89 cairo_set_source (cr, pattern);
90 cairo_pattern_destroy (pattern);
91 cairo_rectangle (cr, -0.5, -0.5, 1, 1);
95 static cairo_test_status_t
96 draw (cairo_t *cr, int width, int height)
100 cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
103 for (i = 0; i < N_GRADIENT_ANGLES; i++)
104 for (j = 0; j < N_ROTATE_ANGLES; j++)
105 for (k = 0; k < N_N_STOPS; k++) {
108 PAD + (PAD + UNIT_SIZE) * i,
109 PAD + (PAD + UNIT_SIZE) * (N_ROTATE_ANGLES * k + j));
110 cairo_scale (cr, UNIT_SIZE, UNIT_SIZE);
113 gradient_angles[i] * M_PI / 180.,
114 rotate_angles[j] * M_PI / 180.,
119 return CAIRO_TEST_SUCCESS;
122 CAIRO_TEST (linear_gradient_subset,
123 "Tests the drawing of linear gradients",
124 "gradient", /* keywords */
125 NULL, /* requirements */