summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-01-12 13:36:36 +0000
committerCarl Worth <cworth@cworth.org>2006-01-12 13:36:36 +0000
commit3647ff95f968a68f938fa7cdea9d48880f1064bd (patch)
tree3a3e7aff45136c2410d2639bef671f9ea9b6a7f7
parent107a52ed6190a72882598eec5f2cf0fab24f4cb1 (diff)
Some fixes for the fact that multi-page output was totally broken for cairo_ps_surface_t (at least):
Move the Y-axis-flipping to be on a per-page basis (as it was before and as it must be). Put page number back in, (still missing th number of pages from the header). Add multi-page output for better testing.
-rw-r--r--ChangeLog20
-rw-r--r--src/cairo-ps-surface.c72
-rw-r--r--test/ps-surface.c29
3 files changed, 92 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 42063c17..4d70d88b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2006-01-12 Carl Worth <cworth@cworth.org>
+
+ Some fixes for the fact that multi-page output was totally broken
+ for cairo_ps_surface_t (at least):
+
+ * src/cairo-ps-surface.c: (_cairo_ps_surface_emit_header),
+ (_cairo_ps_surface_emit_footer),
+ (_cairo_ps_surface_create_for_stream_internal),
+ (_cairo_ps_surface_start_page), (_cairo_ps_surface_end_page),
+ (_cairo_ps_surface_copy_page), (_cairo_ps_surface_show_page),
+ (_cairo_ps_surface_composite), (_cairo_ps_surface_fill_rectangles),
+ (_cairo_ps_surface_composite_trapezoids),
+ (_cairo_ps_surface_old_show_glyphs), (_cairo_ps_surface_fill):
+ Move the Y-axis-flipping to be on a per-page basis (as it was
+ before and as it must be). Put page number back in, (still missing
+ th number of pages from the header).
+
+ * test/ps-surface.c: (draw), (main): Add multi-page output for
+ better testing.
+
2006-01-11 Carl Worth <cworth@cworth.org>
* src/cairo-paginated-surface.c:
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 4b0fdeef..98ebd992 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -68,6 +68,9 @@ typedef struct cairo_ps_surface {
double x_dpi;
double y_dpi;
+ cairo_bool_t need_start_page;
+ int num_pages;
+
#if DONE_ADDING_FONTS_SUPPORT_BACK_AFTER_SWITCHING_TO_PAGINATED
cairo_array_t fonts;
#endif
@@ -104,12 +107,6 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
surface->width,
surface->height);
- _cairo_output_stream_printf (surface->stream,
- "gsave %f %f translate %f %f scale \n",
- 0.0, surface->height,
- 1.0/surface->base.device_x_scale,
- -1.0/surface->base.device_y_scale);
-
/* The "/FlateDecode filter" currently used is a feature of
* LanguageLevel 3 */
_cairo_output_stream_printf (surface->stream,
@@ -123,9 +120,6 @@ static void
_cairo_ps_surface_emit_footer (cairo_ps_surface_t *surface)
{
_cairo_output_stream_printf (surface->stream,
- "grestore\n");
-
- _cairo_output_stream_printf (surface->stream,
"%%%%Trailer\n"
"%%%%EOF\n");
}
@@ -156,6 +150,9 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
surface->base.device_y_scale = surface->y_dpi / 72.0;
#endif
+ surface->need_start_page = TRUE;
+ surface->num_pages = 0;
+
#if DONE_ADDING_FONTS_SUPPORT_BACK_AFTER_SWITCHING_TO_PAGINATED
_cairo_array_init (&surface->fonts, sizeof (cairo_font_subset_t *));
#endif
@@ -274,26 +271,43 @@ _cairo_ps_surface_finish (void *abstract_surface)
return CAIRO_STATUS_SUCCESS;
}
-#if DONE_ADDING_PAGES_SUPPORT_AFTER_SWITCHING_TO_PAGINATED
-static cairo_int_status_t
+static void
_cairo_ps_surface_start_page (cairo_ps_surface_t *surface)
{
_cairo_output_stream_printf (surface->stream,
"%%%%Page: %d\n",
- page_number);
+ ++surface->num_pages);
- return CAIRO_STATUS_SUCCESS;
+
+ _cairo_output_stream_printf (surface->stream,
+ "gsave %f %f translate %f %f scale \n",
+ 0.0, surface->height,
+ 1.0/surface->base.device_x_scale,
+ -1.0/surface->base.device_y_scale);
+
+ surface->need_start_page = FALSE;
+}
+
+static void
+_cairo_ps_surface_end_page (cairo_ps_surface_t *surface)
+{
+ _cairo_output_stream_printf (surface->stream,
+ "grestore\n");
+
+ _cairo_output_stream_printf (surface->stream,
+ "%%%%EndPage\n");
+
+ surface->need_start_page = TRUE;
}
-#endif
static cairo_int_status_t
_cairo_ps_surface_copy_page (void *abstract_surface)
{
cairo_ps_surface_t *surface = abstract_surface;
- _cairo_output_stream_printf (surface->stream,
- "copypage\n"
- "%%%%EndPage\n");
+ _cairo_output_stream_printf (surface->stream, "copypage\n");
+
+ _cairo_ps_surface_end_page (surface);
return CAIRO_STATUS_SUCCESS;
}
@@ -303,9 +317,11 @@ _cairo_ps_surface_show_page (void *abstract_surface)
{
cairo_ps_surface_t *surface = abstract_surface;
- _cairo_output_stream_printf (surface->stream,
- "showpage\n"
- "%%%%EndPage\n");
+ _cairo_output_stream_printf (surface->stream, "showpage\n");
+
+ _cairo_ps_surface_end_page (surface);
+
+ surface->need_start_page = TRUE;
return CAIRO_STATUS_SUCCESS;
}
@@ -828,6 +844,9 @@ _cairo_ps_surface_composite (cairo_operator_t op,
cairo_image_surface_t *image;
void *image_extra;
+ if (surface->need_start_page)
+ _cairo_ps_surface_start_page (surface);
+
if (mask_pattern) {
/* FIXME: Investigate how this can be done... we'll probably
* need pixmap fallbacks for this, though. */
@@ -894,6 +913,9 @@ _cairo_ps_surface_fill_rectangles (void *abstract_surface,
if (!num_rects)
return CAIRO_STATUS_SUCCESS;
+
+ if (surface->need_start_page)
+ _cairo_ps_surface_start_page (surface);
if (color_operation_needs_fallback (op, color)) {
int min_x = rects[0].x;
@@ -960,6 +982,9 @@ _cairo_ps_surface_composite_trapezoids (cairo_operator_t op,
if (pattern_operation_needs_fallback (op, pattern))
return _cairo_ps_surface_add_fallback_area (surface, x_dst, y_dst, width, height);
+ if (surface->need_start_page)
+ _cairo_ps_surface_start_page (surface);
+
_cairo_output_stream_printf (stream,
"%% _cairo_ps_surface_composite_trapezoids\n");
@@ -1156,6 +1181,9 @@ _cairo_ps_surface_old_show_glyphs (cairo_scaled_font_t *scaled_font,
if (surface->fallback)
return CAIRO_STATUS_SUCCESS;
+ if (surface->need_start_page)
+ _cairo_ps_surface_start_page (surface);
+
/* XXX: Need to fix this to work with a general cairo_scaled_font_t. */
if (! _cairo_scaled_font_is_ft (scaled_font))
return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -1223,6 +1251,10 @@ _cairo_ps_surface_fill (void *abstract_surface,
0, 0,
surface->width,
surface->height);
+
+ if (surface->need_start_page)
+ _cairo_ps_surface_start_page (surface);
+
_cairo_output_stream_printf (stream,
"%% _cairo_ps_surface_fill\n");
diff --git a/test/ps-surface.c b/test/ps-surface.c
index 0bf9824b..aff74805 100644
--- a/test/ps-surface.c
+++ b/test/ps-surface.c
@@ -39,12 +39,17 @@
#define HEIGHT_IN_POINTS (HEIGHT_IN_INCHES * 72.0)
static void
-draw (cairo_t *cr, double width, double height)
+draw (cairo_t *cr, double width, double height, double smile_ratio)
{
#define STROKE_WIDTH .04
-
double size;
+ double theta = M_PI / 4 * smile_ratio;
+ double dx = sqrt (0.005) * cos (theta);
+ double dy = sqrt (0.005) * sin (theta);
+
+ cairo_save (cr);
+
if (width > height)
size = height;
else
@@ -72,12 +77,15 @@ draw (cairo_t *cr, double width, double height)
cairo_fill (cr);
/* Mouth */
- cairo_move_to (cr, 0.3, 0.7);
+ cairo_move_to (cr,
+ 0.35 - dx, 0.75 - dy);
cairo_curve_to (cr,
- 0.4, 0.8,
- 0.6, 0.8,
- 0.7, 0.7);
+ 0.35 + dx, 0.75 + dy,
+ 0.65 - dx, 0.75 + dy,
+ 0.65 + dx, 0.75 - dy);
cairo_stroke (cr);
+
+ cairo_restore (cr);
}
int
@@ -86,6 +94,7 @@ main (void)
cairo_t *cr;
const char *filename = "ps-surface.ps";
cairo_surface_t *surface;
+ int i;
printf("\n");
@@ -98,9 +107,11 @@ main (void)
cr = cairo_create (surface);
- draw (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
-
- cairo_show_page (cr);
+#define NUM_PAGES 5
+ for (i=0; i < NUM_PAGES; i++) {
+ draw (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS, (double) i / (NUM_PAGES - 1));
+ cairo_show_page (cr);
+ }
cairo_destroy (cr);
cairo_surface_destroy (surface);