~ubuntu-branches/ubuntu/intrepid/cairo/intrepid-updates

« back to all changes in this revision

Viewing changes to test/get-path-extents.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-09-25 16:22:33 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080925162233-btx61ymk181i7mcc
Tags: 1.7.6-0ubuntu1
* New upstream version. Most noticable changes are:
  - some API changes with especially the removal of
    cairo_font_options_set_lcd_filter and cairo_font_options_get_lcd_filter
  - xlib: Faster bookkeeping
  - PS: Fix gradients with non-constant alpha
  - Fix deadlock in user-font code
* debian/patches/00list: Remove 03_from_git_fix_lcd_filter_default.dpatch,
  add debian/patches/03_fix_ftbfs_withing_xcb.dpatch
* debian/libcairo2.symbols, debian/libcairo-directfb2.symbols: update
  list of symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
static cairo_test_draw_function_t draw;
31
31
 
32
 
cairo_test_t test = {
 
32
static const cairo_test_t test = {
33
33
    "get-path-extents",
34
34
    "Test cairo_fill_extents and cairo_stroke_extents",
35
35
    0, 0,
41
41
enum Relation { EQUALS, APPROX_EQUALS, CONTAINS };
42
42
 
43
43
static cairo_bool_t
44
 
check_extents (const char *message, cairo_t *cr, enum ExtentsType type,
 
44
check_extents (const cairo_test_context_t *ctx,
 
45
               const char *message, cairo_t *cr, enum ExtentsType type,
45
46
               enum Relation relation,
46
47
               double x, double y, double width, double height)
47
48
{
97
98
        break;
98
99
    }
99
100
 
100
 
    cairo_test_log ("Error: %s; %s extents (%g, %g) x (%g, %g) should %s (%g, %g) x (%g, %g)\n",
 
101
    cairo_test_log (ctx, "Error: %s; %s extents (%g, %g) x (%g, %g) should %s (%g, %g) x (%g, %g)\n",
101
102
                    message, type_string,
102
103
                    ext_x1, ext_y1, ext_x2 - ext_x1, ext_y2 - ext_y1,
103
104
                    relation_string,
108
109
static cairo_test_status_t
109
110
draw (cairo_t *cr, int width, int height)
110
111
{
 
112
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
111
113
    cairo_surface_t *surface;
112
114
    cairo_t         *cr2;
113
115
    const char      *phase;
127
129
    cairo_set_miter_limit (cr2, 100);
128
130
 
129
131
    phase = "No path";
130
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
131
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
132
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 0, 0, 0, 0);
 
132
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
133
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
 
134
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 0, 0, 0);
133
135
 
134
136
    cairo_save (cr2);
135
137
 
137
139
    cairo_move_to (cr2, 200, 400);
138
140
    cairo_rel_line_to (cr2, 0., 0.);
139
141
    phase = "Degenerate line";
140
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
141
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
142
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
 
142
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
143
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
 
144
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
143
145
 
144
146
    cairo_new_path (cr2);
145
147
    cairo_move_to (cr2, 200, 400);
146
148
    cairo_rel_curve_to (cr2, 0., 0., 0., 0., 0., 0.);
147
149
    phase = "Degenerate curve";
148
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
149
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
150
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
 
150
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
151
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
 
152
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
151
153
 
152
154
    cairo_new_path (cr2);
153
155
    cairo_arc (cr2, 200, 400, 0., 0, 2 * M_PI);
154
156
    phase = "Degenerate arc (R=0)";
155
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
156
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
157
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
 
157
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
158
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
 
159
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
158
160
 
159
161
    cairo_new_path (cr2);
160
162
    cairo_arc (cr2, 200, 400, 10., 0, 0);
161
163
    phase = "Degenerate arc (Θ=0)";
162
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
163
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
164
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
 
164
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
165
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
 
166
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
165
167
 
166
168
    cairo_new_path (cr2);
167
169
    cairo_restore (cr2);
176
178
    cairo_move_to (cr2, 200, 400);
177
179
    cairo_rel_line_to (cr2, 0, 0);
178
180
    phase = "Single 'dot'";
179
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
180
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 190, 390, 20, 20);
181
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
 
181
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
182
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 190, 390, 20, 20);
 
183
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);
182
184
 
183
185
    /* Add another dot without starting a new path */
184
186
    cairo_move_to (cr2, 100, 500);
185
187
    cairo_rel_line_to (cr2, 0, 0);
186
188
    phase = "Multiple 'dots'";
187
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
188
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 90, 390, 120, 120);
189
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 100, 400, 100, 100);
 
189
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
190
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 90, 390, 120, 120);
 
191
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 100, 400, 100, 100);
190
192
 
191
193
    cairo_new_path (cr2);
192
194
 
199
201
    cairo_set_line_join (cr2, CAIRO_LINE_JOIN_ROUND);
200
202
    cairo_move_to (cr2, 0, 180);
201
203
    cairo_line_to (cr2, 750, 180);
202
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
203
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, -5, 175, 760, 10);
204
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 0, 180, 755, 0);
 
204
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
 
205
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, -5, 175, 760, 10);
 
206
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 180, 755, 0);
205
207
    cairo_new_path (cr2);
206
208
    cairo_restore (cr2);
207
209
 
208
210
    phase = "Simple rect";
209
211
    cairo_save (cr2);
210
212
    cairo_rectangle (cr2, 10, 10, 80, 80);
211
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
212
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
213
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
 
213
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
 
214
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
 
215
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
214
216
    cairo_new_path (cr2);
215
217
    cairo_restore (cr2);
216
218
 
218
220
    cairo_save (cr2);
219
221
    cairo_rectangle (cr2, 10, 10, 10, 10);
220
222
    cairo_rectangle (cr2, 20, 20, 10, 10);
221
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 20, 20);
222
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 5, 5, 30, 30);
223
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 20, 20);
 
223
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 20, 20);
 
224
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 30, 30);
 
225
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 20, 20);
224
226
    cairo_new_path (cr2);
225
227
    cairo_restore (cr2);
226
228
 
232
234
    cairo_close_path (cr2);
233
235
    /* miter joins protrude 5*(1+sqrt(2)) above the top-left corner and to
234
236
       the right of the bottom-right corner */
235
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
236
 
    errors += !check_extents (phase, cr2, STROKE, CONTAINS, 0, 5, 95, 95);
237
 
    errors += !check_extents (phase, cr2, PATH, CONTAINS, 10, 10, 80, 80);
 
237
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
 
238
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, 0, 5, 95, 95);
 
239
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, 10, 10, 80, 80);
238
240
    cairo_new_path (cr2);
239
241
    cairo_restore (cr2);
240
242
 
247
249
 
248
250
    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
249
251
    phase = "EVEN_ODD overlapping rectangles";
250
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
251
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
252
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
 
252
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
 
253
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
 
254
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
253
255
 
254
256
    /* Test other fill rule with the same path. */
255
257
 
256
258
    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
257
259
    phase = "WINDING overlapping rectangles";
258
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 30, 30);
259
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
260
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
 
260
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 30, 30);
 
261
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
 
262
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
261
263
 
262
264
    /* Now, change the direction of the second rectangle and test both
263
265
     * fill rules again. */
267
269
 
268
270
    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
269
271
    phase = "EVEN_ODD overlapping rectangles";
270
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
271
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
272
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
 
272
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
 
273
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
 
274
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
273
275
 
274
276
    /* Test other fill rule with the same path. */
275
277
 
276
278
    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
277
279
    phase = "WINDING overlapping rectangles";
278
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
279
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
280
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
 
280
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
 
281
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
 
282
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);
281
283
 
282
284
    cairo_new_path (cr2);
283
285
 
288
290
    cairo_save (cr2);
289
291
    cairo_arc (cr2, 250.0, 250.0, 157.0, 5.147, 3.432);
290
292
    cairo_set_line_width (cr2, 154.0);
291
 
    errors += !check_extents (phase, cr2, STROKE, APPROX_EQUALS, 16, 38, 468, 446);
 
293
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS, 16, 38, 468, 446);
292
294
    cairo_new_path (cr2);
293
295
    cairo_restore (cr2);
294
296
 
304
306
                                    string,
305
307
                                    &scaled_font_extents);
306
308
    if (memcmp (&extents, &scaled_font_extents, sizeof (extents))) {
307
 
        cairo_test_log ("Error: cairo_text_extents() does not match cairo_scaled_font_text_extents() - font extents (%f, %f) x (%f, %f) should be (%f, %f) x (%f, %f)\n",
 
309
        cairo_test_log (ctx, "Error: cairo_text_extents() does not match cairo_scaled_font_text_extents() - font extents (%f, %f) x (%f, %f) should be (%f, %f) x (%f, %f)\n",
308
310
                        scaled_font_extents.x_bearing,
309
311
                        scaled_font_extents.y_bearing,
310
312
                        scaled_font_extents.width,
322
324
    /* XXX: We'd like to be able to use EQUALS here, but currently
323
325
     * when hinting is enabled freetype returns integer extents. See
324
326
     * http://cairographics.org/todo */
325
 
    errors += !check_extents (phase, cr2, FILL, APPROX_EQUALS,
 
327
    errors += !check_extents (ctx, phase, cr2, FILL, APPROX_EQUALS,
326
328
                              0, 0, extents.width, extents.height);
327
 
    errors += !check_extents (phase, cr2, STROKE, APPROX_EQUALS,
 
329
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS,
328
330
                              -1, -1, extents.width+2, extents.height+2);
329
 
    errors += !check_extents (phase, cr2, PATH, APPROX_EQUALS,
 
331
    errors += !check_extents (ctx, phase, cr2, PATH, APPROX_EQUALS,
330
332
                              0, 0, extents.width, extents.height);
331
333
    cairo_new_path (cr2);
332
334
    cairo_restore (cr2);
335
337
    cairo_save (cr2);
336
338
    cairo_scale (cr2, 2, 2);
337
339
    cairo_rectangle (cr2, 5, 5, 40, 40);
338
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 5, 5, 40, 40);
339
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 50, 50);
340
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 5, 5, 40, 40);
 
340
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 5, 5, 40, 40);
 
341
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 50, 50);
 
342
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 5, 5, 40, 40);
341
343
    cairo_new_path (cr2);
342
344
    cairo_restore (cr2);
343
345
 
347
349
    cairo_scale (cr2, 2, 2);
348
350
    cairo_rectangle (cr2, 5, 5, 40, 40);
349
351
    cairo_restore (cr2);
350
 
    errors += !check_extents (phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
351
 
    errors += !check_extents (phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
352
 
    errors += !check_extents (phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
 
352
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
 
353
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
 
354
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
353
355
    cairo_new_path (cr2);
354
356
    cairo_restore (cr2);
355
357
 
366
368
       the axes. With the stroke width added to the rotated path,
367
369
       the largest axis-aligned square is a bit over 38 on either side of
368
370
       the axes. */
369
 
    errors += !check_extents (phase, cr2, FILL, CONTAINS, -35, -35, 35, 35);
370
 
    errors += !check_extents (phase, cr2, STROKE, CONTAINS, -38, -38, 38, 38);
371
 
    errors += !check_extents (phase, cr2, PATH, CONTAINS, -35, -35, 35, 35);
 
371
    errors += !check_extents (ctx, phase, cr2, FILL, CONTAINS, -35, -35, 35, 35);
 
372
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, -38, -38, 38, 38);
 
373
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, -35, -35, 35, 35);
372
374
    cairo_new_path (cr2);
373
375
    cairo_restore (cr2);
374
376