[PATCH 1/2] API ps: Export the ability to set the creation date of the surface

Chris Wilson <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
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 <[email protected]>
---
 boilerplate/cairo-boilerplate-ps.c |   20 +-------------------
 src/cairo-ps-surface.c             |   25 +++++++++++++++++++++++++
 src/cairo-ps.h                     |    5 +++++
 3 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c
index ae61239..411c11e 100644
--- a/boilerplate/cairo-boilerplate-ps.c
+++ b/boilerplate/cairo-boilerplate-ps.c
@@ -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,
@@ -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_set_creation_date (surface, 0);
     cairo_surface_set_fallback_resolution (surface, 72., 72.);
 
     if (content == CAIRO_CONTENT_COLOR) {
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index c5ea680..fae3ba3 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -1359,6 +1359,31 @@ cairo_ps_surface_set_size (cairo_surface_t	*surface,
 }
 
 /**
+ * cairo_ps_surface_set_creation_data:
+ * @surface: a PostScript #cairo_surface_t
+ * @date: A time_t
+ *
+ * Changes the embedded creation date of a PostScript surface.
+ *
+ * This function can be called at any point before the surface is finished,
+ *
+ * Since: 1.12.2
+ **/
+void
+cairo_ps_surface_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
  * @comment: a comment string to be emitted into the PostScript output
diff --git a/src/cairo-ps.h b/src/cairo-ps.h
index 33d0e0d..920052b 100644
--- a/src/cairo-ps.h
+++ b/src/cairo-ps.h
@@ -42,6 +42,7 @@
 #if CAIRO_HAS_PS_SURFACE
 
 #include <stdio.h>
+#include <time.h>
 
 CAIRO_BEGIN_DECLS
 
@@ -98,6 +99,10 @@ cairo_ps_surface_set_size (cairo_surface_t	*surface,
 			   double		 height_in_points);
 
 cairo_public void
+cairo_ps_surface_set_creation_date (cairo_surface_t *abstract_surface,
+				    time_t	  date);
+
+cairo_public void
 cairo_ps_surface_dsc_comment (cairo_surface_t	*surface,
 			      const char	*comment);
 
-- 
1.7.9.5

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.