/work/workdir/UnpackedTarball/cairo/src/cairo-path-bounds.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ |
2 | | /* cairo - a vector graphics library with display and print output |
3 | | * |
4 | | * Copyright © 2003 University of Southern California |
5 | | * |
6 | | * This library is free software; you can redistribute it and/or |
7 | | * modify it either under the terms of the GNU Lesser General Public |
8 | | * License version 2.1 as published by the Free Software Foundation |
9 | | * (the "LGPL") or, at your option, under the terms of the Mozilla |
10 | | * Public License Version 1.1 (the "MPL"). If you do not alter this |
11 | | * notice, a recipient may use your version of this file under either |
12 | | * the MPL or the LGPL. |
13 | | * |
14 | | * You should have received a copy of the LGPL along with this library |
15 | | * in the file COPYING-LGPL-2.1; if not, write to the Free Software |
16 | | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA |
17 | | * You should have received a copy of the MPL along with this library |
18 | | * in the file COPYING-MPL-1.1 |
19 | | * |
20 | | * The contents of this file are subject to the Mozilla Public License |
21 | | * Version 1.1 (the "License"); you may not use this file except in |
22 | | * compliance with the License. You may obtain a copy of the License at |
23 | | * http://www.mozilla.org/MPL/ |
24 | | * |
25 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY |
26 | | * OF ANY KIND, either express or implied. See the LGPL or the MPL for |
27 | | * the specific language governing rights and limitations. |
28 | | * |
29 | | * The Original Code is the cairo graphics library. |
30 | | * |
31 | | * The Initial Developer of the Original Code is University of Southern |
32 | | * California. |
33 | | * |
34 | | * Contributor(s): |
35 | | * Carl D. Worth <cworth@cworth.org> |
36 | | */ |
37 | | |
38 | | #include "cairoint.h" |
39 | | #include "cairo-box-inline.h" |
40 | | #include "cairo-error-private.h" |
41 | | #include "cairo-path-fixed-private.h" |
42 | | |
43 | | typedef struct _cairo_path_bounder { |
44 | | cairo_point_t current_point; |
45 | | cairo_bool_t has_extents; |
46 | | cairo_box_t extents; |
47 | | } cairo_path_bounder_t; |
48 | | |
49 | | static cairo_status_t |
50 | | _cairo_path_bounder_move_to (void *closure, |
51 | | const cairo_point_t *point) |
52 | 0 | { |
53 | 0 | cairo_path_bounder_t *bounder = closure; |
54 | |
|
55 | 0 | bounder->current_point = *point; |
56 | |
|
57 | 0 | if (likely (bounder->has_extents)) { |
58 | 0 | _cairo_box_add_point (&bounder->extents, point); |
59 | 0 | } else { |
60 | 0 | bounder->has_extents = TRUE; |
61 | 0 | _cairo_box_set (&bounder->extents, point, point); |
62 | 0 | } |
63 | |
|
64 | 0 | return CAIRO_STATUS_SUCCESS; |
65 | 0 | } |
66 | | |
67 | | static cairo_status_t |
68 | | _cairo_path_bounder_line_to (void *closure, |
69 | | const cairo_point_t *point) |
70 | 0 | { |
71 | 0 | cairo_path_bounder_t *bounder = closure; |
72 | |
|
73 | 0 | bounder->current_point = *point; |
74 | 0 | _cairo_box_add_point (&bounder->extents, point); |
75 | |
|
76 | 0 | return CAIRO_STATUS_SUCCESS; |
77 | 0 | } |
78 | | |
79 | | static cairo_status_t |
80 | | _cairo_path_bounder_curve_to (void *closure, |
81 | | const cairo_point_t *b, |
82 | | const cairo_point_t *c, |
83 | | const cairo_point_t *d) |
84 | 0 | { |
85 | 0 | cairo_path_bounder_t *bounder = closure; |
86 | |
|
87 | 0 | _cairo_box_add_curve_to (&bounder->extents, |
88 | 0 | &bounder->current_point, |
89 | 0 | b, c, d); |
90 | 0 | bounder->current_point = *d; |
91 | |
|
92 | 0 | return CAIRO_STATUS_SUCCESS; |
93 | 0 | } |
94 | | |
95 | | static cairo_status_t |
96 | | _cairo_path_bounder_close_path (void *closure) |
97 | 0 | { |
98 | 0 | return CAIRO_STATUS_SUCCESS; |
99 | 0 | } |
100 | | |
101 | | cairo_bool_t |
102 | | _cairo_path_bounder_extents (const cairo_path_fixed_t *path, |
103 | | cairo_box_t *extents) |
104 | 0 | { |
105 | 0 | cairo_path_bounder_t bounder; |
106 | 0 | cairo_status_t status; |
107 | |
|
108 | 0 | bounder.has_extents = FALSE; |
109 | 0 | status = _cairo_path_fixed_interpret (path, |
110 | 0 | _cairo_path_bounder_move_to, |
111 | 0 | _cairo_path_bounder_line_to, |
112 | 0 | _cairo_path_bounder_curve_to, |
113 | 0 | _cairo_path_bounder_close_path, |
114 | 0 | &bounder); |
115 | 0 | assert (!status); |
116 | | |
117 | 0 | if (bounder.has_extents) |
118 | 0 | *extents = bounder.extents; |
119 | |
|
120 | 0 | return bounder.has_extents; |
121 | 0 | } |
122 | | |
123 | | void |
124 | | _cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t *path, |
125 | | cairo_rectangle_int_t *extents) |
126 | 0 | { |
127 | 0 | _cairo_path_fixed_approximate_fill_extents (path, extents); |
128 | 0 | } |
129 | | |
130 | | void |
131 | | _cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path, |
132 | | cairo_rectangle_int_t *extents) |
133 | 6.57M | { |
134 | 6.57M | _cairo_path_fixed_fill_extents (path, CAIRO_FILL_RULE_WINDING, 0, extents); |
135 | 6.57M | } |
136 | | |
137 | | void |
138 | | _cairo_path_fixed_fill_extents (const cairo_path_fixed_t *path, |
139 | | cairo_fill_rule_t fill_rule, |
140 | | double tolerance, |
141 | | cairo_rectangle_int_t *extents) |
142 | 6.57M | { |
143 | 6.57M | if (path->extents.p1.x < path->extents.p2.x && |
144 | 6.57M | path->extents.p1.y < path->extents.p2.y) { |
145 | 6.56M | _cairo_box_round_to_rectangle (&path->extents, extents); |
146 | 6.56M | } else { |
147 | 14.1k | extents->x = extents->y = 0; |
148 | 14.1k | extents->width = extents->height = 0; |
149 | 14.1k | } |
150 | 6.57M | } |
151 | | |
152 | | /* Adjusts the fill extents (above) by the device-space pen. */ |
153 | | void |
154 | | _cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path, |
155 | | const cairo_stroke_style_t *style, |
156 | | const cairo_matrix_t *ctm, |
157 | | cairo_bool_t is_vector, |
158 | | cairo_rectangle_int_t *extents) |
159 | 834k | { |
160 | 834k | if (path->has_extents) { |
161 | 834k | cairo_box_t box_extents; |
162 | 834k | double dx, dy; |
163 | | |
164 | 834k | _cairo_stroke_style_max_distance_from_path (style, path, ctm, &dx, &dy); |
165 | 834k | if (is_vector) |
166 | 0 | { |
167 | | /* When calculating extents for vector surfaces, ensure lines thinner |
168 | | * than the fixed point resolution are not optimized away. */ |
169 | 0 | double min = _cairo_fixed_to_double (CAIRO_FIXED_EPSILON*2); |
170 | 0 | if (dx < min) |
171 | 0 | dx = min; |
172 | |
|
173 | 0 | if (dy < min) |
174 | 0 | dy = min; |
175 | 0 | } |
176 | | |
177 | 834k | box_extents = path->extents; |
178 | 834k | box_extents.p1.x -= _cairo_fixed_from_double (dx); |
179 | 834k | box_extents.p1.y -= _cairo_fixed_from_double (dy); |
180 | 834k | box_extents.p2.x += _cairo_fixed_from_double (dx); |
181 | 834k | box_extents.p2.y += _cairo_fixed_from_double (dy); |
182 | | |
183 | 834k | _cairo_box_round_to_rectangle (&box_extents, extents); |
184 | 834k | } else { |
185 | 266 | extents->x = extents->y = 0; |
186 | 266 | extents->width = extents->height = 0; |
187 | 266 | } |
188 | 834k | } |
189 | | |
190 | | cairo_status_t |
191 | | _cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, |
192 | | const cairo_stroke_style_t *stroke_style, |
193 | | const cairo_matrix_t *ctm, |
194 | | const cairo_matrix_t *ctm_inverse, |
195 | | double tolerance, |
196 | | cairo_rectangle_int_t *extents) |
197 | 0 | { |
198 | 0 | cairo_polygon_t polygon; |
199 | 0 | cairo_status_t status; |
200 | 0 | cairo_stroke_style_t style; |
201 | | |
202 | | /* When calculating extents for vector surfaces, ensure lines thinner |
203 | | * than one point are not optimized away. */ |
204 | 0 | double min_line_width = _cairo_matrix_transformed_circle_major_axis (ctm_inverse, 1.0); |
205 | 0 | if (stroke_style->line_width < min_line_width) |
206 | 0 | { |
207 | 0 | style = *stroke_style; |
208 | 0 | style.line_width = min_line_width; |
209 | 0 | stroke_style = &style; |
210 | 0 | } |
211 | |
|
212 | 0 | _cairo_polygon_init (&polygon, NULL, 0); |
213 | 0 | status = _cairo_path_fixed_stroke_to_polygon (path, |
214 | 0 | stroke_style, |
215 | 0 | ctm, ctm_inverse, |
216 | 0 | tolerance, |
217 | 0 | &polygon); |
218 | 0 | _cairo_box_round_to_rectangle (&polygon.extents, extents); |
219 | 0 | _cairo_polygon_fini (&polygon); |
220 | |
|
221 | 0 | return status; |
222 | 0 | } |
223 | | |
224 | | cairo_bool_t |
225 | | _cairo_path_fixed_extents (const cairo_path_fixed_t *path, |
226 | | cairo_box_t *box) |
227 | 7.58M | { |
228 | 7.58M | *box = path->extents; |
229 | 7.58M | return path->has_extents; |
230 | 7.58M | } |