summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-01-11 11:53:33 +0000
committerCarl Worth <cworth@cworth.org>2006-01-11 11:53:33 +0000
commitc23d7d4758c7915505437b0fc8b57df9ef628289 (patch)
tree1d49c62e1c2d2446c5ae4c21adecbebfa3ad1587 /src
parent953561ebbd7e58ecb3e6cec0e2446cf3dac3f146 (diff)
downloadcairo-c23d7d4758c7915505437b0fc8b57df9ef628289.tar.gz
Note that from here on out, the PDF output should always pass the entire test suite!
Add new functions needed by users of cairo_paginated_surface_t. Always snapshot a paginated surface to an image surface, rather than a surface similar to the target. We do this since paginated target surfaces are allowed to not be complete surfaces, (such as not implementing acquire_source_surface). Switch the implementation of cairo_pdf_surface_t to use cairo_paginated_surface_t. For now this means that all PDF output is fallback images, but this can change incrementally as we go forward.
Diffstat (limited to 'src')
-rw-r--r--src/cairo-paginated-surface-private.h6
-rw-r--r--src/cairo-paginated-surface.c24
-rw-r--r--src/cairo-pdf-surface.c32
3 files changed, 53 insertions, 9 deletions
diff --git a/src/cairo-paginated-surface-private.h b/src/cairo-paginated-surface-private.h
index ccec6047b..eef07178f 100644
--- a/src/cairo-paginated-surface-private.h
+++ b/src/cairo-paginated-surface-private.h
@@ -43,4 +43,10 @@ _cairo_paginated_surface_create (cairo_surface_t *target,
int width,
int height);
+cairo_private cairo_surface_t *
+_cairo_paginated_surface_get_target (cairo_surface_t *surface);
+
+cairo_bool_t
+_cairo_surface_is_paginated (cairo_surface_t *surface);
+
#endif /* CAIRO_PAGINATED_SURFACE_H */
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 601909b34..e6b2f4689 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -126,6 +126,23 @@ _cairo_paginated_surface_create (cairo_surface_t *target,
return (cairo_surface_t*) &_cairo_surface_nil;
}
+cairo_bool_t
+_cairo_surface_is_paginated (cairo_surface_t *surface)
+{
+ return surface->backend == &cairo_paginated_surface_backend;
+}
+
+cairo_surface_t *
+_cairo_paginated_surface_get_target (cairo_surface_t *surface)
+{
+ assert (_cairo_surface_is_paginated (surface));
+
+ cairo_paginated_surface_t *paginated_surface =
+ (cairo_paginated_surface_t *) surface;
+
+ return paginated_surface->target;
+}
+
static cairo_status_t
_cairo_paginated_surface_finish (void *abstract_surface)
{
@@ -358,10 +375,9 @@ _cairo_paginated_surface_snapshot (void *abstract_other)
_cairo_surface_get_extents (other->target, &extents);
- surface = cairo_surface_create_similar (other->target,
- CAIRO_CONTENT_COLOR_ALPHA,
- extents.width,
- extents.height);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ extents.width,
+ extents.height);
_cairo_meta_surface_replay (other->meta, surface);
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index d72b8cc0f..a562f7e9a 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -38,6 +38,7 @@
#include "cairo-pdf.h"
#include "cairo-font-subset-private.h"
#include "cairo-ft-private.h"
+#include "cairo-paginated-surface-private.h"
#include <time.h>
#include <zlib.h>
@@ -290,7 +291,7 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream,
double height)
{
cairo_pdf_document_t *document;
- cairo_surface_t *surface;
+ cairo_surface_t *target;
document = _cairo_pdf_document_create (stream, width, height);
if (document == NULL) {
@@ -298,12 +299,12 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream,
return (cairo_surface_t*) &_cairo_surface_nil;
}
- surface = _cairo_pdf_surface_create_for_document (document, width, height);
+ target = _cairo_pdf_surface_create_for_document (document, width, height);
- document->owner = surface;
+ document->owner = target;
_cairo_pdf_document_destroy (document);
- return surface;
+ return _cairo_paginated_surface_create (target, width, height);
}
cairo_surface_t *
@@ -339,6 +340,12 @@ cairo_pdf_surface_create (const char *filename,
return _cairo_pdf_surface_create_for_stream_internal (stream, width, height);
}
+static cairo_bool_t
+_cairo_surface_is_pdf (cairo_surface_t *surface)
+{
+ return surface->backend == &cairo_pdf_surface_backend;
+}
+
/**
* cairo__surface_set_dpi:
* @surface: a postscript cairo_surface_t
@@ -354,7 +361,22 @@ cairo_pdf_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi)
{
- cairo_pdf_surface_t *pdf_surface = (cairo_pdf_surface_t *) surface;
+ cairo_surface_t *target;
+ cairo_pdf_surface_t *pdf_surface;
+
+ if (! _cairo_surface_is_paginated (surface)) {
+ _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+ return;
+ }
+
+ target = _cairo_paginated_surface_get_target (surface);
+
+ if (! _cairo_surface_is_pdf (surface)) {
+ _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+ return;
+ }
+
+ pdf_surface = (cairo_pdf_surface_t *) target;
pdf_surface->document->x_dpi = x_dpi;
pdf_surface->document->y_dpi = y_dpi;