Skip to content

Commit

Permalink
ps (API): Export the ability to set the creation date of the surface
Browse files Browse the repository at this point in the history
A PostScript surface embeds a CreationDate comment into its document
description pre-amble. Normally this is set to the time the surface is
written out, except we set this to a constant value in the boilerplate
for the purposes of mimicking a reference file. It may also be useful
for external applications, so make it a public export.

References: https://bugs.freedesktop.org/show_bug.cgi?id=48577
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
  • Loading branch information
Chris Wilson committed Apr 12, 2012
1 parent bf5adaf commit 6ad8c96
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
20 changes: 1 addition & 19 deletions boilerplate/cairo-boilerplate-ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ typedef struct _ps_target_closure {
cairo_ps_level_t level;
} ps_target_closure_t;

static cairo_status_t
_cairo_boilerplate_ps_surface_set_creation_date (cairo_surface_t *abstract_surface,
time_t date)
{
cairo_paginated_surface_t *paginated = (cairo_paginated_surface_t*) abstract_surface;
cairo_ps_surface_t *surface;

if (cairo_surface_get_type (abstract_surface) != CAIRO_SURFACE_TYPE_PS)
return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;

surface = (cairo_ps_surface_t*) paginated->target;

surface->has_creation_date = TRUE;
surface->creation_date = date;

return CAIRO_STATUS_SUCCESS;
}

static cairo_surface_t *
_cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
Expand Down Expand Up @@ -106,7 +88,7 @@ _cairo_boilerplate_ps_create_surface (const char *name,
goto CLEANUP_FILENAME;

cairo_ps_surface_restrict_to_level (surface, level);
_cairo_boilerplate_ps_surface_set_creation_date (surface, 0);
cairo_ps_surface_debug_set_creation_date (surface, 0);
cairo_surface_set_fallback_resolution (surface, 72., 72.);

if (content == CAIRO_CONTENT_COLOR) {
Expand Down
27 changes: 27 additions & 0 deletions src/cairo-ps-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,33 @@ cairo_ps_surface_set_size (cairo_surface_t *surface,
status = _cairo_surface_set_error (surface, status);
}

/**
* cairo_ps_surface_debug_set_creation_data:
* @surface: a PostScript #cairo_surface_t
* @date: A time_t
*
* Changes the embedded creation date of a PostScript surface.
*
* This function is only intended to be used by conformance test suites which
* require complete control over embedded strings.
*
* This function can be called at any point before the surface is finished,
*
* Since: 1.12.2
**/
void
cairo_ps_surface_debug_set_creation_date (cairo_surface_t *abstract_surface,
time_t date)
{
cairo_ps_surface_t *surface = NULL;

if (! _extract_ps_surface (abstract_surface, TRUE, &surface))
return;

surface->has_creation_date = TRUE;
surface->creation_date = date;
}

/**
* cairo_ps_surface_dsc_comment:
* @surface: a PostScript #cairo_surface_t
Expand Down
7 changes: 7 additions & 0 deletions src/cairo-ps.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#if CAIRO_HAS_PS_SURFACE

#include <stdio.h>
#include <time.h>

CAIRO_BEGIN_DECLS

Expand Down Expand Up @@ -107,6 +108,12 @@ cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface);
cairo_public void
cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface);

/* debug interface */

cairo_public void
cairo_ps_surface_debug_set_creation_date (cairo_surface_t *abstract_surface,
time_t date);

CAIRO_END_DECLS

#else /* CAIRO_HAS_PS_SURFACE */
Expand Down

0 comments on commit 6ad8c96

Please sign in to comment.