[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1569-g00af0eb
[email protected] (Ken Sharp)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
The ghostpdl branch, master has been updated
via 00af0eb11b82c4dfddbe91bcb70caed2e61a1cc8 (commit)
from 813d7e96c8733f85d59a62732171cf7cedfc087d (commit)
----------------------------------------------------------------------
commit 00af0eb11b82c4dfddbe91bcb70caed2e61a1cc8
Author: Ken Sharp <[email protected]>
Date: Thu Aug 15 09:52:04 2019 +0100
pdfwrite/ps2write/pdfimage - record args used
Following on from commit 813d7e96c8733f85d59a62732171cf7cedfc087d this
adds functionality to the pdfwrite and pdfimage families of devices to
actually write the args that were used to generate the output file into
the final output file, as comments.
Output files are somewhat larger with this commit, but only very small
files are in any way significantly larger. We do have a number of such
files in our test suite which exhibit larger output ( > 5%increase).
diff --git a/devices/gdevpdfimg.c b/devices/gdevpdfimg.c
index 7ad8169..1007853 100644
--- a/devices/gdevpdfimg.c
+++ b/devices/gdevpdfimg.c
@@ -186,6 +186,50 @@ const gx_device_pdf_image gs_pdfimage32_device = {
0 /* JPEGQ */
};
+static int
+pdfimage_write_args_comment(gx_device_pdf_image *pdev, stream *s)
+{
+ char **argv = NULL, *arg;
+ int towrite, length, i, j, argc;
+
+ argc = gs_lib_ctx_get_args(pdev->memory->gs_lib_ctx, (const char ***)&argv);
+
+ stream_write(s, (byte *)"%%Invocation:", 13);
+ length = 12;
+ for (i=0;i < argc; i++) {
+ arg = argv[i];
+
+ if ((strlen(arg) + length) > 255) {
+ stream_write(s, (byte *)"\n%%+ ", 5);
+ length = 5;
+ } else {
+ stream_write(s, (byte *)" ", 1);
+ length++;
+ }
+
+ if (strlen(arg) > 250)
+ towrite = 250;
+ else
+ towrite = strlen(arg);
+
+ length += towrite;
+
+ for (j=0;j < towrite;j++) {
+ if (arg[j] == 0x0A) {
+ stream_write(s, (byte *)"<0A>", 4);
+ } else {
+ if (arg[j] == 0x0D) {
+ stream_write(s, (byte *)"<0D>", 4);
+ } else {
+ stream_write(s, (byte *)&arg[j], 1);
+ }
+ }
+ }
+ }
+ stream_write(s, (byte *)"\n", 1);
+ return 0;
+}
+
static int gdev_pdf_image_begin_page(gx_device_pdf_image *pdf_dev,
gp_file *file)
{
@@ -251,6 +295,7 @@ static int gdev_pdf_image_begin_page(gx_device_pdf_image *pdf_dev,
stream_puts(pdf_dev->strm, "%PDF-1.3\n");
stream_puts(pdf_dev->strm, "%\307\354\217\242\n");
+ pdfimage_write_args_comment(pdf_dev, pdf_dev->strm);
pdf_dev->Pages = page;
} else {
pdfimage_page *current = pdf_dev->Pages;
diff --git a/devices/vector/gdevpdf.c b/devices/vector/gdevpdf.c
index d1db9b3..1071ffa 100644
--- a/devices/vector/gdevpdf.c
+++ b/devices/vector/gdevpdf.c
@@ -1782,6 +1782,7 @@ static int pdf_linearise(gx_device_pdf *pdev, pdf_linearisation_t *linear_params
gp_fwrite(Header, strlen(Header), 1, linear_params->Lin_File.file);
if (pdev->binary_ok)
gp_fwrite(Binary, strlen(Binary), 1, linear_params->Lin_File.file);
+ pdfwrite_fwrite_args_comment(pdev, linear_params->Lin_File.file);
pdf_record_usage(pdev, linear_params->LastResource + 1, resource_usage_part1_structure);
pdev->ResourceUsage[linear_params->LastResource + 1].OriginalOffset = 0;
diff --git a/devices/vector/gdevpdfu.c b/devices/vector/gdevpdfu.c
index d57bec8..74f8dc3 100644
--- a/devices/vector/gdevpdfu.c
+++ b/devices/vector/gdevpdfu.c
@@ -394,6 +394,103 @@ encode(stream **s, const stream_template *t, gs_memory_t *mem)
/* ------ Document ------ */
+/* Write out the arguments used to invoke GS as a comment in the PDF/PS
+ * file. We don't write out paths, passwords, or any unrecognised string
+ * parameters (all sanitised by the arg code) for privacy/security
+ * reasons. This routine is only called by the PDF linearisation code.
+ */
+int
+pdfwrite_fwrite_args_comment(gx_device_pdf *pdev, gp_file *f)
+{
+ char **argv = NULL, *arg;
+ int towrite, length, i, j, argc;
+
+ argc = gs_lib_ctx_get_args(pdev->memory->gs_lib_ctx, (const char ***)&argv);
+
+ gp_fwrite("%%Invocation:", 13, 1, f);
+ length = 12;
+ for (i=0;i < argc; i++) {
+ arg = argv[i];
+
+ if ((strlen(arg) + length) > 255) {
+ gp_fwrite("\n%%+ ", 5, 1, f);
+ length = 5;
+ } else {
+ gp_fwrite(" ", 1, 1, f);
+ length++;
+ }
+
+ if (strlen(arg) > 250)
+ towrite = 250;
+ else
+ towrite = strlen(arg);
+
+ length += towrite;
+
+ for (j=0;j < towrite;j++) {
+ if (arg[j] == 0x0A) {
+ gp_fwrite("<0A>", 4, 1, f);
+ } else {
+ if (arg[j] == 0x0D) {
+ gp_fwrite("<0D>", 4, 1, f);
+ } else {
+ gp_fwrite(&arg[j], 1, 1, f);
+ }
+ }
+ }
+ }
+ gp_fwrite("\n", 1, 1, f);
+ return 0;
+}
+
+/* Exactly the same as pdfwrite_fwrite_args_comment() above, but uses a stream
+ * instead of a gp_file *, because of course we aren't consistent.... This
+ * routine is called by the regular PDF or PS file output code.
+ */
+int
+pdfwrite_write_args_comment(gx_device_pdf *pdev, stream *s)
+{
+ char **argv = NULL, *arg;
+ int towrite, length, i, j, argc;
+
+ argc = gs_lib_ctx_get_args(pdev->memory->gs_lib_ctx, (const char ***)&argv);
+
+ stream_write(s, (byte *)"%%Invocation:", 13);
+ length = 12;
+ for (i=0;i < argc; i++) {
+ arg = argv[i];
+
+ if ((strlen(arg) + length) > 255) {
+ stream_write(s, (byte *)"\n%%+ ", 5);
+ length = 5;
+ } else {
+ stream_write(s, (byte *)" ", 1);
+ length++;
+ }
+
+ if (strlen(arg) > 250)
+ towrite = 250;
+ else
+ towrite = strlen(arg);
+
+ length += towrite;
+
+ for (j=0;j < towrite;j++) {
+ if (arg[j] == 0x0A) {
+ stream_write(s, (byte *)"<0A>", 4);
+ } else {
+ if (arg[j] == 0x0D) {
+ stream_write(s, (byte *)"<0D>", 4);
+ } else {
+ stream_write(s, (byte *)&arg[j], 1);
+ }
+ }
+ }
+ }
+ stream_write(s, (byte *)"\n", 1);
+ return 0;
+}
+
int ps2write_dsc_header(gx_device_pdf * pdev, int pages)
{
stream *s = pdev->strm;
@@ -407,6 +504,7 @@ int ps2write_dsc_header(gx_device_pdf * pdev, int pages)
stream_write(s, (byte *)"%!PS-Adobe-3.0 EPSF-3.0\n", 24);
else
stream_write(s, (byte *)"%!PS-Adobe-3.0\n", 15);
+ pdfwrite_write_args_comment(pdev, s);
/* We need to calculate the document BoundingBox which is a 'high water'
* mark derived from the BoundingBox of all the individual pages.
*/
@@ -553,6 +651,7 @@ pdfwrite_pdf_open_document(gx_device_pdf * pdev)
pprintd2(s, "%%PDF-%d.%d\n", level / 10, level % 10);
if (pdev->binary_ok)
stream_puts(s, "%\307\354\217\242\n");
+ pdfwrite_write_args_comment(pdev, s);
}
}
/*
diff --git a/devices/vector/gdevpdfx.h b/devices/vector/gdevpdfx.h
index ca95a36..b7e0048 100644
--- a/devices/vector/gdevpdfx.h
+++ b/devices/vector/gdevpdfx.h
@@ -996,6 +996,10 @@ void pdf_reset_text(gx_device_pdf *pdev);
/* ------ Document ------ */
+/* Utility functions to write args into the file as comments */
+int pdfwrite_fwrite_args_comment(gx_device_pdf *pdev, gp_file *f);
+int pdfwrite_write_args_comment(gx_device_pdf *pdev, stream *s);
+
/* Write a DSC compliant header to the file */
int ps2write_dsc_header(gx_device_pdf * pdev, int pages);
Summary of changes:
devices/gdevpdfimg.c | 45 +++++++++++++++++++++
devices/vector/gdevpdf.c | 1 +
devices/vector/gdevpdfu.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
devices/vector/gdevpdfx.h | 4 ++
4 files changed, 149 insertions(+)