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"
|
2007-04-20 02:37:15 -04:00
|
|
|
#include "cairo-pdf-surface-private.h"
|
2006-05-15 10:04:53 -07:00
|
|
|
#include "cairo-scaled-font-subsets-private.h"
|
2007-04-21 02:25:51 -04:00
|
|
|
#include "cairo-paginated-private.h"
|
2006-04-19 11:04:37 -07:00
|
|
|
#include "cairo-path-fixed-private.h"
|
2006-06-12 03:07:19 -04:00
|
|
|
#include "cairo-output-stream-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.
|
|
|
|
|
*
|
|
|
|
|
* - 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() ?
|
|
|
|
|
*
|
2007-01-07 02:08:15 -05:00
|
|
|
* - What if you create a similar surface and does show_page and then
|
2005-01-05 14:29:31 +00:00
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-05-15 09:52:57 -07:00
|
|
|
typedef struct _cairo_pdf_object {
|
2005-01-05 14:29:31 +00:00
|
|
|
long offset;
|
2006-05-15 09:52:57 -07:00
|
|
|
} cairo_pdf_object_t;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
typedef struct _cairo_pdf_font {
|
|
|
|
|
unsigned int font_id;
|
|
|
|
|
unsigned int subset_id;
|
|
|
|
|
cairo_pdf_resource_t subset_resource;
|
|
|
|
|
} cairo_pdf_font_t;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
typedef struct _cairo_pdf_rgb_linear_function {
|
|
|
|
|
cairo_pdf_resource_t resource;
|
|
|
|
|
double color1[3];
|
|
|
|
|
double color2[3];
|
|
|
|
|
} cairo_pdf_rgb_linear_function_t;
|
|
|
|
|
|
|
|
|
|
typedef struct _cairo_pdf_alpha_linear_function {
|
|
|
|
|
cairo_pdf_resource_t resource;
|
|
|
|
|
double alpha1;
|
|
|
|
|
double alpha2;
|
|
|
|
|
} cairo_pdf_alpha_linear_function_t;
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
cairo_bool_t compressed,
|
2006-05-12 14:56:11 -07:00
|
|
|
const char *fmt,
|
2006-09-24 00:55:20 +09:30
|
|
|
...) CAIRO_PRINTF_FORMAT(3, 4);
|
2007-04-10 13:51:46 -07:00
|
|
|
static cairo_status_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface);
|
2005-06-21 15:38:51 +00:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
static cairo_status_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_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
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
|
|
|
|
static cairo_pdf_resource_t
|
|
|
|
|
_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
|
|
|
|
static cairo_pdf_resource_t
|
|
|
|
|
_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
|
|
|
|
static long
|
|
|
|
|
_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface);
|
|
|
|
|
|
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
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
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;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
object.offset = _cairo_output_stream_get_position (surface->output);
|
2005-11-04 16:13:30 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
status = _cairo_array_append (&surface->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 14:56:11 -07:00
|
|
|
resource = surface->next_available_resource;
|
|
|
|
|
surface->next_available_resource.id++;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
|
|
|
|
return resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-17 09:40:00 +00:00
|
|
|
static void
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_update_object (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_resource_t resource)
|
2005-01-17 09:40:00 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_object_t *object;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
object = _cairo_array_index (&surface->objects, resource.id - 1);
|
|
|
|
|
object->offset = _cairo_output_stream_get_position (surface->output);
|
2005-01-17 09:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
static cairo_status_t
|
2005-01-05 14:29:31 +00:00
|
|
|
_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
|
|
|
{
|
2007-04-11 01:55:59 -07:00
|
|
|
return _cairo_array_append (&surface->streams, &stream);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
static cairo_status_t
|
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
|
|
|
{
|
2007-04-11 01:55:59 -07:00
|
|
|
return _cairo_array_append (&surface->patterns, &pattern);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
static cairo_status_t
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_add_smask (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_resource_t smask)
|
|
|
|
|
{
|
|
|
|
|
return _cairo_array_append (&surface->smasks, &smask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, double alpha, int *index)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
|
|
|
|
int num_alphas, i;
|
|
|
|
|
double other;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
|
|
|
|
num_alphas = _cairo_array_num_elements (&surface->alphas);
|
|
|
|
|
for (i = 0; i < num_alphas; i++) {
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_array_copy_element (&surface->alphas, i, &other);
|
|
|
|
|
if (alpha == other) {
|
|
|
|
|
*index = i;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
status = _cairo_array_append (&surface->alphas, &alpha);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
*index = _cairo_array_num_elements (&surface->alphas) - 1;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
static cairo_surface_t *
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *output,
|
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
|
|
|
{
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_pdf_surface_t *surface;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_status_t status;
|
|
|
|
|
int alpha;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface = malloc (sizeof (cairo_pdf_surface_t));
|
|
|
|
|
if (surface == NULL) {
|
2005-07-27 15:39:34 +00:00
|
|
|
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
|
|
|
|
}
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-24 17:05:51 -07:00
|
|
|
_cairo_surface_init (&surface->base, &cairo_pdf_surface_backend,
|
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA);
|
2006-05-12 14:56:11 -07:00
|
|
|
|
|
|
|
|
surface->output = output;
|
|
|
|
|
|
|
|
|
|
surface->width = width;
|
|
|
|
|
surface->height = height;
|
|
|
|
|
|
|
|
|
|
_cairo_array_init (&surface->objects, sizeof (cairo_pdf_object_t));
|
|
|
|
|
_cairo_array_init (&surface->pages, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->patterns, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->xobjects, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->streams, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->alphas, sizeof (double));
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_array_init (&surface->smasks, sizeof (cairo_pdf_resource_t));
|
|
|
|
|
_cairo_array_init (&surface->rgb_linear_functions, sizeof (cairo_pdf_rgb_linear_function_t));
|
|
|
|
|
_cairo_array_init (&surface->alpha_linear_functions, sizeof (cairo_pdf_alpha_linear_function_t));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Add alpha=1 as the first element in the list of alpha values as
|
|
|
|
|
* this is the most frequently referenced value. */
|
|
|
|
|
status = _cairo_pdf_surface_add_alpha (surface, 1, &alpha);
|
|
|
|
|
if (status) {
|
|
|
|
|
_cairo_error (status);
|
|
|
|
|
goto fail1;
|
|
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
surface->font_subsets = _cairo_scaled_font_subsets_create_composite ();
|
2006-05-15 10:04:53 -07:00
|
|
|
if (! surface->font_subsets) {
|
|
|
|
|
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
2007-04-27 09:49:45 -07:00
|
|
|
goto fail2;
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_array_init (&surface->fonts, sizeof (cairo_pdf_font_t));
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->next_available_resource.id = 1;
|
|
|
|
|
surface->pages_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
|
|
|
|
|
surface->current_stream.active = FALSE;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->has_clip = FALSE;
|
|
|
|
|
|
|
|
|
|
surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE;
|
|
|
|
|
|
2007-04-21 02:50:53 -04:00
|
|
|
surface->force_fallbacks = FALSE;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
/* Document header */
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%%PDF-1.4\r\n");
|
2006-08-04 16:39:40 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%%%c%c%c%c\r\n", 181, 237, 174, 251);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return _cairo_paginated_surface_create (&surface->base,
|
2006-01-19 17:48:22 +00:00
|
|
|
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);
|
2007-04-27 09:49:45 -07:00
|
|
|
|
|
|
|
|
fail1:
|
|
|
|
|
free (surface);
|
|
|
|
|
fail2:
|
|
|
|
|
return (cairo_surface_t*) &_cairo_surface_nil;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-18 16:40:17 +00:00
|
|
|
/**
|
|
|
|
|
* cairo_pdf_surface_create_for_stream:
|
2006-06-30 00:46:48 +02:00
|
|
|
* @write_func: a #cairo_write_func_t to accept the output data
|
|
|
|
|
* @closure: the closure argument for @write_func
|
2006-01-18 16:40:17 +00:00
|
|
|
* @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)
|
2006-05-12 14:56:11 -07:00
|
|
|
*
|
2006-01-18 16:40:17 +00:00
|
|
|
* Creates a PDF surface of the specified size in points to be written
|
2006-06-30 00:46:48 +02:00
|
|
|
* incrementally to the stream represented by @write_func and @closure.
|
2006-01-18 16:40:17 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
2006-06-29 18:36:53 +02:00
|
|
|
*
|
|
|
|
|
* Since: 1.2
|
2006-01-18 16:40:17 +00:00
|
|
|
*/
|
2005-03-16 12:08:41 +00:00
|
|
|
cairo_surface_t *
|
2006-06-30 00:46:48 +02:00
|
|
|
cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func,
|
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;
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_output_stream_t *output;
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-06-30 00:46:48 +02:00
|
|
|
output = _cairo_output_stream_create (write_func, NULL, closure);
|
2006-05-12 14:56:11 -07:00
|
|
|
status = _cairo_output_stream_get_status (output);
|
2006-04-04 10:45:38 -07:00
|
|
|
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-05-12 14:56:11 -07:00
|
|
|
return _cairo_pdf_surface_create_for_stream_internal (output,
|
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)
|
2006-05-12 14:56:11 -07:00
|
|
|
*
|
2006-01-18 16:40:17 +00:00
|
|
|
* Creates a PDF surface of the specified size in points to be written
|
|
|
|
|
* to @filename.
|
2006-05-12 14:56:11 -07:00
|
|
|
*
|
2006-01-18 16:40:17 +00:00
|
|
|
* 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.
|
2006-06-29 18:36:53 +02:00
|
|
|
*
|
|
|
|
|
* Since: 1.2
|
2006-01-18 16:40:17 +00:00
|
|
|
**/
|
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;
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_output_stream_t *output;
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
output = _cairo_output_stream_create_for_filename (filename);
|
|
|
|
|
status = _cairo_output_stream_get_status (output);
|
2006-04-04 10:45:38 -07:00
|
|
|
if (status) {
|
|
|
|
|
_cairo_error (status);
|
2007-02-08 15:29:58 -08:00
|
|
|
return (status == CAIRO_STATUS_WRITE_ERROR) ?
|
|
|
|
|
(cairo_surface_t*) &_cairo_surface_nil_write_error :
|
|
|
|
|
(cairo_surface_t*) &_cairo_surface_nil;
|
2005-07-27 15:39:34 +00:00
|
|
|
}
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return _cairo_pdf_surface_create_for_stream_internal (output,
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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)
|
2006-05-12 14:56:11 -07:00
|
|
|
*
|
2006-05-03 12:39:23 -07:00
|
|
|
* 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().
|
2006-06-29 18:36:53 +02:00
|
|
|
*
|
|
|
|
|
* Since: 1.2
|
2006-05-03 12:39:23 -07:00
|
|
|
**/
|
|
|
|
|
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 void
|
|
|
|
|
_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
_cairo_array_truncate (&surface->streams, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
cairo_bool_t compressed,
|
2006-05-12 14:56:11 -07:00
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-05-13 14:04:22 +00:00
|
|
|
va_list ap;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->current_stream.active = TRUE;
|
|
|
|
|
surface->current_stream.self = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
surface->current_stream.length = _cairo_pdf_surface_new_object (surface);
|
2006-09-24 00:55:20 +09:30
|
|
|
surface->current_stream.compressed = compressed;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
2005-05-13 14:04:22 +00:00
|
|
|
"<< /Length %d 0 R\r\n",
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->current_stream.self.id,
|
|
|
|
|
surface->current_stream.length.id);
|
2006-09-24 00:55:20 +09:30
|
|
|
if (compressed)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Filter /FlateDecode\r\n");
|
2005-05-13 14:04:22 +00:00
|
|
|
|
|
|
|
|
if (fmt != NULL) {
|
|
|
|
|
va_start (ap, fmt);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_vprintf (surface->output, fmt, ap);
|
2005-05-13 14:04:22 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-05-13 14:04:22 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->current_stream.start_offset = _cairo_output_stream_get_position (surface->output);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-09-24 00:55:20 +09:30
|
|
|
if (compressed) {
|
|
|
|
|
surface->current_stream.old_output = surface->output;
|
|
|
|
|
surface->output = _cairo_deflate_stream_create (surface->output);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return surface->current_stream.self;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
static cairo_status_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2007-04-10 13:51:46 -07:00
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
long length;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
if (! surface->current_stream.active)
|
2007-04-10 13:51:46 -07:00
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-09-24 00:55:20 +09:30
|
|
|
if (surface->current_stream.compressed) {
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_output_stream_destroy (surface->output);
|
2006-09-24 00:55:20 +09:30
|
|
|
surface->output = surface->current_stream.old_output;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
length = _cairo_output_stream_get_position (surface->output) -
|
|
|
|
|
surface->current_stream.start_offset;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_update_object (surface,
|
|
|
|
|
surface->current_stream.length);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
" %ld\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->current_stream.length.id,
|
2005-03-16 12:08:41 +00:00
|
|
|
length);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->current_stream.active = FALSE;
|
2007-04-10 13:51:46 -07:00
|
|
|
|
|
|
|
|
return status;
|
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
|
|
|
{
|
2007-04-10 13:51:46 -07:00
|
|
|
cairo_status_t status, status2;
|
2005-01-05 14:29:31 +00:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2006-05-12 14:56:11 -07:00
|
|
|
long offset;
|
|
|
|
|
cairo_pdf_resource_t info, catalog;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_pdf_surface_emit_font_subsets (surface);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_pages (surface);
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
info = _cairo_pdf_surface_write_info (surface);
|
|
|
|
|
catalog = _cairo_pdf_surface_write_catalog (surface);
|
|
|
|
|
offset = _cairo_pdf_surface_write_xref (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"trailer\r\n"
|
|
|
|
|
"<< /Size %d\r\n"
|
|
|
|
|
" /Root %d 0 R\r\n"
|
|
|
|
|
" /Info %d 0 R\r\n"
|
|
|
|
|
">>\r\n",
|
|
|
|
|
surface->next_available_resource.id,
|
|
|
|
|
catalog.id,
|
|
|
|
|
info.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"startxref\r\n"
|
|
|
|
|
"%ld\r\n"
|
|
|
|
|
"%%%%EOF\r\n",
|
|
|
|
|
offset);
|
|
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status2 = _cairo_output_stream_destroy (surface->output);
|
|
|
|
|
if (status == CAIRO_STATUS_SUCCESS)
|
|
|
|
|
status = status2;
|
2006-05-12 14:56:11 -07:00
|
|
|
|
|
|
|
|
_cairo_array_fini (&surface->objects);
|
|
|
|
|
_cairo_array_fini (&surface->pages);
|
2005-07-14 17:52:17 +00:00
|
|
|
_cairo_array_fini (&surface->patterns);
|
|
|
|
|
_cairo_array_fini (&surface->xobjects);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_array_fini (&surface->streams);
|
2005-07-14 17:52:17 +00:00
|
|
|
_cairo_array_fini (&surface->alphas);
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_array_fini (&surface->smasks);
|
|
|
|
|
_cairo_array_fini (&surface->rgb_linear_functions);
|
|
|
|
|
_cairo_array_fini (&surface->alpha_linear_functions);
|
2005-07-14 17:52:17 +00:00
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
if (surface->font_subsets) {
|
|
|
|
|
_cairo_scaled_font_subsets_destroy (surface->font_subsets);
|
|
|
|
|
surface->font_subsets = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_array_fini (&surface->fonts);
|
|
|
|
|
|
2005-03-16 12:08:41 +00:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
static cairo_status_t
|
2006-05-12 13:31:12 -07:00
|
|
|
_cairo_pdf_surface_pause_content_stream (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
2007-04-10 13:51:46 -07:00
|
|
|
return _cairo_pdf_surface_close_stream (surface);
|
2006-05-12 13:31:12 -07:00
|
|
|
}
|
|
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
static cairo_status_t
|
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
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
stream = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
TRUE,
|
2006-05-12 14:56:11 -07:00
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
return _cairo_pdf_surface_add_stream (surface, stream);
|
2006-05-12 13:31:12 -07:00
|
|
|
}
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_begin_group (cairo_pdf_surface_t *surface, cairo_pdf_resource_t *group)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_resource_t g;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_pause_content_stream (surface);
|
|
|
|
|
g = _cairo_pdf_surface_open_stream (surface,
|
|
|
|
|
TRUE,
|
|
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n"
|
|
|
|
|
" /Group <<\r\n"
|
|
|
|
|
" /Type /Group\r\n"
|
|
|
|
|
" /S /Transparency\r\n"
|
|
|
|
|
" /CS /DeviceRGB\r\n"
|
|
|
|
|
" >>\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
status = _cairo_array_append (&surface->xobjects, &g);
|
|
|
|
|
*group = g;
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_end_group (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
_cairo_pdf_surface_close_stream (surface);
|
|
|
|
|
_cairo_pdf_surface_resume_content_stream (surface);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_start_page (void *abstract_surface)
|
|
|
|
|
{
|
2007-04-11 01:55:59 -07:00
|
|
|
cairo_status_t status;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_pdf_resource_t stream;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
stream = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
TRUE,
|
2006-05-12 14:56:11 -07:00
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
status = _cairo_pdf_surface_add_stream (surface, stream);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-05-12 13:31:12 -07:00
|
|
|
"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
|
2007-01-07 02:03:30 +00:00
|
|
|
* an id that can be used to reference the resulting SMask object.
|
2006-04-25 03:45:37 -07:00
|
|
|
*
|
|
|
|
|
* 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
|
2007-03-07 15:54:20 -05:00
|
|
|
_cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
|
2006-04-25 03:45:37 -07:00
|
|
|
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;
|
|
|
|
|
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 14:56:11 -07:00
|
|
|
*stream_ret = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
FALSE,
|
2006-05-12 14:56:11 -07:00
|
|
|
" /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);
|
|
|
|
|
_cairo_output_stream_write (surface->output, alpha_compressed, alpha_compressed_size);
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "\r\n");
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
2006-04-25 03:45:37 -07:00
|
|
|
|
|
|
|
|
free (alpha_compressed);
|
|
|
|
|
CLEANUP_ALPHA:
|
|
|
|
|
free (alpha);
|
|
|
|
|
CLEANUP:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
/* Emit image data into the given surface, providing a resource that
|
|
|
|
|
* can be used to reference the data in image_ret. */
|
2006-04-20 10:01:45 -07:00
|
|
|
static cairo_status_t
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_emit_image (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_image_surface_t *image,
|
|
|
|
|
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-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-18 21:48:38 -07:00
|
|
|
cairo_pdf_resource_t smask = {0}; /* squelch bogus compiler warning */
|
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
|
2006-05-24 14:02:30 -07:00
|
|
|
* makes things a lot simpler here). This is enforced through
|
2007-03-07 15:54:20 -05:00
|
|
|
* _cairo_pdf_surface_analyze_operation which only accept source surfaces of
|
2006-05-12 14:56:11 -07:00
|
|
|
* CONTENT_COLOR or CONTENT_COLOR_ALPHA.
|
2006-04-25 03:45:37 -07:00
|
|
|
*/
|
|
|
|
|
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) {
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_smask (surface, 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 14:56:11 -07:00
|
|
|
*image_ret = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
FALSE,
|
2006-05-12 14:56:11 -07:00
|
|
|
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 14:56:11 -07:00
|
|
|
*image_ret = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
FALSE,
|
2006-05-12 14:56:11 -07:00
|
|
|
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-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_write (surface->output, compressed, compressed_size);
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "\r\n");
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
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
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_emit_solid_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_solid_pattern_t *pattern)
|
2005-02-01 20:47:43 +00:00
|
|
|
{
|
2007-04-27 09:49:45 -07:00
|
|
|
int alpha;
|
2007-04-11 01:55:59 -07:00
|
|
|
cairo_status_t status;
|
2006-04-18 16:53:23 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
status = _cairo_pdf_surface_add_alpha (surface, pattern->color.alpha, &alpha);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
surface->emitted_pattern.type = CAIRO_PATTERN_TYPE_SOLID;
|
|
|
|
|
surface->emitted_pattern.red = pattern->color.red;
|
|
|
|
|
surface->emitted_pattern.green = pattern->color.green;
|
|
|
|
|
surface->emitted_pattern.blue = pattern->color.blue;
|
|
|
|
|
surface->emitted_pattern.alpha = alpha;
|
|
|
|
|
surface->emitted_pattern.smask.id = 0;
|
|
|
|
|
surface->emitted_pattern.pattern.id = 0;
|
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
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_surface_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t stream;
|
2007-02-22 13:40:55 -05:00
|
|
|
cairo_surface_t *pat_surface;
|
|
|
|
|
cairo_surface_attributes_t pat_attr;
|
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;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t image_resource = {0}; /* squelch bogus compiler warning */
|
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);
|
2007-02-27 18:47:47 -05:00
|
|
|
double xstep, ystep;
|
2006-06-06 16:54:03 -07:00
|
|
|
cairo_rectangle_int16_t surface_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
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_pause_content_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-02-22 13:40:55 -05:00
|
|
|
status = _cairo_pattern_acquire_surface ((cairo_pattern_t *)pattern,
|
|
|
|
|
(cairo_surface_t *)surface,
|
|
|
|
|
0, 0, -1, -1,
|
|
|
|
|
&pat_surface, &pat_attr);
|
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
|
|
|
|
2007-02-22 13:40:55 -05:00
|
|
|
status = _cairo_surface_acquire_source_image (pat_surface, &image, &image_extra);
|
|
|
|
|
if (status)
|
|
|
|
|
goto BAIL2;
|
|
|
|
|
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_image (surface, image, &image_resource);
|
2006-04-20 10:01:45 -07:00
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-08 21:26:33 +01:00
|
|
|
status = _cairo_surface_get_extents (&surface->base, &surface_extents);
|
|
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2006-04-24 16:11:21 -07:00
|
|
|
|
|
|
|
|
switch (extend) {
|
2007-03-01 19:14:40 -05:00
|
|
|
/* We implement EXTEND_PAD like EXTEND_NONE for now */
|
|
|
|
|
case CAIRO_EXTEND_PAD:
|
2006-04-24 16:11:21 -07:00
|
|
|
case CAIRO_EXTEND_NONE:
|
2007-01-19 23:11:09 -08:00
|
|
|
{
|
2007-02-27 18:47:47 -05:00
|
|
|
/* In PS/PDF, (as far as I can tell), all patterns are
|
2007-01-19 23:11:09 -08:00
|
|
|
* repeating. So we support cairo's EXTEND_NONE semantics
|
|
|
|
|
* by setting the repeat step size to a size large enough
|
2007-01-19 23:23:32 -08:00
|
|
|
* to guarantee that no more than a single occurrence will
|
2007-01-19 23:11:09 -08:00
|
|
|
* be visible.
|
|
|
|
|
*
|
2007-02-27 18:47:47 -05:00
|
|
|
* First, map the surface extents into pattern space (since
|
|
|
|
|
* xstep and ystep are in pattern space). Then use an upper
|
|
|
|
|
* bound on the length of the diagonal of the pattern image
|
|
|
|
|
* and the surface as repeat size. This guarantees to never
|
|
|
|
|
* repeat visibly.
|
2007-01-19 23:11:09 -08:00
|
|
|
*/
|
|
|
|
|
double x1 = 0.0, y1 = 0.0;
|
2007-02-27 18:47:47 -05:00
|
|
|
double x2 = surface->width, y2 = surface->height;
|
|
|
|
|
_cairo_matrix_transform_bounding_box (&pattern->base.matrix,
|
2007-01-19 23:11:09 -08:00
|
|
|
&x1, &y1, &x2, &y2,
|
|
|
|
|
NULL);
|
2007-02-27 18:47:47 -05:00
|
|
|
|
2007-01-19 23:11:09 -08:00
|
|
|
/* Rather than computing precise bounds of the union, just
|
2007-01-19 23:23:32 -08:00
|
|
|
* add the surface extents unconditionally. We only
|
2007-01-19 23:11:09 -08:00
|
|
|
* required an answer that's large enough, we don't really
|
2007-02-27 18:47:47 -05:00
|
|
|
* care if it's not as tight as possible.*/
|
|
|
|
|
xstep = ystep = ceil ((x2 - x1) + (y2 - y1) +
|
|
|
|
|
image->width + image->height);
|
2007-01-19 23:11:09 -08:00
|
|
|
}
|
2006-04-24 16:11:21 -07:00
|
|
|
break;
|
|
|
|
|
case CAIRO_EXTEND_REPEAT:
|
2007-02-22 13:40:55 -05:00
|
|
|
case CAIRO_EXTEND_REFLECT:
|
2006-04-24 16:11:21 -07:00
|
|
|
xstep = image->width;
|
|
|
|
|
ystep = image->height;
|
|
|
|
|
break;
|
2007-03-01 19:14:40 -05:00
|
|
|
/* All the rest (if any) should have been analyzed away, so this
|
|
|
|
|
* case should be unreachable. */
|
2006-04-24 16:11:21 -07:00
|
|
|
default:
|
2006-07-31 11:47:45 -07:00
|
|
|
ASSERT_NOT_REACHED;
|
2006-04-24 16:11:21 -07:00
|
|
|
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;
|
2007-04-11 01:35:11 -07:00
|
|
|
status = cairo_matrix_invert (&cairo_p2d);
|
|
|
|
|
/* cairo_pattern_set_matrix ensures the matrix is invertible */
|
|
|
|
|
assert (status == CAIRO_STATUS_SUCCESS);
|
2006-04-24 16:11:21 -07:00
|
|
|
|
|
|
|
|
cairo_matrix_init_identity (&pdf_p2d);
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_matrix_translate (&pdf_p2d, 0.0, surface_extents.height);
|
2006-04-24 16:11:21 -07:00
|
|
|
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);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
stream = _cairo_pdf_surface_open_stream (surface,
|
2006-09-24 00:55:20 +09:30
|
|
|
FALSE,
|
2006-05-12 14:56:11 -07:00
|
|
|
" /BBox [0 0 %d %d]\r\n"
|
2007-02-27 18:47:47 -05:00
|
|
|
" /XStep %f\r\n"
|
|
|
|
|
" /YStep %f\r\n"
|
2006-05-12 14:56:11 -07:00
|
|
|
" /PatternType 1\r\n"
|
|
|
|
|
" /TilingType 1\r\n"
|
|
|
|
|
" /PaintType 1\r\n"
|
|
|
|
|
" /Matrix [ %f %f %f %f %f %f ]\r\n"
|
|
|
|
|
" /Resources << /XObject << /res%d %d 0 R >> >>\r\n",
|
|
|
|
|
image->width, image->height,
|
|
|
|
|
xstep, ystep,
|
|
|
|
|
pdf_p2d.xx, pdf_p2d.yx,
|
|
|
|
|
pdf_p2d.xy, pdf_p2d.yy,
|
|
|
|
|
pdf_p2d.x0, pdf_p2d.y0,
|
|
|
|
|
image_resource.id,
|
|
|
|
|
image_resource.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->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
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
status = _cairo_pdf_surface_resume_content_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
status = _cairo_pdf_surface_add_pattern (surface, stream);
|
|
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
status = _cairo_pdf_surface_add_alpha (surface, 1.0, &surface->emitted_pattern.alpha);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
|
|
|
|
goto BAIL;
|
2007-04-27 09:49:45 -07:00
|
|
|
surface->emitted_pattern.type = CAIRO_PATTERN_TYPE_SURFACE;
|
|
|
|
|
surface->emitted_pattern.smask.id = 0;
|
|
|
|
|
surface->emitted_pattern.pattern = stream;
|
2005-01-31 08:50:22 +00:00
|
|
|
|
2006-04-20 10:01:45 -07:00
|
|
|
BAIL:
|
2007-02-22 13:40:55 -05:00
|
|
|
_cairo_surface_release_source_image (pat_surface, image, image_extra);
|
|
|
|
|
BAIL2:
|
|
|
|
|
_cairo_pattern_release_surface ((cairo_pattern_t *)pattern, pat_surface, &pat_attr);
|
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-07 13:21:01 +00:00
|
|
|
typedef struct _cairo_pdf_color_stop {
|
2007-04-27 09:49:45 -07:00
|
|
|
double offset;
|
|
|
|
|
double color[4];
|
|
|
|
|
cairo_pdf_resource_t resource;
|
2005-10-07 13:21:01 +00:00
|
|
|
} cairo_pdf_color_stop_t;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
cairo_pdf_surface_emit_rgb_linear_function (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_color_stop_t *stop1,
|
|
|
|
|
cairo_pdf_color_stop_t *stop2,
|
|
|
|
|
cairo_pdf_resource_t *function)
|
|
|
|
|
{
|
|
|
|
|
int num_elems, i;
|
|
|
|
|
cairo_pdf_rgb_linear_function_t elem;
|
|
|
|
|
cairo_pdf_resource_t res;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
|
|
|
|
num_elems = _cairo_array_num_elements (&surface->rgb_linear_functions);
|
|
|
|
|
for (i = 0; i < num_elems; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->rgb_linear_functions, i, &elem);
|
|
|
|
|
if (memcmp (&elem.color1[0], &stop1->color[0], sizeof (double)*3) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (memcmp (&elem.color2[0], &stop2->color[0], sizeof (double)*3) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
*function = elem.resource;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = _cairo_pdf_surface_new_object (surface);
|
2006-05-12 14:56:11 -07:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
2007-04-27 09:49:45 -07:00
|
|
|
"<< /FunctionType 2\r\n"
|
2005-10-11 13:20:44 +00:00
|
|
|
" /Domain [ 0 1 ]\r\n"
|
2007-04-27 09:49:45 -07:00
|
|
|
" /C0 [ %f %f %f ]\r\n"
|
|
|
|
|
" /C1 [ %f %f %f ]\r\n"
|
|
|
|
|
" /N 1\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
2007-04-27 09:49:45 -07:00
|
|
|
"endobj\r\n",
|
|
|
|
|
res.id,
|
|
|
|
|
stop1->color[0],
|
|
|
|
|
stop1->color[1],
|
|
|
|
|
stop1->color[2],
|
|
|
|
|
stop2->color[0],
|
|
|
|
|
stop2->color[1],
|
|
|
|
|
stop2->color[2]);
|
|
|
|
|
|
|
|
|
|
elem.resource = res;
|
|
|
|
|
memcpy (&elem.color1[0], &stop1->color[0], sizeof (double)*3);
|
|
|
|
|
memcpy (&elem.color2[0], &stop2->color[0], sizeof (double)*3);
|
|
|
|
|
|
|
|
|
|
status = _cairo_array_append (&surface->rgb_linear_functions, &elem);
|
|
|
|
|
*function = res;
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
cairo_pdf_surface_emit_alpha_linear_function (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_color_stop_t *stop1,
|
|
|
|
|
cairo_pdf_color_stop_t *stop2,
|
|
|
|
|
cairo_pdf_resource_t *function)
|
|
|
|
|
{
|
|
|
|
|
int num_elems, i;
|
|
|
|
|
cairo_pdf_alpha_linear_function_t elem;
|
|
|
|
|
cairo_pdf_resource_t res;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
|
|
|
|
num_elems = _cairo_array_num_elements (&surface->alpha_linear_functions);
|
|
|
|
|
for (i = 0; i < num_elems; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->alpha_linear_functions, i, &elem);
|
|
|
|
|
if (elem.alpha1 != stop1->color[3])
|
|
|
|
|
continue;
|
|
|
|
|
if (elem.alpha2 != stop2->color[3])
|
|
|
|
|
continue;
|
|
|
|
|
*function = elem.resource;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = _cairo_pdf_surface_new_object (surface);
|
2005-10-07 13:21:01 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-27 09:49:45 -07:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /FunctionType 2\r\n"
|
|
|
|
|
" /Domain [ 0 1 ]\r\n"
|
|
|
|
|
" /C0 [ %f ]\r\n"
|
|
|
|
|
" /C1 [ %f ]\r\n"
|
|
|
|
|
" /N 1\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
res.id,
|
|
|
|
|
stop1->color[3],
|
|
|
|
|
stop2->color[3]);
|
|
|
|
|
|
|
|
|
|
elem.resource = res;
|
|
|
|
|
elem.alpha1 = stop1->color[3];
|
|
|
|
|
elem.alpha2 = stop2->color[3];
|
|
|
|
|
|
|
|
|
|
status = _cairo_array_append (&surface->alpha_linear_functions, &elem);
|
|
|
|
|
*function = res;
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
return status;
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_stitched_colorgradient (cairo_pdf_surface_t *surface,
|
|
|
|
|
unsigned int n_stops,
|
|
|
|
|
cairo_pdf_color_stop_t *stops,
|
|
|
|
|
cairo_bool_t is_alpha,
|
|
|
|
|
cairo_pdf_resource_t *function)
|
2005-10-11 13:20:44 +00:00
|
|
|
{
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t res;
|
2005-10-11 13:20:44 +00:00
|
|
|
unsigned int i;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_status_t status;
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
/* emit linear gradients between pairs of subsequent stops... */
|
|
|
|
|
for (i = 0; i < n_stops-1; i++) {
|
2007-04-27 09:49:45 -07:00
|
|
|
if (is_alpha) {
|
|
|
|
|
status = cairo_pdf_surface_emit_alpha_linear_function (surface,
|
|
|
|
|
&stops[i],
|
|
|
|
|
&stops[i+1],
|
|
|
|
|
&stops[i].resource);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
} else {
|
|
|
|
|
status = cairo_pdf_surface_emit_rgb_linear_function (surface,
|
|
|
|
|
&stops[i],
|
|
|
|
|
&stops[i+1],
|
|
|
|
|
&stops[i].resource);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-01-07 02:03:30 +00:00
|
|
|
/* ... and stitch them together */
|
2007-04-27 09:49:45 -07:00
|
|
|
res = _cairo_pdf_surface_new_object (surface);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-10-11 13:20:44 +00:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /FunctionType 3\r\n"
|
2006-05-12 14:56:11 -07:00
|
|
|
" /Domain [ 0 1 ]\r\n",
|
2007-04-27 09:49:45 -07:00
|
|
|
res.id);
|
2006-05-12 14:56:11 -07:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Functions [ ");
|
2005-10-11 13:20:44 +00:00
|
|
|
for (i = 0; i < n_stops-1; i++)
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-27 09:49:45 -07:00
|
|
|
"%d 0 R ", stops[i].resource.id);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"]\r\n");
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-10-11 13:20:44 +00:00
|
|
|
" /Bounds [ ");
|
|
|
|
|
for (i = 1; i < n_stops-1; i++)
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%f ", stops[i].offset);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"]\r\n");
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-10-11 13:20:44 +00:00
|
|
|
" /Encode [ ");
|
|
|
|
|
for (i = 1; i < n_stops; i++)
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"0 1 ");
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"]\r\n");
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-10-11 13:20:44 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
*function = res;
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2005-10-11 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-07 02:03:30 +00:00
|
|
|
#define COLOR_STOP_EPSILON 1e-6
|
2005-10-11 13:20:44 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_gradient_pattern_t *pattern,
|
|
|
|
|
cairo_pdf_resource_t *color_function,
|
|
|
|
|
cairo_pdf_resource_t *alpha_function)
|
2005-10-11 13:20:44 +00:00
|
|
|
{
|
|
|
|
|
cairo_pdf_color_stop_t *allstops, *stops;
|
2007-04-27 09:49:45 -07:00
|
|
|
unsigned int n_stops;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
cairo_bool_t emit_alpha = FALSE;
|
|
|
|
|
cairo_status_t status;
|
2005-10-11 13:20:44 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
color_function->id = 0;
|
|
|
|
|
alpha_function->id = 0;
|
2005-10-11 13:20:44 +00:00
|
|
|
|
|
|
|
|
allstops = malloc ((pattern->n_stops + 2) * sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
if (allstops == NULL) {
|
2007-04-27 09:49:45 -07:00
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
2005-10-07 13:21:01 +00:00
|
|
|
}
|
2007-04-27 09:49:45 -07:00
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
stops = &allstops[1];
|
|
|
|
|
n_stops = pattern->n_stops;
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
for (i = 0; i < n_stops; i++) {
|
|
|
|
|
stops[i].color[0] = pattern->stops[i].color.red / 65535.0;
|
|
|
|
|
stops[i].color[1] = pattern->stops[i].color.green / 65535.0;
|
|
|
|
|
stops[i].color[2] = pattern->stops[i].color.blue / 65535.0;
|
|
|
|
|
stops[i].color[3] = pattern->stops[i].color.alpha / 65535.0;
|
|
|
|
|
if (!CAIRO_ALPHA_IS_OPAQUE (stops[i].color[3]))
|
|
|
|
|
emit_alpha = TRUE;
|
2006-01-05 05:06:50 +00:00
|
|
|
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.) */
|
2007-01-07 02:03:30 +00:00
|
|
|
if (stops[0].offset > COLOR_STOP_EPSILON) {
|
2005-10-11 13:20:44 +00:00
|
|
|
memcpy (allstops, stops, sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
stops = allstops;
|
|
|
|
|
n_stops++;
|
|
|
|
|
}
|
2007-04-27 09:49:45 -07:00
|
|
|
stops[0].offset = 0.0;
|
|
|
|
|
|
2007-01-07 02:03:30 +00:00
|
|
|
if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) {
|
2006-05-12 14:56:11 -07:00
|
|
|
memcpy (&stops[n_stops],
|
|
|
|
|
&stops[n_stops - 1],
|
2005-10-11 13:20:44 +00:00
|
|
|
sizeof (cairo_pdf_color_stop_t));
|
|
|
|
|
n_stops++;
|
|
|
|
|
}
|
2007-04-27 09:49:45 -07:00
|
|
|
stops[n_stops].offset = 1.0;
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2005-10-11 13:20:44 +00:00
|
|
|
if (n_stops == 2) {
|
2007-04-27 09:49:45 -07:00
|
|
|
/* no need for stitched function */
|
|
|
|
|
status = cairo_pdf_surface_emit_rgb_linear_function (surface,
|
|
|
|
|
&stops[0],
|
|
|
|
|
&stops[1],
|
|
|
|
|
color_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
if (emit_alpha) {
|
|
|
|
|
status = cairo_pdf_surface_emit_alpha_linear_function (surface,
|
|
|
|
|
&stops[0],
|
|
|
|
|
&stops[1],
|
|
|
|
|
alpha_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2005-10-11 13:20:44 +00:00
|
|
|
} else {
|
2007-04-27 09:49:45 -07:00
|
|
|
/* multiple stops: stitch. XXX possible optimization: regulary spaced
|
|
|
|
|
* stops do not require stitching. XXX */
|
|
|
|
|
status = _cairo_pdf_surface_emit_stitched_colorgradient (surface,
|
|
|
|
|
n_stops,
|
|
|
|
|
stops,
|
|
|
|
|
FALSE,
|
|
|
|
|
color_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-03-16 12:08:41 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (emit_alpha) {
|
|
|
|
|
status = _cairo_pdf_surface_emit_stitched_colorgradient (surface,
|
|
|
|
|
n_stops,
|
|
|
|
|
stops,
|
|
|
|
|
TRUE,
|
|
|
|
|
alpha_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-10-11 13:20:44 +00:00
|
|
|
free (allstops);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_pdf_resource_t
|
|
|
|
|
cairo_pdf_surface_emit_transparency_group (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_pdf_resource_t gradient_mask)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_resource_t xobj_resource, smask_resource, gstate_resource;
|
|
|
|
|
|
|
|
|
|
xobj_resource = _cairo_pdf_surface_open_stream (surface,
|
|
|
|
|
TRUE,
|
|
|
|
|
" /Type /XObject\r\n"
|
|
|
|
|
" /Subtype /Form\r\n"
|
|
|
|
|
" /FormType 1\r\n"
|
|
|
|
|
" /BBox [ 0 0 %f %f ]\r\n"
|
|
|
|
|
" /Resources\r\n"
|
|
|
|
|
" << /ExtGState\r\n"
|
|
|
|
|
" << /a0 << /ca 1 /CA 1 >>"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
" /Pattern\r\n"
|
|
|
|
|
" << /res%d %d 0 R >>\r\n"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
" /Group\r\n"
|
|
|
|
|
" << /Type /Group\r\n"
|
|
|
|
|
" /S /Transparency\r\n"
|
|
|
|
|
" /CS /DeviceGray\r\n"
|
|
|
|
|
" >>\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height,
|
|
|
|
|
gradient_mask.id,
|
|
|
|
|
gradient_mask.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q\r\n"
|
|
|
|
|
"/a0 gs\r\n"
|
|
|
|
|
"/Pattern cs /res%d scn\r\n"
|
|
|
|
|
"0 0 %f %f re\r\n"
|
|
|
|
|
"f\r\n"
|
|
|
|
|
"Q\r\n",
|
|
|
|
|
gradient_mask.id,
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_close_stream (surface);
|
|
|
|
|
|
|
|
|
|
smask_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Mask\r\n"
|
|
|
|
|
" /S /Luminosity\r\n"
|
|
|
|
|
" /G %d 0 R\r\n"
|
|
|
|
|
" /BC [ 0.0 ]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
smask_resource.id,
|
|
|
|
|
xobj_resource.id);
|
|
|
|
|
|
|
|
|
|
/* Create GState which uses the transparency group as an SMask. */
|
|
|
|
|
gstate_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /ExtGState\r\n"
|
|
|
|
|
" /SMask %d 0 R\r\n"
|
|
|
|
|
" /ca 1\r\n"
|
|
|
|
|
" /CA 1\r\n"
|
|
|
|
|
" /AIS false\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
gstate_resource.id,
|
|
|
|
|
smask_resource.id);
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_add_smask (surface, gstate_resource);
|
|
|
|
|
|
|
|
|
|
return gstate_resource;
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_linear_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t pattern_resource, smask;
|
|
|
|
|
cairo_pdf_resource_t color_function, alpha_function;
|
2005-01-05 14:29:31 +00:00
|
|
|
double x0, y0, x1, y1;
|
|
|
|
|
cairo_matrix_t p2u;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_extend_t extend;
|
2007-03-28 15:50:12 +01:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
extend = cairo_pattern_get_extend (&pattern->base.base);
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_pause_content_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
status = _cairo_pdf_surface_emit_pattern_stops (surface,
|
|
|
|
|
&pattern->base,
|
|
|
|
|
&color_function,
|
|
|
|
|
&alpha_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-06 13:32:53 +00:00
|
|
|
p2u = pattern->base.base.matrix;
|
2007-03-28 15:50:12 +01:00
|
|
|
status = cairo_matrix_invert (&p2u);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
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 14:56:11 -07:00
|
|
|
pattern_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-27 09:49:45 -07:00
|
|
|
"%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",
|
|
|
|
|
pattern_resource.id,
|
|
|
|
|
surface->height,
|
|
|
|
|
x0, y0, x1, y1,
|
|
|
|
|
color_function.id);
|
|
|
|
|
|
|
|
|
|
if (extend == CAIRO_EXTEND_PAD) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ true true ]\r\n");
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ false false ]\r\n");
|
|
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
if (alpha_function.id == 0) {
|
|
|
|
|
surface->emitted_pattern.smask.id = 0;
|
|
|
|
|
} else {
|
|
|
|
|
cairo_pdf_resource_t mask_resource;
|
|
|
|
|
|
|
|
|
|
/* Create pattern for SMask. */
|
|
|
|
|
mask_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->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 /DeviceGray\r\n"
|
|
|
|
|
" /Coords [ %f %f %f %f ]\r\n"
|
|
|
|
|
" /Function %d 0 R\r\n",
|
|
|
|
|
mask_resource.id,
|
|
|
|
|
surface->height,
|
|
|
|
|
x0, y0, x1, y1,
|
|
|
|
|
alpha_function.id);
|
|
|
|
|
|
|
|
|
|
if (extend == CAIRO_EXTEND_PAD) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ true true ]\r\n");
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ false false ]\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
status = _cairo_pdf_surface_add_pattern (surface, mask_resource);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
smask = cairo_pdf_surface_emit_transparency_group (surface, mask_resource);
|
|
|
|
|
surface->emitted_pattern.smask = smask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface->emitted_pattern.type = CAIRO_PATTERN_TYPE_LINEAR;
|
|
|
|
|
status = _cairo_pdf_surface_add_alpha (surface, 1, &surface->emitted_pattern.alpha);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
2007-04-27 09:49:45 -07:00
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
surface->emitted_pattern.pattern = pattern_resource;
|
|
|
|
|
status = _cairo_pdf_surface_add_pattern (surface, pattern_resource);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2006-05-12 13:31:12 -07:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
return _cairo_pdf_surface_resume_content_stream (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2005-10-07 13:21:01 +00:00
|
|
|
static cairo_status_t
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_radial_pattern_t *pattern)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t pattern_resource, smask;
|
|
|
|
|
cairo_pdf_resource_t color_function, alpha_function;
|
2005-01-05 14:29:31 +00:00
|
|
|
double x0, y0, x1, y1, r0, r1;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_matrix_t p2u, pdf_p2d;
|
|
|
|
|
cairo_extend_t extend;
|
2007-04-08 21:26:33 +01:00
|
|
|
cairo_status_t status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
extend = cairo_pattern_get_extend (&pattern->base.base);
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_pause_content_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
status = _cairo_pdf_surface_emit_pattern_stops (surface,
|
|
|
|
|
&pattern->base,
|
|
|
|
|
&color_function,
|
|
|
|
|
&alpha_function);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2005-05-06 13:32:53 +00:00
|
|
|
p2u = pattern->base.base.matrix;
|
2007-04-08 21:26:33 +01:00
|
|
|
status = cairo_matrix_invert (&p2u);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-02-25 16:01:10 +01:00
|
|
|
x0 = _cairo_fixed_to_double (pattern->gradient.c1.x);
|
|
|
|
|
y0 = _cairo_fixed_to_double (pattern->gradient.c1.y);
|
|
|
|
|
r0 = _cairo_fixed_to_double (pattern->gradient.c1.radius);
|
|
|
|
|
x1 = _cairo_fixed_to_double (pattern->gradient.c2.x);
|
|
|
|
|
y1 = _cairo_fixed_to_double (pattern->gradient.c2.y);
|
|
|
|
|
r1 = _cairo_fixed_to_double (pattern->gradient.c2.radius);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_matrix_init_identity (&pdf_p2d);
|
|
|
|
|
cairo_matrix_translate (&pdf_p2d, 0.0, surface->height);
|
|
|
|
|
cairo_matrix_scale (&pdf_p2d, 1.0, -1.0);
|
|
|
|
|
cairo_matrix_multiply (&pdf_p2d, &p2u, &pdf_p2d);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
pattern_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-27 09:49:45 -07:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pattern\r\n"
|
|
|
|
|
" /PatternType 2\r\n"
|
|
|
|
|
" /Matrix [ %f %f %f %f %f %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",
|
|
|
|
|
pattern_resource.id,
|
|
|
|
|
pdf_p2d.xx, pdf_p2d.yx,
|
|
|
|
|
pdf_p2d.xy, pdf_p2d.yy,
|
|
|
|
|
pdf_p2d.x0, pdf_p2d.y0,
|
|
|
|
|
x0, y0, r0, x1, y1, r1,
|
|
|
|
|
color_function.id);
|
|
|
|
|
|
|
|
|
|
if (extend == CAIRO_EXTEND_PAD) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ true true ]\r\n");
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ false false ]\r\n");
|
|
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
if (alpha_function.id == 0) {
|
|
|
|
|
surface->emitted_pattern.smask.id = 0;
|
|
|
|
|
} else {
|
|
|
|
|
cairo_pdf_resource_t mask_resource;
|
|
|
|
|
|
|
|
|
|
/* Create pattern for SMask. */
|
|
|
|
|
mask_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pattern\r\n"
|
|
|
|
|
" /PatternType 2\r\n"
|
|
|
|
|
" /Matrix [ %f %f %f %f %f %f ]\r\n"
|
|
|
|
|
" /Shading\r\n"
|
|
|
|
|
" << /ShadingType 3\r\n"
|
|
|
|
|
" /ColorSpace /DeviceGray\r\n"
|
|
|
|
|
" /Coords [ %f %f %f %f %f %f ]\r\n"
|
|
|
|
|
" /Function %d 0 R\r\n",
|
|
|
|
|
mask_resource.id,
|
|
|
|
|
pdf_p2d.xx, pdf_p2d.yx,
|
|
|
|
|
pdf_p2d.xy, pdf_p2d.yy,
|
|
|
|
|
pdf_p2d.x0, pdf_p2d.y0,
|
|
|
|
|
x0, y0, r0, x1, y1, r1,
|
|
|
|
|
alpha_function.id);
|
|
|
|
|
|
|
|
|
|
if (extend == CAIRO_EXTEND_PAD) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ true true ]\r\n");
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Extend [ false false ]\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
smask = cairo_pdf_surface_emit_transparency_group (surface, mask_resource);
|
|
|
|
|
surface->emitted_pattern.smask = smask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface->emitted_pattern.type = CAIRO_PATTERN_TYPE_RADIAL;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_add_alpha (surface, 1.0, &surface->emitted_pattern.alpha);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
surface->emitted_pattern.pattern = pattern_resource;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_add_pattern (surface, pattern_resource);
|
2007-04-11 01:55:59 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2007-04-11 01:55:59 -07:00
|
|
|
return _cairo_pdf_surface_resume_content_stream (surface);
|
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
|
2007-03-07 15:54:20 -05:00
|
|
|
_cairo_pdf_surface_emit_pattern (cairo_pdf_surface_t *surface, cairo_pattern_t *pattern)
|
2005-02-01 20:47:43 +00:00
|
|
|
{
|
|
|
|
|
switch (pattern->type) {
|
2006-02-24 15:25:19 -08:00
|
|
|
case CAIRO_PATTERN_TYPE_SOLID:
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_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:
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_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:
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_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:
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern);
|
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
|
|
|
}
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_bool_t is_stroke)
|
|
|
|
|
{
|
|
|
|
|
if (surface->emitted_pattern.type == CAIRO_PATTERN_TYPE_SOLID) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%f %f %f ",
|
|
|
|
|
surface->emitted_pattern.red,
|
|
|
|
|
surface->emitted_pattern.green,
|
|
|
|
|
surface->emitted_pattern.blue);
|
|
|
|
|
|
|
|
|
|
if (is_stroke)
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "RG ");
|
|
|
|
|
else
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "rg ");
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/a%d gs\r\n",
|
|
|
|
|
surface->emitted_pattern.alpha);
|
|
|
|
|
} else {
|
|
|
|
|
if (is_stroke) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/Pattern CS /res%d SCN ",
|
|
|
|
|
surface->emitted_pattern.pattern);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/Pattern cs /res%d scn ",
|
|
|
|
|
surface->emitted_pattern.pattern);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/a%d gs ",
|
|
|
|
|
surface->emitted_pattern.alpha );
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "\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;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return _cairo_pdf_surface_write_page (surface);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_show_page (void *abstract_surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
|
|
|
|
cairo_int_status_t status;
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
status = _cairo_pdf_surface_write_page (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,
|
2006-06-06 16:54:03 -07:00
|
|
|
cairo_rectangle_int16_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-05-23 11:17:01 -07:00
|
|
|
typedef struct _pdf_path_info {
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_output_stream_t *output;
|
2006-04-25 04:04:10 -07:00
|
|
|
cairo_matrix_t *ctm_inverse;
|
2006-05-23 11:17:01 -07:00
|
|
|
} pdf_path_info_t;
|
2006-04-25 04:04:10 -07:00
|
|
|
|
|
|
|
|
static cairo_status_t
|
2006-05-23 11:23:27 -07:00
|
|
|
_cairo_pdf_path_move_to (void *closure, cairo_point_t *point)
|
2006-04-25 04:04:10 -07:00
|
|
|
{
|
2006-05-23 11:17:01 -07:00
|
|
|
pdf_path_info_t *info = closure;
|
2006-04-25 04:04:10 -07:00
|
|
|
double x = _cairo_fixed_to_double (point->x);
|
|
|
|
|
double y = _cairo_fixed_to_double (point->y);
|
|
|
|
|
|
2006-05-23 11:23:27 -07:00
|
|
|
if (info->ctm_inverse)
|
|
|
|
|
cairo_matrix_transform_point (info->ctm_inverse, &x, &y);
|
2006-04-25 04:04:10 -07:00
|
|
|
|
2006-05-23 11:17:01 -07:00
|
|
|
_cairo_output_stream_printf (info->output,
|
2006-04-25 04:04:10 -07:00
|
|
|
"%f %f m ", x, y);
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2006-05-23 11:23:27 -07:00
|
|
|
_cairo_pdf_path_line_to (void *closure, cairo_point_t *point)
|
2006-04-25 04:04:10 -07:00
|
|
|
{
|
2006-05-23 11:17:01 -07:00
|
|
|
pdf_path_info_t *info = closure;
|
2006-04-25 04:04:10 -07:00
|
|
|
double x = _cairo_fixed_to_double (point->x);
|
|
|
|
|
double y = _cairo_fixed_to_double (point->y);
|
|
|
|
|
|
2006-05-23 11:23:27 -07:00
|
|
|
if (info->ctm_inverse)
|
|
|
|
|
cairo_matrix_transform_point (info->ctm_inverse, &x, &y);
|
2006-04-25 04:04:10 -07:00
|
|
|
|
2006-05-23 11:17:01 -07:00
|
|
|
_cairo_output_stream_printf (info->output,
|
2006-04-25 04:04:10 -07:00
|
|
|
"%f %f l ", x, y);
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2006-05-23 11:23:27 -07:00
|
|
|
_cairo_pdf_path_curve_to (void *closure,
|
|
|
|
|
cairo_point_t *b,
|
|
|
|
|
cairo_point_t *c,
|
|
|
|
|
cairo_point_t *d)
|
2006-04-25 04:04:10 -07:00
|
|
|
{
|
2006-05-23 11:17:01 -07:00
|
|
|
pdf_path_info_t *info = closure;
|
2006-04-25 04:04:10 -07:00
|
|
|
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);
|
|
|
|
|
|
2006-05-23 11:23:27 -07:00
|
|
|
if (info->ctm_inverse) {
|
|
|
|
|
cairo_matrix_transform_point (info->ctm_inverse, &bx, &by);
|
|
|
|
|
cairo_matrix_transform_point (info->ctm_inverse, &cx, &cy);
|
|
|
|
|
cairo_matrix_transform_point (info->ctm_inverse, &dx, &dy);
|
|
|
|
|
}
|
2006-04-25 04:04:10 -07:00
|
|
|
|
2006-05-23 11:17:01 -07:00
|
|
|
_cairo_output_stream_printf (info->output,
|
2006-04-25 04:04:10 -07:00
|
|
|
"%f %f %f %f %f %f c ",
|
|
|
|
|
bx, by, cx, cy, dx, dy);
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2006-05-23 11:23:27 -07:00
|
|
|
_cairo_pdf_path_close_path (void *closure)
|
2006-04-25 04:04:10 -07:00
|
|
|
{
|
2006-05-23 11:17:01 -07:00
|
|
|
pdf_path_info_t *info = closure;
|
2006-04-25 04:04:10 -07:00
|
|
|
|
2006-05-23 11:17:01 -07:00
|
|
|
_cairo_output_stream_printf (info->output,
|
2006-04-25 04:04:10 -07:00
|
|
|
"h\r\n");
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-14 19:45:22 +00:00
|
|
|
static cairo_int_status_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_intersect_clip_path (void *abstract_surface,
|
2005-06-14 19:45:22 +00:00
|
|
|
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
|
|
|
{
|
2006-05-12 14:56:11 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2005-06-14 19:45:22 +00:00
|
|
|
cairo_status_t status;
|
|
|
|
|
const char *pdf_operator;
|
2006-05-23 11:23:27 -07:00
|
|
|
pdf_path_info_t info;
|
2005-06-14 19:45:22 +00:00
|
|
|
|
|
|
|
|
if (path == NULL) {
|
|
|
|
|
if (surface->has_clip)
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, "Q\r\n");
|
2005-06-14 19:45:22 +00:00
|
|
|
surface->has_clip = FALSE;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!surface->has_clip) {
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, "q ");
|
2005-06-14 19:45:22 +00:00
|
|
|
surface->has_clip = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-23 11:23:27 -07:00
|
|
|
info.output = surface->output;
|
|
|
|
|
info.ctm_inverse = NULL;
|
|
|
|
|
|
2005-06-14 19:45:22 +00:00
|
|
|
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-05-23 11:23:27 -07:00
|
|
|
&info);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-06-14 19:45:22 +00:00
|
|
|
"%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);
|
2006-08-08 06:04:01 -04:00
|
|
|
cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY);
|
2005-07-21 06:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t info;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
info = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
2006-10-15 23:11:30 +09:30
|
|
|
"<< /Creator (cairo %s (http://cairographics.org))\r\n"
|
|
|
|
|
" /Producer (cairo %s (http://cairographics.org))\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-10-15 23:11:30 +09:30
|
|
|
info.id,
|
|
|
|
|
cairo_version_string (),
|
|
|
|
|
cairo_version_string ());
|
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
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t page, *res, smask;
|
2006-05-15 10:04:53 -07:00
|
|
|
cairo_pdf_font_t font;
|
|
|
|
|
int num_pages, num_fonts, i;
|
2007-04-27 09:49:45 -07:00
|
|
|
int num_alphas, num_smasks, num_resources;
|
2006-05-15 10:00:18 -07:00
|
|
|
double alpha;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_update_object (surface, surface->pages_resource);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Pages\r\n"
|
|
|
|
|
" /Kids [ ",
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->pages_resource.id);
|
|
|
|
|
|
|
|
|
|
num_pages = _cairo_array_num_elements (&surface->pages);
|
2005-01-05 14:29:31 +00:00
|
|
|
for (i = 0; i < num_pages; i++) {
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_array_copy_element (&surface->pages, i, &page);
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "%d 0 R ", page.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, "]\r\n");
|
|
|
|
|
_cairo_output_stream_printf (surface->output, " /Count %d\r\n", num_pages);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-15 10:00:18 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, " /Resources <<\r\n");
|
|
|
|
|
|
|
|
|
|
num_alphas = _cairo_array_num_elements (&surface->alphas);
|
2007-04-27 09:49:45 -07:00
|
|
|
num_smasks = _cairo_array_num_elements (&surface->smasks);
|
|
|
|
|
if (num_alphas > 0 || num_smasks > 0) {
|
2006-05-15 10:00:18 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /ExtGState <<\r\n");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_alphas; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->alphas, i, &alpha);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /a%d << /CA %f /ca %f >>\r\n",
|
|
|
|
|
i, alpha, alpha);
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
for (i = 0; i < num_smasks; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->smasks, i, &smask);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /sm%d %d 0 R\r\n",
|
|
|
|
|
smask.id, smask.id);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-15 10:00:18 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_resources = _cairo_array_num_elements (&surface->patterns);
|
|
|
|
|
if (num_resources > 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Pattern <<");
|
|
|
|
|
for (i = 0; i < num_resources; i++) {
|
|
|
|
|
res = _cairo_array_index (&surface->patterns, i);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /res%d %d 0 R",
|
|
|
|
|
res->id, res->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_resources = _cairo_array_num_elements (&surface->xobjects);
|
|
|
|
|
if (num_resources > 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /XObject <<");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_resources; i++) {
|
|
|
|
|
res = _cairo_array_index (&surface->xobjects, i);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /res%d %d 0 R",
|
|
|
|
|
res->id, res->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
num_fonts = _cairo_array_num_elements (&surface->fonts);
|
2007-04-27 09:49:45 -07:00
|
|
|
if (num_fonts > 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output," /Font <<\r\n");
|
|
|
|
|
num_fonts = _cairo_array_num_elements (&surface->fonts);
|
|
|
|
|
for (i = 0; i < num_fonts; i++) {
|
|
|
|
|
_cairo_array_copy_element (&surface->fonts, i, &font);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /CairoFont-%d-%d %d 0 R\r\n",
|
|
|
|
|
font.font_id,
|
|
|
|
|
font.subset_id,
|
|
|
|
|
font.subset_resource.id);
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output, " >>\r\n");
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
2006-05-15 10:00:18 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" >>\r\n");
|
|
|
|
|
|
2005-01-05 14:29:31 +00:00
|
|
|
/* TODO: Figure out wich other defaults to be inherited by /Page
|
|
|
|
|
* objects. */
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
2006-05-16 01:04:16 -07:00
|
|
|
"endobj\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-07 22:35:59 +10:30
|
|
|
static cairo_pdf_resource_t
|
2007-04-10 13:53:58 -07:00
|
|
|
_cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface,
|
2007-04-20 22:44:04 +09:30
|
|
|
cairo_scaled_font_subset_t *font_subset,
|
|
|
|
|
cairo_bool_t is_composite)
|
2007-02-07 22:35:59 +10:30
|
|
|
{
|
|
|
|
|
const cairo_scaled_font_backend_t *backend;
|
|
|
|
|
cairo_pdf_resource_t stream;
|
2007-04-20 22:44:04 +09:30
|
|
|
unsigned int i, num_bfchar;
|
2007-04-10 13:51:46 -07:00
|
|
|
cairo_status_t status;
|
2007-02-07 22:35:59 +10:30
|
|
|
|
|
|
|
|
if (font_subset->to_unicode == NULL) {
|
|
|
|
|
stream.id = 0;
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_cairo_truetype_create_glyph_to_unicode_map (font_subset) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
|
backend = font_subset->scaled_font->backend;
|
|
|
|
|
if (backend->map_glyphs_to_unicode == NULL) {
|
|
|
|
|
stream.id = 0;
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
backend->map_glyphs_to_unicode (font_subset->scaled_font, font_subset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream = _cairo_pdf_surface_open_stream (surface, FALSE, NULL);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/CIDInit /ProcSet findresource begin\r\n"
|
|
|
|
|
"12 dict begin\r\n"
|
|
|
|
|
"begincmap\r\n"
|
|
|
|
|
"/CIDSystemInfo\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
"<< /Registry (Adobe)\r\n"
|
|
|
|
|
" /Ordering (UCS)\r\n"
|
2007-02-07 22:35:59 +10:30
|
|
|
" /Supplement 0\r\n"
|
|
|
|
|
">> def\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
"/CMapName /Adobe-Identity-UCS def\r\n"
|
2007-02-07 22:35:59 +10:30
|
|
|
"/CMapType 2 def\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
"1 begincodespacerange\r\n");
|
|
|
|
|
|
|
|
|
|
if (is_composite) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"<0000> <ffff>\r\n");
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"<00> <ff>\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"endcodespacerange\r\n");
|
2007-02-07 22:35:59 +10:30
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
num_bfchar = font_subset->num_glyphs - 1;
|
2007-02-07 22:35:59 +10:30
|
|
|
/* The CMap specification has a limit of 100 characters per beginbfchar operator */
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d beginbfchar\r\n",
|
2007-04-20 22:44:04 +09:30
|
|
|
num_bfchar > 100 ? 100 : num_bfchar);
|
|
|
|
|
for (i = 0; i < num_bfchar; i++) {
|
2007-02-07 22:35:59 +10:30
|
|
|
if (i != 0 && i % 100 == 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"endbfchar\r\n"
|
|
|
|
|
"%d beginbfchar\r\n",
|
2007-04-20 22:44:04 +09:30
|
|
|
num_bfchar - i > 100 ? 100 : num_bfchar - i);
|
|
|
|
|
}
|
|
|
|
|
if (is_composite) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"<%04x> <%04x>\r\n",
|
|
|
|
|
i + 1, font_subset->to_unicode[i + 1]);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"<%02x> <%04x>\r\n",
|
|
|
|
|
i + 1, font_subset->to_unicode[i + 1]);
|
2007-02-07 22:35:59 +10:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"endbfchar\r\n");
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"endcmap\r\n"
|
|
|
|
|
"CMapName currentdict /CMap defineresource pop\r\n"
|
|
|
|
|
"end\r\n"
|
2007-02-07 22:35:59 +10:30
|
|
|
"end\r\n");
|
|
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
stream.id = 0;
|
2007-02-07 22:35:59 +10:30
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-27 00:00:24 +09:30
|
|
|
static cairo_status_t
|
2007-04-20 22:44:04 +09:30
|
|
|
_cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset,
|
|
|
|
|
cairo_cff_subset_t *subset)
|
2006-10-27 00:00:24 +09:30
|
|
|
{
|
2007-04-20 22:44:04 +09:30
|
|
|
cairo_pdf_resource_t stream, descriptor, cidfont_dict;
|
|
|
|
|
cairo_pdf_resource_t subset_resource, to_unicode_stream;
|
2006-10-27 00:00:24 +09:30
|
|
|
cairo_pdf_font_t font;
|
|
|
|
|
unsigned long compressed_length;
|
|
|
|
|
char *compressed;
|
|
|
|
|
unsigned int i;
|
2007-04-20 22:44:04 +09:30
|
|
|
cairo_status_t status;
|
2006-10-27 00:00:24 +09:30
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
compressed = compress_dup (subset->data, subset->data_length, &compressed_length);
|
|
|
|
|
if (compressed == NULL)
|
2006-10-27 00:00:24 +09:30
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
|
|
stream = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Filter /FlateDecode\r\n"
|
|
|
|
|
" /Length %lu\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
" /Subtype /CIDFontType0C\r\n"
|
2006-10-27 00:00:24 +09:30
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n",
|
|
|
|
|
stream.id,
|
|
|
|
|
compressed_length);
|
|
|
|
|
_cairo_output_stream_write (surface->output, compressed, compressed_length);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"\r\n"
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
free (compressed);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset, TRUE);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
2006-10-27 00:00:24 +09:30
|
|
|
descriptor = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /FontDescriptor\r\n"
|
|
|
|
|
" /FontName /%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"
|
|
|
|
|
" /FontFile3 %u 0 R\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
descriptor.id,
|
2007-04-20 22:44:04 +09:30
|
|
|
subset->base_font,
|
|
|
|
|
subset->x_min,
|
|
|
|
|
subset->y_min,
|
|
|
|
|
subset->x_max,
|
|
|
|
|
subset->y_max,
|
|
|
|
|
subset->ascent,
|
|
|
|
|
subset->descent,
|
2006-10-27 00:00:24 +09:30
|
|
|
stream.id);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
cidfont_dict = _cairo_pdf_surface_new_object (surface);
|
2006-10-27 00:00:24 +09:30
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /CIDFontType0\r\n"
|
|
|
|
|
" /BaseFont /%s\r\n"
|
|
|
|
|
" /CIDSystemInfo\r\n"
|
|
|
|
|
" << /Registry (Adobe)\r\n"
|
|
|
|
|
" /Ordering (Identity)\r\n"
|
|
|
|
|
" /Supplement 0\r\n"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
" /FontDescriptor %d 0 R\r\n"
|
|
|
|
|
" /W [0 [",
|
|
|
|
|
cidfont_dict.id,
|
|
|
|
|
subset->base_font,
|
|
|
|
|
descriptor.id);
|
2006-10-27 00:00:24 +09:30
|
|
|
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" %d",
|
2007-04-20 22:44:04 +09:30
|
|
|
subset->widths[i]);
|
2006-10-27 00:00:24 +09:30
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
" ]]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
subset_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /Type0\r\n"
|
|
|
|
|
" /BaseFont /%s\r\n"
|
|
|
|
|
" /Encoding /Identity-H\r\n"
|
|
|
|
|
" /DescendantFonts [ %d 0 R]\r\n",
|
|
|
|
|
subset_resource.id,
|
|
|
|
|
subset->base_font,
|
|
|
|
|
cidfont_dict.id);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
|
|
|
|
if (to_unicode_stream.id != 0)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
" /ToUnicode %d 0 R\r\n",
|
2007-02-07 22:35:59 +10:30
|
|
|
to_unicode_stream.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-10-27 00:00:24 +09:30
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
font.font_id = font_subset->font_id;
|
|
|
|
|
font.subset_id = font_subset->subset_id;
|
|
|
|
|
font.subset_resource = subset_resource;
|
2007-04-08 21:26:33 +01:00
|
|
|
status = _cairo_array_append (&surface->fonts, &font);
|
2006-10-27 00:00:24 +09:30
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_cff_subset_t subset;
|
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
|
|
snprintf (name, sizeof name, "CairoFont-%d-%d",
|
|
|
|
|
font_subset->font_id, font_subset->subset_id);
|
|
|
|
|
status = _cairo_cff_subset_init (&subset, name, font_subset);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset);
|
|
|
|
|
|
2006-10-27 00:00:24 +09:30
|
|
|
_cairo_cff_subset_fini (&subset);
|
|
|
|
|
|
2007-04-08 21:26:33 +01:00
|
|
|
return status;
|
2006-10-27 00:00:24 +09:30
|
|
|
}
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_cff_fallback_font (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_cff_subset_t subset;
|
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
|
|
snprintf (name, sizeof name, "CairoFont-%d-%d",
|
|
|
|
|
font_subset->font_id, font_subset->subset_id);
|
|
|
|
|
status = _cairo_cff_fallback_init (&subset, name, font_subset);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset);
|
|
|
|
|
|
|
|
|
|
_cairo_cff_fallback_fini (&subset);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-17 17:17:02 -04:00
|
|
|
static cairo_status_t
|
2006-09-05 15:57:47 -04:00
|
|
|
_cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset,
|
|
|
|
|
cairo_type1_subset_t *subset)
|
2006-05-17 17:17:02 -04:00
|
|
|
{
|
2007-02-07 22:35:59 +10:30
|
|
|
cairo_pdf_resource_t stream, descriptor, subset_resource, to_unicode_stream;
|
2006-05-17 17:17:02 -04:00
|
|
|
cairo_pdf_font_t font;
|
|
|
|
|
unsigned long length, compressed_length;
|
|
|
|
|
char *compressed;
|
2006-08-07 15:18:38 -07:00
|
|
|
unsigned int i;
|
2006-05-17 17:17:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* We ignore the zero-trailer and set Length3 to 0. */
|
2006-09-05 15:57:47 -04:00
|
|
|
length = subset->header_length + subset->data_length;
|
|
|
|
|
compressed = compress_dup (subset->data, length, &compressed_length);
|
|
|
|
|
if (compressed == NULL)
|
2006-05-17 17:17:02 -04:00
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
|
|
stream = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Filter /FlateDecode\r\n"
|
|
|
|
|
" /Length %lu\r\n"
|
|
|
|
|
" /Length1 %lu\r\n"
|
|
|
|
|
" /Length2 %lu\r\n"
|
|
|
|
|
" /Length3 0\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n",
|
|
|
|
|
stream.id,
|
|
|
|
|
compressed_length,
|
2006-09-05 15:57:47 -04:00
|
|
|
subset->header_length,
|
|
|
|
|
subset->data_length);
|
2006-05-17 17:17:02 -04:00
|
|
|
_cairo_output_stream_write (surface->output, compressed, compressed_length);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"\r\n"
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
free (compressed);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset, FALSE);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
2006-05-17 17:17:02 -04:00
|
|
|
descriptor = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /FontDescriptor\r\n"
|
|
|
|
|
" /FontName /%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"
|
|
|
|
|
" /FontFile %u 0 R\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
descriptor.id,
|
2006-09-05 15:57:47 -04:00
|
|
|
subset->base_font,
|
|
|
|
|
subset->x_min,
|
|
|
|
|
subset->y_min,
|
|
|
|
|
subset->x_max,
|
|
|
|
|
subset->y_max,
|
|
|
|
|
subset->ascent,
|
|
|
|
|
subset->descent,
|
2006-05-17 17:17:02 -04:00
|
|
|
stream.id);
|
|
|
|
|
|
|
|
|
|
subset_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /Type1\r\n"
|
|
|
|
|
" /BaseFont /%s\r\n"
|
|
|
|
|
" /FirstChar 0\r\n"
|
|
|
|
|
" /LastChar %d\r\n"
|
|
|
|
|
" /FontDescriptor %d 0 R\r\n"
|
|
|
|
|
" /Widths [",
|
|
|
|
|
subset_resource.id,
|
2006-09-05 15:57:47 -04:00
|
|
|
subset->base_font,
|
2006-09-05 14:19:48 -04:00
|
|
|
font_subset->num_glyphs - 1,
|
2006-05-17 17:17:02 -04:00
|
|
|
descriptor.id);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" %d",
|
2006-09-05 15:57:47 -04:00
|
|
|
subset->widths[i]);
|
2006-05-17 17:17:02 -04:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-02-07 22:35:59 +10:30
|
|
|
" ]\r\n");
|
|
|
|
|
|
|
|
|
|
if (to_unicode_stream.id != 0)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /ToUnicode %d 0 R\r\n",
|
|
|
|
|
to_unicode_stream.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-05-17 17:17:02 -04:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
font.font_id = font_subset->font_id;
|
|
|
|
|
font.subset_id = font_subset->subset_id;
|
|
|
|
|
font.subset_resource = subset_resource;
|
2007-04-08 21:26:33 +01:00
|
|
|
return _cairo_array_append (&surface->fonts, &font);
|
2006-05-17 17:17:02 -04:00
|
|
|
}
|
2006-09-05 15:57:47 -04:00
|
|
|
|
|
|
|
|
#if CAIRO_HAS_FT_FONT
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_type1_font_subset (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_type1_subset_t subset;
|
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
|
|
snprintf (name, sizeof name, "CairoFont-%d-%d",
|
|
|
|
|
font_subset->font_id, font_subset->subset_id);
|
|
|
|
|
status = _cairo_type1_subset_init (&subset, name, font_subset, FALSE);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset);
|
|
|
|
|
|
|
|
|
|
_cairo_type1_subset_fini (&subset);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2006-08-02 19:12:51 -04:00
|
|
|
#endif
|
2006-05-17 17:17:02 -04:00
|
|
|
|
2006-09-05 15:57:47 -04:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_type1_subset_t subset;
|
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
|
|
snprintf (name, sizeof name, "CairoFont-%d-%d",
|
|
|
|
|
font_subset->font_id, font_subset->subset_id);
|
2006-10-15 23:07:38 +09:30
|
|
|
status = _cairo_type1_fallback_init_binary (&subset, name, font_subset);
|
2006-09-05 15:57:47 -04:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset);
|
|
|
|
|
|
|
|
|
|
_cairo_type1_fallback_fini (&subset);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-07 23:10:47 +10:30
|
|
|
#define PDF_UNITS_PER_EM 1000
|
2007-02-04 23:47:28 +10:30
|
|
|
|
2006-05-16 16:42:44 -04:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
|
|
|
|
{
|
2007-04-20 22:44:04 +09:30
|
|
|
cairo_pdf_resource_t stream, descriptor, cidfont_dict;
|
|
|
|
|
cairo_pdf_resource_t subset_resource, to_unicode_stream;
|
2006-05-16 19:01:15 -04:00
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_pdf_font_t font;
|
|
|
|
|
cairo_truetype_subset_t subset;
|
|
|
|
|
unsigned long compressed_length;
|
|
|
|
|
char *compressed;
|
2006-08-07 15:18:38 -07:00
|
|
|
unsigned int i;
|
2006-05-16 19:01:15 -04:00
|
|
|
|
|
|
|
|
status = _cairo_truetype_subset_init (&subset, font_subset);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
compressed = compress_dup (subset.data, subset.data_length,
|
|
|
|
|
&compressed_length);
|
|
|
|
|
if (compressed == NULL) {
|
|
|
|
|
_cairo_truetype_subset_fini (&subset);
|
|
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Filter /FlateDecode\r\n"
|
|
|
|
|
" /Length %lu\r\n"
|
|
|
|
|
" /Length1 %lu\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"stream\r\n",
|
|
|
|
|
stream.id,
|
|
|
|
|
compressed_length,
|
|
|
|
|
subset.data_length);
|
|
|
|
|
_cairo_output_stream_write (surface->output, compressed, compressed_length);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"\r\n"
|
|
|
|
|
"endstream\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
free (compressed);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset, TRUE);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
2006-05-16 19:01:15 -04:00
|
|
|
descriptor = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /FontDescriptor\r\n"
|
2007-02-07 22:35:59 +10:30
|
|
|
" /FontName /%s\r\n"
|
2006-05-16 19:01:15 -04:00
|
|
|
" /Flags 4\r\n"
|
|
|
|
|
" /FontBBox [ %ld %ld %ld %ld ]\r\n"
|
|
|
|
|
" /ItalicAngle 0\r\n"
|
|
|
|
|
" /Ascent %ld\r\n"
|
|
|
|
|
" /Descent %ld\r\n"
|
2007-02-04 23:47:28 +10:30
|
|
|
" /CapHeight %ld\r\n"
|
2006-05-16 19:01:15 -04:00
|
|
|
" /StemV 80\r\n"
|
|
|
|
|
" /StemH 80\r\n"
|
|
|
|
|
" /FontFile2 %u 0 R\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
|
|
|
|
descriptor.id,
|
|
|
|
|
subset.base_font,
|
2007-02-07 23:10:47 +10:30
|
|
|
(long)(subset.x_min*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.y_min*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.x_max*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.y_max*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.ascent*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.descent*PDF_UNITS_PER_EM),
|
|
|
|
|
(long)(subset.y_max*PDF_UNITS_PER_EM),
|
2006-05-16 19:01:15 -04:00
|
|
|
stream.id);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
cidfont_dict = _cairo_pdf_surface_new_object (surface);
|
2007-02-04 19:00:16 +10:30
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /CIDFontType2\r\n"
|
|
|
|
|
" /BaseFont /%s\r\n"
|
|
|
|
|
" /CIDSystemInfo\r\n"
|
|
|
|
|
" << /Registry (Adobe)\r\n"
|
|
|
|
|
" /Ordering (Identity)\r\n"
|
|
|
|
|
" /Supplement 0\r\n"
|
|
|
|
|
" >>\r\n"
|
|
|
|
|
" /FontDescriptor %d 0 R\r\n"
|
|
|
|
|
" /W [0 [",
|
|
|
|
|
cidfont_dict.id,
|
|
|
|
|
subset.base_font,
|
|
|
|
|
descriptor.id);
|
2007-02-04 19:00:16 +10:30
|
|
|
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
2007-04-20 22:44:04 +09:30
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" %ld",
|
|
|
|
|
(long)(subset.widths[i]*PDF_UNITS_PER_EM));
|
2007-02-04 19:00:16 +10:30
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
" ]]\r\n"
|
2007-02-04 19:00:16 +10:30
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
2006-05-16 19:01:15 -04:00
|
|
|
subset_resource = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
" /Subtype /Type0\r\n"
|
2006-05-16 19:01:15 -04:00
|
|
|
" /BaseFont /%s\r\n"
|
2007-04-20 22:44:04 +09:30
|
|
|
" /Encoding /Identity-H\r\n"
|
|
|
|
|
" /DescendantFonts [ %d 0 R]\r\n",
|
2006-05-16 19:01:15 -04:00
|
|
|
subset_resource.id,
|
|
|
|
|
subset.base_font,
|
2007-04-20 22:44:04 +09:30
|
|
|
cidfont_dict.id);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
|
|
|
|
if (to_unicode_stream.id != 0)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
" /ToUnicode %d 0 R\r\n",
|
2007-02-07 22:35:59 +10:30
|
|
|
to_unicode_stream.id);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-05-16 19:01:15 -04:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
font.font_id = font_subset->font_id;
|
|
|
|
|
font.subset_id = font_subset->subset_id;
|
|
|
|
|
font.subset_resource = subset_resource;
|
2007-04-08 21:26:33 +01:00
|
|
|
status = _cairo_array_append (&surface->fonts, &font);
|
2006-05-16 19:01:15 -04:00
|
|
|
|
|
|
|
|
_cairo_truetype_subset_fini (&subset);
|
|
|
|
|
|
2007-04-08 21:26:33 +01:00
|
|
|
return status;
|
2006-05-16 16:42:44 -04:00
|
|
|
}
|
|
|
|
|
|
2006-06-13 12:48:00 -07:00
|
|
|
static cairo_int_status_t
|
2006-06-20 23:12:58 -07:00
|
|
|
_cairo_pdf_surface_emit_outline_glyph (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_t *scaled_font,
|
|
|
|
|
unsigned long glyph_index,
|
|
|
|
|
cairo_pdf_resource_t *glyph_ret)
|
2006-05-15 10:04:53 -07:00
|
|
|
{
|
|
|
|
|
cairo_scaled_glyph_t *scaled_glyph;
|
2006-05-23 11:23:27 -07:00
|
|
|
pdf_path_info_t info;
|
2006-06-20 23:12:58 -07:00
|
|
|
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
2006-05-15 10:04:53 -07:00
|
|
|
|
|
|
|
|
status = _cairo_scaled_glyph_lookup (scaled_font,
|
2006-06-13 12:48:00 -07:00
|
|
|
glyph_index,
|
2006-05-15 10:04:53 -07:00
|
|
|
CAIRO_SCALED_GLYPH_INFO_METRICS|
|
|
|
|
|
CAIRO_SCALED_GLYPH_INFO_PATH,
|
|
|
|
|
&scaled_glyph);
|
|
|
|
|
if (status)
|
2006-06-13 12:48:00 -07:00
|
|
|
return status;
|
2006-05-15 10:04:53 -07:00
|
|
|
|
2006-09-24 00:55:20 +09:30
|
|
|
*glyph_ret = _cairo_pdf_surface_open_stream (surface, FALSE, NULL);
|
2006-06-20 23:12:58 -07:00
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-06-13 12:48:00 -07:00
|
|
|
"0 0 %f %f %f %f d1\r\n",
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
|
|
|
|
|
-_cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
|
|
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p2.x),
|
|
|
|
|
-_cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
|
|
|
|
|
|
2006-05-23 11:23:27 -07:00
|
|
|
info.output = surface->output;
|
|
|
|
|
info.ctm_inverse = NULL;
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
status = _cairo_path_fixed_interpret (scaled_glyph->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-05-23 11:23:27 -07:00
|
|
|
&info);
|
2006-05-15 10:04:53 -07:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" f");
|
|
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
return _cairo_pdf_surface_close_stream (surface);
|
2006-06-13 12:48:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
2006-06-20 23:12:58 -07:00
|
|
|
_cairo_pdf_surface_emit_bitmap_glyph (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_t *scaled_font,
|
|
|
|
|
unsigned long glyph_index,
|
2007-02-11 21:50:46 +10:30
|
|
|
cairo_pdf_resource_t *glyph_ret,
|
|
|
|
|
cairo_box_t *bbox,
|
|
|
|
|
double *width)
|
2006-06-13 12:48:00 -07:00
|
|
|
{
|
|
|
|
|
cairo_scaled_glyph_t *scaled_glyph;
|
|
|
|
|
cairo_status_t status;
|
2006-06-21 17:23:35 -07:00
|
|
|
cairo_image_surface_t *image;
|
|
|
|
|
unsigned char *row, *byte;
|
2007-01-11 17:59:16 -05:00
|
|
|
int rows, cols;
|
2007-02-11 21:50:46 +10:30
|
|
|
double x_advance, y_advance;
|
2006-06-13 12:48:00 -07:00
|
|
|
|
|
|
|
|
status = _cairo_scaled_glyph_lookup (scaled_font,
|
|
|
|
|
glyph_index,
|
|
|
|
|
CAIRO_SCALED_GLYPH_INFO_METRICS|
|
|
|
|
|
CAIRO_SCALED_GLYPH_INFO_SURFACE,
|
|
|
|
|
&scaled_glyph);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-02-11 21:50:46 +10:30
|
|
|
x_advance = scaled_glyph->metrics.x_advance;
|
|
|
|
|
y_advance = scaled_glyph->metrics.y_advance;
|
|
|
|
|
cairo_matrix_transform_distance (&scaled_font->ctm, &x_advance, &y_advance);
|
|
|
|
|
*bbox = scaled_glyph->bbox;
|
|
|
|
|
*width = x_advance;
|
|
|
|
|
|
2006-06-21 17:23:35 -07:00
|
|
|
image = scaled_glyph->surface;
|
2006-08-17 15:23:32 -07:00
|
|
|
if (image->format != CAIRO_FORMAT_A1) {
|
|
|
|
|
image = _cairo_image_surface_clone (image, CAIRO_FORMAT_A1);
|
2006-08-18 16:12:43 -07:00
|
|
|
if (cairo_surface_status (&image->base))
|
|
|
|
|
return cairo_surface_status (&image->base);
|
2006-08-17 15:23:32 -07:00
|
|
|
}
|
2006-06-21 17:23:35 -07:00
|
|
|
|
2007-02-11 21:57:43 +10:30
|
|
|
*glyph_ret = _cairo_pdf_surface_open_stream (surface, TRUE, NULL);
|
2006-06-20 23:12:58 -07:00
|
|
|
|
2006-06-13 12:48:00 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-02-11 21:50:46 +10:30
|
|
|
"%f 0 %f %f %f %f d1\r\n",
|
|
|
|
|
x_advance,
|
2006-06-13 12:48:00 -07:00
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
|
2007-02-11 21:50:46 +10:30
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
|
2006-06-13 12:48:00 -07:00
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p2.x),
|
2007-02-11 21:50:46 +10:30
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
|
2006-06-13 12:48:00 -07:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-02-11 21:50:46 +10:30
|
|
|
"%f 0 0 %f %f %f cm\r\n",
|
2006-06-13 12:48:00 -07:00
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p2.x) - _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
|
2006-06-21 17:23:35 -07:00
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p1.y) - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
|
|
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
|
|
|
|
|
_cairo_fixed_to_double (scaled_glyph->bbox.p2.y));
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"BI\r\n"
|
|
|
|
|
"/IM true\r\n"
|
|
|
|
|
"/W %d\r\n"
|
|
|
|
|
"/H %d\r\n"
|
|
|
|
|
"/BPC 1\r\n"
|
|
|
|
|
"/D [1 0]\r\n",
|
|
|
|
|
image->width,
|
|
|
|
|
image->height);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"ID ");
|
|
|
|
|
for (row = image->data, rows = image->height; rows; row += image->stride, rows--) {
|
|
|
|
|
for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) {
|
|
|
|
|
unsigned char output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
|
|
|
|
|
_cairo_output_stream_write (surface->output, &output_byte, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"\r\nEI\r\n");
|
2006-06-13 12:48:00 -07:00
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
2006-06-20 23:12:58 -07:00
|
|
|
|
2006-08-17 15:23:32 -07:00
|
|
|
if (image != scaled_glyph->surface)
|
|
|
|
|
cairo_surface_destroy (&image->base);
|
|
|
|
|
|
2006-06-13 12:48:00 -07:00
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_emit_glyph (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_t *scaled_font,
|
|
|
|
|
unsigned long glyph_index,
|
2007-02-11 21:50:46 +10:30
|
|
|
cairo_pdf_resource_t *glyph_ret,
|
|
|
|
|
cairo_box_t *bbox,
|
|
|
|
|
double *width)
|
2006-06-13 12:48:00 -07:00
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
2006-06-20 23:12:58 -07:00
|
|
|
status = _cairo_pdf_surface_emit_outline_glyph (surface,
|
|
|
|
|
scaled_font,
|
|
|
|
|
glyph_index,
|
|
|
|
|
glyph_ret);
|
2006-06-13 12:48:00 -07:00
|
|
|
if (status == CAIRO_INT_STATUS_UNSUPPORTED)
|
2006-06-20 23:12:58 -07:00
|
|
|
status = _cairo_pdf_surface_emit_bitmap_glyph (surface,
|
|
|
|
|
scaled_font,
|
|
|
|
|
glyph_index,
|
2007-02-11 21:50:46 +10:30
|
|
|
glyph_ret,
|
|
|
|
|
bbox,
|
|
|
|
|
width);
|
2006-05-15 10:04:53 -07:00
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
|
_cairo_surface_set_error (&surface->base, status);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 16:42:44 -04:00
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface,
|
|
|
|
|
cairo_scaled_font_subset_t *font_subset)
|
2006-05-15 10:04:53 -07:00
|
|
|
{
|
2007-04-10 17:16:39 -07:00
|
|
|
cairo_status_t status;
|
2007-02-07 22:35:59 +10:30
|
|
|
cairo_pdf_resource_t *glyphs, encoding, char_procs, subset_resource, to_unicode_stream;
|
2006-05-15 10:04:53 -07:00
|
|
|
cairo_pdf_font_t font;
|
2006-05-16 22:53:05 -04:00
|
|
|
cairo_matrix_t matrix;
|
2007-02-11 21:50:46 +10:30
|
|
|
double *widths;
|
2006-08-07 15:18:38 -07:00
|
|
|
unsigned int i;
|
2007-02-11 21:50:46 +10:30
|
|
|
cairo_box_t font_bbox = {{0,0},{0,0}};
|
|
|
|
|
cairo_box_t bbox = {{0,0},{0,0}};
|
2006-05-15 10:04:53 -07:00
|
|
|
|
|
|
|
|
glyphs = malloc (font_subset->num_glyphs * sizeof (cairo_pdf_resource_t));
|
|
|
|
|
if (glyphs == NULL) {
|
|
|
|
|
_cairo_surface_set_error (&surface->base, CAIRO_STATUS_NO_MEMORY);
|
2006-05-16 16:42:44 -04:00
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
2007-02-11 21:50:46 +10:30
|
|
|
widths = malloc (font_subset->num_glyphs * sizeof (double));
|
|
|
|
|
if (widths == NULL) {
|
|
|
|
|
free (glyphs);
|
|
|
|
|
_cairo_surface_set_error (&surface->base, CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++) {
|
|
|
|
|
_cairo_pdf_surface_emit_glyph (surface,
|
|
|
|
|
font_subset->scaled_font,
|
2006-06-13 12:48:00 -07:00
|
|
|
font_subset->glyphs[i],
|
2007-02-11 21:50:46 +10:30
|
|
|
&glyphs[i],
|
|
|
|
|
&bbox,
|
|
|
|
|
&widths[i]);
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
font_bbox.p1.x = bbox.p1.x;
|
|
|
|
|
font_bbox.p1.y = bbox.p1.y;
|
|
|
|
|
font_bbox.p2.x = bbox.p2.x;
|
|
|
|
|
font_bbox.p2.y = bbox.p2.y;
|
|
|
|
|
} else {
|
|
|
|
|
if (bbox.p1.x < font_bbox.p1.x)
|
|
|
|
|
font_bbox.p1.x = bbox.p1.x;
|
|
|
|
|
if (bbox.p1.y < font_bbox.p1.y)
|
|
|
|
|
font_bbox.p1.y = bbox.p1.y;
|
|
|
|
|
if (bbox.p2.x > font_bbox.p2.x)
|
|
|
|
|
font_bbox.p2.x = bbox.p2.x;
|
|
|
|
|
if (bbox.p2.y > font_bbox.p2.y)
|
|
|
|
|
font_bbox.p2.y = bbox.p2.y;
|
|
|
|
|
}
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
encoding = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Encoding\r\n"
|
|
|
|
|
" /Differences [0", encoding.id);
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /%d", i);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"]\r\n"
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
char_procs = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<<\r\n", char_procs.id);
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /%d %d 0 R\r\n",
|
|
|
|
|
i, glyphs[i].id);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
2006-08-08 15:30:56 -04:00
|
|
|
free (glyphs);
|
|
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset, FALSE);
|
2007-02-07 22:35:59 +10:30
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
subset_resource = _cairo_pdf_surface_new_object (surface);
|
2006-05-16 22:53:05 -04:00
|
|
|
matrix = font_subset->scaled_font->scale;
|
2007-04-10 17:16:39 -07:00
|
|
|
status = cairo_matrix_invert (&matrix);
|
|
|
|
|
/* _cairo_scaled_font_init ensures the matrix is invertible */
|
|
|
|
|
assert (status == CAIRO_STATUS_SUCCESS);
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Font\r\n"
|
|
|
|
|
" /Subtype /Type3\r\n"
|
2007-02-11 21:50:46 +10:30
|
|
|
" /FontBBox [%f %f %f %f]\r\n"
|
2006-05-16 22:53:05 -04:00
|
|
|
" /FontMatrix [ %f %f %f %f 0 0 ]\r\n"
|
2006-05-15 10:04:53 -07:00
|
|
|
" /Encoding %d 0 R\r\n"
|
|
|
|
|
" /CharProcs %d 0 R\r\n"
|
|
|
|
|
" /FirstChar 0\r\n"
|
|
|
|
|
" /LastChar %d\r\n",
|
|
|
|
|
subset_resource.id,
|
2007-02-11 21:50:46 +10:30
|
|
|
_cairo_fixed_to_double (font_bbox.p1.x),
|
|
|
|
|
_cairo_fixed_to_double (font_bbox.p1.y),
|
|
|
|
|
_cairo_fixed_to_double (font_bbox.p2.x),
|
|
|
|
|
_cairo_fixed_to_double (font_bbox.p2.y),
|
2006-05-16 22:53:05 -04:00
|
|
|
matrix.xx,
|
|
|
|
|
matrix.yx,
|
|
|
|
|
-matrix.xy,
|
|
|
|
|
-matrix.yy,
|
2006-05-15 10:04:53 -07:00
|
|
|
encoding.id,
|
|
|
|
|
char_procs.id,
|
|
|
|
|
font_subset->num_glyphs - 1);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /Widths [");
|
|
|
|
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
2007-02-11 21:50:46 +10:30
|
|
|
_cairo_output_stream_printf (surface->output, " %f", widths[i]);
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"]\r\n");
|
2007-02-11 21:50:46 +10:30
|
|
|
free (widths);
|
2006-05-15 10:04:53 -07:00
|
|
|
|
2007-02-07 22:35:59 +10:30
|
|
|
if (to_unicode_stream.id != 0)
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /ToUnicode %d 0 R\r\n",
|
|
|
|
|
to_unicode_stream.id);
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
|
|
|
|
|
|
|
|
|
font.font_id = font_subset->font_id;
|
|
|
|
|
font.subset_id = font_subset->subset_id;
|
|
|
|
|
font.subset_resource = subset_resource;
|
2007-04-08 21:26:33 +01:00
|
|
|
return _cairo_array_append (&surface->fonts, &font);
|
2006-05-16 16:42:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-02-21 00:32:07 +10:30
|
|
|
_cairo_pdf_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_subset,
|
|
|
|
|
void *closure)
|
2006-05-16 16:42:44 -04:00
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = closure;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
2007-04-20 22:45:12 +09:30
|
|
|
if (font_subset->is_composite) {
|
|
|
|
|
status = _cairo_pdf_surface_emit_cff_font_subset (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_truetype_font_subset (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
status = _cairo_pdf_surface_emit_cff_fallback_font (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2006-08-02 19:12:51 -04:00
|
|
|
#if CAIRO_HAS_FT_FONT
|
2007-04-20 22:45:12 +09:30
|
|
|
status = _cairo_pdf_surface_emit_type1_font_subset (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
2006-08-02 19:12:51 -04:00
|
|
|
#endif
|
2006-05-17 17:17:02 -04:00
|
|
|
|
2007-04-20 22:45:12 +09:30
|
|
|
status = _cairo_pdf_surface_emit_type1_fallback_font (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-02-21 00:32:07 +10:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_pdf_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subset,
|
|
|
|
|
void *closure)
|
|
|
|
|
{
|
|
|
|
|
cairo_pdf_surface_t *surface = closure;
|
|
|
|
|
cairo_status_t status;
|
2006-09-05 15:57:47 -04:00
|
|
|
|
2006-05-16 16:42:44 -04:00
|
|
|
status = _cairo_pdf_surface_emit_type3_font_subset (surface, font_subset);
|
|
|
|
|
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
|
|
|
|
return;
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
2007-02-21 00:32:07 +10:30
|
|
|
status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets,
|
|
|
|
|
_cairo_pdf_surface_emit_unscaled_font_subset,
|
|
|
|
|
surface);
|
|
|
|
|
status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets,
|
|
|
|
|
_cairo_pdf_surface_emit_scaled_font_subset,
|
|
|
|
|
surface);
|
2006-05-15 10:04:53 -07:00
|
|
|
_cairo_scaled_font_subsets_destroy (surface->font_subsets);
|
|
|
|
|
surface->font_subsets = NULL;
|
|
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 13:31:12 -07:00
|
|
|
static cairo_pdf_resource_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t catalog;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
catalog = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%d 0 obj\r\n"
|
|
|
|
|
"<< /Type /Catalog\r\n"
|
2006-05-12 14:56:11 -07:00
|
|
|
" /Pages %d 0 R\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n",
|
2006-05-12 13:31:12 -07:00
|
|
|
catalog.id,
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->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
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface)
|
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
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
num_objects = _cairo_array_num_elements (&surface->objects);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
offset = _cairo_output_stream_get_position (surface->output);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"xref\r\n"
|
|
|
|
|
"%d %d\r\n",
|
|
|
|
|
0, num_objects + 1);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"0000000000 65535 f\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
for (i = 0; i < num_objects; i++) {
|
2006-05-12 14:56:11 -07:00
|
|
|
object = _cairo_array_index (&surface->objects, i);
|
2005-05-13 14:04:22 +00:00
|
|
|
snprintf (buffer, sizeof buffer, "%010ld", object->offset);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->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-03-16 12:08:41 +00:00
|
|
|
static cairo_status_t
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
|
2005-01-05 14:29:31 +00:00
|
|
|
{
|
2005-11-04 16:13:30 +00:00
|
|
|
cairo_status_t status;
|
2006-05-12 13:31:12 -07:00
|
|
|
cairo_pdf_resource_t page;
|
|
|
|
|
cairo_pdf_resource_t stream;
|
2006-05-15 10:00:18 -07:00
|
|
|
int num_streams, i;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-04-21 02:46:20 -07:00
|
|
|
if (surface->has_clip) {
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, "Q\r\n");
|
2006-04-21 02:46:20 -07:00
|
|
|
surface->has_clip = FALSE;
|
|
|
|
|
}
|
2005-06-14 19:45:22 +00:00
|
|
|
|
2007-04-10 13:51:46 -07:00
|
|
|
status = _cairo_pdf_surface_close_stream (surface);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
page = _cairo_pdf_surface_new_object (surface);
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
"%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,
|
2006-05-12 14:56:11 -07:00
|
|
|
surface->pages_resource.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-16 01:04:16 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
" /MediaBox [ 0 0 %f %f ]\r\n",
|
|
|
|
|
surface->width,
|
|
|
|
|
surface->height);
|
2006-05-03 12:39:23 -07:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-05-03 12:39:23 -07:00
|
|
|
" /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);
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2005-03-16 12:08:41 +00:00
|
|
|
" %d 0 R",
|
2006-05-12 13:31:12 -07:00
|
|
|
stream.id);
|
2005-01-05 14:29:31 +00:00
|
|
|
}
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-03-06 23:11:38 +10:30
|
|
|
" ]\r\n"
|
|
|
|
|
" /Group <<\r\n"
|
|
|
|
|
" /Type /Group\r\n"
|
|
|
|
|
" /S /Transparency\r\n"
|
|
|
|
|
" /CS /DeviceRGB\r\n"
|
|
|
|
|
" >>\r\n"
|
2005-03-16 12:08:41 +00:00
|
|
|
">>\r\n"
|
|
|
|
|
"endobj\r\n");
|
2005-01-05 14:29:31 +00:00
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
status = _cairo_array_append (&surface->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:
|
|
|
|
|
case CAIRO_EXTEND_REFLECT:
|
2007-03-01 19:14:40 -05:00
|
|
|
/* There's no point returning FALSE for EXTEND_PAD, as the image
|
|
|
|
|
* surface does not currently implement it either */
|
2006-04-25 03:45:37 -07:00
|
|
|
case CAIRO_EXTEND_PAD:
|
2007-03-01 19:14:40 -05:00
|
|
|
return TRUE;
|
2006-04-25 03:45:37 -07:00
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
static cairo_bool_t
|
|
|
|
|
_gradient_pattern_supported (cairo_pattern_t *pattern)
|
|
|
|
|
{
|
|
|
|
|
cairo_extend_t extend;
|
|
|
|
|
|
|
|
|
|
extend = cairo_pattern_get_extend (pattern);
|
|
|
|
|
|
|
|
|
|
if (extend == CAIRO_EXTEND_REPEAT ||
|
|
|
|
|
extend == CAIRO_EXTEND_REFLECT) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Radial gradients are currently only supported when one circle
|
|
|
|
|
* is inside the other. */
|
|
|
|
|
if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL) {
|
|
|
|
|
double x1, y1, x2, y2, r1, r2, d;
|
|
|
|
|
cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) pattern;
|
|
|
|
|
|
|
|
|
|
x1 = _cairo_fixed_to_double (radial->gradient.c1.x);
|
|
|
|
|
y1 = _cairo_fixed_to_double (radial->gradient.c1.y);
|
|
|
|
|
r1 = _cairo_fixed_to_double (radial->gradient.c1.radius);
|
|
|
|
|
x2 = _cairo_fixed_to_double (radial->gradient.c2.x);
|
|
|
|
|
y2 = _cairo_fixed_to_double (radial->gradient.c2.y);
|
|
|
|
|
r2 = _cairo_fixed_to_double (radial->gradient.c2.radius);
|
|
|
|
|
|
|
|
|
|
d = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
|
|
|
|
|
if (d > fabs(r2 - r1)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-18 11:31:59 -07:00
|
|
|
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;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR ||
|
|
|
|
|
pattern->type == CAIRO_PATTERN_TYPE_RADIAL)
|
|
|
|
|
return _gradient_pattern_supported (pattern);
|
|
|
|
|
|
2006-04-18 11:31:59 -07:00
|
|
|
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-05-12 14:56:11 -07:00
|
|
|
|
2006-04-18 11:31:59 -07:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_int_status_t
|
2007-04-20 02:57:12 -04:00
|
|
|
_cairo_pdf_surface_operation_supported (cairo_pdf_surface_t *surface,
|
2006-04-18 11:31:59 -07:00
|
|
|
cairo_operator_t op,
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
2007-04-21 02:50:53 -04:00
|
|
|
if (surface->force_fallbacks)
|
2006-05-24 14:02:30 -07:00
|
|
|
return FALSE;
|
|
|
|
|
|
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
|
2007-03-07 15:54:20 -05:00
|
|
|
_cairo_pdf_surface_analyze_operation (cairo_pdf_surface_t *surface,
|
2006-04-18 11:31:59 -07:00
|
|
|
cairo_operator_t op,
|
2006-04-25 03:45:37 -07:00
|
|
|
cairo_pattern_t *pattern)
|
2006-04-18 11:31:59 -07:00
|
|
|
{
|
2007-04-20 02:57:12 -04:00
|
|
|
if (_cairo_pdf_surface_operation_supported (surface, op, pattern))
|
2006-04-18 11:31:59 -07:00
|
|
|
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;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t group = {0}; /* squelch bogus compiler warning */
|
2006-04-18 23:24:14 -07:00
|
|
|
cairo_status_t status;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
|
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_analyze_operation (surface, op, source);
|
2006-04-18 23:24:14 -07:00
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
/*
|
2007-04-20 02:57:12 -04:00
|
|
|
assert (_cairo_pdf_surface_operation_supported (op, source));
|
2006-04-18 23:24:14 -07:00
|
|
|
*/
|
|
|
|
|
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_pattern (surface, source);
|
2006-04-18 23:24:14 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
status = _cairo_pdf_surface_begin_group (surface, &group);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"1 0 0 -1 0 %f cm\r\n",
|
|
|
|
|
surface->height);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "q ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_select_pattern (surface, FALSE);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-18 23:24:14 -07:00
|
|
|
"0 0 %f %f re f\r\n",
|
|
|
|
|
surface->width, surface->height);
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
_cairo_pdf_surface_end_group (surface);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q 1 0 0 -1 0 %f cm /sm%d gs /res%d Do Q\r\n",
|
|
|
|
|
surface->height,
|
|
|
|
|
surface->emitted_pattern.smask,
|
|
|
|
|
group.id);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "Q\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return _cairo_output_stream_get_status (surface->output);
|
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_stroke_style_t *style)
|
|
|
|
|
{
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"%f w\r\n",
|
|
|
|
|
style->line_width);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"%d J\r\n",
|
|
|
|
|
_cairo_pdf_line_cap (style->line_cap));
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"%d j\r\n",
|
|
|
|
|
_cairo_pdf_line_join (style->line_join));
|
|
|
|
|
|
|
|
|
|
if (style->num_dashes) {
|
2006-07-28 16:59:54 -07:00
|
|
|
unsigned int d;
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, "[");
|
2006-04-18 16:53:23 -07:00
|
|
|
for (d = 0; d < style->num_dashes; d++)
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output, " %f", style->dash[d]);
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "] %f d\r\n",
|
2006-04-18 16:53:23 -07:00
|
|
|
style->dash_offset);
|
2006-07-13 10:20:12 -07:00
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "[] 0.0 d\r\n");
|
2006-04-18 16:53:23 -07:00
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-18 16:53:23 -07:00
|
|
|
"%f M ",
|
|
|
|
|
style->miter_limit);
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
return _cairo_output_stream_get_status (surface->output);
|
2006-04-18 16:53:23 -07:00
|
|
|
}
|
|
|
|
|
|
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;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t group = {0}; /* squelch bogus compiler warning */
|
2006-05-23 11:17:01 -07:00
|
|
|
pdf_path_info_t info;
|
2006-04-18 16:53:23 -07:00
|
|
|
cairo_status_t status;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2006-06-19 11:03:32 -07:00
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_analyze_operation (surface, op, source);
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2007-04-20 02:57:12 -04:00
|
|
|
assert (_cairo_pdf_surface_operation_supported (surface, op, source));
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_pattern (surface, source);
|
2006-04-18 16:53:23 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
status = _cairo_pdf_surface_begin_group (surface, &group);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"1 0 0 -1 0 %f cm\r\n",
|
|
|
|
|
surface->height);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "q ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_select_pattern (surface, TRUE);
|
|
|
|
|
|
2006-05-23 13:41:00 -07:00
|
|
|
status = _cairo_pdf_surface_emit_stroke_style (surface,
|
|
|
|
|
style);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2006-05-23 11:17:01 -07:00
|
|
|
info.output = surface->output;
|
|
|
|
|
info.ctm_inverse = ctm_inverse;
|
2006-05-23 11:23:27 -07:00
|
|
|
|
2006-10-25 21:40:08 -04:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q %f %f %f %f %f %f cm\r\n",
|
|
|
|
|
ctm->xx, ctm->yx, ctm->xy, ctm->yy,
|
|
|
|
|
ctm->x0, ctm->y0);
|
|
|
|
|
|
2006-04-25 04:04:10 -07:00
|
|
|
status = _cairo_path_fixed_interpret (path,
|
|
|
|
|
CAIRO_DIRECTION_FORWARD,
|
2006-05-23 11:23:27 -07:00
|
|
|
_cairo_pdf_path_move_to,
|
|
|
|
|
_cairo_pdf_path_line_to,
|
|
|
|
|
_cairo_pdf_path_curve_to,
|
|
|
|
|
_cairo_pdf_path_close_path,
|
2006-05-23 11:17:01 -07:00
|
|
|
&info);
|
2006-05-12 14:56:11 -07:00
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "S Q\r\n");
|
2006-04-18 16:53:23 -07:00
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
_cairo_pdf_surface_end_group (surface);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q 1 0 0 -1 0 %f cm /sm%d gs /res%d Do Q\r\n",
|
|
|
|
|
surface->height,
|
|
|
|
|
surface->emitted_pattern.smask,
|
|
|
|
|
group.id);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "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;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t group = {0}; /* squelch bogus compiler warning */
|
2006-04-14 15:23:30 -07:00
|
|
|
const char *pdf_operator;
|
|
|
|
|
cairo_status_t status;
|
2006-05-23 11:23:27 -07:00
|
|
|
pdf_path_info_t info;
|
2006-04-14 15:23:30 -07:00
|
|
|
|
2006-06-19 11:03:32 -07:00
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_analyze_operation (surface, op, source);
|
2006-04-18 11:31:59 -07:00
|
|
|
|
2007-04-20 02:57:12 -04:00
|
|
|
assert (_cairo_pdf_surface_operation_supported (surface, op, source));
|
2006-04-14 15:23:30 -07:00
|
|
|
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_pattern (surface, source);
|
2006-04-14 15:23:30 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
status = _cairo_pdf_surface_begin_group (surface, &group);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"1 0 0 -1 0 %f cm\r\n",
|
|
|
|
|
surface->height);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "q ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_select_pattern (surface, FALSE);
|
2006-05-23 11:23:27 -07:00
|
|
|
info.output = surface->output;
|
|
|
|
|
info.ctm_inverse = NULL;
|
2006-04-14 15:23:30 -07:00
|
|
|
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-05-23 11:23:27 -07:00
|
|
|
&info);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-12 14:56:11 -07:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
2006-04-14 15:23:30 -07:00
|
|
|
"%s\r\n",
|
|
|
|
|
pdf_operator);
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
_cairo_pdf_surface_end_group (surface);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q 1 0 0 -1 0 %f cm /sm%d gs /res%d Do Q\r\n",
|
|
|
|
|
surface->height,
|
|
|
|
|
surface->emitted_pattern.smask,
|
|
|
|
|
group.id);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "Q\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-23 23:08:46 +10:30
|
|
|
#define GLYPH_POSITION_TOLERANCE 0.001
|
|
|
|
|
|
2006-04-14 15:23:30 -07:00
|
|
|
static cairo_int_status_t
|
|
|
|
|
_cairo_pdf_surface_show_glyphs (void *abstract_surface,
|
|
|
|
|
cairo_operator_t op,
|
|
|
|
|
cairo_pattern_t *source,
|
2006-12-11 01:39:51 -05:00
|
|
|
cairo_glyph_t *glyphs,
|
2006-04-14 15:23:30 -07:00
|
|
|
int num_glyphs,
|
|
|
|
|
cairo_scaled_font_t *scaled_font)
|
|
|
|
|
{
|
2006-04-14 16:50:16 -07:00
|
|
|
cairo_pdf_surface_t *surface = abstract_surface;
|
2007-04-27 09:49:45 -07:00
|
|
|
cairo_pdf_resource_t group = {0}; /* squelch bogus compiler warning */
|
2006-07-28 16:59:54 -07:00
|
|
|
unsigned int current_subset_id = (unsigned int)-1;
|
2007-03-23 23:08:46 +10:30
|
|
|
cairo_scaled_font_subsets_glyph_t subset_glyph;
|
|
|
|
|
cairo_bool_t diagonal, in_TJ;
|
2006-04-19 11:04:37 -07:00
|
|
|
cairo_status_t status;
|
2007-03-23 23:08:46 +10:30
|
|
|
double Tlm_x = 0, Tlm_y = 0;
|
|
|
|
|
double Tm_x = 0, y;
|
2007-04-20 22:44:04 +09:30
|
|
|
int i, hex_width;
|
2006-04-14 16:50:16 -07:00
|
|
|
|
|
|
|
|
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
|
2007-03-07 15:54:20 -05:00
|
|
|
return _cairo_pdf_surface_analyze_operation (surface, op, source);
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2007-04-20 02:57:12 -04:00
|
|
|
assert (_cairo_pdf_surface_operation_supported (surface, op, source));
|
2006-04-14 16:50:16 -07:00
|
|
|
|
2007-03-07 15:54:20 -05:00
|
|
|
status = _cairo_pdf_surface_emit_pattern (surface, source);
|
2006-04-19 11:04:37 -07:00
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
status = _cairo_pdf_surface_begin_group (surface, &group);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"1 0 0 -1 0 %f cm\r\n",
|
|
|
|
|
surface->height);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "q ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_pdf_surface_select_pattern (surface, FALSE);
|
|
|
|
|
|
2006-05-16 22:53:05 -04:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"BT\r\n");
|
|
|
|
|
|
2006-09-24 00:48:36 +09:30
|
|
|
if (scaled_font->scale.xy == 0.0 &&
|
|
|
|
|
scaled_font->scale.yx == 0.0)
|
|
|
|
|
diagonal = TRUE;
|
|
|
|
|
else
|
|
|
|
|
diagonal = FALSE;
|
|
|
|
|
|
2007-03-23 23:08:46 +10:30
|
|
|
in_TJ = FALSE;
|
2006-05-15 10:04:53 -07:00
|
|
|
for (i = 0; i < num_glyphs; i++) {
|
2007-03-23 23:08:46 +10:30
|
|
|
status = _cairo_scaled_font_subsets_map_glyph (surface->font_subsets,
|
|
|
|
|
scaled_font, glyphs[i].index,
|
|
|
|
|
&subset_glyph);
|
2006-05-15 10:04:53 -07:00
|
|
|
if (status)
|
2007-03-23 23:08:46 +10:30
|
|
|
return status;
|
2006-04-19 11:04:37 -07:00
|
|
|
|
2007-04-20 22:44:04 +09:30
|
|
|
if (subset_glyph.is_composite)
|
|
|
|
|
hex_width = 4;
|
|
|
|
|
else
|
|
|
|
|
hex_width = 2;
|
|
|
|
|
|
2007-03-23 23:08:46 +10:30
|
|
|
if (subset_glyph.is_scaled == FALSE) {
|
|
|
|
|
y = 0.0;
|
|
|
|
|
cairo_matrix_transform_distance (&scaled_font->scale,
|
|
|
|
|
&subset_glyph.x_advance,
|
|
|
|
|
&y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (subset_glyph.subset_id != current_subset_id) {
|
|
|
|
|
if (in_TJ) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, ">] TJ\r\n");
|
|
|
|
|
in_TJ = FALSE;
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"/CairoFont-%d-%d 1 Tf\r\n",
|
|
|
|
|
subset_glyph.font_id,
|
|
|
|
|
subset_glyph.subset_id);
|
|
|
|
|
}
|
2006-05-16 22:53:05 -04:00
|
|
|
|
2007-03-23 23:08:46 +10:30
|
|
|
if (subset_glyph.subset_id != current_subset_id || !diagonal) {
|
2006-09-24 00:48:36 +09:30
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-03-23 23:08:46 +10:30
|
|
|
"%f %f %f %f %f %f Tm\r\n",
|
2006-09-24 00:48:36 +09:30
|
|
|
scaled_font->scale.xx,
|
|
|
|
|
scaled_font->scale.yx,
|
|
|
|
|
-scaled_font->scale.xy,
|
|
|
|
|
-scaled_font->scale.yy,
|
|
|
|
|
glyphs[i].x,
|
2007-03-23 23:08:46 +10:30
|
|
|
glyphs[i].y);
|
|
|
|
|
current_subset_id = subset_glyph.subset_id;
|
|
|
|
|
Tlm_x = glyphs[i].x;
|
|
|
|
|
Tlm_y = glyphs[i].y;
|
|
|
|
|
Tm_x = Tlm_x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (diagonal) {
|
|
|
|
|
if (i < num_glyphs - 1 &&
|
|
|
|
|
fabs((glyphs[i].y - glyphs[i+1].y)/scaled_font->scale.yy) < GLYPH_POSITION_TOLERANCE &&
|
|
|
|
|
fabs((glyphs[i].x - glyphs[i+1].x)/scaled_font->scale.xx) < 10)
|
|
|
|
|
{
|
|
|
|
|
if (!in_TJ) {
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%f %f Td\r\n",
|
|
|
|
|
(glyphs[i].x - Tlm_x)/scaled_font->scale.xx,
|
|
|
|
|
(glyphs[i].y - Tlm_y)/-scaled_font->scale.yy);
|
|
|
|
|
Tlm_x = glyphs[i].x;
|
|
|
|
|
Tlm_y = glyphs[i].y;
|
|
|
|
|
Tm_x = Tlm_x;
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"[<%0*x",
|
|
|
|
|
hex_width,
|
2007-03-23 23:08:46 +10:30
|
|
|
subset_glyph.subset_glyph_index);
|
|
|
|
|
Tm_x += subset_glyph.x_advance;
|
|
|
|
|
in_TJ = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
|
|
|
|
|
double delta = glyphs[i].x - Tm_x;
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"> %f <",
|
|
|
|
|
-1000.0*delta/scaled_font->scale.xx);
|
|
|
|
|
Tm_x += delta;
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"%0*x",
|
|
|
|
|
hex_width,
|
2007-03-23 23:08:46 +10:30
|
|
|
subset_glyph.subset_glyph_index);
|
|
|
|
|
Tm_x += subset_glyph.x_advance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (in_TJ) {
|
|
|
|
|
if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
|
|
|
|
|
double delta = glyphs[i].x - Tm_x;
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"> %f <",
|
|
|
|
|
-1000.0*delta/scaled_font->scale.xx);
|
|
|
|
|
Tm_x += delta;
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"%0*x>] TJ\r\n",
|
|
|
|
|
hex_width,
|
2007-03-23 23:08:46 +10:30
|
|
|
subset_glyph.subset_glyph_index);
|
|
|
|
|
Tm_x += subset_glyph.x_advance;
|
|
|
|
|
in_TJ = FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"%f %f Td ",
|
|
|
|
|
(glyphs[i].x - Tlm_x)/scaled_font->scale.xx,
|
2007-04-12 06:32:29 +09:30
|
|
|
(glyphs[i].y - Tlm_y)/-scaled_font->scale.yy);
|
2007-03-23 23:08:46 +10:30
|
|
|
Tlm_x = glyphs[i].x;
|
|
|
|
|
Tlm_y = glyphs[i].y;
|
|
|
|
|
Tm_x = Tlm_x;
|
|
|
|
|
}
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"<%0*x> Tj ",
|
|
|
|
|
hex_width,
|
2007-03-23 23:08:46 +10:30
|
|
|
subset_glyph.subset_glyph_index);
|
|
|
|
|
Tm_x += subset_glyph.x_advance;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-24 00:48:36 +09:30
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
2007-04-20 22:44:04 +09:30
|
|
|
"<%0*x> Tj\r\n",
|
|
|
|
|
hex_width,
|
2007-03-23 23:08:46 +10:30
|
|
|
subset_glyph.subset_glyph_index);
|
2006-09-24 00:48:36 +09:30
|
|
|
}
|
2006-05-15 10:04:53 -07:00
|
|
|
}
|
|
|
|
|
|
2006-05-16 22:53:05 -04:00
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"ET\r\n");
|
|
|
|
|
|
2007-04-27 09:49:45 -07:00
|
|
|
if (surface->emitted_pattern.smask.id != 0) {
|
|
|
|
|
_cairo_pdf_surface_end_group (surface);
|
|
|
|
|
|
|
|
|
|
_cairo_output_stream_printf (surface->output,
|
|
|
|
|
"q 1 0 0 -1 0 %f cm /sm%d gs /res%d Do Q\r\n",
|
|
|
|
|
surface->height,
|
|
|
|
|
surface->emitted_pattern.smask,
|
|
|
|
|
group.id);
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_output_stream_printf (surface->output, "Q\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-15 10:04:53 -07:00
|
|
|
return _cairo_output_stream_get_status (surface->output);
|
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,
|
2006-07-31 14:41:27 -04:00
|
|
|
NULL, /* create_similar */
|
2006-04-13 12:56:58 -07:00
|
|
|
_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
|
|
|
|
|
};
|