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.,
83 cairo_pattern_add_color_stop_rgb (pattern, 1.,
86 cairo_pattern_add_color_stop_rgb (pattern, 0.,
88 cairo_pattern_add_color_stop_rgb (pattern, 0.5,
90 cairo_pattern_add_color_stop_rgb (pattern, 1.,
94 cairo_set_source (cr, pattern);
95 cairo_pattern_destroy (pattern);
96 cairo_rectangle (cr, -0.5, -0.5, 1, 1);
100 static cairo_test_status_t
101 draw (cairo_t *cr, int width, int height)
105 cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
108 for (i = 0; i < N_GRADIENT_ANGLES; i++)
109 for (j = 0; j < N_ROTATE_ANGLES; j++)
110 for (k = 0; k < N_N_STOPS; k++) {
113 PAD + (PAD + UNIT_SIZE) * i,
114 PAD + (PAD + UNIT_SIZE) * (N_ROTATE_ANGLES * k + j));
115 cairo_scale (cr, UNIT_SIZE, UNIT_SIZE);
118 gradient_angles[i] * M_PI / 180.,
119 rotate_angles[j] * M_PI / 180.,
124 return CAIRO_TEST_SUCCESS;
127 CAIRO_TEST (linear_gradient,
128 "Tests the drawing of linear gradients",
129 "gradient", /* keywords */
130 NULL, /* requirements */