1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
Description: Make CUPS reading all option settings in PostScript print
jobs and add the option settings to the filter command line before
starting the filter chain. This fixes the problem that in the PDF
printing workflow (where incoming PostScript gets converted to PDF by
pstopdf) option settings embedded in the incoming PostScript code do
not get obeyed. Especially the options of jobs from Windows clients get
ignored.
Origin: vendor
Author: Till Kamppeter <till.kamppeter@gmail.com>
Bug: https://www.cups.org/str.php?L4344
--- a/scheduler/ipp.c
+++ b/scheduler/ipp.c
@@ -8381,6 +8381,11 @@
ipp_attribute_t *attr, /* Current attribute */
*attr2, /* Job attribute */
*prev2; /* Previous job attribute */
+ int foundfirstpage; /* Did we find the first page already
+ in the PostScript input? */
+ int num_copies; /* Number of copies according to
+ PostScript command in input file */
+ char *s, *t, buffer[10];
/*
@@ -8442,6 +8447,85 @@
}
/*
+ * Read option settings embedded in the file...
+ */
+
+ foundfirstpage = 0;
+
+ while (cupsFileGets(fp, line, sizeof(line)))
+ {
+ /*
+ * Stop at the second page, we read also the settings of the first PageSetup
+ * to work around a bug in OpenOffice.org. This app puts options intended
+ * for the whole document into the page setup of the first page
+ */
+
+ if (!strncmp(line, "%%Page:", 7))
+ {
+ if (foundfirstpage == 1)
+ break;
+ foundfirstpage = 1;
+ }
+
+ /*
+ * Add the embedded option settings to the option array...
+ */
+
+ s = NULL;
+ if (!strncmp(line, "%%BeginFeature:", 15))
+ s = line + 15;
+ else if (!strncmp(line, "%%IncludeFeature:", 17))
+ s = line + 17;
+ else if (!strncmp(line, "%%BeginNonPPDFeature:", 21))
+ s = line + 21;
+
+ if (s && (t = strstr(s, "NumCopies")) != NULL)
+ {
+ t += 9;
+ while ((*t == ' ') || (*t == '\t')) t++;
+ if (sscanf(t, "%9d", &num_copies) == 1)
+ {
+ sprintf(buffer, "%d", num_copies);
+ num_options = cupsAddOption("copies", buffer, num_options, &options);
+ }
+ }
+ else if (s)
+ {
+ while ((*s == ' ') || (*s == '\t')) s++;
+ if (*s == '*') s++;
+ t = s;
+ while (*t && (*t != ' ') && (*t != '\t')) t++;
+ if ((*t == ' ') || (*t == '\t')) *t = '=';
+ num_options = cupsParseOptions(s, num_options, &options);
+ }
+
+ /*
+ * Read out "/#copies XXX def" and "/NumCopies XXX def" expressions from
+ * PostScript input. Some apps insert these expressions to set the
+ * number of copies.
+ */
+
+ s = NULL;
+ if ((s = strstr(line, "/#copies")) != NULL)
+ s += 8;
+ else if ((s = strstr(line, "/NumCopies")) != NULL)
+ s += 10;
+ if (s)
+ {
+ while ((*s == ' ') || (*s == '\t')) s++;
+ if (sscanf(s, "%9d %as ", &num_copies, &t) == 2)
+ {
+ if (!strncmp(t, "def", 3))
+ {
+ sprintf(buffer, "%d", num_copies);
+ num_options = cupsAddOption("copies", buffer, num_options, &options);
+ }
+ free(t);
+ }
+ }
+ }
+
+ /*
* Done with the file; see if we have any options...
*/
|