File gstoraster-gstopdf-Make-number-of-copies-as-embedded.patch of Package cups-filters

From de6e216f63ef0b83f62387e159fd3925bc399271 Mon Sep 17 00:00:00 2001
From: Till Kamppeter <till.kamppeter@gmail.com>
Date: Fri, 26 Jun 2020 21:53:44 +0200
Subject: [PATCH] gstoraster, gstopdf: Make number of copies as embedded
 PostScript command work

(cherry picked from commit 6157b8f6178b89fa7a040c2057ff91eb9ac8885d)
---
 filter/gstoraster.c | 31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+)

diff --git a/filter/gstoraster.c b/filter/gstoraster.c
index 16b2a9bdf..e053c5742 100644
--- a/filter/gstoraster.c
+++ b/filter/gstoraster.c
@@ -813,6 +813,37 @@ main (int argc, char **argv, char *envp[])
 
   /* Special Ghostscript options for PDF output */
   if (outformat == OUTPUT_FORMAT_PDF) {
+    /* If we output PDF we are running as a PostScript-to-PDF filter
+       for incoming PostScript jobs. If the client embeds a command
+       for multiple copies in the PostScript job instead of using the
+       CUPS argument for the number of copies, we need to run
+       Ghostscript with the "-dDoNumCopies" option so that it respects
+       the embedded command for the number of copies.
+
+       We always supply this option if the number of copies CUPS got
+       told about is 1, as this is the case if a client sets the
+       number of copies as embedded PostScript command, and it is also
+       not doing the wrong thing if the command is missing when the
+       client only wants a single copy, independent how the client
+       actually triggers multiple copies. If the CUPS arguments tells
+       us that the clients wants more than one copy we do not supply
+       "-dDoNumCopies" as the client does the right, modern CUPS way,
+       and if the client got a "dirty" PostScript file with an
+       embedded multi-copy setting, he does not get unwished copies.
+       also a buggy client supplying the number of copies both via
+       PostScript and CUPS will not cause an unwished number of copies
+       this way.
+
+       See https://github.com/OpenPrinting/cups-filters/issues/255
+
+       This was already correctly implemented in the former pdftops
+       shell-script-based filter but overlooked when the filter's
+       functionality got folded into this gstoraster.c filter. It was
+       not seen for long time as clients sending PostScript jobs with
+       embedded number of copies are rare. */
+    if (atoi(argv[4]) <= 1)
+      cupsArrayAdd(gs_args, strdup("-dDoNumCopies"));
+
     cupsArrayAdd(gs_args, strdup("-dCompatibilityLevel=1.3"));
     cupsArrayAdd(gs_args, strdup("-dAutoRotatePages=/None"));
     cupsArrayAdd(gs_args, strdup("-dAutoFilterColorImages=false"));
-- 
2.35.3

openSUSE Build Service is sponsored by