diff options
-rw-r--r-- | boilerplate/cairo-boilerplate-pdf.c | 1 | ||||
-rw-r--r-- | build/configure.ac.system | 2 | ||||
-rw-r--r-- | src/cairo-pdf-interchange.c | 50 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 1 |
4 files changed, 52 insertions, 2 deletions
diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c index 177cdf174..c6c6b634c 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 915b42b46..def75cdc1 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 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; diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index d0bb953af..0645d3a30 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: |