[cairo-commit] 2 commits - boilerplate/cairo-boilerplate-pdf.c build/configure.ac.system src/cairo-pdf-interchange.c src/cairo-pdf-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Tue Oct 24 11:18:03 UTC 2017


 boilerplate/cairo-boilerplate-pdf.c |    1 
 build/configure.ac.system           |    2 -
 src/cairo-pdf-interchange.c         |   50 ++++++++++++++++++++++++++++++++++++
 src/cairo-pdf-surface.c             |   10 -------
 4 files changed, 52 insertions(+), 11 deletions(-)

New commits:
commit 3322580f0488ff77f53d86c2b4d3cf59e6dca4c7
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Tue Oct 24 21:30:45 2017 +1030

    pdf: remove old comment
    
    These issues have been fixed.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 0645d3a3..058451b3 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -65,15 +65,6 @@
 
 #include <zlib.h>
 
-/* Issues:
- *
- * - 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.
- *
- * - Backend specific meta data.
- */
-
 /*
  * Page Structure of the Generated PDF:
  *
commit 1674d2b8850f9264232e60e82cb5b2827426632c
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Tue Oct 24 21:26:56 2017 +1030

    pdf: set default create date

diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c
index 177cdf17..c6c6b634 100644
--- a/boilerplate/cairo-boilerplate-pdf.c
+++ b/boilerplate/cairo-boilerplate-pdf.c
@@ -84,6 +84,7 @@ _cairo_boilerplate_pdf_create_surface (const char		 *name,
     if (cairo_surface_status (surface))
 	goto CLEANUP_FILENAME;
 
+    cairo_pdf_surface_set_metadata (surface, CAIRO_PDF_METADATA_CREATE_DATE, NULL);
     cairo_surface_set_fallback_resolution (surface, 72., 72.);
 
     if (content == CAIRO_CONTENT_COLOR) {
diff --git a/build/configure.ac.system b/build/configure.ac.system
index 915b42b4..def75cdc 100644
--- a/build/configure.ac.system
+++ b/build/configure.ac.system
@@ -108,7 +108,7 @@ AC_CHECK_HEADER(fenv.h,
 
 dnl check for misc headers and functions
 AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h sys/wait.h])
-AC_CHECK_FUNCS([ctime_r drand48 flockfile funlockfile getline link strndup])
+AC_CHECK_FUNCS([ctime_r localtime_r gmtime_r drand48 flockfile funlockfile getline link strndup])
 
 dnl Check if the runtime platform is a native Win32 host.
 AC_COMPILE_IFELSE([[
diff --git a/src/cairo-pdf-interchange.c b/src/cairo-pdf-interchange.c
index c6ba056a..78a8db67 100644
--- a/src/cairo-pdf-interchange.c
+++ b/src/cairo-pdf-interchange.c
@@ -43,6 +43,7 @@
  *  - page labels
  */
 
+#define _DEFAULT_SOURCE /* for localtime_r(), gmtime_r(), snprintf(), strdup() */
 #include "cairoint.h"
 
 #include "cairo-pdf.h"
@@ -52,6 +53,15 @@
 #include "cairo-error-private.h"
 #include "cairo-output-stream-private.h"
 
+#include <time.h>
+
+#ifndef HAVE_LOCALTIME_R
+#define localtime_r(T, BUF) (*(BUF) = *localtime (T))
+#endif
+#ifndef HAVE_GMTIME_R
+#define gmtime_r(T, BUF) (*(BUF) = *gmtime (T))
+#endif
+
 static void
 write_rect_to_pdf_quad_points (cairo_output_stream_t   *stream,
 			       const cairo_rectangle_t *rect,
@@ -1312,6 +1322,45 @@ _cairo_pdf_interchange_write_document_objects (cairo_pdf_surface_t *surface)
     return status;
 }
 
+static void
+_cairo_pdf_interchange_set_create_date (cairo_pdf_surface_t *surface)
+{
+    time_t utc, local, offset;
+    struct tm tm_local, tm_utc;
+    char buf[50];
+    int buf_size;
+    char *p;
+    cairo_pdf_interchange_t *ic = &surface->interchange;
+
+    utc = time (NULL);
+    localtime_r (&utc, &tm_local);
+    strftime (buf, sizeof(buf), "(D:%Y%m%d%H%M%S", &tm_local);
+
+    /* strftime "%z" is non standard and does not work on windows (it prints zone name, not offset).
+     * Calculate time zone offset by comparing local and utc time_t values for the same time.
+     */
+    gmtime_r (&utc, &tm_utc);
+    tm_utc.tm_isdst = tm_local.tm_isdst;
+    local = mktime (&tm_utc);
+    offset = difftime (utc, local);
+
+    if (offset == 0) {
+	strcat (buf, "Z");
+    } else {
+	if (offset > 0) {
+	    strcat (buf, "+");
+	} else {
+	    strcat (buf, "-");
+	    offset = -offset;
+	}
+	p = buf + strlen (buf);
+	buf_size = sizeof (buf) - strlen (buf);
+	snprintf (p, buf_size, "%02d'%02d", (int)(offset/3600), (int)(offset%3600)/60);
+    }
+    strcat (buf, ")");
+    ic->docinfo.create_date = strdup (buf);
+}
+
 cairo_int_status_t
 _cairo_pdf_interchange_init (cairo_pdf_surface_t *surface)
 {
@@ -1349,6 +1398,7 @@ _cairo_pdf_interchange_init (cairo_pdf_surface_t *surface)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     memset (&ic->docinfo, 0, sizeof (ic->docinfo));
+    _cairo_pdf_interchange_set_create_date (surface);
     status = _cairo_array_append (&ic->outline, &outline_root);
 
     return status;
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index d0bb953a..0645d3a3 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -63,7 +63,6 @@
 #include "cairo-surface-subsurface-private.h"
 #include "cairo-type3-glyph-surface-private.h"
 
-#include <time.h>
 #include <zlib.h>
 
 /* Issues:


More information about the cairo-commit mailing list