diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index f606805..e38222f 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -26,7 +26,10 @@ #include +#include #include +#include +#include #include <2geom/pathvector.h> #include @@ -804,6 +807,43 @@ CairoRenderContext::setupSurface(double width, double height) case CAIRO_SURFACE_TYPE_PDF: surface = cairo_pdf_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, width, height); cairo_pdf_surface_restrict_to_version(surface, (cairo_pdf_version_t)_pdf_level); + char* source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) { + char buffer[25]; + char *endptr; + time_t now; + struct tm *build_time; + unsigned long long epoch; + errno = 0; + epoch = strtoull(source_date_epoch, &endptr, 10); + if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) + || (errno != 0 && epoch == 0)) { + g_printerr ("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", + strerror(errno); + exit (1); + } + if (endptr == source_date_epoch) { + g_printerr ("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", + endptr); + exit (1); + } + if (*endptr != '\0') { + g_printerr ("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", + endptr); + exit (1); + } + if (epoch > ULONG_MAX) { + g_printerr ("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu \n", + ULONG_MAX, epoch); + exit (1); + } + now = (time_t) epoch; + build_time = gmtime(&now); + g_assert (strftime(buffer, 23, "%Y-%m-%dT%H:%M:%S%z", build_time)); + cairo_pdf_surface_set_metadata (surface, + CAIRO_PDF_METADATA_CREATE_DATE, + buffer); + } break; #endif #ifdef CAIRO_HAS_PS_SURFACE