2005-01-05 14:29:31 +00:00
|
|
|
/* cairo - a vector graphics library with display and print output
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2004 Red Hat, Inc
|
2006-04-18 16:53:23 -07:00
|
|
|
* Copyright © 2006 Red Hat, Inc
|
2005-01-05 14:29:31 +00:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it either under the terms of the GNU Lesser General Public
|
|
|
|
|
* License version 2.1 as published by the Free Software Foundation
|
|
|
|
|
* (the "LGPL") or, at your option, under the terms of the Mozilla
|
|
|
|
|
* Public License Version 1.1 (the "MPL"). If you do not alter this
|
|
|
|
|
* notice, a recipient may use your version of this file under either
|
|
|
|
|
* the MPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the LGPL along with this library
|
|
|
|
|
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
* You should have received a copy of the MPL along with this library
|
|
|
|
|
* in the file COPYING-MPL-1.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
|
|
|
|
|
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
|
|
|
|
|
* the specific language governing rights and limitations.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is the cairo graphics library.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is University of Southern
|
|
|
|
|
* California.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
* Kristian Høgsberg <krh@redhat.com>
|
2006-04-18 16:53:23 -07:00
|
|
|
* Carl Worth <cworth@cworth.org>
|
2005-01-05 14:29:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairoint.h"
|
2005-01-20 08:28:54 +00:00
|
|
|
#include "cairo-pdf.h"
|
2005-06-21 15:38:51 +00:00
|
|
|
#include "cairo-font-subset-private.h"
|
Change cairo_font_t to refer to a font scaled to a particular output device resolution.
src/cairoint.h src/cairo_font.c src/cairo_ft_font.c src/cairo_xlib_surface.c src/cairo_pdf_surface.c src/cairo_gstate.c src/cairo.c: Switch many internal methods from handling cairo_unscaled_font_t and cairo_font_scale_t pairs to handling cairo_font_t.
src/cairo-ft-private.h src/cairo_ft_fontc: Add some internal interfaces for use by the FreeType backend.
Clear the gstate's current font when the transform or target surface changes.
src/cairo.h src/cairo_ft_font.c: Rename cairo_ft_font_pattern to cairo_ft_font_get_pattern().
src/cairo.h src/cairo_ft_font.c: Make cairo_ft_font_create() and cairo_ft_font_create_for_ft_face() take a font scale; make the latter take load_flags for FT_Load_Glyph() as well. Change cairo_ft_font_face() to Xft-style cairo_ft_font_lock_face, cairo_ft_font_unlock_face.
Remove the name/slant/weight=>unscaled font cache, it didn't work with the new cairo_font_t setup. If it turns out to be needed, it can be added back in some other form.
src/cairoint.h src/cairo_font.c: Add a 'flags' field to cairo_glyph_cache_key_t, we use it for load flags with freetype backend.
Switch the caching to be from resolved fontconfig pattern => file; keep only a fixed number of FT_Face objects open at once, similar to FreeType.
src/cairo_gstate.c src/cairoint.h: Add public cairo_font_glyph_extents, use it to implement _cairo_gstate_glyph_extents().
Add refcounting for glyph cache elements; there was an bug where elements got ejected from the cache and freed before they could be used.
src/cairoint.h src/cairo_cache.c (_cairo_cache_random_entry()) New function to return a random entry in the cache matching a predicate; reuse the internals for the previous _random_live_entry().
src/cairoint.h src/cairo_cache.c (_cairo_cache_lookup()): Add an optional created_entry return value.
src/cairo_ft_font.c src/cairo_xlib_surface.c: Adapt to _cairo_cache_lookup() change.
Support max_memory == 0 to indicate an unbounded cache.
src/cairoint.h src/cairo_cache.c (_cairo_cache_remove()): Add a function to manually remove entries from the cache.
Update for changes, document cairo_matrix_t, cairo_glyph_t, etc.
src/cairo.h src/cairo-atsui.h src/cairo-ft.h src/cairo-glitz.h src/cairo-pdf.h src/cairo-png.h src/cairo-ps.h src/cairo-quartz.h src/cairo-xcb.h src/cairo-xlib.h: Add CAIRO_BEGIN/END_DECLS for extern "C", use it on all public headers. Move header guards outermost.
Fix encoding.
2005-01-21 14:33:47 +00:00
|
|
|
#include "cairo-ft-private.h"
|
2006-01-11 11:53:33 +00:00
|
|
|
#include "cairo-paginated-surface-private.h"
|
2006-04-19 11:04:37 -07:00
|
|
|
#include "cairo-path-fixed-private.h"
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
#include <time.h>
|
2005-01-05 17:46:31 +00:00
|
|
|
#include <zlib.h>
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
/* Issues:
|
|
|
|
|
*
|
|
|
|
|
* - Why doesn't pages inherit /alpha%d GS dictionaries from the Pages
|
|
|
|
|
* object?
|
|
|
|
|
*
|
|
|
|
|
* - We embed an image in the stream each time it's composited. We
|
|
|
|
|
* could add generation counters to surfaces and remember the stream
|
|
|
|
|
* ID for a particular generation for a particular surface.
|
|
|
|
|
*
|
|
|
|
|
* - Clipping: must be able to reset clipping
|
|
|
|
|
*
|
|
|
|
|
* - Images of other formats than 8 bit RGBA.
|
|
|
|
|
*
|
|
|
|
|
* - Backend specific meta data.
|
|
|
|
|
*
|
|
|
|
|
* - Surface patterns.
|
|
|
|
|
*
|
|
|
|
|
* - Alpha channels in gradients.
|
|
|
|
|
*
|
|
|
|
|
* - Should/does cairo support drawing into a scratch surface and then
|
|
|
|
|
* using that as a fill pattern? For this backend, that would involve
|
|
|
|
|
* using a tiling pattern (4.6.2). How do you create such a scratch
|
|
|
|
|
* surface? cairo_surface_create_similar() ?
|
|
|
|
|
*
|
|
|
|
|
* - What if you create a similiar surface and does show_page and then
|
|
|
|
|
* does show_surface on another surface?
|
|
|
|
|
*
|
|
|
|
|
* - Output TM so page scales to the right size - PDF default user
|
|
|
|
|
* space has 1 unit = 1 / 72 inch.
|
|
|
|
|
*
|
|
|
|
|
* - Add test case for RGBA images.
|
|
|
|
|
*
|
|
|
|
|
* - Add test case for RGBA gradients.
|
|
|
|
|
*
|
|
|
|
|
* - Coordinate space for create_similar() args?
|
|
|
|
|
*
|
|
|
|
|
* - Investigate /Matrix entry in content stream dicts for pages
|
|
|
|
|
* instead of outputting the cm operator in every page.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct cairo_pdf_object cairo_pdf_object_t;
|
|
|
|
|
typedef struct cairo_pdf_resource cairo_pdf_resource_t;
|
|
|
|
|
typedef struct cairo_pdf_document cairo_pdf_document_t;
|
|
|
|
|
typedef struct cairo_pdf_surface cairo_pdf_surface_t;
|
|
|
|
|
|
|
|
|
|
struct cairo_pdf_object {
|
|
|
|
|
long offset;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct cairo_pdf_resource {
|
|
|
|
|
unsigned int id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct cairo_pdf_document {
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output_stream;
|
2005-07-25 16:23:05 +00:00
|
|
|
unsigned long ref_count;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_surface_t *owner;
|
|
|
|
|
cairo_bool_t finished;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-13 09:26:20 +00:00
|
|
|
double width;
|
|
|
|
|
double height;
|
2005-05-16 11:41:42 +00:00
|
|
|
double x_dpi;
|
|
|
|
|
double y_dpi;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t next_available_resource;
|
|
|
|
|
cairo_pdf_resource_t pages_resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
struct {
|
|
|
|
|
cairo_bool_t active;
|
|
|
|
|
cairo_pdf_resource_t self;
|
|
|
|
|
cairo_pdf_resource_t length;
|
|
|
|
|
long start_offset;
|
|
|
|
|
} current_stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
cairo_array_t objects;
|
|
|
|
|
cairo_array_t pages;
|
2005-01-17 09:40:00 +00:00
|
|
|
|
|
|
|
|
cairo_array_t fonts;
|
2005-01-05 14:29:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct cairo_pdf_surface {
|
|
|
|
|
cairo_surface_t base;
|
|
|
|
|
|
2005-05-13 09:26:20 +00:00
|
|
|
double width;
|
|
|
|
|
double height;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
cairo_pdf_document_t *document;
|
|
|
|
|
|
|
|
|
|
cairo_array_t patterns;
|
|
|
|
|
cairo_array_t xobjects;
|
|
|
|
|
cairo_array_t streams;
|
|
|
|
|
cairo_array_t alphas;
|
2005-01-17 09:40:00 +00:00
|
|
|
cairo_array_t fonts;
|
2005-06-14 19:45:22 +00:00
|
|
|
cairo_bool_t has_clip;
|
2006-03-24 11:48:35 -08:00
|
|
|
|
|
|
|
|
cairo_paginated_mode_t paginated_mode;
|
2005-01-05 14:29:31 +00:00
|
|
|
};
|
|
|
|
|
|
2005-05-16 11:41:42 +00:00
|
|
|
#define DEFAULT_DPI 300
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
static cairo_pdf_document_t *
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_pdf_document_create (cairo_output_stream_t *stream,
|
2005-05-13 09:26:20 +00:00
|
|
|
double width,
|
|
|
|
|
double height);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_destroy (cairo_pdf_document_t *document);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_document_finish (cairo_pdf_document_t *document);
|
|
|
|
|
|
2005-08-04 18:44:29 +00:00
|
|
|
static cairo_pdf_document_t *
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_reference (cairo_pdf_document_t *document);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-17 09:40:00 +00:00
|
|
|
_cairo_pdf_document_new_object (cairo_pdf_document_t *document);
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_document_add_page (cairo_pdf_document_t *document,
|
|
|
|
|
cairo_pdf_surface_t *surface);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_open_stream (cairo_pdf_document_t *document,
|
2005-05-13 14:04:22 +00:00
|
|
|
const char *fmt,
|
2006-04-18 23:24:14 -07:00
|
|
|
...) CAIRO_PRINTF_FORMAT(2, 3);
|
2005-06-21 15:38:51 +00:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_close_stream (cairo_pdf_document_t *document);
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static cairo_surface_t *
|
|
|
|
|
_cairo_pdf_surface_create_for_document (cairo_pdf_document_t *document,
|
2005-05-13 09:26:20 +00:00
|
|
|
double width,
|
|
|
|
|
double height);
|
2005-01-05 14:29:31 +00:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_add_stream (cairo_pdf_surface_t *surface,
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
static const cairo_surface_backend_t cairo_pdf_surface_backend;
|
2006-04-14 11:33:48 -07:00
|
|
|
static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_new_object (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t resource;
|
2005-11-04 16:13:30 +00:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_pdf_object_t object;
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
object.offset = _cairo_output_stream_get_position (document->output_stream);
|
2005-11-04 16:13:30 +00:00
|
|
|
|
|
|
|
|
status = _cairo_array_append (&document->objects, &object);
|
2006-05-12 13:31:12 -07:00
|
|
|
if (status) {
|
|
|
|
|
resource.id = 0;
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
resource = document->next_available_resource;
|
|
|
|
|
document->next_available_resource.id++;
|
|
|
|
|
|
|
|
|
|
return resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_update_object (cairo_pdf_document_t *document,
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t resource)
|
2005-01-17 09:40:00 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_object_t *object;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
object = _cairo_array_index (&document->objects, resource.id - 1);
|
2005-03-16 12:08:41 +00:00
|
|
|
object->offset = _cairo_output_stream_get_position (document->output_stream);
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_add_stream (cairo_pdf_surface_t *surface,
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-11-04 16:13:30 +00:00
|
|
|
/* XXX: Should be checking the return value here. */
|
|
|
|
|
_cairo_array_append (&surface->streams, &stream);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_add_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_resource_t pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-11-04 16:13:30 +00:00
|
|
|
/* XXX: Should be checking the return value here. */
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_array_append (&surface->patterns, &pattern);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, double alpha)
|
|
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
int num_alphas, i;
|
|
|
|
|
double other;
|
|
|
|
|
|
|
|
|
|
num_alphas = _cairo_array_num_elements (&surface->alphas);
|
|
|
|
|
for (i = 0; i < num_alphas; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->alphas, i, &other);
|
2006-05-12 13:31:12 -07:00
|
|
|
if (alpha == other) {
|
|
|
|
|
resource.id = i;
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-11-04 16:13:30 +00:00
|
|
|
/* XXX: Should be checking the return value here. */
|
|
|
|
|
_cairo_array_append (&surface->alphas, &alpha);
|
2006-05-12 13:31:12 -07:00
|
|
|
|
|
|
|
|
resource.id = _cairo_array_num_elements (&surface->alphas) - 1;
|
|
|
|
|
return resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
static cairo_surface_t *
|
2005-05-17 05:58:01 +00:00
|
|
|
_cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream,
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
double width,
|
|
|
|
|
double height)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document;
|
2006-01-11 11:53:33 +00:00
|
|
|
cairo_surface_t *target;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-13 09:26:20 +00:00
|
|
|
document = _cairo_pdf_document_create (stream, width, height);
|
2005-07-27 15:39:34 +00:00
|
|
|
if (document == NULL) {
|
|
|
|
|
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-01-11 11:53:33 +00:00
|
|
|
target = _cairo_pdf_surface_create_for_document (document, width, height);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-01-11 11:53:33 +00:00
|
|
|
document->owner = target;
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_destroy (document);
|
|
|
|
|
|
2006-01-19 17:48:22 +00:00
|
|
|
return _cairo_paginated_surface_create (target,
|
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA,
|
2006-02-27 19:47:14 +01:00
|
|
|
width, height,
|
2006-04-14 11:33:48 -07:00
|
|
|
&cairo_pdf_surface_paginated_backend);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-18 16:40:17 +00:00
|
|
|
/**
|
|
|
|
|
* cairo_pdf_surface_create_for_stream:
|
|
|
|
|
* @write: a #cairo_write_func_t to accept the output data
|
|
|
|
|
* @closure: the closure argument for @write
|
|
|
|
|
* @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
|
|
|
|
|
* @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
|
|
|
|
|
*
|
|
|
|
|
* Creates a PDF surface of the specified size in points to be written
|
|
|
|
|
* incrementally to the stream represented by @write and @closure.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a pointer to the newly created surface. The caller
|
|
|
|
|
* owns the surface and should call cairo_surface_destroy when done
|
|
|
|
|
* with it.
|
|
|
|
|
*
|
|
|
|
|
* This function always returns a valid pointer, but it will return a
|
|
|
|
|
* pointer to a "nil" surface if an error such as out of memory
|
|
|
|
|
* occurs. You can use cairo_surface_status() to check for this.
|
|
|
|
|
*/
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_surface_t *
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
cairo_pdf_surface_create_for_stream (cairo_write_func_t write,
|
2005-05-13 09:26:20 +00:00
|
|
|
void *closure,
|
2006-01-18 16:40:17 +00:00
|
|
|
double width_in_points,
|
|
|
|
|
double height_in_points)
|
2005-03-16 12:08:41 +00:00
|
|
|
{
|
2006-04-04 10:45:38 -07:00
|
|
|
cairo_status_t status;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *stream;
|
|
|
|
|
|
2006-04-03 23:44:51 -07:00
|
|
|
stream = _cairo_output_stream_create (write, NULL, closure);
|
2006-04-04 10:45:38 -07:00
|
|
|
status = _cairo_output_stream_get_status (stream);
|
|
|
|
|
if (status) {
|
|
|
|
|
_cairo_error (status);
|
2005-07-27 15:39:34 +00:00
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
|
|
|
|
}
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-01-19 17:48:22 +00:00
|
|
|
return _cairo_pdf_surface_create_for_stream_internal (stream,
|
2006-01-18 16:44:19 +00:00
|
|
|
width_in_points,
|
|
|
|
|
height_in_points);
|
2005-03-16 12:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-18 16:40:17 +00:00
|
|
|
/**
|
|
|
|
|
* cairo_pdf_surface_create:
|
|
|
|
|
* @filename: a filename for the PDF output (must be writable)
|
|
|
|
|
* @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
|
|
|
|
|
* @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
|
|
|
|
|
*
|
|
|
|
|
* Creates a PDF surface of the specified size in points to be written
|
|
|
|
|
* to @filename.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a pointer to the newly created surface. The caller
|
|
|
|
|
* owns the surface and should call cairo_surface_destroy when done
|
|
|
|
|
* with it.
|
|
|
|
|
*
|
|
|
|
|
* This function always returns a valid pointer, but it will return a
|
|
|
|
|
* pointer to a "nil" surface if an error such as out of memory
|
|
|
|
|
* occurs. You can use cairo_surface_status() to check for this.
|
|
|
|
|
**/
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_surface_t *
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
cairo_pdf_surface_create (const char *filename,
|
2006-01-18 16:40:17 +00:00
|
|
|
double width_in_points,
|
|
|
|
|
double height_in_points)
|
2005-03-16 12:08:41 +00:00
|
|
|
{
|
2006-04-04 10:45:38 -07:00
|
|
|
cairo_status_t status;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *stream;
|
|
|
|
|
|
2006-04-08 21:29:14 -07:00
|
|
|
stream = _cairo_output_stream_create_for_filename (filename);
|
2006-04-04 10:45:38 -07:00
|
|
|
status = _cairo_output_stream_get_status (stream);
|
|
|
|
|
if (status) {
|
|
|
|
|
_cairo_error (status);
|
2005-07-27 15:39:34 +00:00
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
|
|
|
|
}
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-01-19 17:48:22 +00:00
|
|
|
return _cairo_pdf_surface_create_for_stream_internal (stream,
|
2006-01-18 16:44:19 +00:00
|
|
|
width_in_points,
|
|
|
|
|
height_in_points);
|
2005-05-13 09:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 11:53:33 +00:00
|
|
|
static cairo_bool_t
|
|
|
|
|
_cairo_surface_is_pdf (cairo_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
return surface->backend == &cairo_pdf_surface_backend;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
/* If the abstract_surface is a paginated surface, and that paginated
|
|
|
|
|
* surface's target is a pdf_surface, then set pdf_surface to that
|
|
|
|
|
* target. Otherwise return CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
|
|
|
|
|
*/
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_extract_pdf_surface (cairo_surface_t *surface,
|
|
|
|
|
cairo_pdf_surface_t **pdf_surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_t *target;
|
|
|
|
|
|
|
|
|
|
if (! _cairo_surface_is_paginated (surface))
|
|
|
|
|
return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
|
|
|
|
|
|
|
|
|
|
target = _cairo_paginated_surface_get_target (surface);
|
|
|
|
|
|
|
|
|
|
if (! _cairo_surface_is_pdf (target))
|
|
|
|
|
return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
|
|
|
|
|
|
|
|
|
|
*pdf_surface = (cairo_pdf_surface_t *) target;
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-19 10:36:43 +00:00
|
|
|
/**
|
2006-04-14 22:55:48 +02:00
|
|
|
* cairo_pdf_surface_set_dpi:
|
2006-05-03 12:39:23 -07:00
|
|
|
* @surface: a PDF cairo_surface_t
|
2005-08-19 10:36:43 +00:00
|
|
|
* @x_dpi: horizontal dpi
|
|
|
|
|
* @y_dpi: vertical dpi
|
|
|
|
|
*
|
2006-01-18 16:40:17 +00:00
|
|
|
* Set the horizontal and vertical resolution for image fallbacks.
|
|
|
|
|
* When the pdf backend needs to fall back to image overlays, it will
|
|
|
|
|
* use this resolution. These DPI values are not used for any other
|
|
|
|
|
* purpose, (in particular, they do not have any bearing on the size
|
|
|
|
|
* passed to cairo_pdf_surface_create() nor on the CTM).
|
2005-08-19 10:36:43 +00:00
|
|
|
**/
|
2005-05-13 09:26:20 +00:00
|
|
|
void
|
2005-05-16 11:41:42 +00:00
|
|
|
cairo_pdf_surface_set_dpi (cairo_surface_t *surface,
|
|
|
|
|
double x_dpi,
|
|
|
|
|
double y_dpi)
|
2005-05-13 09:26:20 +00:00
|
|
|
{
|
2006-01-11 11:53:33 +00:00
|
|
|
cairo_pdf_surface_t *pdf_surface;
|
2006-05-03 12:39:23 -07:00
|
|
|
cairo_status_t status;
|
2006-01-11 11:53:33 +00:00
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
status = _extract_pdf_surface (surface, &pdf_surface);
|
|
|
|
|
if (status) {
|
|
|
|
|
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
|
2006-01-11 11:53:33 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
pdf_surface->document->x_dpi = x_dpi;
|
|
|
|
|
pdf_surface->document->y_dpi = y_dpi;
|
|
|
|
|
}
|
2006-01-11 11:53:33 +00:00
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
/**
|
|
|
|
|
* cairo_pdf_surface_set_size:
|
|
|
|
|
* @surface: a PDF cairo_surface_t
|
|
|
|
|
* @width_in_points: new surface width, in points (1 point == 1/72.0 inch)
|
|
|
|
|
* @height_in_points: new surface height, in points (1 point == 1/72.0 inch)
|
|
|
|
|
*
|
|
|
|
|
* Changes the size of a PDF surface for the current (and
|
|
|
|
|
* subsequent) pages.
|
|
|
|
|
*
|
|
|
|
|
* This function should only be called before any drawing operations
|
|
|
|
|
* have been performed on the current page. The simplest way to do
|
|
|
|
|
* this is to call this function immediately after creating the
|
|
|
|
|
* surface or immediately after completing a page with either
|
|
|
|
|
* cairo_show_page() or cairo_copy_page().
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
cairo_pdf_surface_set_size (cairo_surface_t *surface,
|
|
|
|
|
double width_in_points,
|
|
|
|
|
double height_in_points)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *pdf_surface;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
|
|
|
|
status = _extract_pdf_surface (surface, &pdf_surface);
|
|
|
|
|
if (status) {
|
|
|
|
|
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
|
2006-01-11 11:53:33 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
pdf_surface->width = width_in_points;
|
|
|
|
|
pdf_surface->height = height_in_points;
|
2005-03-16 12:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static cairo_surface_t *
|
|
|
|
|
_cairo_pdf_surface_create_for_document (cairo_pdf_document_t *document,
|
2005-05-13 09:26:20 +00:00
|
|
|
double width,
|
|
|
|
|
double height)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface;
|
|
|
|
|
|
|
|
|
|
surface = malloc (sizeof (cairo_pdf_surface_t));
|
2005-07-27 15:39:34 +00:00
|
|
|
if (surface == NULL) {
|
|
|
|
|
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
_cairo_surface_init (&surface->base, &cairo_pdf_surface_backend);
|
|
|
|
|
|
2005-05-13 09:26:20 +00:00
|
|
|
surface->width = width;
|
|
|
|
|
surface->height = height;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-08-04 18:44:29 +00:00
|
|
|
surface->document = _cairo_pdf_document_reference (document);
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_array_init (&surface->streams, sizeof (cairo_pdf_resource_t));
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_array_init (&surface->patterns, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->xobjects, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->alphas, sizeof (double));
|
2005-02-13 20:36:28 +00:00
|
|
|
_cairo_array_init (&surface->fonts, sizeof (cairo_pdf_resource_t));
|
2005-06-14 19:45:22 +00:00
|
|
|
surface->has_clip = FALSE;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-03-24 11:48:35 -08:00
|
|
|
surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE;
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
return &surface->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
_cairo_array_truncate (&surface->streams, 0);
|
|
|
|
|
_cairo_array_truncate (&surface->patterns, 0);
|
|
|
|
|
_cairo_array_truncate (&surface->xobjects, 0);
|
|
|
|
|
_cairo_array_truncate (&surface->alphas, 0);
|
2005-01-17 09:40:00 +00:00
|
|
|
_cairo_array_truncate (&surface->fonts, 0);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
2005-07-08 10:12:28 +00:00
|
|
|
_cairo_pdf_surface_create_similar (void *abstract_src,
|
|
|
|
|
cairo_content_t content,
|
2005-01-05 14:29:31 +00:00
|
|
|
int width,
|
|
|
|
|
int height)
|
|
|
|
|
{
|
2006-04-20 22:07:52 +02:00
|
|
|
cairo_format_t format = _cairo_format_from_content (content);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-20 22:07:52 +02:00
|
|
|
/* Just return an image for now, until PDF surface can be used
|
|
|
|
|
* as source. */
|
|
|
|
|
return cairo_image_surface_create (format, width, height);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_open_stream (cairo_pdf_document_t *document,
|
2005-05-13 14:04:22 +00:00
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output_stream = document->output_stream;
|
2005-05-13 14:04:22 +00:00
|
|
|
va_list ap;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.active = TRUE;
|
|
|
|
|
document->current_stream.self = _cairo_pdf_document_new_object (document);
|
|
|
|
|
document->current_stream.length = _cairo_pdf_document_new_object (document);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
"%d 0 obj\r\n"
|
2005-05-13 14:04:22 +00:00
|
|
|
"<< /Length %d 0 R\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.self.id,
|
|
|
|
|
document->current_stream.length.id);
|
2005-05-13 14:04:22 +00:00
|
|
|
|
|
|
|
|
if (fmt != NULL) {
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
|
_cairo_output_stream_vprintf (output_stream, fmt, ap);
|
|
|
|
|
va_end (ap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.start_offset = _cairo_output_stream_get_position (output_stream);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return document->current_stream.self;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_close_stream (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output_stream = document->output_stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
long length;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
if (! document->current_stream.active)
|
2005-01-05 14:29:31 +00:00
|
|
|
return;
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
length = _cairo_output_stream_get_position (output_stream) -
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.start_offset;
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_document_update_object (document,
|
|
|
|
|
document->current_stream.length);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
" %ld\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.length.id,
|
2005-03-16 12:08:41 +00:00
|
|
|
length);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.active = FALSE;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_finish (void *abstract_surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_document_close_stream (document);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
if (document->owner == &surface->base)
|
|
|
|
|
status = _cairo_pdf_document_finish (document);
|
|
|
|
|
else
|
|
|
|
|
status = CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_destroy (document);
|
|
|
|
|
|
2005-07-14 17:52:17 +00:00
|
|
|
_cairo_array_fini (&surface->streams);
|
|
|
|
|
_cairo_array_fini (&surface->patterns);
|
|
|
|
|
_cairo_array_fini (&surface->xobjects);
|
|
|
|
|
_cairo_array_fini (&surface->alphas);
|
|
|
|
|
_cairo_array_fini (&surface->fonts);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_pause_content_stream (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_document_close_stream (document);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static void
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_resume_content_stream (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
|
|
|
|
|
|
|
|
|
stream = _cairo_pdf_document_open_stream (document,
|
|
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_add_stream (surface, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_start_page (void *abstract_surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
stream = _cairo_pdf_document_open_stream (document,
|
|
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_add_stream (surface, stream);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"1 0 0 -1 0 %f cm\r\n",
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
static void *
|
|
|
|
|
compress_dup (const void *data, unsigned long data_size,
|
|
|
|
|
unsigned long *compressed_size)
|
2005-01-06 23:20:07 +00:00
|
|
|
{
|
2005-01-17 09:40:00 +00:00
|
|
|
void *compressed;
|
|
|
|
|
|
|
|
|
|
/* Bound calculation taken from zlib. */
|
|
|
|
|
*compressed_size = data_size + (data_size >> 12) + (data_size >> 14) + 11;
|
|
|
|
|
compressed = malloc (*compressed_size);
|
|
|
|
|
if (compressed == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
compress (compressed, compressed_size, data, data_size);
|
|
|
|
|
|
|
|
|
|
return compressed;
|
2005-01-06 23:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
/* Emit alpha channel from the image into the given data, providing
|
|
|
|
|
* and id that can be used to reference the resulting SMask object.
|
|
|
|
|
*
|
|
|
|
|
* In the case that the alpha channel happens to be all opaque, then
|
|
|
|
|
* no SMask object will be emitted and *id_ret will be set to 0.
|
|
|
|
|
*/
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
emit_smask (cairo_pdf_document_t *document,
|
|
|
|
|
cairo_image_surface_t *image,
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t *stream_ret)
|
2006-04-25 03:45:37 -07:00
|
|
|
{
|
|
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
|
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
|
|
|
|
char *alpha, *alpha_compressed;
|
|
|
|
|
unsigned long alpha_size, alpha_compressed_size;
|
|
|
|
|
pixman_bits_t *pixel;
|
|
|
|
|
int i, x, y;
|
|
|
|
|
cairo_bool_t opaque;
|
|
|
|
|
uint8_t a;
|
|
|
|
|
|
|
|
|
|
/* This is the only image format we support, which simplfies things. */
|
|
|
|
|
assert (image->format == CAIRO_FORMAT_ARGB32);
|
|
|
|
|
|
|
|
|
|
alpha_size = image->height * image->width;
|
|
|
|
|
alpha = malloc (alpha_size);
|
|
|
|
|
if (alpha == NULL) {
|
|
|
|
|
status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
goto CLEANUP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opaque = TRUE;
|
|
|
|
|
i = 0;
|
|
|
|
|
for (y = 0; y < image->height; y++) {
|
|
|
|
|
pixel = (pixman_bits_t *) (image->data + y * image->stride);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < image->width; x++, pixel++) {
|
|
|
|
|
a = (*pixel & 0xff000000) >> 24;
|
|
|
|
|
alpha[i++] = a;
|
|
|
|
|
if (a != 0xff)
|
|
|
|
|
opaque = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Bail out without emitting smask if it's all opaque. */
|
|
|
|
|
if (opaque) {
|
2006-05-12 13:31:12 -07:00
|
|
|
stream_ret->id = 0;
|
2006-04-25 03:45:37 -07:00
|
|
|
goto CLEANUP_ALPHA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alpha_compressed = compress_dup (alpha, alpha_size, &alpha_compressed_size);
|
|
|
|
|
if (alpha_compressed == NULL) {
|
|
|
|
|
status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
goto CLEANUP_ALPHA;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
*stream_ret = _cairo_pdf_document_open_stream (document,
|
|
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Image\r\n"
|
|
|
|
|
" /Width %d\r\n"
|
|
|
|
|
" /Height %d\r\n"
|
|
|
|
|
" /ColorSpace /DeviceGray\r\n"
|
|
|
|
|
" /BitsPerComponent 8\r\n"
|
|
|
|
|
" /Filter /FlateDecode\r\n",
|
|
|
|
|
image->width, image->height);
|
2006-04-25 03:45:37 -07:00
|
|
|
_cairo_output_stream_write (output, alpha_compressed, alpha_compressed_size);
|
|
|
|
|
_cairo_output_stream_printf (output, "\r\n");
|
|
|
|
|
_cairo_pdf_document_close_stream (document);
|
|
|
|
|
|
|
|
|
|
free (alpha_compressed);
|
|
|
|
|
CLEANUP_ALPHA:
|
|
|
|
|
free (alpha);
|
|
|
|
|
CLEANUP:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-20 10:01:45 -07:00
|
|
|
/* Emit image data into the given document, providing an id that can
|
|
|
|
|
* be used to reference the data in id_ret. */
|
|
|
|
|
static cairo_status_t
|
2006-04-25 03:45:37 -07:00
|
|
|
emit_image (cairo_pdf_document_t *document,
|
|
|
|
|
cairo_image_surface_t *image,
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t *image_ret)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2005-01-05 17:46:31 +00:00
|
|
|
char *rgb, *compressed;
|
|
|
|
|
unsigned long rgb_size, compressed_size;
|
|
|
|
|
pixman_bits_t *pixel;
|
2006-04-25 03:45:37 -07:00
|
|
|
int i, x, y;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t smask;
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_bool_t need_smask;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
/* XXX: Need to rewrite this as a pdf_surface function with
|
|
|
|
|
* pause/resume of content_stream, (currently the only caller does
|
|
|
|
|
* the pause/resume already, but that is expected to change in the
|
|
|
|
|
* future). */
|
|
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
/* These are the only image formats we currently support, (which
|
|
|
|
|
* makes things a lot simpler here). This is enforeced through
|
|
|
|
|
* _analyze_operation which only accept source surfaces of
|
|
|
|
|
* CONTENT_COLOR or CONTENT_COLOR_ALPHA.
|
|
|
|
|
*/
|
|
|
|
|
assert (image->format == CAIRO_FORMAT_RGB24 || image->format == CAIRO_FORMAT_ARGB32);
|
2005-01-05 17:46:31 +00:00
|
|
|
|
|
|
|
|
rgb_size = image->height * image->width * 3;
|
|
|
|
|
rgb = malloc (rgb_size);
|
2006-04-25 03:45:37 -07:00
|
|
|
if (rgb == NULL) {
|
|
|
|
|
status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
goto CLEANUP;
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 17:46:31 +00:00
|
|
|
i = 0;
|
|
|
|
|
for (y = 0; y < image->height; y++) {
|
2006-04-25 03:45:37 -07:00
|
|
|
pixel = (pixman_bits_t *) (image->data + y * image->stride);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < image->width; x++, pixel++) {
|
|
|
|
|
/* XXX: We're un-premultiplying alpha here. My reading of the PDF
|
|
|
|
|
* specification suggests that we should be able to avoid having
|
|
|
|
|
* to do this by filling in the SMask's Matte dictionary
|
|
|
|
|
* appropriately, but my attempts to do that so far have
|
|
|
|
|
* failed. */
|
|
|
|
|
if (image->format == CAIRO_FORMAT_ARGB32) {
|
|
|
|
|
uint8_t a;
|
|
|
|
|
a = (*pixel & 0xff000000) >> 24;
|
|
|
|
|
if (a == 0) {
|
|
|
|
|
rgb[i++] = 0;
|
|
|
|
|
rgb[i++] = 0;
|
|
|
|
|
rgb[i++] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
rgb[i++] = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a;
|
|
|
|
|
rgb[i++] = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a;
|
|
|
|
|
rgb[i++] = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rgb[i++] = (*pixel & 0x00ff0000) >> 16;
|
|
|
|
|
rgb[i++] = (*pixel & 0x0000ff00) >> 8;
|
|
|
|
|
rgb[i++] = (*pixel & 0x000000ff) >> 0;
|
|
|
|
|
}
|
2005-01-05 17:46:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
compressed = compress_dup (rgb, rgb_size, &compressed_size);
|
|
|
|
|
if (compressed == NULL) {
|
2006-04-25 03:45:37 -07:00
|
|
|
status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
goto CLEANUP_RGB;
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
need_smask = FALSE;
|
|
|
|
|
if (image->format == CAIRO_FORMAT_ARGB32) {
|
2006-05-12 13:31:12 -07:00
|
|
|
status = emit_smask (document, image, &smask);
|
2006-04-25 03:45:37 -07:00
|
|
|
if (status)
|
|
|
|
|
goto CLEANUP_COMPRESSED;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
if (smask.id)
|
2006-04-25 03:45:37 -07:00
|
|
|
need_smask = TRUE;
|
|
|
|
|
}
|
2005-05-13 14:04:22 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
#define IMAGE_DICTIONARY " /Type /XObject\r\n" \
|
|
|
|
|
" /Subtype /Image\r\n" \
|
|
|
|
|
" /Width %d\r\n" \
|
|
|
|
|
" /Height %d\r\n" \
|
|
|
|
|
" /ColorSpace /DeviceRGB\r\n" \
|
|
|
|
|
" /BitsPerComponent 8\r\n" \
|
|
|
|
|
" /Filter /FlateDecode\r\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (need_smask)
|
2006-05-12 13:31:12 -07:00
|
|
|
*image_ret = _cairo_pdf_document_open_stream (document,
|
|
|
|
|
IMAGE_DICTIONARY
|
|
|
|
|
" /SMask %d 0 R\r\n",
|
|
|
|
|
image->width, image->height,
|
|
|
|
|
smask.id);
|
2006-04-25 03:45:37 -07:00
|
|
|
else
|
2006-05-12 13:31:12 -07:00
|
|
|
*image_ret = _cairo_pdf_document_open_stream (document,
|
|
|
|
|
IMAGE_DICTIONARY,
|
|
|
|
|
image->width, image->height);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
#undef IMAGE_DICTIONARY
|
2005-01-05 17:46:31 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
_cairo_output_stream_write (output, compressed, compressed_size);
|
|
|
|
|
_cairo_output_stream_printf (output, "\r\n");
|
|
|
|
|
_cairo_pdf_document_close_stream (document);
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
CLEANUP_COMPRESSED:
|
|
|
|
|
free (compressed);
|
|
|
|
|
CLEANUP_RGB:
|
|
|
|
|
free (rgb);
|
|
|
|
|
CLEANUP:
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2005-03-03 17:40:04 +00:00
|
|
|
emit_solid_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_solid_pattern_t *pattern)
|
2005-02-01 20:47:43 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t alpha;
|
2006-04-18 16:53:23 -07:00
|
|
|
|
2005-04-14 14:42:26 +00:00
|
|
|
alpha = _cairo_pdf_surface_add_alpha (surface, pattern->color.alpha);
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
/* With some work, we could separate the stroking
|
|
|
|
|
* or non-stroking color here as actually needed. */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"%f %f %f RG "
|
|
|
|
|
"%f %f %f rg "
|
|
|
|
|
"/a%d gs\r\n",
|
|
|
|
|
pattern->color.red,
|
|
|
|
|
pattern->color.green,
|
|
|
|
|
pattern->color.blue,
|
2005-04-14 14:42:26 +00:00
|
|
|
pattern->color.red,
|
|
|
|
|
pattern->color.green,
|
|
|
|
|
pattern->color.blue,
|
2006-05-12 13:31:12 -07:00
|
|
|
alpha.id);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-02-01 20:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2005-02-01 20:47:43 +00:00
|
|
|
emit_surface_pattern (cairo_pdf_surface_t *dst,
|
2005-10-11 13:20:44 +00:00
|
|
|
cairo_surface_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = dst->document;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_image_surface_t *image;
|
2005-01-31 08:50:22 +00:00
|
|
|
void *image_extra;
|
2006-04-20 10:01:45 -07:00
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t alpha, image_resource;
|
2006-04-24 16:11:21 -07:00
|
|
|
cairo_matrix_t cairo_p2d, pdf_p2d;
|
|
|
|
|
cairo_extend_t extend = cairo_pattern_get_extend (&pattern->base);
|
|
|
|
|
int xstep, ystep;
|
2006-05-04 03:43:34 -07:00
|
|
|
cairo_rectangle_fixed_t dst_extents;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
/* XXX: Should do something clever here for PDF source surfaces ? */
|
2005-01-31 08:50:22 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_pause_content_stream (dst);
|
|
|
|
|
|
2005-03-03 17:40:04 +00:00
|
|
|
status = _cairo_surface_acquire_source_image (pattern->surface, &image, &image_extra);
|
2005-06-10 12:18:20 +00:00
|
|
|
if (status)
|
2005-10-10 09:36:39 +00:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
status = emit_image (dst->document, image, &image_resource);
|
2006-04-20 10:01:45 -07:00
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-24 16:11:21 -07:00
|
|
|
_cairo_surface_get_extents (&dst->base, &dst_extents);
|
|
|
|
|
|
|
|
|
|
/* In PDF, (as far as I can tell), all patterns are repeating. So
|
|
|
|
|
* we support cairo's EXTEND_NONE semantics by setting the repeat
|
|
|
|
|
* step size to the larger of the image size and the extents of
|
|
|
|
|
* the destination surface. That way we guarantee the pattern will
|
|
|
|
|
* not repeat.
|
|
|
|
|
*/
|
|
|
|
|
switch (extend) {
|
|
|
|
|
case CAIRO_EXTEND_NONE:
|
|
|
|
|
xstep = MAX(image->width, dst_extents.width);
|
|
|
|
|
ystep = MAX(image->height, dst_extents.height);
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_EXTEND_REPEAT:
|
|
|
|
|
xstep = image->width;
|
|
|
|
|
ystep = image->height;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED; /* all others should be analyzed away */
|
|
|
|
|
xstep = 0;
|
|
|
|
|
ystep = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* At this point, (that is, within the surface backend interface),
|
|
|
|
|
* the pattern's matrix maps from cairo's device space to cairo's
|
|
|
|
|
* pattern space, (both with their origin at the upper-left, and
|
|
|
|
|
* cairo's pattern space of size width,height).
|
|
|
|
|
*
|
|
|
|
|
* Then, we must emit a PDF pattern object that maps from its own
|
|
|
|
|
* pattern space, (which has a size that we establish in the BBox
|
|
|
|
|
* dictionary entry), to the PDF page's *initial* space, (which
|
|
|
|
|
* does not benefit from the Y-axis flipping matrix that we emit
|
|
|
|
|
* on each page). So the PDF patterns patrix maps from a
|
|
|
|
|
* (width,height) pattern space to a device space with the origin
|
|
|
|
|
* in the lower-left corner.
|
|
|
|
|
*
|
|
|
|
|
* So to handle all of that, we start with an identity matrix for
|
|
|
|
|
* the PDF pattern to device matrix. We translate it up by the
|
|
|
|
|
* image height then flip it in the Y direction, (moving us from
|
|
|
|
|
* the PDF origin to cairo's origin). We then multiply in the
|
|
|
|
|
* inverse of the cairo pattern matrix, (since it maps from device
|
|
|
|
|
* to pattern, while we're setting up pattern to device). Finally,
|
|
|
|
|
* we translate back down by the image height and flip again to
|
|
|
|
|
* end up at the lower-left origin that PDF expects.
|
|
|
|
|
*
|
|
|
|
|
* Additionally, within the stream that paints the pattern itself,
|
|
|
|
|
* we are using a PDF image object that has a size of (1,1) so we
|
|
|
|
|
* have to scale it up by the image width and height to fill our
|
|
|
|
|
* pattern cell.
|
|
|
|
|
*/
|
|
|
|
|
cairo_p2d = pattern->base.matrix;
|
|
|
|
|
cairo_matrix_invert (&cairo_p2d);
|
|
|
|
|
|
|
|
|
|
cairo_matrix_init_identity (&pdf_p2d);
|
|
|
|
|
cairo_matrix_translate (&pdf_p2d, 0.0, dst_extents.height);
|
|
|
|
|
cairo_matrix_scale (&pdf_p2d, 1.0, -1.0);
|
|
|
|
|
cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &pdf_p2d);
|
|
|
|
|
cairo_matrix_translate (&pdf_p2d, 0.0, image->height);
|
|
|
|
|
cairo_matrix_scale (&pdf_p2d, 1.0, -1.0);
|
|
|
|
|
|
2005-05-13 14:04:22 +00:00
|
|
|
stream = _cairo_pdf_document_open_stream (document,
|
2006-04-24 16:11:21 -07:00
|
|
|
" /BBox [0 0 %d %d]\r\n"
|
2006-04-18 23:24:14 -07:00
|
|
|
" /XStep %d\r\n"
|
|
|
|
|
" /YStep %d\r\n"
|
2005-05-13 14:04:22 +00:00
|
|
|
" /PatternType 1\r\n"
|
|
|
|
|
" /TilingType 1\r\n"
|
|
|
|
|
" /PaintType 1\r\n"
|
2006-04-24 16:11:21 -07:00
|
|
|
" /Matrix [ %f %f %f %f %f %f ]\r\n"
|
2005-05-13 14:04:22 +00:00
|
|
|
" /Resources << /XObject << /res%d %d 0 R >> >>\r\n",
|
2006-04-18 23:24:14 -07:00
|
|
|
image->width, image->height,
|
2006-04-24 16:11:21 -07:00
|
|
|
xstep, ystep,
|
|
|
|
|
pdf_p2d.xx, pdf_p2d.yx,
|
|
|
|
|
pdf_p2d.xy, pdf_p2d.yy,
|
|
|
|
|
pdf_p2d.x0, pdf_p2d.y0,
|
2006-05-12 13:31:12 -07:00
|
|
|
image_resource.id,
|
|
|
|
|
image_resource.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-03 14:28:50 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-24 16:11:21 -07:00
|
|
|
"q %d 0 0 %d 0 0 cm /res%d Do Q\r\n",
|
|
|
|
|
image->width, image->height,
|
2006-05-12 13:31:12 -07:00
|
|
|
image_resource.id);
|
2005-02-01 20:47:43 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_document_close_stream (document);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_resume_content_stream (dst);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_add_pattern (dst, stream);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
alpha = _cairo_pdf_surface_add_alpha (dst, 1.0);
|
2006-04-18 16:53:23 -07:00
|
|
|
/* With some work, we could separate the stroking
|
|
|
|
|
* or non-stroking pattern here as actually needed. */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"/Pattern CS /res%d SCN "
|
|
|
|
|
"/Pattern cs /res%d scn "
|
|
|
|
|
"/a%d gs\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
stream.id, stream.id, alpha.id);
|
2005-01-31 08:50:22 +00:00
|
|
|
|
2006-04-20 10:01:45 -07:00
|
|
|
BAIL:
|
2005-03-03 17:40:04 +00:00
|
|
|
_cairo_surface_release_source_image (pattern->surface, image, image_extra);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
2006-04-20 10:01:45 -07:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
typedef struct _cairo_pdf_color_stop {
|
2006-05-12 13:31:12 -07:00
|
|
|
double offset;
|
|
|
|
|
cairo_pdf_resource_t gradient;
|
|
|
|
|
unsigned char color_char[4];
|
2005-10-07 13:21:01 +00:00
|
|
|
} cairo_pdf_color_stop_t;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-10-11 13:20:44 +00:00
|
|
|
emit_linear_colorgradient (cairo_pdf_document_t *document,
|
|
|
|
|
cairo_pdf_color_stop_t *stop1,
|
|
|
|
|
cairo_pdf_color_stop_t *stop2)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t function = _cairo_pdf_document_new_object (document);
|
2005-10-11 13:20:44 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /FunctionType 0\r\n"
|
2005-10-11 13:20:44 +00:00
|
|
|
" /Domain [ 0 1 ]\r\n"
|
|
|
|
|
" /Size [ 2 ]\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
" /BitsPerSample 8\r\n"
|
2005-10-11 13:20:44 +00:00
|
|
|
" /Range [ 0 1 0 1 0 1 ]\r\n"
|
|
|
|
|
" /Length 6\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
function.id);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
_cairo_output_stream_write (output, stop1->color_char, 3);
|
|
|
|
|
_cairo_output_stream_write (output, stop2->color_char, 3);
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"\r\n"
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return function;
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-10-11 13:20:44 +00:00
|
|
|
emit_stiched_colorgradient (cairo_pdf_document_t *document,
|
|
|
|
|
unsigned int n_stops,
|
|
|
|
|
cairo_pdf_color_stop_t stops[])
|
|
|
|
|
{
|
|
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t function;
|
2005-10-11 13:20:44 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
/* emit linear gradients between pairs of subsequent stops... */
|
|
|
|
|
for (i = 0; i < n_stops-1; i++) {
|
2006-05-12 13:31:12 -07:00
|
|
|
stops[i].gradient = emit_linear_colorgradient (document,
|
|
|
|
|
&stops[i],
|
|
|
|
|
&stops[i+1]);
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ... and stich them together */
|
2006-05-12 13:31:12 -07:00
|
|
|
function = _cairo_pdf_document_new_object (document);
|
2005-10-11 13:20:44 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /FunctionType 3\r\n"
|
|
|
|
|
" /Domain [ 0 1 ]\r\n"
|
|
|
|
|
" /Functions [ ",
|
2006-05-12 13:31:12 -07:00
|
|
|
function.id);
|
2005-10-11 13:20:44 +00:00
|
|
|
for (i = 0; i < n_stops-1; i++)
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_output_stream_printf (output, "%d 0 R ", stops[i].gradient.id);
|
2005-10-11 13:20:44 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"]\r\n"
|
|
|
|
|
" /Bounds [ ");
|
|
|
|
|
for (i = 1; i < n_stops-1; i++)
|
|
|
|
|
_cairo_output_stream_printf (output, "%f ", stops[i].offset);
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"]\r\n"
|
|
|
|
|
" /Encode [ ");
|
|
|
|
|
for (i = 1; i < n_stops; i++)
|
|
|
|
|
_cairo_output_stream_printf (output, "0 1 ");
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return function;
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define COLOR_STOP_EPSILLON 1e-6
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-10-11 13:20:44 +00:00
|
|
|
emit_pattern_stops (cairo_pdf_surface_t *surface, cairo_gradient_pattern_t *pattern)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t function;
|
2005-10-11 13:20:44 +00:00
|
|
|
cairo_pdf_color_stop_t *allstops, *stops;
|
|
|
|
|
unsigned int n_stops;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
function = _cairo_pdf_document_new_object (document);
|
2005-10-11 13:20:44 +00:00
|
|
|
|
|
|
|
|
allstops = malloc ((pattern->n_stops + 2) * sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
if (allstops == NULL) {
|
2005-10-07 13:21:01 +00:00
|
|
|
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
2006-05-12 13:31:12 -07:00
|
|
|
function.id = 0;
|
|
|
|
|
return function;
|
2005-10-07 13:21:01 +00:00
|
|
|
}
|
2005-10-11 13:20:44 +00:00
|
|
|
stops = &allstops[1];
|
|
|
|
|
n_stops = pattern->n_stops;
|
2005-10-07 13:21:01 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < pattern->n_stops; i++) {
|
2006-01-05 05:06:50 +00:00
|
|
|
stops[i].color_char[0] = pattern->stops[i].color.red >> 8;
|
|
|
|
|
stops[i].color_char[1] = pattern->stops[i].color.green >> 8;
|
|
|
|
|
stops[i].color_char[2] = pattern->stops[i].color.blue >> 8;
|
|
|
|
|
stops[i].color_char[3] = pattern->stops[i].color.alpha >> 8;
|
|
|
|
|
stops[i].offset = _cairo_fixed_to_double (pattern->stops[i].x);
|
2005-10-07 13:21:01 +00:00
|
|
|
}
|
2005-10-11 13:20:44 +00:00
|
|
|
|
|
|
|
|
/* make sure first offset is 0.0 and last offset is 1.0. (Otherwise Acrobat
|
|
|
|
|
* Reader chokes.) */
|
|
|
|
|
if (stops[0].offset > COLOR_STOP_EPSILLON) {
|
|
|
|
|
memcpy (allstops, stops, sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
stops = allstops;
|
|
|
|
|
stops[0].offset = 0.0;
|
|
|
|
|
n_stops++;
|
|
|
|
|
}
|
|
|
|
|
if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILLON) {
|
|
|
|
|
memcpy (&stops[n_stops],
|
|
|
|
|
&stops[n_stops - 1],
|
|
|
|
|
sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
stops[n_stops].offset = 1.0;
|
|
|
|
|
n_stops++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n_stops == 2) {
|
|
|
|
|
/* no need for stiched function */
|
2006-05-12 13:31:12 -07:00
|
|
|
function = emit_linear_colorgradient (document, &stops[0], &stops[1]);
|
2005-10-11 13:20:44 +00:00
|
|
|
} else {
|
|
|
|
|
/* multiple stops: stich. XXX possible optimization: regulary spaced
|
|
|
|
|
* stops do not require stiching. XXX */
|
2006-05-12 13:31:12 -07:00
|
|
|
function = emit_stiched_colorgradient (document,
|
|
|
|
|
n_stops,
|
|
|
|
|
stops);
|
2005-10-07 13:21:01 +00:00
|
|
|
}
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
free (allstops);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return function;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2005-03-03 17:40:04 +00:00
|
|
|
emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_linear_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t function, pattern_resource, alpha;
|
2005-01-05 14:29:31 +00:00
|
|
|
double x0, y0, x1, y1;
|
|
|
|
|
cairo_matrix_t p2u;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_pause_content_stream (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
function = emit_pattern_stops (surface, &pattern->base);
|
|
|
|
|
if (function.id == 0)
|
2005-10-07 13:21:01 +00:00
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-06 13:32:53 +00:00
|
|
|
p2u = pattern->base.base.matrix;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_invert (&p2u);
|
|
|
|
|
|
2006-01-05 05:06:50 +00:00
|
|
|
x0 = _cairo_fixed_to_double (pattern->gradient.p1.x);
|
|
|
|
|
y0 = _cairo_fixed_to_double (pattern->gradient.p1.y);
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_transform_point (&p2u, &x0, &y0);
|
2006-01-05 05:06:50 +00:00
|
|
|
x1 = _cairo_fixed_to_double (pattern->gradient.p2.x);
|
|
|
|
|
y1 = _cairo_fixed_to_double (pattern->gradient.p2.y);
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_transform_point (&p2u, &x1, &y1);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pattern\r\n"
|
|
|
|
|
" /PatternType 2\r\n"
|
|
|
|
|
" /Matrix [ 1 0 0 -1 0 %f ]\r\n"
|
|
|
|
|
" /Shading\r\n"
|
|
|
|
|
" << /ShadingType 2\r\n"
|
|
|
|
|
" /ColorSpace /DeviceRGB\r\n"
|
|
|
|
|
" /Coords [ %f %f %f %f ]\r\n"
|
|
|
|
|
" /Function %d 0 R\r\n"
|
|
|
|
|
" /Extend [ true true ]\r\n"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource.id,
|
2005-05-13 09:26:20 +00:00
|
|
|
document->height,
|
2005-03-16 12:08:41 +00:00
|
|
|
x0, y0, x1, y1,
|
2006-05-12 13:31:12 -07:00
|
|
|
function.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_add_pattern (surface, pattern_resource);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
alpha = _cairo_pdf_surface_add_alpha (surface, 1.0);
|
|
|
|
|
|
|
|
|
|
/* Use pattern */
|
2006-04-18 16:53:23 -07:00
|
|
|
/* With some work, we could separate the stroking
|
|
|
|
|
* or non-stroking pattern here as actually needed. */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"/Pattern CS /res%d SCN "
|
|
|
|
|
"/Pattern cs /res%d scn "
|
|
|
|
|
"/a%d gs\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource.id,
|
|
|
|
|
pattern_resource.id,
|
|
|
|
|
alpha.id);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_resume_content_stream (surface);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2005-03-03 17:40:04 +00:00
|
|
|
emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radial_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t function, pattern_resource, alpha;
|
2005-01-05 14:29:31 +00:00
|
|
|
double x0, y0, x1, y1, r0, r1;
|
|
|
|
|
cairo_matrix_t p2u;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_pause_content_stream (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
function = emit_pattern_stops (surface, &pattern->base);
|
|
|
|
|
if (function.id == 0)
|
2005-10-07 13:21:01 +00:00
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-06 13:32:53 +00:00
|
|
|
p2u = pattern->base.base.matrix;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_invert (&p2u);
|
|
|
|
|
|
2006-01-05 05:06:50 +00:00
|
|
|
x0 = _cairo_fixed_to_double (pattern->gradient.inner.x);
|
|
|
|
|
y0 = _cairo_fixed_to_double (pattern->gradient.inner.y);
|
|
|
|
|
r0 = _cairo_fixed_to_double (pattern->gradient.inner.radius);
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_transform_point (&p2u, &x0, &y0);
|
2006-01-05 05:06:50 +00:00
|
|
|
x1 = _cairo_fixed_to_double (pattern->gradient.outer.x);
|
|
|
|
|
y1 = _cairo_fixed_to_double (pattern->gradient.outer.y);
|
|
|
|
|
r1 = _cairo_fixed_to_double (pattern->gradient.outer.radius);
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_matrix_transform_point (&p2u, &x1, &y1);
|
|
|
|
|
|
|
|
|
|
/* FIXME: This is surely crack, but how should you scale a radius
|
|
|
|
|
* in a non-orthogonal coordinate system? */
|
|
|
|
|
cairo_matrix_transform_distance (&p2u, &r0, &r1);
|
|
|
|
|
|
2005-02-01 20:47:43 +00:00
|
|
|
/* FIXME: There is a difference between the cairo gradient extend
|
|
|
|
|
* semantics and PDF extend semantics. PDFs extend=false means
|
|
|
|
|
* that nothing is painted outside the gradient boundaries,
|
|
|
|
|
* whereas cairo takes this to mean that the end color is padded
|
|
|
|
|
* to infinity. Setting extend=true in PDF gives the cairo default
|
|
|
|
|
* behavoir, not yet sure how to implement the cairo mirror and
|
|
|
|
|
* repeat behaviour. */
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pattern\r\n"
|
|
|
|
|
" /PatternType 2\r\n"
|
|
|
|
|
" /Matrix [ 1 0 0 -1 0 %f ]\r\n"
|
|
|
|
|
" /Shading\r\n"
|
|
|
|
|
" << /ShadingType 3\r\n"
|
|
|
|
|
" /ColorSpace /DeviceRGB\r\n"
|
|
|
|
|
" /Coords [ %f %f %f %f %f %f ]\r\n"
|
|
|
|
|
" /Function %d 0 R\r\n"
|
|
|
|
|
" /Extend [ true true ]\r\n"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource.id,
|
2005-05-13 09:26:20 +00:00
|
|
|
document->height,
|
2005-03-16 12:08:41 +00:00
|
|
|
x0, y0, r0, x1, y1, r1,
|
2006-05-12 13:31:12 -07:00
|
|
|
function.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_add_pattern (surface, pattern_resource);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
alpha = _cairo_pdf_surface_add_alpha (surface, 1.0);
|
|
|
|
|
|
|
|
|
|
/* Use pattern */
|
2006-04-18 16:53:23 -07:00
|
|
|
/* With some work, we could separate the stroking
|
|
|
|
|
* or non-stroking pattern here as actually needed. */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"/Pattern CS /res%d SCN "
|
|
|
|
|
"/Pattern cs /res%d scn "
|
|
|
|
|
"/a%d gs\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
pattern_resource.id,
|
|
|
|
|
pattern_resource.id,
|
|
|
|
|
alpha.id);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_resume_content_stream (surface);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
2006-04-18 16:53:23 -07:00
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2005-02-01 20:47:43 +00:00
|
|
|
emit_pattern (cairo_pdf_surface_t *surface, cairo_pattern_t *pattern)
|
|
|
|
|
{
|
|
|
|
|
switch (pattern->type) {
|
2006-02-24 15:25:19 -08:00
|
|
|
case CAIRO_PATTERN_TYPE_SOLID:
|
2005-10-07 13:21:01 +00:00
|
|
|
return emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern);
|
2005-02-01 20:47:43 +00:00
|
|
|
|
2006-02-24 15:25:19 -08:00
|
|
|
case CAIRO_PATTERN_TYPE_SURFACE:
|
2005-10-07 13:21:01 +00:00
|
|
|
return emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern);
|
2005-02-01 20:47:43 +00:00
|
|
|
|
2006-02-24 15:25:19 -08:00
|
|
|
case CAIRO_PATTERN_TYPE_LINEAR:
|
2005-10-07 13:21:01 +00:00
|
|
|
return emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern);
|
2005-02-01 20:47:43 +00:00
|
|
|
|
2006-02-24 15:25:19 -08:00
|
|
|
case CAIRO_PATTERN_TYPE_RADIAL:
|
2005-10-07 13:21:01 +00:00
|
|
|
return emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern);
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2005-02-01 20:47:43 +00:00
|
|
|
}
|
2005-10-07 13:21:01 +00:00
|
|
|
|
|
|
|
|
ASSERT_NOT_REACHED;
|
2005-10-12 13:33:38 +00:00
|
|
|
return CAIRO_STATUS_PATTERN_TYPE_MISMATCH;
|
2005-02-01 20:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-03 14:28:50 +00:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_path_move_to (void *closure, cairo_point_t *point)
|
|
|
|
|
{
|
2006-02-23 22:01:07 -08:00
|
|
|
cairo_output_stream_t *output_stream = closure;
|
2005-05-03 14:28:50 +00:00
|
|
|
|
2006-02-23 22:01:07 -08:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
2005-05-03 14:28:50 +00:00
|
|
|
"%f %f m ",
|
|
|
|
|
_cairo_fixed_to_double (point->x),
|
|
|
|
|
_cairo_fixed_to_double (point->y));
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_path_line_to (void *closure, cairo_point_t *point)
|
|
|
|
|
{
|
2006-02-23 22:01:07 -08:00
|
|
|
cairo_output_stream_t *output_stream = closure;
|
2005-05-03 14:28:50 +00:00
|
|
|
|
2006-02-23 22:01:07 -08:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
"%f %f l ",
|
2005-05-03 14:28:50 +00:00
|
|
|
_cairo_fixed_to_double (point->x),
|
2006-02-23 22:01:07 -08:00
|
|
|
_cairo_fixed_to_double (point->y));
|
2005-05-03 14:28:50 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_path_curve_to (void *closure,
|
|
|
|
|
cairo_point_t *b,
|
|
|
|
|
cairo_point_t *c,
|
|
|
|
|
cairo_point_t *d)
|
|
|
|
|
{
|
2006-02-23 22:01:07 -08:00
|
|
|
cairo_output_stream_t *output_stream = closure;
|
2005-05-03 14:28:50 +00:00
|
|
|
|
2006-02-23 22:01:07 -08:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
2005-05-03 14:28:50 +00:00
|
|
|
"%f %f %f %f %f %f c ",
|
|
|
|
|
_cairo_fixed_to_double (b->x),
|
|
|
|
|
_cairo_fixed_to_double (b->y),
|
|
|
|
|
_cairo_fixed_to_double (c->x),
|
|
|
|
|
_cairo_fixed_to_double (c->y),
|
|
|
|
|
_cairo_fixed_to_double (d->x),
|
|
|
|
|
_cairo_fixed_to_double (d->y));
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_path_close_path (void *closure)
|
|
|
|
|
{
|
2006-02-23 22:01:07 -08:00
|
|
|
cairo_output_stream_t *output_stream = closure;
|
2005-05-03 14:28:50 +00:00
|
|
|
|
2006-02-23 22:01:07 -08:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
2005-05-03 14:28:50 +00:00
|
|
|
"h\r\n");
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_copy_page (void *abstract_surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
|
|
|
|
|
return _cairo_pdf_document_add_page (document, surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_show_page (void *abstract_surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
cairo_int_status_t status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_document_add_page (document, surface);
|
2005-06-10 12:46:49 +00:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-06-10 12:46:49 +00:00
|
|
|
_cairo_pdf_surface_clear (surface);
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-19 16:29:04 +00:00
|
|
|
static cairo_int_status_t
|
2006-05-04 03:43:34 -07:00
|
|
|
_cairo_pdf_surface_get_extents (void *abstract_surface,
|
|
|
|
|
cairo_rectangle_fixed_t *rectangle)
|
2005-04-19 16:29:04 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
|
|
|
|
|
rectangle->x = 0;
|
|
|
|
|
rectangle->y = 0;
|
|
|
|
|
|
|
|
|
|
/* XXX: The conversion to integers here is pretty bogus, (not to
|
|
|
|
|
* mention the aribitray limitation of width to a short(!). We
|
|
|
|
|
* may need to come up with a better interface for get_size.
|
|
|
|
|
*/
|
2005-05-13 09:26:20 +00:00
|
|
|
rectangle->width = (int) ceil (surface->width);
|
|
|
|
|
rectangle->height = (int) ceil (surface->height);
|
2005-04-19 16:29:04 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-25 04:04:10 -07:00
|
|
|
typedef struct _pdf_stroke {
|
|
|
|
|
cairo_output_stream_t *output_stream;
|
|
|
|
|
cairo_matrix_t *ctm_inverse;
|
|
|
|
|
} pdf_stroke_t;
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_stroke_move_to (void *closure, cairo_point_t *point)
|
|
|
|
|
{
|
|
|
|
|
pdf_stroke_t *stroke = closure;
|
|
|
|
|
double x = _cairo_fixed_to_double (point->x);
|
|
|
|
|
double y = _cairo_fixed_to_double (point->y);
|
|
|
|
|
|
|
|
|
|
cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stroke->output_stream,
|
|
|
|
|
"%f %f m ", x, y);
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_stroke_line_to (void *closure, cairo_point_t *point)
|
|
|
|
|
{
|
|
|
|
|
pdf_stroke_t *stroke = closure;
|
|
|
|
|
double x = _cairo_fixed_to_double (point->x);
|
|
|
|
|
double y = _cairo_fixed_to_double (point->y);
|
|
|
|
|
|
|
|
|
|
cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stroke->output_stream,
|
|
|
|
|
"%f %f l ", x, y);
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_stroke_curve_to (void *closure,
|
|
|
|
|
cairo_point_t *b,
|
|
|
|
|
cairo_point_t *c,
|
|
|
|
|
cairo_point_t *d)
|
|
|
|
|
{
|
|
|
|
|
pdf_stroke_t *stroke = closure;
|
|
|
|
|
double bx = _cairo_fixed_to_double (b->x);
|
|
|
|
|
double by = _cairo_fixed_to_double (b->y);
|
|
|
|
|
double cx = _cairo_fixed_to_double (c->x);
|
|
|
|
|
double cy = _cairo_fixed_to_double (c->y);
|
|
|
|
|
double dx = _cairo_fixed_to_double (d->x);
|
|
|
|
|
double dy = _cairo_fixed_to_double (d->y);
|
|
|
|
|
|
|
|
|
|
cairo_matrix_transform_point (stroke->ctm_inverse, &bx, &by);
|
|
|
|
|
cairo_matrix_transform_point (stroke->ctm_inverse, &cx, &cy);
|
|
|
|
|
cairo_matrix_transform_point (stroke->ctm_inverse, &dx, &dy);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stroke->output_stream,
|
|
|
|
|
"%f %f %f %f %f %f c ",
|
|
|
|
|
bx, by, cx, cy, dx, dy);
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_stroke_close_path (void *closure)
|
|
|
|
|
{
|
|
|
|
|
pdf_stroke_t *stroke = closure;
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stroke->output_stream,
|
|
|
|
|
"h\r\n");
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-14 19:45:22 +00:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_intersect_clip_path (void *dst,
|
|
|
|
|
cairo_path_fixed_t *path,
|
|
|
|
|
cairo_fill_rule_t fill_rule,
|
2005-08-08 18:35:22 +00:00
|
|
|
double tolerance,
|
|
|
|
|
cairo_antialias_t antialias)
|
2005-06-14 19:45:22 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = dst;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
const char *pdf_operator;
|
|
|
|
|
|
|
|
|
|
if (path == NULL) {
|
|
|
|
|
if (surface->has_clip)
|
|
|
|
|
_cairo_output_stream_printf (output, "Q\r\n");
|
|
|
|
|
surface->has_clip = FALSE;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!surface->has_clip) {
|
|
|
|
|
_cairo_output_stream_printf (output, "q ");
|
|
|
|
|
surface->has_clip = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = _cairo_path_fixed_interpret (path,
|
|
|
|
|
CAIRO_DIRECTION_FORWARD,
|
|
|
|
|
_cairo_pdf_path_move_to,
|
|
|
|
|
_cairo_pdf_path_line_to,
|
|
|
|
|
_cairo_pdf_path_curve_to,
|
|
|
|
|
_cairo_pdf_path_close_path,
|
2006-02-23 22:01:07 -08:00
|
|
|
document->output_stream);
|
2005-06-14 19:45:22 +00:00
|
|
|
|
|
|
|
|
switch (fill_rule) {
|
|
|
|
|
case CAIRO_FILL_RULE_WINDING:
|
|
|
|
|
pdf_operator = "W";
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_FILL_RULE_EVEN_ODD:
|
|
|
|
|
pdf_operator = "W*";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (document->output_stream,
|
|
|
|
|
"%s n\r\n",
|
|
|
|
|
pdf_operator);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-21 06:52:13 +00:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_get_font_options (void *abstract_surface,
|
|
|
|
|
cairo_font_options_t *options)
|
|
|
|
|
{
|
2006-04-25 05:44:08 -07:00
|
|
|
_cairo_font_options_init_default (options);
|
2005-07-21 06:52:13 +00:00
|
|
|
|
2006-04-25 05:44:08 -07:00
|
|
|
cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
|
|
|
|
|
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
|
2005-07-21 06:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
static cairo_pdf_document_t *
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_pdf_document_create (cairo_output_stream_t *output_stream,
|
2005-05-13 09:26:20 +00:00
|
|
|
double width,
|
|
|
|
|
double height)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_document_t *document;
|
|
|
|
|
|
|
|
|
|
document = malloc (sizeof (cairo_pdf_document_t));
|
|
|
|
|
if (document == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
document->output_stream = output_stream;
|
2005-07-25 16:23:05 +00:00
|
|
|
document->ref_count = 1;
|
2005-03-16 12:08:41 +00:00
|
|
|
document->owner = NULL;
|
|
|
|
|
document->finished = FALSE;
|
2005-05-13 09:26:20 +00:00
|
|
|
document->width = width;
|
|
|
|
|
document->height = height;
|
2005-05-16 11:41:42 +00:00
|
|
|
document->x_dpi = DEFAULT_DPI;
|
|
|
|
|
document->y_dpi = DEFAULT_DPI;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
_cairo_array_init (&document->objects, sizeof (cairo_pdf_object_t));
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_array_init (&document->pages, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
document->next_available_resource.id = 1;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
document->current_stream.active = FALSE;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
document->pages_resource = _cairo_pdf_document_new_object (document);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-06-21 15:38:51 +00:00
|
|
|
_cairo_array_init (&document->fonts, sizeof (cairo_font_subset_t *));
|
2005-01-17 09:40:00 +00:00
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
/* Document header */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output_stream,
|
|
|
|
|
"%%PDF-1.4\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
return document;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_write_info (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t info;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
info = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Creator (cairographics.org)\r\n"
|
|
|
|
|
" /Producer (cairographics.org)\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
info.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return info;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_write_pages (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *stream = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t page;
|
2005-01-05 14:29:31 +00:00
|
|
|
int num_pages, i;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_document_update_object (document, document->pages_resource);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pages\r\n"
|
|
|
|
|
" /Kids [ ",
|
2006-05-12 13:31:12 -07:00
|
|
|
document->pages_resource.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
num_pages = _cairo_array_num_elements (&document->pages);
|
|
|
|
|
for (i = 0; i < num_pages; i++) {
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_array_copy_element (&document->pages, i, &page);
|
|
|
|
|
_cairo_output_stream_printf (stream, "%d 0 R ", page.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (stream, "]\r\n");
|
|
|
|
|
_cairo_output_stream_printf (stream, " /Count %d\r\n", num_pages);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
/* TODO: Figure out wich other defaults to be inherited by /Page
|
|
|
|
|
* objects. */
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
" /MediaBox [ 0 0 %f %f ]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2005-05-13 09:26:20 +00:00
|
|
|
document->width,
|
|
|
|
|
document->height);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_document_write_fonts (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2005-06-21 15:38:51 +00:00
|
|
|
cairo_font_subset_t *font;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t font_resource;
|
2005-01-17 09:40:00 +00:00
|
|
|
int num_fonts, i, j;
|
|
|
|
|
const char *data;
|
|
|
|
|
char *compressed;
|
|
|
|
|
unsigned long data_size, compressed_size;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream, descriptor;
|
2005-01-17 09:40:00 +00:00
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
num_fonts = _cairo_array_num_elements (&document->fonts);
|
|
|
|
|
for (i = 0; i < num_fonts; i++) {
|
|
|
|
|
_cairo_array_copy_element (&document->fonts, i, &font);
|
|
|
|
|
|
2005-06-21 15:38:51 +00:00
|
|
|
status = _cairo_font_subset_generate (font, &data, &data_size);
|
2005-01-17 09:40:00 +00:00
|
|
|
if (status)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
compressed = compress_dup (data, data_size, &compressed_size);
|
|
|
|
|
if (compressed == NULL) {
|
|
|
|
|
status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
stream = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Filter /FlateDecode\r\n"
|
|
|
|
|
" /Length %lu\r\n"
|
|
|
|
|
" /Length1 %lu\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
stream.id,
|
2005-03-16 12:08:41 +00:00
|
|
|
compressed_size,
|
|
|
|
|
data_size);
|
|
|
|
|
_cairo_output_stream_write (output, compressed, compressed_size);
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"\r\n"
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-17 09:40:00 +00:00
|
|
|
free (compressed);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
descriptor = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /FontDescriptor\r\n"
|
|
|
|
|
" /FontName /7%s\r\n"
|
|
|
|
|
" /Flags 4\r\n"
|
|
|
|
|
" /FontBBox [ %ld %ld %ld %ld ]\r\n"
|
|
|
|
|
" /ItalicAngle 0\r\n"
|
|
|
|
|
" /Ascent %ld\r\n"
|
|
|
|
|
" /Descent %ld\r\n"
|
|
|
|
|
" /CapHeight 500\r\n"
|
|
|
|
|
" /StemV 80\r\n"
|
|
|
|
|
" /StemH 80\r\n"
|
|
|
|
|
" /FontFile2 %u 0 R\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
descriptor.id,
|
2005-03-16 12:08:41 +00:00
|
|
|
font->base_font,
|
|
|
|
|
font->x_min,
|
|
|
|
|
font->y_min,
|
|
|
|
|
font->x_max,
|
|
|
|
|
font->y_max,
|
|
|
|
|
font->ascent,
|
|
|
|
|
font->descent,
|
2006-05-12 13:31:12 -07:00
|
|
|
stream.id);
|
2005-01-17 09:40:00 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
font_resource.id = font->font_id;
|
|
|
|
|
_cairo_pdf_document_update_object (document, font_resource);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /TrueType\r\n"
|
|
|
|
|
" /BaseFont /%s\r\n"
|
|
|
|
|
" /FirstChar 0\r\n"
|
|
|
|
|
" /LastChar %d\r\n"
|
|
|
|
|
" /FontDescriptor %d 0 R\r\n"
|
|
|
|
|
" /Widths ",
|
|
|
|
|
font->font_id,
|
|
|
|
|
font->base_font,
|
|
|
|
|
font->num_glyphs,
|
2006-05-12 13:31:12 -07:00
|
|
|
descriptor.id);
|
2005-03-16 12:08:41 +00:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"[");
|
2005-01-17 09:40:00 +00:00
|
|
|
|
|
|
|
|
for (j = 0; j < font->num_glyphs; j++)
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" %d",
|
|
|
|
|
font->widths[j]);
|
2005-01-17 09:40:00 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" ]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-17 09:40:00 +00:00
|
|
|
|
|
|
|
|
fail:
|
2005-06-21 15:38:51 +00:00
|
|
|
_cairo_font_subset_destroy (font);
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_write_catalog (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t catalog;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
catalog = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Catalog\r\n"
|
|
|
|
|
" /Pages %d 0 R\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
catalog.id,
|
|
|
|
|
document->pages_resource.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
return catalog;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long
|
|
|
|
|
_cairo_pdf_document_write_xref (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_pdf_object_t *object;
|
|
|
|
|
int num_objects, i;
|
|
|
|
|
long offset;
|
2005-05-13 14:04:22 +00:00
|
|
|
char buffer[11];
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
num_objects = _cairo_array_num_elements (&document->objects);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
offset = _cairo_output_stream_get_position (output);
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"xref\r\n"
|
|
|
|
|
"%d %d\r\n",
|
|
|
|
|
0, num_objects + 1);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"0000000000 65535 f\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
for (i = 0; i < num_objects; i++) {
|
|
|
|
|
object = _cairo_array_index (&document->objects, i);
|
2005-05-13 14:04:22 +00:00
|
|
|
snprintf (buffer, sizeof buffer, "%010ld", object->offset);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2005-05-13 14:04:22 +00:00
|
|
|
"%s 00000 n\r\n", buffer);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-04 18:44:29 +00:00
|
|
|
static cairo_pdf_document_t *
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_reference (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-07-25 16:23:05 +00:00
|
|
|
document->ref_count++;
|
2005-08-04 18:44:29 +00:00
|
|
|
|
|
|
|
|
return document;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_document_destroy (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-07-25 16:23:05 +00:00
|
|
|
document->ref_count--;
|
|
|
|
|
if (document->ref_count > 0)
|
2005-01-05 14:29:31 +00:00
|
|
|
return;
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_pdf_document_finish (document);
|
|
|
|
|
|
|
|
|
|
free (document);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_document_finish (cairo_pdf_document_t *document)
|
|
|
|
|
{
|
2005-05-17 12:40:55 +00:00
|
|
|
cairo_status_t status;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
|
|
|
|
long offset;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t info, catalog;
|
2005-03-16 12:08:41 +00:00
|
|
|
|
|
|
|
|
if (document->finished)
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_close_stream (document);
|
|
|
|
|
_cairo_pdf_document_write_pages (document);
|
2005-01-17 09:40:00 +00:00
|
|
|
_cairo_pdf_document_write_fonts (document);
|
2006-05-12 13:31:12 -07:00
|
|
|
info = _cairo_pdf_document_write_info (document);
|
|
|
|
|
catalog = _cairo_pdf_document_write_catalog (document);
|
2005-01-05 14:29:31 +00:00
|
|
|
offset = _cairo_pdf_document_write_xref (document);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"trailer\r\n"
|
|
|
|
|
"<< /Size %d\r\n"
|
|
|
|
|
" /Root %d 0 R\r\n"
|
|
|
|
|
" /Info %d 0 R\r\n"
|
|
|
|
|
">>\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
document->next_available_resource.id,
|
|
|
|
|
catalog.id,
|
|
|
|
|
info.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"startxref\r\n"
|
|
|
|
|
"%ld\r\n"
|
|
|
|
|
"%%%%EOF\r\n",
|
|
|
|
|
offset);
|
|
|
|
|
|
2005-05-17 12:40:55 +00:00
|
|
|
status = _cairo_output_stream_get_status (output);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_destroy (output);
|
2005-05-17 12:40:55 +00:00
|
|
|
|
2005-07-14 17:52:17 +00:00
|
|
|
_cairo_array_fini (&document->objects);
|
|
|
|
|
_cairo_array_fini (&document->pages);
|
|
|
|
|
_cairo_array_fini (&document->fonts);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
document->finished = TRUE;
|
|
|
|
|
|
2005-05-17 12:40:55 +00:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_document_add_page (cairo_pdf_document_t *document,
|
|
|
|
|
cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
2005-11-04 16:13:30 +00:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_pdf_resource_t *res;
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_output_stream_t *output = document->output_stream;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t page;
|
2005-01-05 14:29:31 +00:00
|
|
|
double alpha;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
int num_streams, num_alphas, num_resources, i;
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
assert (!document->finished);
|
|
|
|
|
|
2006-04-21 02:46:20 -07:00
|
|
|
if (surface->has_clip) {
|
2005-06-14 19:45:22 +00:00
|
|
|
_cairo_output_stream_printf (output, "Q\r\n");
|
2006-04-21 02:46:20 -07:00
|
|
|
surface->has_clip = FALSE;
|
|
|
|
|
}
|
2005-06-14 19:45:22 +00:00
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_pdf_document_close_stream (document);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
page = _cairo_pdf_document_new_object (document);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Page\r\n"
|
2006-05-03 12:39:23 -07:00
|
|
|
" /Parent %d 0 R\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
page.id,
|
|
|
|
|
document->pages_resource.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-03 12:39:23 -07:00
|
|
|
if (surface->width != document->width ||
|
|
|
|
|
surface->height != document->height)
|
|
|
|
|
{
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /MediaBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /Contents [");
|
2005-01-05 14:29:31 +00:00
|
|
|
num_streams = _cairo_array_num_elements (&surface->streams);
|
|
|
|
|
for (i = 0; i < num_streams; i++) {
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_array_copy_element (&surface->streams, i, &stream);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" %d 0 R",
|
2006-05-12 13:31:12 -07:00
|
|
|
stream.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
2006-05-03 12:39:23 -07:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" ]\r\n");
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /Resources <<\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
num_resources = _cairo_array_num_elements (&surface->fonts);
|
|
|
|
|
if (num_resources > 0) {
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /Font <<");
|
2005-01-17 09:40:00 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < num_resources; i++) {
|
|
|
|
|
res = _cairo_array_index (&surface->fonts, i);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /res%d %d 0 R",
|
|
|
|
|
res->id, res->id);
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" >>\r\n");
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
num_alphas = _cairo_array_num_elements (&surface->alphas);
|
|
|
|
|
if (num_alphas > 0) {
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /ExtGState <<\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < num_alphas; i++) {
|
2006-04-18 16:53:23 -07:00
|
|
|
/* With some work, we could separate the stroking
|
|
|
|
|
* or non-stroking alpha here as actually needed. */
|
2005-01-05 14:29:31 +00:00
|
|
|
_cairo_array_copy_element (&surface->alphas, i, &alpha);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
2006-04-18 16:53:23 -07:00
|
|
|
" /a%d << /CA %f /ca %f >>\r\n",
|
|
|
|
|
i, alpha, alpha);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" >>\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_resources = _cairo_array_num_elements (&surface->patterns);
|
|
|
|
|
if (num_resources > 0) {
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /Pattern <<");
|
2005-01-05 14:29:31 +00:00
|
|
|
for (i = 0; i < num_resources; i++) {
|
|
|
|
|
res = _cairo_array_index (&surface->patterns, i);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /res%d %d 0 R",
|
|
|
|
|
res->id, res->id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" >>\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_resources = _cairo_array_num_elements (&surface->xobjects);
|
|
|
|
|
if (num_resources > 0) {
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /XObject <<");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < num_resources; i++) {
|
|
|
|
|
res = _cairo_array_index (&surface->xobjects, i);
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" /res%d %d 0 R",
|
|
|
|
|
res->id, res->id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" >>\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
_cairo_output_stream_printf (output,
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
status = _cairo_array_append (&document->pages, &page);
|
2005-11-04 16:13:30 +00:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
2006-03-24 11:48:35 -08:00
|
|
|
|
2006-04-18 11:31:59 -07:00
|
|
|
static cairo_bool_t
|
2006-04-25 03:45:37 -07:00
|
|
|
_surface_pattern_supported (cairo_surface_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_extend_t extend;
|
|
|
|
|
|
|
|
|
|
if (pattern->surface->backend->acquire_source_image == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Does an ALPHA-only source surface even make sense? Maybe, but I
|
|
|
|
|
* don't think it's worth the extra code to support it. */
|
|
|
|
|
|
|
|
|
|
/* XXX: Need to write this function here...
|
|
|
|
|
content = cairo_surface_get_content (pattern->surface);
|
|
|
|
|
if (content == CAIRO_CONTENT_ALPHA)
|
|
|
|
|
return FALSE;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
extend = cairo_pattern_get_extend (&pattern->base);
|
|
|
|
|
switch (extend) {
|
|
|
|
|
case CAIRO_EXTEND_NONE:
|
|
|
|
|
case CAIRO_EXTEND_REPEAT:
|
2006-04-18 11:31:59 -07:00
|
|
|
return TRUE;
|
2006-04-25 03:45:37 -07:00
|
|
|
case CAIRO_EXTEND_REFLECT:
|
|
|
|
|
case CAIRO_EXTEND_PAD:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2006-04-18 11:31:59 -07:00
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
ASSERT_NOT_REACHED;
|
2006-04-18 11:31:59 -07:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_bool_t
|
2006-04-25 03:45:37 -07:00
|
|
|
_pattern_supported (cairo_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
|
|
|
|
if (pattern->type == CAIRO_PATTERN_TYPE_SOLID)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE)
|
2006-04-25 03:45:37 -07:00
|
|
|
return _surface_pattern_supported ((cairo_surface_pattern_t *) pattern);
|
2006-04-18 11:31:59 -07:00
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_operation_supported (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_operator_t op,
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
|
|
|
|
if (! _pattern_supported (pattern))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
/* XXX: We can probably support a fair amount more than just OVER,
|
|
|
|
|
* but this should cover many common cases at least. */
|
|
|
|
|
if (op == CAIRO_OPERATOR_OVER)
|
2006-04-18 11:31:59 -07:00
|
|
|
return TRUE;
|
|
|
|
|
|
2006-04-25 03:45:37 -07:00
|
|
|
return FALSE;
|
2006-04-18 11:31:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_analyze_operation (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_operator_t op,
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
|
|
|
|
if (_operation_supported (surface, op, pattern))
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
else
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_paint (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
|
|
|
|
cairo_pattern_t *source)
|
|
|
|
|
{
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2006-04-18 23:24:14 -07:00
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
cairo_status_t status;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
|
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2006-04-18 23:24:14 -07:00
|
|
|
return _analyze_operation (surface, op, source);
|
|
|
|
|
|
|
|
|
|
/* XXX: It would be nice to be able to assert this condition
|
|
|
|
|
* here. But, we actually allow one 'cheat' that is used when
|
|
|
|
|
* painting the final image-based fallbacks. The final fallbacks
|
|
|
|
|
* do have alpha which we support by blending with white. This is
|
|
|
|
|
* possible only because there is nothing between the fallback
|
|
|
|
|
* images and the paper, nor is anything painted above. */
|
|
|
|
|
/*
|
|
|
|
|
assert (_operation_supported (op, source));
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
status = emit_pattern (surface, source);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (document->output_stream,
|
|
|
|
|
"0 0 %f %f re f\r\n",
|
|
|
|
|
surface->width, surface->height);
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-18 23:24:14 -07:00
|
|
|
return _cairo_output_stream_get_status (document->output_stream);
|
2006-04-14 15:23:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_mask (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
|
|
|
|
cairo_pattern_t *source,
|
|
|
|
|
cairo_pattern_t *mask)
|
|
|
|
|
{
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
|
|
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_REACHED;
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
static int
|
|
|
|
|
_cairo_pdf_line_cap (cairo_line_cap_t cap)
|
|
|
|
|
{
|
|
|
|
|
switch (cap) {
|
|
|
|
|
case CAIRO_LINE_CAP_BUTT:
|
|
|
|
|
return 0;
|
|
|
|
|
case CAIRO_LINE_CAP_ROUND:
|
|
|
|
|
return 1;
|
|
|
|
|
case CAIRO_LINE_CAP_SQUARE:
|
|
|
|
|
return 2;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_cairo_pdf_line_join (cairo_line_join_t join)
|
|
|
|
|
{
|
|
|
|
|
switch (join) {
|
|
|
|
|
case CAIRO_LINE_JOIN_MITER:
|
|
|
|
|
return 0;
|
|
|
|
|
case CAIRO_LINE_JOIN_ROUND:
|
|
|
|
|
return 1;
|
|
|
|
|
case CAIRO_LINE_JOIN_BEVEL:
|
|
|
|
|
return 2;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_stroke_style (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_output_stream_t *stream,
|
|
|
|
|
cairo_stroke_style_t *style)
|
|
|
|
|
{
|
|
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
"%f w\r\n",
|
|
|
|
|
style->line_width);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
"%d J\r\n",
|
|
|
|
|
_cairo_pdf_line_cap (style->line_cap));
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
"%d j\r\n",
|
|
|
|
|
_cairo_pdf_line_join (style->line_join));
|
|
|
|
|
|
|
|
|
|
if (style->num_dashes) {
|
|
|
|
|
int d;
|
|
|
|
|
_cairo_output_stream_printf (stream, "[");
|
|
|
|
|
for (d = 0; d < style->num_dashes; d++)
|
|
|
|
|
_cairo_output_stream_printf (stream, " %f", style->dash[d]);
|
|
|
|
|
_cairo_output_stream_printf (stream, "] %f d\r\n",
|
|
|
|
|
style->dash_offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (stream,
|
|
|
|
|
"%f M ",
|
|
|
|
|
style->miter_limit);
|
|
|
|
|
|
|
|
|
|
return _cairo_output_stream_get_status (stream);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_stroke (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
|
|
|
|
cairo_pattern_t *source,
|
|
|
|
|
cairo_path_fixed_t *path,
|
|
|
|
|
cairo_stroke_style_t *style,
|
|
|
|
|
cairo_matrix_t *ctm,
|
|
|
|
|
cairo_matrix_t *ctm_inverse,
|
|
|
|
|
double tolerance,
|
|
|
|
|
cairo_antialias_t antialias)
|
|
|
|
|
{
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2006-04-18 16:53:23 -07:00
|
|
|
cairo_pdf_document_t *document = surface->document;
|
2006-04-25 04:04:10 -07:00
|
|
|
pdf_stroke_t stroke;
|
2006-04-18 16:53:23 -07:00
|
|
|
cairo_status_t status;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-18 23:31:16 -07:00
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
|
|
|
|
|
/* XXX: Does PDF provide a way we can preserve this hint? For now,
|
|
|
|
|
* this will trigger a fallback. */
|
|
|
|
|
if (antialias == CAIRO_ANTIALIAS_NONE)
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
return _analyze_operation (surface, op, source);
|
2006-04-18 23:31:16 -07:00
|
|
|
}
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
assert (_operation_supported (surface, op, source));
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
status = emit_pattern (surface, source);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2006-04-25 04:04:10 -07:00
|
|
|
stroke.output_stream = document->output_stream;
|
|
|
|
|
stroke.ctm_inverse = ctm_inverse;
|
|
|
|
|
status = _cairo_path_fixed_interpret (path,
|
|
|
|
|
CAIRO_DIRECTION_FORWARD,
|
|
|
|
|
_cairo_pdf_stroke_move_to,
|
|
|
|
|
_cairo_pdf_stroke_line_to,
|
|
|
|
|
_cairo_pdf_stroke_curve_to,
|
|
|
|
|
_cairo_pdf_stroke_close_path,
|
|
|
|
|
&stroke);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (document->output_stream,
|
|
|
|
|
"q %f %f %f %f %f %f cm\r\n",
|
|
|
|
|
ctm->xx, ctm->yx, ctm->xy, ctm->yy,
|
|
|
|
|
ctm->x0, ctm->y0);
|
|
|
|
|
|
2006-04-18 16:53:23 -07:00
|
|
|
status = _cairo_pdf_surface_emit_stroke_style (surface,
|
|
|
|
|
document->output_stream,
|
|
|
|
|
style);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2006-04-25 04:04:10 -07:00
|
|
|
_cairo_output_stream_printf (document->output_stream, "S Q\r\n");
|
2006-04-18 16:53:23 -07:00
|
|
|
|
|
|
|
|
return status;
|
2006-04-14 15:23:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_fill (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pattern_t *source,
|
2006-04-14 15:23:30 -07:00
|
|
|
cairo_path_fixed_t *path,
|
|
|
|
|
cairo_fill_rule_t fill_rule,
|
|
|
|
|
double tolerance,
|
|
|
|
|
cairo_antialias_t antialias)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_document_t *document = surface->document;
|
|
|
|
|
const char *pdf_operator;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
2006-04-18 23:31:16 -07:00
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
|
|
|
|
|
/* XXX: Does PDF provide a way we can preserve this hint? For now,
|
|
|
|
|
* this will trigger a fallback. */
|
|
|
|
|
if (antialias == CAIRO_ANTIALIAS_NONE)
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
2006-04-18 11:31:59 -07:00
|
|
|
return _analyze_operation (surface, op, source);
|
2006-04-18 23:31:16 -07:00
|
|
|
}
|
2006-04-18 11:31:59 -07:00
|
|
|
|
|
|
|
|
assert (_operation_supported (surface, op, source));
|
2006-04-14 15:23:30 -07:00
|
|
|
|
2006-04-14 16:50:16 -07:00
|
|
|
status = emit_pattern (surface, source);
|
2006-04-14 15:23:30 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_path_fixed_interpret (path,
|
|
|
|
|
CAIRO_DIRECTION_FORWARD,
|
|
|
|
|
_cairo_pdf_path_move_to,
|
|
|
|
|
_cairo_pdf_path_line_to,
|
|
|
|
|
_cairo_pdf_path_curve_to,
|
|
|
|
|
_cairo_pdf_path_close_path,
|
2006-04-18 15:18:31 -07:00
|
|
|
document->output_stream);
|
2006-04-14 15:23:30 -07:00
|
|
|
|
|
|
|
|
switch (fill_rule) {
|
|
|
|
|
case CAIRO_FILL_RULE_WINDING:
|
|
|
|
|
pdf_operator = "f";
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_FILL_RULE_EVEN_ODD:
|
|
|
|
|
pdf_operator = "f*";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (document->output_stream,
|
|
|
|
|
"%s\r\n",
|
|
|
|
|
pdf_operator);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_show_glyphs (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
|
|
|
|
cairo_pattern_t *source,
|
|
|
|
|
const cairo_glyph_t *glyphs,
|
|
|
|
|
int num_glyphs,
|
|
|
|
|
cairo_scaled_font_t *scaled_font)
|
|
|
|
|
{
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2006-04-19 11:04:37 -07:00
|
|
|
cairo_path_fixed_t path;
|
|
|
|
|
cairo_status_t status;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
|
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2006-04-19 11:04:37 -07:00
|
|
|
return _analyze_operation (surface, op, source);
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-19 11:04:37 -07:00
|
|
|
assert (_operation_supported (surface, op, source));
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-04-19 11:04:37 -07:00
|
|
|
status = emit_pattern (surface, source);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
_cairo_path_fixed_init (&path);
|
|
|
|
|
_cairo_scaled_font_glyph_path (scaled_font, glyphs, num_glyphs, &path);
|
|
|
|
|
status = _cairo_pdf_surface_fill (surface, op, source,
|
|
|
|
|
&path, CAIRO_FILL_RULE_WINDING,
|
|
|
|
|
0.1, scaled_font->options.antialias);
|
|
|
|
|
_cairo_path_fixed_fini (&path);
|
|
|
|
|
|
|
|
|
|
return status;
|
2006-04-14 15:23:30 -07:00
|
|
|
}
|
|
|
|
|
|
2006-03-24 11:48:35 -08:00
|
|
|
static void
|
2006-04-14 11:33:48 -07:00
|
|
|
_cairo_pdf_surface_set_paginated_mode (void *abstract_surface,
|
|
|
|
|
cairo_paginated_mode_t paginated_mode)
|
2006-03-24 11:48:35 -08:00
|
|
|
{
|
2006-04-14 11:33:48 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2006-03-24 11:48:35 -08:00
|
|
|
|
|
|
|
|
surface->paginated_mode = paginated_mode;
|
|
|
|
|
}
|
2006-04-13 12:56:58 -07:00
|
|
|
|
|
|
|
|
static const cairo_surface_backend_t cairo_pdf_surface_backend = {
|
|
|
|
|
CAIRO_SURFACE_TYPE_PDF,
|
|
|
|
|
_cairo_pdf_surface_create_similar,
|
|
|
|
|
_cairo_pdf_surface_finish,
|
|
|
|
|
NULL, /* acquire_source_image */
|
|
|
|
|
NULL, /* release_source_image */
|
|
|
|
|
NULL, /* acquire_dest_image */
|
|
|
|
|
NULL, /* release_dest_image */
|
|
|
|
|
NULL, /* clone_similar */
|
2006-04-25 02:33:18 -07:00
|
|
|
NULL, /* composite */
|
|
|
|
|
NULL, /* fill_rectangles */
|
|
|
|
|
NULL, /* composite_trapezoids */
|
2006-04-13 12:56:58 -07:00
|
|
|
_cairo_pdf_surface_copy_page,
|
|
|
|
|
_cairo_pdf_surface_show_page,
|
|
|
|
|
NULL, /* set_clip_region */
|
|
|
|
|
_cairo_pdf_surface_intersect_clip_path,
|
|
|
|
|
_cairo_pdf_surface_get_extents,
|
2006-04-25 02:33:18 -07:00
|
|
|
NULL, /* old_show_glyphs */
|
2006-04-13 12:56:58 -07:00
|
|
|
_cairo_pdf_surface_get_font_options,
|
|
|
|
|
NULL, /* flush */
|
|
|
|
|
NULL, /* mark_dirty_rectangle */
|
|
|
|
|
NULL, /* scaled_font_fini */
|
|
|
|
|
NULL, /* scaled_glyph_fini */
|
|
|
|
|
|
|
|
|
|
/* Here are the drawing functions */
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
_cairo_pdf_surface_paint,
|
|
|
|
|
_cairo_pdf_surface_mask,
|
|
|
|
|
_cairo_pdf_surface_stroke,
|
2006-04-13 12:56:58 -07:00
|
|
|
_cairo_pdf_surface_fill,
|
2006-04-14 15:23:30 -07:00
|
|
|
_cairo_pdf_surface_show_glyphs,
|
|
|
|
|
NULL, /* snapshot */
|
2006-04-13 12:56:58 -07:00
|
|
|
};
|
2006-04-14 11:33:48 -07:00
|
|
|
|
|
|
|
|
static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend = {
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_start_page,
|
2006-04-14 11:33:48 -07:00
|
|
|
_cairo_pdf_surface_set_paginated_mode
|
|
|
|
|
};
|