~ubuntu-branches/ubuntu/breezy/libcairo/breezy-security

« back to all changes in this revision

Viewing changes to src/cairo_path_fill.c

  • Committer: Bazaar Package Importer
  • Author(s): Dave Beckett
  • Date: 2004-05-29 21:10:58 UTC
  • Revision ID: james.westby@ubuntu.com-20040529211058-h596wztdkmpvul0k
Tags: upstream-0.1.23
Import upstream version 0.1.23

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright � 2002 University of Southern California
 
3
 *
 
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 the
 
9
 * University of Southern California not be used in advertising or
 
10
 * publicity pertaining to distribution of the software without
 
11
 * specific, written prior permission. The University of Southern
 
12
 * California makes no representations about the suitability of this
 
13
 * software for any purpose.  It is provided "as is" without express
 
14
 * or implied warranty.
 
15
 *
 
16
 * THE UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
 
17
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
 
18
 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF
 
19
 * SOUTHERN CALIFORNIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
20
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
21
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
22
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
23
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
24
 *
 
25
 * Author: Carl D. Worth <cworth@isi.edu>
 
26
 */
 
27
 
 
28
#include "cairoint.h"
 
29
 
 
30
typedef struct cairo_filler {
 
31
    cairo_gstate_t *gstate;
 
32
    cairo_traps_t *traps;
 
33
 
 
34
    cairo_point_t current_point;
 
35
 
 
36
    cairo_polygon_t polygon;
 
37
} cairo_filler_t;
 
38
 
 
39
static void
 
40
_cairo_filler_init (cairo_filler_t *filler, cairo_gstate_t *gstate, cairo_traps_t *traps);
 
41
 
 
42
static void
 
43
_cairo_filler_fini (cairo_filler_t *filler);
 
44
 
 
45
static cairo_status_t
 
46
_cairo_filler_move_to (void *closure, cairo_point_t *point);
 
47
 
 
48
static cairo_status_t
 
49
_cairo_filler_line_to (void *closure, cairo_point_t *point);
 
50
 
 
51
static cairo_status_t
 
52
_cairo_filler_curve_to (void *closure,
 
53
                        cairo_point_t *b,
 
54
                        cairo_point_t *c,
 
55
                        cairo_point_t *d);
 
56
 
 
57
static cairo_status_t
 
58
_cairo_filler_close_path (void *closure);
 
59
 
 
60
static void
 
61
_cairo_filler_init (cairo_filler_t *filler, cairo_gstate_t *gstate, cairo_traps_t *traps)
 
62
{
 
63
    filler->gstate = gstate;
 
64
    filler->traps = traps;
 
65
 
 
66
    filler->current_point.x = 0;
 
67
    filler->current_point.y = 0;
 
68
 
 
69
    _cairo_polygon_init (&filler->polygon);
 
70
}
 
71
 
 
72
static void
 
73
_cairo_filler_fini (cairo_filler_t *filler)
 
74
{
 
75
    _cairo_polygon_fini (&filler->polygon);
 
76
}
 
77
 
 
78
static cairo_status_t
 
79
_cairo_filler_move_to (void *closure, cairo_point_t *point)
 
80
{
 
81
    cairo_status_t status;
 
82
    cairo_filler_t *filler = closure;
 
83
    cairo_polygon_t *polygon = &filler->polygon;
 
84
 
 
85
    status = _cairo_polygon_close (polygon);
 
86
    if (status)
 
87
        return status;
 
88
      
 
89
    status = _cairo_polygon_move_to (polygon, point);
 
90
    if (status)
 
91
        return status;
 
92
 
 
93
    filler->current_point = *point;
 
94
 
 
95
    return CAIRO_STATUS_SUCCESS;
 
96
}
 
97
 
 
98
static cairo_status_t
 
99
_cairo_filler_line_to (void *closure, cairo_point_t *point)
 
100
{
 
101
    cairo_status_t status;
 
102
    cairo_filler_t *filler = closure;
 
103
    cairo_polygon_t *polygon = &filler->polygon;
 
104
 
 
105
    status = _cairo_polygon_line_to (polygon, point);
 
106
    if (status)
 
107
        return status;
 
108
 
 
109
    filler->current_point = *point;
 
110
 
 
111
    return CAIRO_STATUS_SUCCESS;
 
112
}
 
113
 
 
114
static cairo_status_t
 
115
_cairo_filler_curve_to (void *closure,
 
116
                        cairo_point_t *b,
 
117
                        cairo_point_t *c,
 
118
                        cairo_point_t *d)
 
119
{
 
120
    int i;
 
121
    cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
122
    cairo_filler_t *filler = closure;
 
123
    cairo_polygon_t *polygon = &filler->polygon;
 
124
    cairo_gstate_t *gstate = filler->gstate;
 
125
    cairo_spline_t spline;
 
126
 
 
127
    status = _cairo_spline_init (&spline, &filler->current_point, b, c, d);
 
128
 
 
129
    if (status == CAIRO_INT_STATUS_DEGENERATE)
 
130
        return CAIRO_STATUS_SUCCESS;
 
131
 
 
132
    _cairo_spline_decompose (&spline, gstate->tolerance);
 
133
    if (status)
 
134
        goto CLEANUP_SPLINE;
 
135
 
 
136
    for (i = 1; i < spline.num_points; i++) {
 
137
        status = _cairo_polygon_line_to (polygon, &spline.points[i]);
 
138
        if (status)
 
139
            break;
 
140
    }
 
141
 
 
142
  CLEANUP_SPLINE:
 
143
    _cairo_spline_fini (&spline);
 
144
 
 
145
    filler->current_point = *d;
 
146
 
 
147
    return status;
 
148
}
 
149
 
 
150
static cairo_status_t
 
151
_cairo_filler_close_path (void *closure)
 
152
{
 
153
    cairo_status_t status;
 
154
    cairo_filler_t *filler = closure;
 
155
    cairo_polygon_t *polygon = &filler->polygon;
 
156
 
 
157
    status = _cairo_polygon_close (polygon);
 
158
    if (status)
 
159
        return status;
 
160
 
 
161
    return CAIRO_STATUS_SUCCESS;
 
162
}
 
163
 
 
164
cairo_status_t
 
165
_cairo_path_fill_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps)
 
166
{
 
167
    cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
168
    cairo_filler_t filler;
 
169
 
 
170
    _cairo_filler_init (&filler, gstate, traps);
 
171
 
 
172
    status = _cairo_path_interpret (path,
 
173
                                    CAIRO_DIRECTION_FORWARD,
 
174
                                    _cairo_filler_move_to,
 
175
                                    _cairo_filler_line_to,
 
176
                                    _cairo_filler_curve_to,
 
177
                                    _cairo_filler_close_path,
 
178
                                    &filler);
 
179
    if (status)
 
180
        goto BAIL;
 
181
 
 
182
    status = _cairo_polygon_close (&filler.polygon);
 
183
    if (status)
 
184
        goto BAIL;
 
185
 
 
186
    status = _cairo_traps_tessellate_polygon (filler.traps,
 
187
                                              &filler.polygon,
 
188
                                              filler.gstate->fill_rule);
 
189
    if (status)
 
190
        goto BAIL;
 
191
 
 
192
BAIL:
 
193
    _cairo_filler_fini (&filler);
 
194
 
 
195
    return status;
 
196
}
 
197