89
102
media_limits[3] = get_float_option("page-top",
90
103
noptions, options,
91
104
fabs(pagesize->top));
108
if ((val = cupsGetOption("media-size", noptions, options)) != NULL ||
109
(val = cupsGetOption("MediaSize", noptions, options)) != NULL ||
110
(val = cupsGetOption("page-size", noptions, options)) != NULL ||
111
(val = cupsGetOption("PageSize", noptions, options)) != NULL ||
112
(val = cupsGetOption("media", noptions, options)) != NULL) {
113
for (ptr1 = (char *)val; *ptr1;) {
114
for (ptr2 = s; *ptr1 && *ptr1 != ',' && (ptr2 - s) < (sizeof(s) - 1);)
120
if ((size_found = pwgMediaForPWG(s)) == NULL)
121
if ((size_found = pwgMediaForPPD(s)) == NULL)
122
size_found = pwgMediaForLegacy(s);
123
if (size_found != NULL) {
124
*width = size_found->width * 72.0 / 2540.0;
125
*length = size_found->length * 72.0 / 2540.0;
126
media_limits[2] += (*width - 612.0);
127
media_limits[3] += (*length - 792.0);
131
if ((val = cupsGetOption("media-left-margin", noptions, options))
133
media_limits[0] = atol(val) * 72.0 / 2540.0;
134
if ((val = cupsGetOption("media-bottom-margin", noptions, options))
136
media_limits[1] = atol(val) * 72.0 / 2540.0;
137
if ((val = cupsGetOption("media-right-margin", noptions, options))
139
media_limits[2] = *width - atol(val) * 72.0 / 2540.0;
140
if ((val = cupsGetOption("media-top-margin", noptions, options))
142
media_limits[3] = *length - atol(val) * 72.0 / 2540.0;
144
#endif /* HAVE_CUPS_1_7 */
95
static int duplex_marked(ppd_file_t *ppd)
148
static int duplex_marked(ppd_file_t *ppd,
150
cups_option_t *options)
152
const char *val; /* Pointer into value */
98
ppdIsMarked(ppd, "Duplex", "DuplexNoTumble") ||
155
(ppdIsMarked(ppd, "Duplex", "DuplexNoTumble") ||
99
156
ppdIsMarked(ppd, "Duplex", "DuplexTumble") ||
100
157
ppdIsMarked(ppd, "JCLDuplex", "DuplexNoTumble") ||
101
158
ppdIsMarked(ppd, "JCLDuplex", "DuplexTumble") ||
102
159
ppdIsMarked(ppd, "EFDuplex", "DuplexNoTumble") ||
103
160
ppdIsMarked(ppd, "EFDuplex", "DuplexTumble") ||
104
161
ppdIsMarked(ppd, "KD03Duplex", "DuplexNoTumble") ||
105
ppdIsMarked(ppd, "KD03Duplex", "DuplexTumble");
162
ppdIsMarked(ppd, "KD03Duplex", "DuplexTumble"))) ||
163
((val = cupsGetOption("Duplex", noptions, options))
165
(!strcasecmp(val, "DuplexNoTumble") ||
166
!strcasecmp(val, "DuplexTumble"))) ||
167
((val = cupsGetOption("sides", noptions, options))
169
(!strcasecmp(val, "two-sided-long-edge") ||
170
!strcasecmp(val, "two-sided-short-edge")));
144
209
info_line(s, key, "unknown");
212
static const char *human_time(const char *timestamp)
215
int size = sizeof(char) * 40;
216
char *buf = malloc(size);
217
strcpy(buf, "unknown");
220
time = (time_t)atoll(timestamp);
221
strftime(buf, size, "%c", localtime(&time));
228
* Add new key & value.
230
static opt_t* add_opt(opt_t *in_opt, const char *key, const char *val) {
231
if ( ! key || ! val ) {
235
if ( !strlen(key) || !strlen(val) ) {
239
opt_t *entry = malloc(sizeof(opt_t));
246
entry->next = in_opt;
252
* Collect all known info about current task.
253
* Bond PDF form field name with collected info.
255
* Create PDF form's field names according above.
257
opt_t *get_known_opts(
261
const char *jobtitle,
263
cups_option_t *options) {
269
opt = add_opt(opt, "job-id", jobid);
272
opt = add_opt(opt, "job-title", jobtitle);
275
opt = add_opt(opt, "user", user);
278
opt = add_opt(opt, "printer-name", getenv("PRINTER"));
281
opt = add_opt(opt, "printer-info", getenv("PRINTER_INFO"));
283
/* Time at creation */
284
opt = add_opt(opt, "time-at-creation",
285
human_time(cupsGetOption("time-at-creation", noptions, options)));
287
/* Processing time */
288
opt = add_opt(opt, "time-at-processing",
289
human_time(cupsGetOption("time-at-processing", noptions, options)));
291
/* Billing information */
292
opt = add_opt(opt, "job-billing",
293
cupsGetOption("job-billing", noptions, options));
295
/* Source hostname */
296
opt = add_opt(opt, "job-originating-host-name",
297
cupsGetOption("job-originating-host-name", noptions, options));
300
opt = add_opt(opt, "banner-font",
301
cupsGetOption("banner-font", noptions, options));
303
/* Banner font size */
304
opt = add_opt(opt, "banner-font-size",
305
cupsGetOption("banner-font-size", noptions, options));
308
opt = add_opt(opt, "job-uuid",
309
cupsGetOption("job-uuid", noptions, options));
311
/* Security context */
312
opt = add_opt(opt, "security-context",
313
cupsGetOption("security-context", noptions, options));
315
/* Security context range part */
316
opt = add_opt(opt, "security-context-range",
317
cupsGetOption("security-context-range", noptions, options));
319
/* Security context current range part */
320
const char * full_range = cupsGetOption("security-context-range", noptions, options);
322
size_t cur_size = strcspn(full_range, "-");
323
char * cur_range = strndup(full_range, cur_size);
324
opt = add_opt(opt, "security-context-range-cur", cur_range);
327
/* Security context type part */
328
opt = add_opt(opt, "security-context-type",
329
cupsGetOption("security-context-type", noptions, options));
331
/* Security context role part */
332
opt = add_opt(opt, "security-context-role",
333
cupsGetOption("security-context-role", noptions, options));
335
/* Security context user part */
336
opt = add_opt(opt, "security-context-user",
337
cupsGetOption("security-context-user", noptions, options));
341
opt = add_opt(opt, "driver", ppd->pcfilename);
344
opt = add_opt(opt, "driver-version",
345
(attr = ppdFindAttr(ppd, "FileVersion", NULL)) ?
349
opt = add_opt(opt, "make-and-model", ppd->nickname);
148
355
static int generate_banner_pdf(banner_t *banner,
278
485
#endif /* !HAVE_OPEN_MEMSTREAM */
281
pdf_prepend_stream(doc, 1, buf, len);
488
opt_t * known_opts = get_known_opts(ppd,
496
* Try to find a PDF form in PDF template and fill it.
498
int ret = pdf_fill_form(doc, known_opts);
501
* Could we fill a PDF form? If no, just add PDF stream.
504
pdf_prepend_stream(doc, 1, buf, len);
283
507
copies = get_int_option("number-up", noptions, options, 1);
284
if (duplex_marked(ppd))
508
if (duplex_marked(ppd, noptions, options))
312
536
ppd = ppdOpenFile(getenv("PPD"));
314
fprintf(stderr, "Error: could not open PPD file '%s'\n", getenv("PPD"));
538
fprintf(stderr, "DEBUG: Could not open PPD file '%s'\n", getenv("PPD"));
318
540
noptions = cupsParseOptions(argv[5], 0, &options);
319
ppdMarkDefaults(ppd);
320
cupsMarkOptions(ppd, noptions, options);
542
ppdMarkDefaults(ppd);
543
cupsMarkOptions(ppd, noptions, options);
322
banner = banner_new_from_file(argc == 7 ? argv[6] : "-");
546
banner = banner_new_from_file(argc == 7 ? argv[6] : "-", &noptions, &options);
324
548
fprintf(stderr, "Error: could not read banner file\n");