~ubuntu-branches/ubuntu/hardy/cairo/hardy-updates

« back to all changes in this revision

Viewing changes to test/meta-surface-pattern.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-01-17 13:00:59 UTC
  • Revision ID: james.westby@ubuntu.com-20080117130059-3gbudaudr2w8bl4w
Tags: upstream-1.5.6
Import upstream version 1.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2007 Adrian Johnson
 
3
 *
 
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:
 
11
 *
 
12
 * The above copyright notice and this permission notice shall be
 
13
 * included in all copies or substantial portions of the Software.
 
14
 *
 
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
 
22
 * SOFTWARE.
 
23
 *
 
24
 * Author: Adrian Johnson <ajohnson@redneon.com>
 
25
 */
 
26
 
 
27
#include "cairo-test.h"
 
28
 
 
29
static cairo_test_draw_function_t draw;
 
30
 
 
31
#define PAT_WIDTH  120
 
32
#define PAT_HEIGHT 120
 
33
#define SIZE (PAT_WIDTH*2)
 
34
#define PAD 2
 
35
#define WIDTH (PAD + SIZE + PAD)
 
36
#define HEIGHT WIDTH
 
37
 
 
38
 
 
39
/* This test is designed to test painting a meta surface pattern with
 
40
 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
 
41
 */
 
42
 
 
43
cairo_test_t test = {
 
44
    "meta-surface-pattern",
 
45
    "Paint meta surface pattern with non identity pattern matrix",
 
46
    WIDTH, HEIGHT,
 
47
    draw
 
48
};
 
49
 
 
50
 
 
51
static cairo_test_status_t
 
52
draw (cairo_t *cr, int width, int height)
 
53
{
 
54
    cairo_surface_t *pat_surface;
 
55
    cairo_pattern_t *pattern;
 
56
    cairo_matrix_t   mat;
 
57
    cairo_t *cr2;
 
58
 
 
59
    cairo_translate (cr, PAD, PAD);
 
60
 
 
61
    pat_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
 
62
                                                CAIRO_CONTENT_COLOR_ALPHA,
 
63
                                                PAT_WIDTH, PAT_HEIGHT);
 
64
 
 
65
    cr2 = cairo_create (pat_surface);
 
66
 
 
67
    cairo_set_source_rgba (cr2, 1, 0, 1, 0.5);
 
68
    cairo_rectangle (cr2, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
 
69
    cairo_fill (cr2);
 
70
 
 
71
    cairo_set_source_rgba (cr2, 0, 1, 1, 0.5);
 
72
    cairo_rectangle (cr2, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
 
73
    cairo_fill (cr2);
 
74
 
 
75
    cairo_set_line_width (cr2, 1);
 
76
    cairo_move_to (cr2, PAT_WIDTH/6.0, 0);
 
77
    cairo_line_to (cr2, 0, 0);
 
78
    cairo_line_to (cr2, 0, PAT_HEIGHT/6.0);
 
79
    cairo_set_source_rgb (cr2, 1, 0, 0);
 
80
    cairo_stroke (cr2);
 
81
    cairo_move_to (cr2, PAT_WIDTH/6.0, PAT_HEIGHT);
 
82
    cairo_line_to (cr2, 0, PAT_HEIGHT);
 
83
    cairo_line_to (cr2, 0, 5*PAT_HEIGHT/6.0);
 
84
    cairo_set_source_rgb (cr2, 0, 1, 0);
 
85
    cairo_stroke (cr2);
 
86
    cairo_move_to (cr2, 5*PAT_WIDTH/6.0, 0);
 
87
    cairo_line_to (cr2, PAT_WIDTH, 0);
 
88
    cairo_line_to (cr2, PAT_WIDTH, PAT_HEIGHT/6.0);
 
89
    cairo_set_source_rgb (cr2, 0, 0, 1);
 
90
    cairo_stroke (cr2);
 
91
    cairo_move_to (cr2, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
 
92
    cairo_line_to (cr2, PAT_WIDTH, PAT_HEIGHT);
 
93
    cairo_line_to (cr2, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
 
94
    cairo_set_source_rgb (cr2, 1, 1, 0);
 
95
    cairo_stroke (cr2);
 
96
 
 
97
    cairo_set_source_rgb (cr2, 0.5, 0.5, 0.5);
 
98
    cairo_set_line_width (cr2, PAT_WIDTH/10.0);
 
99
 
 
100
    cairo_move_to (cr2, 0,         PAT_HEIGHT/4.0);
 
101
    cairo_line_to (cr2, PAT_WIDTH, PAT_HEIGHT/4.0);
 
102
    cairo_stroke (cr2);
 
103
 
 
104
    cairo_move_to (cr2, PAT_WIDTH/4.0,         0);
 
105
    cairo_line_to (cr2, PAT_WIDTH/4.0, PAT_WIDTH);
 
106
    cairo_stroke (cr2);
 
107
 
 
108
    cairo_destroy (cr2);
 
109
    pattern = cairo_pattern_create_for_surface (pat_surface);
 
110
    cairo_surface_destroy (pat_surface);
 
111
 
 
112
    cairo_matrix_init_identity (&mat);
 
113
    cairo_matrix_scale (&mat, 2, 1.5);
 
114
    cairo_matrix_rotate (&mat, 1);
 
115
    cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
 
116
    cairo_pattern_set_matrix (pattern, &mat);
 
117
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
 
118
 
 
119
    cairo_set_source (cr, pattern);
 
120
    cairo_paint (cr);
 
121
 
 
122
    cairo_pattern_destroy (pattern);
 
123
 
 
124
    return CAIRO_TEST_SUCCESS;
 
125
}
 
126
 
 
127
int
 
128
main (void)
 
129
{
 
130
    return cairo_test (&test);
 
131
}