From 74097ed36f2c2a7b0ed8aeff61924d4e4483699d Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Wed, 18 Jan 2017 17:41:15 +0100 Subject: [PATCH] pdf: allow to set the producer metadata --- src/cairo-pdf-interchange.c | 16 +++++++++++++--- src/cairo-pdf-surface-private.h | 1 + src/cairo-pdf.h | 3 +++ test/pdf-tagged-text.c | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cairo-pdf-interchange.c b/src/cairo-pdf-interchange.c index 1fc8197..76dc72c 100644 --- a/src/cairo-pdf-interchange.c +++ b/src/cairo-pdf-interchange.c @@ -829,9 +829,14 @@ cairo_pdf_interchange_write_docinfo (cairo_pdf_surface_t *surface) _cairo_output_stream_printf (surface->output, "%d 0 obj\n" - "<< /Producer (cairo %s (http://cairographics.org))\n", - surface->docinfo_res.id, - cairo_version_string ()); + "<<\n", + surface->docinfo_res.id); + + if (ic->docinfo.producer) + _cairo_output_stream_printf (surface->output, " /Producer %s\n", ic->docinfo.producer); + else + _cairo_output_stream_printf (surface->output, " /Producer (cairo %s (http://cairographics.org))\n", + cairo_version_string ()); if (ic->docinfo.title) _cairo_output_stream_printf (surface->output, " /Title %s\n", ic->docinfo.title); @@ -1274,6 +1279,7 @@ _cairo_pdf_interchange_fini (cairo_pdf_surface_t *surface) free (outline); } _cairo_array_fini (&ic->outline); + free (ic->docinfo.producer); free (ic->docinfo.title); free (ic->docinfo.author); free (ic->docinfo.subject); @@ -1439,6 +1445,10 @@ _cairo_pdf_interchange_set_metadata (cairo_pdf_surface_t *surface, } switch (metadata) { + case CAIRO_PDF_METADATA_PRODUCER: + free (ic->docinfo.producer); + ic->docinfo.producer = s; + break; case CAIRO_PDF_METADATA_TITLE: free (ic->docinfo.title); ic->docinfo.title = s; diff --git a/src/cairo-pdf-surface-private.h b/src/cairo-pdf-surface-private.h index a5c7d0e..6d51479 100644 --- a/src/cairo-pdf-surface-private.h +++ b/src/cairo-pdf-surface-private.h @@ -207,6 +207,7 @@ typedef struct _cairo_pdf_outline_entry { } cairo_pdf_outline_entry_t; struct docinfo { + char *producer; char *title; char *author; char *subject; diff --git a/src/cairo-pdf.h b/src/cairo-pdf.h index 040c0ed..3bc96e7 100644 --- a/src/cairo-pdf.h +++ b/src/cairo-pdf.h @@ -115,6 +115,8 @@ cairo_pdf_surface_add_outline (cairo_surface_t *surface, /** * cairo_pdf_metadata_t: + * @CAIRO_PDF_METADATA_PRODUCER: the document producer. If not set "cairo" will + * be set as the producer (Since 1.16) * @CAIRO_PDF_METADATA_TITLE: The document title (Since 1.16) * @CAIRO_PDF_METADATA_AUTHOR: The document author (Since 1.16) * @CAIRO_PDF_METADATA_SUBJECT: The document subject (Since 1.16) @@ -129,6 +131,7 @@ cairo_pdf_surface_add_outline (cairo_surface_t *surface, * Since: 1.16 **/ typedef enum _cairo_pdf_metadata { + CAIRO_PDF_METADATA_PRODUCER, CAIRO_PDF_METADATA_TITLE, CAIRO_PDF_METADATA_AUTHOR, CAIRO_PDF_METADATA_SUBJECT, diff --git a/test/pdf-tagged-text.c b/test/pdf-tagged-text.c index 74e7968..5194ce5 100644 --- a/test/pdf-tagged-text.c +++ b/test/pdf-tagged-text.c @@ -315,6 +315,7 @@ create_document (cairo_surface_t *surface, cairo_t *cr) cairo_pdf_surface_set_thumbnail_size (surface, PAGE_WIDTH/10, PAGE_HEIGHT/10); + cairo_pdf_surface_set_metadata (surface, CAIRO_PDF_METADATA_PRODUCER, "cairo"); cairo_pdf_surface_set_metadata (surface, CAIRO_PDF_METADATA_TITLE, "PDF Features Test"); cairo_pdf_surface_set_metadata (surface, CAIRO_PDF_METADATA_AUTHOR, "cairo test suite"); cairo_pdf_surface_set_metadata (surface, CAIRO_PDF_METADATA_SUBJECT, "cairo test"); -- 2.7.4