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 © 2005 Red Hat, Inc
5
 * Copyright © 2007 Adrian Johnson
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it either under the terms of the GNU Lesser General Public
9
 * License version 2.1 as published by the Free Software Foundation
10
 * (the "LGPL") or, at your option, under the terms of the Mozilla
11
 * Public License Version 1.1 (the "MPL"). If you do not alter this
12
 * notice, a recipient may use your version of this file under either
13
 * the MPL or the LGPL.
14
 *
15
 * You should have received a copy of the LGPL along with this library
16
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
18
 * You should have received a copy of the MPL along with this library
19
 * in the file COPYING-MPL-1.1
20
 *
21
 * The contents of this file are subject to the Mozilla Public License
22
 * Version 1.1 (the "License"); you may not use this file except in
23
 * compliance with the License. You may obtain a copy of the License at
24
 * http://www.mozilla.org/MPL/
25
 *
26
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
27
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
28
 * the specific language governing rights and limitations.
29
 *
30
 * The Original Code is the cairo graphics library.
31
 *
32
 * The Initial Developer of the Original Code is Red Hat, Inc.
33
 *
34
 * Contributor(s):
35
 *	Carl Worth <cworth@cworth.org>
36
 *	Keith Packard <keithp@keithp.com>
37
 *	Adrian Johnson <ajohnson@redneon.com>
38
 */
39

            
40
/* The paginated surface layer exists to provide as much code sharing
41
 * as possible for the various paginated surface backends in cairo
42
 * (PostScript, PDF, etc.). See cairo-paginated-private.h for
43
 * more details on how it works and how to use it.
44
 */
45

            
46
#include "cairoint.h"
47

            
48
#include "cairo-paginated-private.h"
49
#include "cairo-paginated-surface-private.h"
50
#include "cairo-recording-surface-private.h"
51
#include "cairo-analysis-surface-private.h"
52
#include "cairo-error-private.h"
53
#include "cairo-image-surface-private.h"
54
#include "cairo-surface-subsurface-inline.h"
55

            
56
static const cairo_surface_backend_t cairo_paginated_surface_backend;
57

            
58
static cairo_int_status_t
59
_cairo_paginated_surface_show_page (void *abstract_surface);
60

            
61
static cairo_surface_t *
62
9
_cairo_paginated_surface_create_similar (void			*abstract_surface,
63
					 cairo_content_t	 content,
64
					 int			 width,
65
					 int			 height)
66
{
67
    cairo_rectangle_t rect;
68
9
    rect.x = rect.y = 0.;
69
9
    rect.width = width;
70
9
    rect.height = height;
71
9
    return cairo_recording_surface_create (content, &rect);
72
}
73

            
74
static cairo_surface_t *
75
48
_create_recording_surface_for_target (cairo_surface_t *target,
76
				      cairo_content_t content)
77
{
78
    cairo_rectangle_int_t rect;
79

            
80
48
    if (_cairo_surface_get_extents (target, &rect)) {
81
	cairo_rectangle_t recording_extents;
82

            
83
30
	recording_extents.x = rect.x;
84
30
	recording_extents.y = rect.y;
85
30
	recording_extents.width = rect.width;
86
30
	recording_extents.height = rect.height;
87

            
88
30
	return cairo_recording_surface_create (content, &recording_extents);
89
    } else {
90
18
	return cairo_recording_surface_create (content, NULL);
91
    }
92
}
93

            
94
cairo_surface_t *
95
24
_cairo_paginated_surface_create (cairo_surface_t				*target,
96
				 cairo_content_t				 content,
97
				 const cairo_paginated_surface_backend_t	*backend)
98
{
99
    cairo_paginated_surface_t *surface;
100
    cairo_status_t status;
101

            
102
24
    surface = _cairo_calloc (sizeof (cairo_paginated_surface_t));
103
24
    if (unlikely (surface == NULL)) {
104
	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
105
	goto FAIL;
106
    }
107

            
108
24
    _cairo_surface_init (&surface->base,
109
			 &cairo_paginated_surface_backend,
110
			 NULL, /* device */
111
			 content,
112
24
			 target->is_vector);
113

            
114
    /* Override surface->base.type with target's type so we don't leak
115
     * evidence of the paginated wrapper out to the user. */
116
24
    surface->base.type = target->type;
117

            
118
24
    surface->target = cairo_surface_reference (target);
119

            
120
24
    surface->content = content;
121
24
    surface->backend = backend;
122

            
123
24
    surface->recording_surface = _create_recording_surface_for_target (target, content);
124
24
    status = surface->recording_surface->status;
125
24
    if (unlikely (status))
126
	goto FAIL_CLEANUP_SURFACE;
127

            
128
24
    surface->page_num = 1;
129
24
    surface->base.is_clear = TRUE;
130

            
131
24
    return &surface->base;
132

            
133
  FAIL_CLEANUP_SURFACE:
134
    cairo_surface_destroy (target);
135
    free (surface);
136
  FAIL:
137
    return _cairo_surface_create_in_error (status);
138
}
139

            
140
cairo_bool_t
141
70
_cairo_surface_is_paginated (cairo_surface_t *surface)
142
{
143
70
    return surface->backend == &cairo_paginated_surface_backend;
144
}
145

            
146
cairo_surface_t *
147
28
_cairo_paginated_surface_get_target (cairo_surface_t *surface)
148
{
149
    cairo_paginated_surface_t *paginated_surface;
150

            
151
28
    assert (_cairo_surface_is_paginated (surface));
152

            
153
28
    paginated_surface = (cairo_paginated_surface_t *) surface;
154
28
    return paginated_surface->target;
155
}
156

            
157
cairo_surface_t *
158
_cairo_paginated_surface_get_recording (cairo_surface_t *surface)
159
{
160
    cairo_paginated_surface_t *paginated_surface;
161

            
162
    assert (_cairo_surface_is_paginated (surface));
163

            
164
    paginated_surface = (cairo_paginated_surface_t *) surface;
165
    return paginated_surface->recording_surface;
166
}
167

            
168
cairo_status_t
169
_cairo_paginated_surface_set_size (cairo_surface_t	*surface,
170
				   double		 width,
171
				   double		 height)
172
{
173
    cairo_paginated_surface_t *paginated_surface;
174
    cairo_status_t status;
175
    cairo_rectangle_t recording_extents;
176

            
177
    assert (_cairo_surface_is_paginated (surface));
178

            
179
    paginated_surface = (cairo_paginated_surface_t *) surface;
180

            
181
    recording_extents.x = 0;
182
    recording_extents.y = 0;
183
    recording_extents.width = width;
184
    recording_extents.height = height;
185

            
186
    cairo_surface_destroy (paginated_surface->recording_surface);
187
    paginated_surface->recording_surface = cairo_recording_surface_create (paginated_surface->content,
188
									   &recording_extents);
189
    status = paginated_surface->recording_surface->status;
190
    if (unlikely (status))
191
	return _cairo_surface_set_error (surface, status);
192

            
193
    return CAIRO_STATUS_SUCCESS;
194
}
195

            
196
static cairo_status_t
197
24
_cairo_paginated_surface_finish (void *abstract_surface)
198
{
199
24
    cairo_paginated_surface_t *surface = abstract_surface;
200
24
    cairo_status_t status = CAIRO_STATUS_SUCCESS;
201

            
202
24
    if (! surface->base.is_clear || surface->page_num == 1) {
203
	/* Bypass some of the sanity checking in cairo-surface.c, as we
204
	 * know that the surface is finished...
205
	 */
206
15
	status = _cairo_paginated_surface_show_page (surface);
207
    }
208

            
209
     /* XXX We want to propagate any errors from destroy(), but those are not
210
      * returned via the api. So we need to explicitly finish the target,
211
      * and check the status afterwards. However, we can only call finish()
212
      * on the target, if we own it.
213
      */
214
48
    if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1)
215
24
	cairo_surface_finish (surface->target);
216
24
    if (status == CAIRO_STATUS_SUCCESS)
217
24
	status = cairo_surface_status (surface->target);
218
24
    cairo_surface_destroy (surface->target);
219

            
220
24
    cairo_surface_finish (surface->recording_surface);
221
24
    if (status == CAIRO_STATUS_SUCCESS)
222
24
	status = cairo_surface_status (surface->recording_surface);
223
24
    cairo_surface_destroy (surface->recording_surface);
224

            
225
24
    return status;
226
}
227

            
228
static cairo_surface_t *
229
36
_cairo_paginated_surface_create_image_surface (void	       *abstract_surface,
230
					       int		width,
231
					       int		height)
232
{
233
36
    cairo_paginated_surface_t *surface = abstract_surface;
234
    cairo_surface_t *image;
235
    cairo_font_options_t options;
236

            
237
36
    image = _cairo_image_surface_create_with_content (surface->content,
238
						      width,
239
						      height);
240

            
241
36
    cairo_surface_get_font_options (&surface->base, &options);
242
36
    _cairo_surface_set_font_options (image, &options);
243

            
244
36
    return image;
245
}
246

            
247
static cairo_surface_t *
248
9
_cairo_paginated_surface_source (void	       *abstract_surface,
249
				 cairo_rectangle_int_t *extents)
250
{
251
9
    cairo_paginated_surface_t *surface = abstract_surface;
252
9
    return _cairo_surface_get_source (surface->target, extents);
253
}
254

            
255
static cairo_status_t
256
9
_cairo_paginated_surface_acquire_source_image (void	       *abstract_surface,
257
					       cairo_image_surface_t **image_out,
258
					       void		   **image_extra)
259
{
260
9
    cairo_paginated_surface_t *surface = abstract_surface;
261
    cairo_bool_t is_bounded;
262
    cairo_surface_t *image;
263
    cairo_status_t status;
264
    cairo_rectangle_int_t extents;
265

            
266
9
    is_bounded = _cairo_surface_get_extents (surface->target, &extents);
267
9
    if (! is_bounded)
268
	return CAIRO_INT_STATUS_UNSUPPORTED;
269

            
270
9
    image = _cairo_paginated_surface_create_image_surface (surface,
271
							   extents.width,
272
							   extents.height);
273

            
274
9
    status = _cairo_recording_surface_replay (surface->recording_surface, image);
275
9
    if (unlikely (status)) {
276
	cairo_surface_destroy (image);
277
	return status;
278
    }
279

            
280
9
    *image_out = (cairo_image_surface_t*) image;
281
9
    *image_extra = NULL;
282

            
283
9
    return CAIRO_STATUS_SUCCESS;
284
}
285

            
286
static void
287
9
_cairo_paginated_surface_release_source_image (void	  *abstract_surface,
288
					       cairo_image_surface_t *image,
289
					       void	       *image_extra)
290
{
291
9
    cairo_surface_destroy (&image->base);
292
9
}
293

            
294
static cairo_int_status_t
295
_paint_thumbnail_image (cairo_paginated_surface_t *surface,
296
			int                        width,
297
			int                        height)
298
{
299
    cairo_surface_pattern_t pattern;
300
    cairo_rectangle_int_t extents;
301
    double x_scale;
302
    double y_scale;
303
    cairo_surface_t *image = NULL;
304
    cairo_surface_t *opaque = NULL;
305
    cairo_status_t status = CAIRO_STATUS_SUCCESS;
306

            
307
    _cairo_surface_get_extents (surface->target, &extents);
308
    x_scale = (double)width / extents.width;
309
    y_scale = (double)height / extents.height;
310

            
311
    image = _cairo_paginated_surface_create_image_surface (surface, width, height);
312
    cairo_surface_set_device_scale (image, x_scale, y_scale);
313
    cairo_surface_set_device_offset (image, -extents.x*x_scale, -extents.y*y_scale);
314
    status = _cairo_recording_surface_replay (surface->recording_surface, image);
315
    if (unlikely (status))
316
	goto cleanup;
317

            
318
    /* flatten transparency */
319

            
320
    opaque = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
321
    if (unlikely (opaque->status)) {
322
	status = opaque->status;
323
	goto cleanup;
324
    }
325

            
326
    status = _cairo_surface_paint (opaque,
327
				   CAIRO_OPERATOR_SOURCE,
328
				   &_cairo_pattern_white.base,
329
				   NULL);
330
    if (unlikely (status))
331
	goto cleanup;
332

            
333
    _cairo_pattern_init_for_surface (&pattern, image);
334
    pattern.base.filter = CAIRO_FILTER_NEAREST;
335
    status = _cairo_surface_paint (opaque, CAIRO_OPERATOR_OVER, &pattern.base, NULL);
336
    _cairo_pattern_fini (&pattern.base);
337
    if (unlikely (status))
338
	goto cleanup;
339

            
340
    status = surface->backend->set_thumbnail_image (surface->target, (cairo_image_surface_t *)opaque);
341

            
342
  cleanup:
343
    if (image)
344
	cairo_surface_destroy (image);
345
    if (opaque)
346
	cairo_surface_destroy (opaque);
347

            
348
    return status;
349
}
350

            
351
static cairo_int_status_t
352
27
_paint_fallback_image (cairo_paginated_surface_t *surface,
353
		       cairo_rectangle_int_t     *rect)
354
{
355
27
    double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution;
356
27
    double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution;
357
    int x, y, width, height;
358
    cairo_status_t status;
359
    cairo_surface_t *image;
360
    cairo_surface_pattern_t pattern;
361
    cairo_clip_t *clip;
362

            
363
27
    x = rect->x;
364
27
    y = rect->y;
365
27
    width = rect->width;
366
27
    height = rect->height;
367
27
    image = _cairo_paginated_surface_create_image_surface (surface,
368
27
							   ceil (width  * x_scale),
369
27
							   ceil (height * y_scale));
370
27
    cairo_surface_set_device_scale (image, x_scale, y_scale);
371
    /* set_device_offset just sets the x0/y0 components of the matrix;
372
     * so we have to do the scaling manually. */
373
27
    cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale);
374

            
375
27
    status = _cairo_recording_surface_replay (surface->recording_surface, image);
376
27
    if (unlikely (status))
377
	goto CLEANUP_IMAGE;
378

            
379
27
    _cairo_pattern_init_for_surface (&pattern, image);
380
27
    cairo_matrix_init (&pattern.base.matrix,
381
27
		       x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale);
382
    /* the fallback should be rendered at native resolution, so disable
383
     * filtering (if possible) to avoid introducing potential artifacts. */
384
27
    pattern.base.filter = CAIRO_FILTER_NEAREST;
385

            
386
27
    clip = _cairo_clip_intersect_rectangle (NULL, rect);
387
27
    status = _cairo_surface_paint (surface->target,
388
				   CAIRO_OPERATOR_SOURCE,
389
				   &pattern.base, clip);
390
27
    _cairo_clip_destroy (clip);
391
27
    _cairo_pattern_fini (&pattern.base);
392

            
393
27
CLEANUP_IMAGE:
394
27
    cairo_surface_destroy (image);
395

            
396
27
    return status;
397
}
398

            
399
static cairo_int_status_t
400
24
_paint_page (cairo_paginated_surface_t *surface)
401
{
402
    cairo_surface_t *analysis;
403
    cairo_int_status_t status;
404
    cairo_bool_t has_supported, has_page_fallback, has_finegrained_fallback;
405
24
    unsigned int regions_id = 0;
406
    cairo_bool_t replay_all;
407

            
408
24
    if (unlikely (surface->target->status))
409
	return surface->target->status;
410

            
411
24
    analysis = _cairo_analysis_surface_create (surface->target, TRUE);
412
24
    if (unlikely (analysis->status))
413
	return _cairo_surface_set_error (surface->target, analysis->status);
414

            
415
24
    status = surface->backend->set_paginated_mode (surface->target,
416
	                                  CAIRO_PAGINATED_MODE_ANALYZE);
417
24
    if (unlikely (status))
418
	goto FAIL;
419

            
420
24
    replay_all = FALSE;
421
29
    if (surface->target->backend->analyze_recording_surface &&
422
5
        _cairo_recording_surface_has_tags (surface->recording_surface))
423
    {
424
        replay_all = TRUE;
425
    }
426

            
427
24
    status = _cairo_recording_surface_region_array_attach (surface->recording_surface, &regions_id);
428
24
    if (status)
429
	goto FAIL;
430

            
431
24
    status = _cairo_recording_surface_replay_and_create_regions (surface->recording_surface,
432
                                                                 regions_id,
433
								 NULL, analysis, FALSE, replay_all);
434
24
    if (status)
435
	goto FAIL;
436

            
437
24
    assert (analysis->status == CAIRO_STATUS_SUCCESS);
438

            
439
24
    if (surface->backend->set_bounding_box) {
440
        cairo_box_t bbox;
441

            
442
5
        _cairo_analysis_surface_get_bounding_box (analysis, &bbox);
443
5
        status = surface->backend->set_bounding_box (surface->target, &bbox);
444
5
        if (unlikely (status))
445
            goto FAIL;
446
    }
447

            
448
24
    if (surface->backend->set_fallback_images_required) {
449
5
	cairo_bool_t has_fallbacks = _cairo_analysis_surface_has_unsupported (analysis);
450

            
451
5
	status = surface->backend->set_fallback_images_required (surface->target,
452
								 has_fallbacks);
453
5
	if (unlikely (status))
454
	    goto FAIL;
455
    }
456

            
457
    /* Finer grained fallbacks are currently only supported for some
458
     * surface types */
459
48
    if (surface->backend->supports_fine_grained_fallbacks != NULL &&
460
24
	surface->backend->supports_fine_grained_fallbacks (surface->target))
461
    {
462
24
	has_supported = _cairo_analysis_surface_has_supported (analysis);
463
24
	has_page_fallback = FALSE;
464
24
	has_finegrained_fallback = _cairo_analysis_surface_has_unsupported (analysis);
465
    }
466
    else
467
    {
468
	if (_cairo_analysis_surface_has_unsupported (analysis)) {
469
	    has_supported = FALSE;
470
	    has_page_fallback = TRUE;
471
	} else {
472
	    has_supported = TRUE;
473
	    has_page_fallback = FALSE;
474
	}
475
	has_finegrained_fallback = FALSE;
476
    }
477

            
478
24
    status = surface->backend->set_paginated_mode (surface->target,
479
						   CAIRO_PAGINATED_MODE_RENDER);
480
24
    if (unlikely (status))
481
	goto FAIL;
482

            
483
24
    if (has_supported) {
484
21
	status = _cairo_recording_surface_replay_region (surface->recording_surface,
485
                                                         regions_id,
486
							 NULL,
487
							 surface->target,
488
							 CAIRO_RECORDING_REGION_NATIVE);
489
21
	assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
490
21
	if (unlikely (status))
491
	    goto FAIL;
492
    }
493

            
494
24
    if (has_page_fallback) {
495
	cairo_rectangle_int_t extents;
496
	cairo_bool_t is_bounded;
497

            
498
	status = surface->backend->set_paginated_mode (surface->target,
499
						       CAIRO_PAGINATED_MODE_FALLBACK);
500
	if (unlikely (status))
501
	    goto FAIL;
502

            
503
	is_bounded = _cairo_surface_get_extents (surface->target, &extents);
504
	if (! is_bounded) {
505
	    status = CAIRO_INT_STATUS_UNSUPPORTED;
506
	    goto FAIL;
507
	}
508

            
509
	status = _paint_fallback_image (surface, &extents);
510
	if (unlikely (status))
511
	    goto FAIL;
512
    }
513

            
514
24
    if (has_finegrained_fallback) {
515
        cairo_region_t *region;
516
        int num_rects, i;
517

            
518
7
	status = surface->backend->set_paginated_mode (surface->target,
519
		                              CAIRO_PAGINATED_MODE_FALLBACK);
520
7
	if (unlikely (status))
521
	    goto FAIL;
522

            
523
7
	region = _cairo_analysis_surface_get_unsupported (analysis);
524

            
525
7
	num_rects = cairo_region_num_rectangles (region);
526
34
	for (i = 0; i < num_rects; i++) {
527
	    cairo_rectangle_int_t rect;
528

            
529
27
	    cairo_region_get_rectangle (region, i, &rect);
530
27
	    status = _paint_fallback_image (surface, &rect);
531
27
	    if (unlikely (status))
532
		goto FAIL;
533
	}
534
    }
535

            
536
24
    if (surface->backend->requires_thumbnail_image) {
537
	int width, height;
538

            
539
5
	if (surface->backend->requires_thumbnail_image (surface->target, &width, &height))
540
	    _paint_thumbnail_image (surface, width, height);
541
    }
542

            
543
19
  FAIL:
544
24
    if (regions_id)
545
24
        _cairo_recording_surface_region_array_remove (surface->recording_surface, regions_id);
546

            
547
24
    cairo_surface_destroy (analysis);
548

            
549
24
    return _cairo_surface_set_error (surface->target, status);
550
}
551

            
552
static cairo_status_t
553
24
_start_page (cairo_paginated_surface_t *surface)
554
{
555
24
    if (surface->target->status)
556
	return surface->target->status;
557

            
558
24
    if (! surface->backend->start_page)
559
14
	return CAIRO_STATUS_SUCCESS;
560

            
561
10
    return _cairo_surface_set_error (surface->target,
562
10
	                        surface->backend->start_page (surface->target));
563
}
564

            
565
static cairo_int_status_t
566
_cairo_paginated_surface_copy_page (void *abstract_surface)
567
{
568
    cairo_status_t status;
569
    cairo_paginated_surface_t *surface = abstract_surface;
570

            
571
    status = _start_page (surface);
572
    if (unlikely (status))
573
	return status;
574

            
575
    status = _paint_page (surface);
576
    if (unlikely (status))
577
	return status;
578

            
579
    surface->page_num++;
580

            
581
    /* XXX: It might make sense to add some support here for calling
582
     * cairo_surface_copy_page on the target surface. It would be an
583
     * optimization for the output, but the interaction with image
584
     * fallbacks gets tricky. For now, we just let the target see a
585
     * show_page and we implement the copying by simply not destroying
586
     * the recording-surface. */
587

            
588
    cairo_surface_show_page (surface->target);
589
    return cairo_surface_status (surface->target);
590
}
591

            
592
static cairo_int_status_t
593
24
_cairo_paginated_surface_show_page (void *abstract_surface)
594
{
595
    cairo_status_t status;
596
24
    cairo_paginated_surface_t *surface = abstract_surface;
597

            
598
24
    status = _start_page (surface);
599
24
    if (unlikely (status))
600
	return status;
601

            
602
24
    status = _paint_page (surface);
603
24
    if (unlikely (status))
604
	return status;
605

            
606
24
    cairo_surface_show_page (surface->target);
607
24
    status = surface->target->status;
608
24
    if (unlikely (status))
609
	return status;
610

            
611
24
    status = surface->recording_surface->status;
612
24
    if (unlikely (status))
613
	return status;
614

            
615
24
    if (! surface->base.finished) {
616
24
	cairo_surface_destroy (surface->recording_surface);
617

            
618
24
	surface->recording_surface = _create_recording_surface_for_target (surface->target,
619
									   surface->content);
620
24
	status = surface->recording_surface->status;
621
24
	if (unlikely (status))
622
	    return status;
623

            
624
24
	surface->page_num++;
625
24
	surface->base.is_clear = TRUE;
626
    }
627

            
628
24
    return CAIRO_STATUS_SUCCESS;
629
}
630

            
631
static cairo_bool_t
632
126
_cairo_paginated_surface_get_extents (void	              *abstract_surface,
633
				      cairo_rectangle_int_t   *rectangle)
634
{
635
126
    cairo_paginated_surface_t *surface = abstract_surface;
636

            
637
126
    return _cairo_surface_get_extents (surface->target, rectangle);
638
}
639

            
640
static void
641
13
_cairo_paginated_surface_get_font_options (void                  *abstract_surface,
642
					   cairo_font_options_t  *options)
643
{
644
13
    cairo_paginated_surface_t *surface = abstract_surface;
645

            
646
13
    cairo_surface_get_font_options (surface->target, options);
647
13
}
648

            
649
static cairo_int_status_t
650
21
_cairo_paginated_surface_paint (void			*abstract_surface,
651
				cairo_operator_t	 op,
652
				const cairo_pattern_t	*source,
653
				const cairo_clip_t	*clip)
654
{
655
21
    cairo_paginated_surface_t *surface = abstract_surface;
656

            
657
21
    return _cairo_surface_paint (surface->recording_surface, op, source, clip);
658
}
659

            
660
static cairo_int_status_t
661
_cairo_paginated_surface_mask (void		*abstract_surface,
662
			       cairo_operator_t	 op,
663
			       const cairo_pattern_t	*source,
664
			       const cairo_pattern_t	*mask,
665
			       const cairo_clip_t		*clip)
666
{
667
    cairo_paginated_surface_t *surface = abstract_surface;
668

            
669
    return _cairo_surface_mask (surface->recording_surface, op, source, mask, clip);
670
}
671

            
672
static cairo_int_status_t
673
_cairo_paginated_surface_stroke (void			*abstract_surface,
674
				 cairo_operator_t	 op,
675
				 const cairo_pattern_t	*source,
676
				 const cairo_path_fixed_t	*path,
677
				 const cairo_stroke_style_t	*style,
678
				 const cairo_matrix_t		*ctm,
679
				 const cairo_matrix_t		*ctm_inverse,
680
				 double			 tolerance,
681
				 cairo_antialias_t	 antialias,
682
				 const cairo_clip_t		*clip)
683
{
684
    cairo_paginated_surface_t *surface = abstract_surface;
685

            
686
    return _cairo_surface_stroke (surface->recording_surface, op, source,
687
				  path, style,
688
				  ctm, ctm_inverse,
689
				  tolerance, antialias,
690
				  clip);
691
}
692

            
693
static cairo_int_status_t
694
84
_cairo_paginated_surface_fill (void			*abstract_surface,
695
			       cairo_operator_t		 op,
696
			       const cairo_pattern_t	*source,
697
			       const cairo_path_fixed_t	*path,
698
			       cairo_fill_rule_t	 fill_rule,
699
			       double			 tolerance,
700
			       cairo_antialias_t	 antialias,
701
			       const cairo_clip_t		*clip)
702
{
703
84
    cairo_paginated_surface_t *surface = abstract_surface;
704

            
705
84
    return _cairo_surface_fill (surface->recording_surface, op, source,
706
				path, fill_rule,
707
				tolerance, antialias,
708
				clip);
709
}
710

            
711
static cairo_bool_t
712
_cairo_paginated_surface_has_show_text_glyphs (void *abstract_surface)
713
{
714
    cairo_paginated_surface_t *surface = abstract_surface;
715

            
716
    return cairo_surface_has_show_text_glyphs (surface->target);
717
}
718

            
719
static cairo_int_status_t
720
_cairo_paginated_surface_show_text_glyphs (void			      *abstract_surface,
721
					   cairo_operator_t	       op,
722
					   const cairo_pattern_t      *source,
723
					   const char		      *utf8,
724
					   int			       utf8_len,
725
					   cairo_glyph_t	      *glyphs,
726
					   int			       num_glyphs,
727
					   const cairo_text_cluster_t *clusters,
728
					   int			       num_clusters,
729
					   cairo_text_cluster_flags_t  cluster_flags,
730
					   cairo_scaled_font_t	      *scaled_font,
731
					   const cairo_clip_t		      *clip)
732
{
733
    cairo_paginated_surface_t *surface = abstract_surface;
734

            
735
    return _cairo_surface_show_text_glyphs (surface->recording_surface, op, source,
736
					    utf8, utf8_len,
737
					    glyphs, num_glyphs,
738
					    clusters, num_clusters,
739
					    cluster_flags,
740
					    scaled_font,
741
					    clip);
742
}
743

            
744
static const char **
745
_cairo_paginated_surface_get_supported_mime_types (void *abstract_surface)
746
{
747
    cairo_paginated_surface_t *surface = abstract_surface;
748

            
749
    if (surface->target->backend->get_supported_mime_types)
750
	return surface->target->backend->get_supported_mime_types (surface->target);
751

            
752
    return NULL;
753
}
754

            
755
static cairo_int_status_t
756
_cairo_paginated_surface_tag (void			 *abstract_surface,
757
			      cairo_bool_t                begin,
758
			      const char                 *tag_name,
759
			      const char                 *attributes)
760
{
761
    cairo_paginated_surface_t *surface = abstract_surface;
762

            
763
    return _cairo_surface_tag (surface->recording_surface,
764
			       begin, tag_name, attributes);
765
}
766

            
767
static cairo_bool_t
768
_cairo_paginated_surface_supports_color_glyph (void                 *abstract_surface,
769
                                               cairo_scaled_font_t  *scaled_font,
770
                                               unsigned long         glyph_index)
771
{
772
    return TRUE;
773
}
774

            
775
static cairo_surface_t *
776
9
_cairo_paginated_surface_snapshot (void *abstract_other)
777
{
778
9
    cairo_paginated_surface_t *other = abstract_other;
779

            
780
9
    return other->recording_surface->backend->snapshot (other->recording_surface);
781
}
782

            
783
static cairo_t *
784
12
_cairo_paginated_context_create (void *target)
785
{
786
12
    cairo_paginated_surface_t *surface = target;
787

            
788
12
    if (_cairo_surface_is_subsurface (&surface->base))
789
	surface = (cairo_paginated_surface_t *)
790
	    _cairo_surface_subsurface_get_target (&surface->base);
791

            
792
12
    return surface->recording_surface->backend->create_context (target);
793
}
794

            
795
static const cairo_surface_backend_t cairo_paginated_surface_backend = {
796
    CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED,
797
    _cairo_paginated_surface_finish,
798

            
799
    _cairo_paginated_context_create,
800

            
801
    _cairo_paginated_surface_create_similar,
802
    NULL, /* create similar image */
803
    NULL, /* map to image */
804
    NULL, /* unmap image */
805

            
806
    _cairo_paginated_surface_source,
807
    _cairo_paginated_surface_acquire_source_image,
808
    _cairo_paginated_surface_release_source_image,
809
    _cairo_paginated_surface_snapshot,
810

            
811
    _cairo_paginated_surface_copy_page,
812
    _cairo_paginated_surface_show_page,
813

            
814
    _cairo_paginated_surface_get_extents,
815
    _cairo_paginated_surface_get_font_options,
816

            
817
    NULL, /* flush */
818
    NULL, /* mark_dirty_rectangle */
819

            
820
    _cairo_paginated_surface_paint,
821
    _cairo_paginated_surface_mask,
822
    _cairo_paginated_surface_stroke,
823
    _cairo_paginated_surface_fill,
824
    NULL, /* fill_stroke */
825
    NULL, /* show_glyphs */
826
    _cairo_paginated_surface_has_show_text_glyphs,
827
    _cairo_paginated_surface_show_text_glyphs,
828
    _cairo_paginated_surface_get_supported_mime_types,
829
    _cairo_paginated_surface_tag,
830
    _cairo_paginated_surface_supports_color_glyph,
831
};