summaryrefslogtreecommitdiff
path: root/src/cairo-pdf-interchange.c
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2017-10-24 21:26:56 +1030
committerAdrian Johnson <ajohnson@redneon.com>2017-10-24 21:44:08 +1030
commit1674d2b8850f9264232e60e82cb5b2827426632c (patch)
treef726f6382a58502332cf9738a2f3975047158e23 /src/cairo-pdf-interchange.c
parent378e8e2f59a109a40da8e40893652a4c003a4dc7 (diff)
downloadcairo-1674d2b8850f9264232e60e82cb5b2827426632c.tar.gz
pdf: set default create date
Diffstat (limited to 'src/cairo-pdf-interchange.c')
-rw-r--r--src/cairo-pdf-interchange.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cairo-pdf-interchange.c b/src/cairo-pdf-interchange.c
index c6ba056aa..78a8db673 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;