2 * Copyright © 2009 Adrian Johnson
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Adrian Johnson <ajohnson@redneon.com>
27 #include "cairo-test.h"
31 #define PAT_HEIGHT 100
32 #define SIZE PAT_WIDTH
34 #define WIDTH (PAD + SIZE + PAD)
39 * This test is designed to paint a mesh pattern which contains 8
40 * circular sectors approximating a conical gradient.
48 sector_patch (cairo_pattern_t *pattern,
50 double A_r, double A_g, double A_b,
52 double B_r, double B_g, double B_b)
54 double r_sin_A, r_cos_A;
55 double r_sin_B, r_cos_B;
58 r_sin_A = RADIUS * sin (angle_A);
59 r_cos_A = RADIUS * cos (angle_A);
60 r_sin_B = RADIUS * sin (angle_B);
61 r_cos_B = RADIUS * cos (angle_B);
63 h = 4.0/3.0 * tan ((angle_B - angle_A) / 4.0);
65 cairo_mesh_pattern_begin_patch (pattern);
67 cairo_mesh_pattern_move_to (pattern, CENTER_X, CENTER_Y);
68 cairo_mesh_pattern_line_to (pattern,
72 cairo_mesh_pattern_curve_to (pattern,
73 CENTER_X + r_cos_A - h * r_sin_A,
74 CENTER_Y + r_sin_A + h * r_cos_A,
75 CENTER_X + r_cos_B + h * r_sin_B,
76 CENTER_Y + r_sin_B - h * r_cos_B,
80 cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 1, 1);
81 cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, A_r, A_g, A_b);
82 cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, B_r, B_g, B_b);
84 cairo_mesh_pattern_end_patch (pattern);
87 static cairo_test_status_t
88 draw (cairo_t *cr, int width, int height)
90 cairo_pattern_t *pattern;
92 cairo_set_source_rgb (cr, 1, 1, 1);
95 cairo_translate (cr, PAD, PAD);
97 pattern = cairo_pattern_create_mesh ();
98 sector_patch (pattern,
101 sector_patch (pattern,
104 sector_patch (pattern,
107 sector_patch (pattern,
110 sector_patch (pattern,
113 sector_patch (pattern,
116 sector_patch (pattern,
119 sector_patch (pattern,
123 cairo_set_source (cr, pattern);
125 cairo_pattern_destroy (pattern);
127 return CAIRO_TEST_SUCCESS;
130 CAIRO_TEST (mesh_pattern_conical,
131 "Paint a conical pattern using a mesh pattern",
132 "conical,mesh,pattern", /* keywords */
133 NULL, /* requirements */