mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-08 21:58:04 +02:00
pdf: set default create date
This commit is contained in:
parent
378e8e2f59
commit
1674d2b885
4 changed files with 52 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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([[
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@
|
|||
#include "cairo-surface-subsurface-private.h"
|
||||
#include "cairo-type3-glyph-surface-private.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <zlib.h>
|
||||
|
||||
/* Issues:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue