2 * PPD cache implementation for CUPS.
4 * Copyright © 2022-2025 by OpenPrinting.
5 * Copyright © 2010-2021 by Apple Inc.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 #include "cups-private.h"
12 #include "ppd-private.h"
13 #include "debug-internal.h"
19 * Macro to test for two almost-equal PWG measurements.
22 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
29 static int cups_connect(http_t
**http
, const char *url
, char *resource
, size_t ressize
);
30 static cups_lang_t
*cups_get_strings(http_t
**http
, const char *printer_uri
, const char *language
);
31 static int cups_get_url(http_t
**http
, const char *url
, const char *suffix
, char *name
, size_t namesize
);
32 static const char *ppd_get_string(cups_lang_t
*base
, cups_lang_t
*printer
, const char *msgid
, char *buffer
, size_t bufsize
);
33 static void ppd_get_strings(ppd_file_t
*ppd
, cups_lang_t
*langs
, const char *option
, ppd_choice_t
*choice
, const char *pwg_msgid
);
34 static const char *ppd_inputslot_for_keyword(_ppd_cache_t
*pc
, const char *keyword
);
35 static void ppd_put_strings(cups_file_t
*fp
, cups_lang_t
*langs
, const char *ppd_option
, const char *ppd_choice
, const char *pwg_msgid
);
36 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
37 static int pwg_compare_finishings(_pwg_finishings_t
*a
, _pwg_finishings_t
*b
, void *data
);
38 static int pwg_compare_sizes(cups_size_t
*a
, cups_size_t
*b
, void *data
);
39 static cups_size_t
*pwg_copy_size(cups_size_t
*size
, void *data
);
40 static void pwg_free_finishings(_pwg_finishings_t
*f
, void *data
);
41 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
42 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
43 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
44 const char *dashchars
);
48 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
50 * This functions converts PPD and CUPS-specific options to their standard IPP
51 * attributes and values and adds them to the specified IPP request.
54 int /* O - New number of copies */
56 ipp_t
*request
, /* I - IPP request */
57 ppd_file_t
*ppd
, /* I - PPD file */
58 _ppd_cache_t
*pc
, /* I - PPD cache info */
59 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
60 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
61 ipp_attribute_t
*print_color_mode_sup
,
62 /* I - Printer supports print-color-mode */
63 const char *user
, /* I - User info */
64 const char *format
, /* I - document-format value */
65 int copies
, /* I - Number of copies */
66 int num_options
, /* I - Number of options */
67 cups_option_t
*options
) /* I - Options */
69 int i
; /* Looping var */
70 const char *keyword
, /* PWG keyword */
71 *password
; /* Password string */
72 pwg_size_t
*size
; /* PWG media size */
73 ipp_t
*media_col
, /* media-col value */
74 *media_size
; /* media-size value */
75 const char *media_source
, /* media-source value */
76 *media_type
, /* media-type value */
77 *collate_str
, /* multiple-document-handling value */
78 *color_attr_name
, /* Supported color attribute */
79 *mandatory
, /* Mandatory attributes */
80 *finishing_template
; /* Finishing template */
81 int num_finishings
= 0, /* Number of finishing values */
82 finishings
[10]; /* Finishing enum values */
83 ppd_choice_t
*choice
; /* Marked choice */
84 int finishings_copies
= copies
,
85 /* Number of copies for finishings */
86 job_pages
= 0, /* job-pages value */
87 number_up
= 1; /* number-up value */
88 const char *value
; /* Option value */
92 * Send standard IPP attributes...
95 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
97 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
99 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
102 if (!strcmp(keyword
, "none"))
105 * Add plain-text job-password...
108 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
113 * Add hashed job-password...
116 unsigned char hash
[64]; /* Hash of password */
117 ssize_t hashlen
; /* Length of hash */
119 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
120 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
124 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
129 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
130 keyword
= cupsGetOption("job-billing", num_options
, options
);
133 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
136 if (pc
->accounting_user_id
)
138 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
142 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
145 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
147 if (strcmp(mandatory
, "copies") &&
148 strcmp(mandatory
, "destination-uris") &&
149 strcmp(mandatory
, "finishings") &&
150 strcmp(mandatory
, "finishings-col") &&
151 strcmp(mandatory
, "finishing-template") &&
152 strcmp(mandatory
, "job-account-id") &&
153 strcmp(mandatory
, "job-accounting-user-id") &&
154 strcmp(mandatory
, "job-password") &&
155 strcmp(mandatory
, "job-password-encryption") &&
156 strcmp(mandatory
, "media") &&
157 strncmp(mandatory
, "media-col", 9) &&
158 strcmp(mandatory
, "multiple-document-handling") &&
159 strcmp(mandatory
, "output-bin") &&
160 strcmp(mandatory
, "print-color-mode") &&
161 strcmp(mandatory
, "print-quality") &&
162 strcmp(mandatory
, "sides") &&
163 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
165 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
167 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
172 case IPP_TAG_INTEGER
:
174 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
176 case IPP_TAG_BOOLEAN
:
177 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
181 int lower
, upper
; /* Range */
183 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
184 lower
= upper
= atoi(keyword
);
186 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
189 case IPP_TAG_STRING
:
190 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
193 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
195 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
196 keyword
= "auto-monochrome";
197 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
198 keyword
= "process-monochrome";
201 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
207 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
208 keyword
= cupsGetOption("media", num_options
, options
);
210 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
211 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
212 size
= _ppdCacheGetSize(pc
, keyword
, /*ppd_size*/NULL
);
214 if (media_col_sup
&& (size
|| media_source
|| media_type
))
217 * Add a media-col value...
220 media_col
= ippNew();
224 media_size
= ippNew();
225 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
226 "x-dimension", size
->width
);
227 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
228 "y-dimension", size
->length
);
230 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
233 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
235 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
236 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
237 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
238 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
239 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
240 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
241 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
242 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
243 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
244 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
245 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
246 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
249 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
252 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
254 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
255 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
259 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
261 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
264 * If we use PPD with standardized PPD option for color support - ColorModel,
265 * prefer it to don't break color/grayscale support for PPDs, either classic
266 * or the ones generated from IPP Get-Printer-Attributes response.
269 if ((keyword
= cupsGetOption("ColorModel", num_options
, options
)) == NULL
)
272 * No ColorModel in options...
275 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
278 * ColorModel is taken from PPD as its default option.
281 if (!strcmp(choice
->choice
, "Gray") || !strcmp(choice
->choice
, "FastGray") || !strcmp(choice
->choice
, "DeviceGray"))
282 keyword
= "monochrome";
288 * print-color-mode is a default option since 2.4.1, use it as a fallback if there is no
289 * ColorModel in options or PPD...
291 keyword
= cupsGetOption("print-color-mode", num_options
, options
);
296 * ColorModel found in options...
299 if (!strcmp(keyword
, "Gray") || !strcmp(keyword
, "FastGray") || !strcmp(keyword
, "DeviceGray"))
300 keyword
= "monochrome";
305 if (keyword
&& !strcmp(keyword
, "monochrome"))
307 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
308 keyword
= "auto-monochrome";
309 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
310 keyword
= "process-monochrome";
314 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
316 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
317 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
318 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
320 if (!_cups_strcasecmp(choice
->choice
, "draft"))
321 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
322 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
323 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
324 else if (!_cups_strcasecmp(choice
->choice
, "high"))
325 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
328 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
329 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
330 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
332 if (pc
->sides_1sided
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
333 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
334 else if (pc
->sides_2sided_long
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
335 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
336 else if (pc
->sides_2sided_short
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
337 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
344 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
346 if (strstr(keyword
, "uncollated"))
351 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
356 if (!_cups_strcasecmp(format
, "image/gif") ||
357 !_cups_strcasecmp(format
, "image/jp2") ||
358 !_cups_strcasecmp(format
, "image/jpeg") ||
359 !_cups_strcasecmp(format
, "image/png") ||
360 !_cups_strcasecmp(format
, "image/tiff") ||
361 !_cups_strncasecmp(format
, "image/x-", 8))
364 * Collation makes no sense for single page image formats...
369 else if (!_cups_strncasecmp(format
, "image/", 6) ||
370 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
373 * Multi-page image formats will have copies applied by the upstream
381 if (doc_handling_sup
)
383 if (!_cups_strcasecmp(keyword
, "true"))
384 collate_str
= "separate-documents-collated-copies";
386 collate_str
= "separate-documents-uncollated-copies";
388 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
390 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
392 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
397 if (i
>= doc_handling_sup
->num_values
)
402 * Map finishing options...
405 if (copies
!= finishings_copies
)
407 // Figure out the proper job-pages-per-set value...
408 if ((value
= cupsGetOption("job-pages", num_options
, options
)) == NULL
)
409 value
= cupsGetOption("com.apple.print.PrintSettings.PMTotalBeginPages..n.", num_options
, options
);
413 if ((job_pages
= atoi(value
)) < 1)
417 // Adjust for number-up
418 if ((value
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
420 if ((number_up
= atoi(value
)) < 1)
424 job_pages
= (job_pages
+ number_up
- 1) / number_up
;
426 // When duplex printing, raster data will include an extra (blank) page to
427 // make the total number of pages even. Make sure this is reflected in the
429 if ((job_pages
& 1) && (keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
&& strcmp(keyword
, "one-sided"))
433 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
434 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
436 if (finishing_template
&& strcmp(finishing_template
, "none"))
438 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
440 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
441 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
444 if (copies
!= finishings_copies
&& job_pages
> 0)
447 * Send job-pages-per-set attribute to apply finishings correctly...
450 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", job_pages
);
455 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
456 if (num_finishings
> 0)
458 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
460 if (copies
!= finishings_copies
&& job_pages
> 0)
463 * Send job-pages-per-set attribute to apply finishings correctly...
466 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", job_pages
);
476 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
479 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
483 _ppd_cache_t
* /* O - PPD cache and mapping data */
484 _ppdCacheCreateWithFile(
485 const char *filename
, /* I - File to read */
486 ipp_t
**attrs
) /* IO - IPP attributes, if any */
488 cups_file_t
*fp
; /* File */
489 _ppd_cache_t
*pc
; /* PWG mapping data */
490 pwg_size_t
*size
; /* Current size */
491 pwg_map_t
*map
; /* Current map */
492 _pwg_finishings_t
*finishings
; /* Current finishings option */
493 int linenum
, /* Current line number */
494 num_bins
, /* Number of bins in file */
495 num_sizes
, /* Number of sizes in file */
496 num_sources
, /* Number of sources in file */
497 num_types
; /* Number of types in file */
498 char line
[2048], /* Current line */
499 *value
, /* Pointer to value in line */
500 *valueptr
, /* Pointer into value */
501 pwg_keyword
[128], /* PWG keyword */
502 ppd_keyword
[PPD_MAX_NAME
];
504 _pwg_print_color_mode_t print_color_mode
;
505 /* Print color mode for preset */
506 _pwg_print_quality_t print_quality
; /* Print quality for preset */
509 DEBUG_printf("_ppdCacheCreateWithFile(filename=\"%s\")", filename
);
512 * Range check input...
520 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
528 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
530 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
535 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
538 if (!cupsFileGets(fp
, line
, sizeof(line
)))
540 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
541 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
546 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
548 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
549 DEBUG_printf("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
);
554 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
556 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
557 DEBUG_printf("_ppdCacheCreateWithFile: Cache file has version %s, expected %d.", line
+ 16, _PPD_CACHE_VERSION
);
563 * Allocate the mapping data structure...
566 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
568 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
569 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
573 pc
->max_copies
= 9999;
585 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
587 DEBUG_printf("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", linenum=%d", line
, value
, linenum
);
591 DEBUG_printf("_ppdCacheCreateWithFile: Missing value on line %d.", linenum
);
592 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
595 else if (!_cups_strcasecmp(line
, "Filter"))
598 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
600 cupsArrayAdd(pc
->filters
, value
);
602 else if (!_cups_strcasecmp(line
, "PreFilter"))
605 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
607 cupsArrayAdd(pc
->prefilters
, value
);
609 else if (!_cups_strcasecmp(line
, "Product"))
611 pc
->product
= strdup(value
);
613 else if (!_cups_strcasecmp(line
, "SingleFile"))
615 pc
->single_file
= !_cups_strcasecmp(value
, "true");
617 else if (!_cups_strcasecmp(line
, "IPP"))
619 off_t pos
= cupsFileTell(fp
), /* Position in file */
620 length
= strtol(value
, NULL
, 10);
621 /* Length of IPP attributes */
625 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
626 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
629 else if (length
<= 0)
631 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
632 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
639 * Read IPP attributes into the provided variable...
644 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
645 *attrs
) != IPP_STATE_DATA
)
647 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
648 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
655 * Skip the IPP data entirely...
658 cupsFileSeek(fp
, pos
+ length
);
661 if (cupsFileTell(fp
) != (pos
+ length
))
663 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
664 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
668 else if (!_cups_strcasecmp(line
, "NumBins"))
672 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
673 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
677 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
679 DEBUG_printf("_ppdCacheCreateWithFile: Bad NumBins value %d on line %d.", num_sizes
, linenum
);
680 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
684 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
686 DEBUG_printf("_ppdCacheCreateWithFile: Unable to allocate %d bins.", num_sizes
);
687 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
691 else if (!_cups_strcasecmp(line
, "Bin"))
693 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
695 DEBUG_printf("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
);
696 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
700 if (pc
->num_bins
>= num_bins
)
702 DEBUG_printf("_ppdCacheCreateWithFile: Too many Bin's on line %d.", linenum
);
703 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
707 map
= pc
->bins
+ pc
->num_bins
;
708 map
->pwg
= strdup(pwg_keyword
);
709 map
->ppd
= strdup(ppd_keyword
);
713 else if (!_cups_strcasecmp(line
, "NumSizes"))
717 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
718 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
722 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
724 DEBUG_printf("_ppdCacheCreateWithFile: Bad NumSizes value %d on line %d.", num_sizes
, linenum
);
725 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
731 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
733 DEBUG_printf("_ppdCacheCreateWithFile: Unable to allocate %d sizes.", num_sizes
);
734 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
739 else if (!_cups_strcasecmp(line
, "Size"))
741 if (pc
->num_sizes
>= num_sizes
)
743 DEBUG_printf("_ppdCacheCreateWithFile: Too many Size's on line %d.", linenum
);
744 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
748 size
= pc
->sizes
+ pc
->num_sizes
;
750 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
751 &(size
->width
), &(size
->length
), &(size
->left
),
752 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
754 DEBUG_printf("_ppdCacheCreateWithFile: Bad Size on line %d.", linenum
);
755 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
759 size
->map
.pwg
= strdup(pwg_keyword
);
760 size
->map
.ppd
= strdup(ppd_keyword
);
764 else if (!_cups_strcasecmp(line
, "CustomSize"))
766 if (pc
->custom_max_width
> 0)
768 DEBUG_printf("_ppdCacheCreateWithFile: Too many CustomSize's on line %d.", linenum
);
769 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
773 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
774 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
775 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
776 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
777 &(pc
->custom_size
.top
)) != 8)
779 DEBUG_printf("_ppdCacheCreateWithFile: Bad CustomSize on line %d.", linenum
);
780 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
784 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
785 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
786 pc
->custom_max_keyword
= strdup(pwg_keyword
);
788 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
789 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
790 pc
->custom_min_keyword
= strdup(pwg_keyword
);
792 else if (!_cups_strcasecmp(line
, "SourceOption"))
794 pc
->source_option
= strdup(value
);
796 else if (!_cups_strcasecmp(line
, "NumSources"))
800 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
802 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
806 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
808 DEBUG_printf("_ppdCacheCreateWithFile: Bad NumSources value %d on line %d.", num_sources
, linenum
);
809 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
813 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
815 DEBUG_printf("_ppdCacheCreateWithFile: Unable to allocate %d sources.", num_sources
);
816 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
820 else if (!_cups_strcasecmp(line
, "Source"))
822 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
824 DEBUG_printf("_ppdCacheCreateWithFile: Bad Source on line %d.", linenum
);
825 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
829 if (pc
->num_sources
>= num_sources
)
831 DEBUG_printf("_ppdCacheCreateWithFile: Too many Source's on line %d.", linenum
);
832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
836 map
= pc
->sources
+ pc
->num_sources
;
837 map
->pwg
= strdup(pwg_keyword
);
838 map
->ppd
= strdup(ppd_keyword
);
842 else if (!_cups_strcasecmp(line
, "NumTypes"))
846 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
847 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
851 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
853 DEBUG_printf("_ppdCacheCreateWithFile: Bad NumTypes value %d on line %d.", num_types
, linenum
);
854 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
858 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
860 DEBUG_printf("_ppdCacheCreateWithFile: Unable to allocate %d types.", num_types
);
861 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
865 else if (!_cups_strcasecmp(line
, "Type"))
867 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
869 DEBUG_printf("_ppdCacheCreateWithFile: Bad Type on line %d.", linenum
);
870 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
874 if (pc
->num_types
>= num_types
)
876 DEBUG_printf("_ppdCacheCreateWithFile: Too many Type's on line %d.", linenum
);
877 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
881 map
= pc
->types
+ pc
->num_types
;
882 map
->pwg
= strdup(pwg_keyword
);
883 map
->ppd
= strdup(ppd_keyword
);
887 else if (!_cups_strcasecmp(line
, "Preset"))
890 * Preset output-mode print-quality name=value ...
893 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
894 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
896 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
897 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
898 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
899 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
900 valueptr
== value
|| !*valueptr
)
902 DEBUG_printf("_ppdCacheCreateWithFile: Bad Preset on line %d.", linenum
);
903 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
907 pc
->num_presets
[print_color_mode
][print_quality
] =
908 cupsParseOptions(valueptr
, 0,
909 pc
->presets
[print_color_mode
] + print_quality
);
911 else if (!_cups_strcasecmp(line
, "SidesOption"))
912 pc
->sides_option
= strdup(value
);
913 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
914 pc
->sides_1sided
= strdup(value
);
915 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
916 pc
->sides_2sided_long
= strdup(value
);
917 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
918 pc
->sides_2sided_short
= strdup(value
);
919 else if (!_cups_strcasecmp(line
, "Finishings"))
923 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
925 (cups_afree_func_t
)pwg_free_finishings
);
927 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
930 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
931 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
932 &(finishings
->options
));
934 cupsArrayAdd(pc
->finishings
, finishings
);
936 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
939 pc
->templates
= cupsArrayNew3((cups_array_func_t
)_cupsArrayStrcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
941 cupsArrayAdd(pc
->templates
, value
);
943 else if (!_cups_strcasecmp(line
, "MaxCopies"))
944 pc
->max_copies
= atoi(value
);
945 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
946 pc
->charge_info_uri
= strdup(value
);
947 else if (!_cups_strcasecmp(line
, "JobAccountId"))
948 pc
->account_id
= !_cups_strcasecmp(value
, "true");
949 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
950 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
951 else if (!_cups_strcasecmp(line
, "JobPassword"))
952 pc
->password
= strdup(value
);
953 else if (!_cups_strcasecmp(line
, "Mandatory"))
956 cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
958 pc
->mandatory
= cupsArrayNewStrings(value
, ' ');
960 else if (!_cups_strcasecmp(line
, "SupportFile"))
962 if (!pc
->support_files
)
963 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
965 cupsArrayAdd(pc
->support_files
, value
);
969 DEBUG_printf("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
, linenum
);
973 if (pc
->num_sizes
< num_sizes
)
975 DEBUG_printf("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).", pc
->num_sizes
, num_sizes
);
976 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
980 if (pc
->num_sources
< num_sources
)
982 DEBUG_printf("_ppdCacheCreateWithFile: Not enough sources (%d < %d).", pc
->num_sources
, num_sources
);
983 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
987 if (pc
->num_types
< num_types
)
989 DEBUG_printf("_ppdCacheCreateWithFile: Not enough types (%d < %d).", pc
->num_types
, num_types
);
990 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
999 * If we get here the file was bad - free any data and return...
1005 _ppdCacheDestroy(pc
);
1018 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1021 _ppd_cache_t
* /* O - PPD cache and mapping data */
1022 _ppdCacheCreateWithPPD(
1023 cups_lang_t
*langs
, /* I - Languages to load */
1024 ppd_file_t
*ppd
) /* I - PPD file */
1026 int i
, j
, k
; /* Looping vars */
1027 _ppd_cache_t
*pc
; /* PWG mapping data */
1028 ppd_option_t
*input_slot
, /* InputSlot option */
1029 *media_type
, /* MediaType option */
1030 *output_bin
, /* OutputBin option */
1031 *color_model
, /* ColorModel option */
1032 *duplex
, /* Duplex option */
1033 *ppd_option
; /* Other PPD option */
1034 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1035 pwg_map_t
*map
; /* Current source/type map */
1036 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1037 int num_options
; /* Number of preset options and props */
1038 cups_option_t
*options
; /* Preset options and properties */
1039 ppd_size_t
*ppd_size
; /* Current PPD size */
1040 pwg_size_t
*pwg_size
; /* Current PWG size */
1041 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1042 /* PWG keyword string */
1043 ppd_name
[PPD_MAX_NAME
];
1044 /* Normalized PPD name */
1045 const char *pwg_name
; /* Standard PWG media name */
1046 pwg_media_t
*pwg_media
, /* PWG media data */
1047 pwg_mediatemp
; /* PWG media data buffer */
1048 _pwg_print_color_mode_t pwg_print_color_mode
;
1049 /* print-color-mode index */
1050 _pwg_print_quality_t pwg_print_quality
;
1051 /* print-quality index */
1052 int similar
; /* Are the old and new size similar? */
1053 pwg_size_t
*old_size
; /* Current old size */
1054 int old_imageable
, /* Old imageable length in 2540ths */
1055 old_borderless
, /* Old borderless state */
1056 old_known_pwg
; /* Old PWG name is well-known */
1057 int new_width
, /* New width in 2540ths */
1058 new_length
, /* New length in 2540ths */
1059 new_left
, /* New left margin in 2540ths */
1060 new_bottom
, /* New bottom margin in 2540ths */
1061 new_right
, /* New right margin in 2540ths */
1062 new_top
, /* New top margin in 2540ths */
1063 new_imageable
, /* New imageable length in 2540ths */
1064 new_borderless
, /* New borderless state */
1065 new_known_pwg
; /* New PWG name is well-known */
1066 pwg_size_t
*new_size
; /* New size to add, if any */
1067 const char *filter
; /* Current filter */
1068 _pwg_finishings_t
*finishings
; /* Current finishings value */
1069 char msg_id
[256]; /* Message identifier */
1070 cups_lang_t
*lang
; /* Current language */
1071 _cups_message_t msg
; /* Message */
1074 DEBUG_printf("_ppdCacheCreateWithPPD(ppd=%p)", (void *)ppd
);
1077 * Range check input...
1084 * Allocate memory...
1087 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1089 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1094 * Copy and convert size data...
1097 if (ppd
->num_sizes
> 0)
1099 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1101 DEBUG_printf("_ppdCacheCreateWithPPD: Unable to allocate %d pwg_size_t's.", ppd
->num_sizes
);
1105 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1110 * Don't copy over custom size...
1113 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1117 * Convert the PPD size name to the corresponding PWG keyword name.
1120 if ((pwg_media
= pwgMediaForSize(PWG_FROM_POINTS(ppd_size
->width
), PWG_FROM_POINTS(ppd_size
->length
))) != NULL
)
1123 * Standard name, do we have conflicts?
1126 for (j
= 0; j
< pc
->num_sizes
; j
++)
1127 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1137 * Standard name and no conflicts, use it!
1140 pwg_name
= pwg_media
->pwg
;
1146 * Not a standard name; convert it to a PWG vendor name of the form:
1148 * pp_lowerppd_WIDTHxHEIGHTuu
1151 pwg_name
= pwg_keyword
;
1154 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1155 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1156 PWG_FROM_POINTS(ppd_size
->width
),
1157 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1161 * If we have a similar paper with non-zero margins then we only want to
1162 * keep it if it has a larger imageable area length. The NULL check is for
1163 * dimensions that are <= 0...
1166 if ((pwg_media
= _pwgMediaNearSize(&pwg_mediatemp
, /*keyword*/NULL
, /*keysize*/0, /*ppdname*/NULL
, /*ppdsize*/0, PWG_FROM_POINTS(ppd_size
->width
), PWG_FROM_POINTS(ppd_size
->length
), /*epsilon*/0)) == NULL
)
1169 new_width
= pwg_media
->width
;
1170 new_length
= pwg_media
->length
;
1171 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1172 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1173 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1174 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1175 new_imageable
= new_length
- new_top
- new_bottom
;
1176 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1177 new_left
== 0 && new_right
== 0;
1179 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1183 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1184 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1185 old_size
->right
== 0 && old_size
->top
== 0;
1186 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1187 strncmp(old_size
->map
.pwg
, "om_", 3);
1189 similar
= old_borderless
== new_borderless
&&
1190 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1191 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1194 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1197 * The new paper has a larger imageable area so it could replace
1198 * the older paper. Regardless of the imageable area, we always
1199 * prefer the size with a well-known PWG name.
1202 new_size
= old_size
;
1203 free(old_size
->map
.ppd
);
1204 free(old_size
->map
.pwg
);
1211 * The paper was unique enough to deserve its own entry so add it to the
1215 new_size
= pwg_size
++;
1225 new_size
->map
.ppd
= strdup(ppd_size
->name
);
1226 new_size
->map
.pwg
= strdup(pwg_name
);
1227 new_size
->width
= new_width
;
1228 new_size
->length
= new_length
;
1229 new_size
->left
= new_left
;
1230 new_size
->bottom
= new_bottom
;
1231 new_size
->right
= new_right
;
1232 new_size
->top
= new_top
;
1237 if (ppd
->variable_sizes
)
1240 * Generate custom size data...
1243 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1244 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1245 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1246 pc
->custom_max_keyword
= strdup(pwg_keyword
);
1247 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1248 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1250 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1251 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1252 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1253 pc
->custom_min_keyword
= strdup(pwg_keyword
);
1254 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1255 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1257 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1258 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1259 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1260 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1264 * Copy and convert InputSlot data...
1267 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1268 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1272 pc
->source_option
= strdup(input_slot
->keyword
);
1274 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1276 DEBUG_printf("_ppdCacheCreateWithPPD: Unable to allocate %d pwg_map_t's for InputSlot.", input_slot
->num_choices
);
1280 pc
->num_sources
= input_slot
->num_choices
;
1282 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1285 i
--, choice
++, map
++)
1287 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1288 !_cups_strncasecmp(choice
->text
, "Auto", 4) ||
1289 !_cups_strcasecmp(choice
->choice
, "Default") ||
1290 !_cups_strcasecmp(choice
->text
, "Default"))
1292 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1294 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1296 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1298 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1299 !_cups_strcasecmp(choice
->choice
, "MP") ||
1300 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1301 pwg_name
= "by-pass-tray";
1302 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1303 pwg_name
= "large-capacity";
1304 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1305 pwg_name
= "bottom";
1306 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1307 pwg_name
= "middle";
1308 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1310 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1312 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1313 pwg_name
= "main-roll";
1314 else if (!_cups_strcasecmp(choice
->choice
, "0"))
1315 pwg_name
= "tray-1";
1316 else if (!_cups_strcasecmp(choice
->choice
, "1"))
1317 pwg_name
= "tray-2";
1318 else if (!_cups_strcasecmp(choice
->choice
, "2"))
1319 pwg_name
= "tray-3";
1320 else if (!_cups_strcasecmp(choice
->choice
, "3"))
1321 pwg_name
= "tray-4";
1322 else if (!_cups_strcasecmp(choice
->choice
, "4"))
1323 pwg_name
= "tray-5";
1324 else if (!_cups_strcasecmp(choice
->choice
, "5"))
1325 pwg_name
= "tray-6";
1326 else if (!_cups_strcasecmp(choice
->choice
, "6"))
1327 pwg_name
= "tray-7";
1328 else if (!_cups_strcasecmp(choice
->choice
, "7"))
1329 pwg_name
= "tray-8";
1330 else if (!_cups_strcasecmp(choice
->choice
, "8"))
1331 pwg_name
= "tray-9";
1332 else if (!_cups_strcasecmp(choice
->choice
, "9"))
1333 pwg_name
= "tray-10";
1337 * Convert PPD name to lowercase...
1340 pwg_name
= pwg_keyword
;
1341 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1345 map
->pwg
= strdup(pwg_name
);
1346 map
->ppd
= strdup(choice
->choice
);
1349 * Add localized text for PWG keyword to message catalog...
1352 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1353 ppd_get_strings(ppd
, langs
, "InputSlot", choice
, msg_id
);
1358 * Copy and convert MediaType data...
1361 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1365 const char *ppd_name
; /* PPD MediaType name or prefix to match */
1366 int match_length
; /* Length of prefix, or -1 to match entire string */
1367 const char *pwg_name
; /* Registered PWG media-type name to use */
1368 } standard_types
[] = {
1369 {"Auto", 4, "auto"},
1370 {"Any", -1, "auto"},
1371 {"Default", -1, "auto"},
1372 {"Card", 4, "cardstock"},
1373 {"Env", 3, "envelope"},
1374 {"Gloss", 5, "photographic-glossy"},
1375 {"HighGloss", -1, "photographic-high-gloss"},
1376 {"Matte", -1, "photographic-matte"},
1377 {"Plain", 5, "stationery"},
1378 {"Coated", 6, "stationery-coated"},
1379 {"Inkjet", -1, "stationery-inkjet"},
1380 {"Letterhead", -1, "stationery-letterhead"},
1381 {"Preprint", 8, "stationery-preprinted"},
1382 {"Recycled", -1, "stationery-recycled"},
1383 {"Transparen", 10, "transparency"},
1385 const int num_standard_types
= (int)(sizeof(standard_types
) / sizeof(standard_types
[0]));
1386 /* Length of the standard_types array */
1387 int match_counts
[sizeof(standard_types
) / sizeof(standard_types
[0])] = {0};
1388 /* Number of matches for each standard type */
1390 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1392 DEBUG_printf("_ppdCacheCreateWithPPD: Unable to allocate %d pwg_map_t's for MediaType.", media_type
->num_choices
);
1396 pc
->num_types
= media_type
->num_choices
;
1398 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1401 i
--, choice
++, map
++)
1405 for (j
= 0; j
< num_standard_types
; j
++)
1407 if (standard_types
[j
].match_length
<= 0)
1409 if (!_cups_strcasecmp(choice
->choice
, standard_types
[j
].ppd_name
))
1411 pwg_name
= standard_types
[j
].pwg_name
;
1415 else if (!_cups_strncasecmp(choice
->choice
, standard_types
[j
].ppd_name
, (size_t)standard_types
[j
].match_length
))
1417 pwg_name
= standard_types
[j
].pwg_name
;
1425 * Convert PPD name to lowercase...
1428 pwg_name
= pwg_keyword
;
1429 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1433 map
->pwg
= strdup(pwg_name
);
1434 map
->ppd
= strdup(choice
->choice
);
1438 * Since three PPD name patterns can map to "auto", their match counts
1439 * should each be the count of all three combined.
1442 i
= match_counts
[0] + match_counts
[1] + match_counts
[2];
1443 match_counts
[0] = match_counts
[1] = match_counts
[2] = i
;
1445 for (i
= 0, choice
= media_type
->choices
, map
= pc
->types
;
1446 i
< media_type
->num_choices
;
1447 i
++, choice
++, map
++)
1450 * If there are two matches for any standard PWG media type, don't give
1451 * the PWG name to either one.
1454 for (j
= 0; j
< num_standard_types
; j
++)
1456 if (match_counts
[j
] > 1 && !strcmp(map
->pwg
, standard_types
[j
].pwg_name
))
1459 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1460 map
->pwg
= strdup(pwg_keyword
);
1465 * Add localized text for PWG keyword to message catalog...
1468 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", map
->pwg
);
1469 ppd_get_strings(ppd
, langs
, "MediaType", choice
, msg_id
);
1474 * Copy and convert OutputBin data...
1477 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1479 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1481 DEBUG_printf("_ppdCacheCreateWithPPD: Unable to allocate %d pwg_map_t's for OutputBin.", output_bin
->num_choices
);
1485 pc
->num_bins
= output_bin
->num_choices
;
1487 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1490 i
--, choice
++, map
++)
1492 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1494 map
->pwg
= strdup(pwg_keyword
);
1495 map
->ppd
= strdup(choice
->choice
);
1498 * Add localized text for PWG keyword to message catalog...
1501 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_keyword
);
1502 ppd_get_strings(ppd
, langs
, "OutputBin", choice
, msg_id
);
1506 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1509 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1512 const char *quality
, /* com.apple.print.preset.quality value */
1513 *output_mode
, /* com.apple.print.preset.output-mode value */
1514 *color_model_val
, /* ColorModel choice */
1515 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1516 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1522 * Add localized text for PWG keyword to message catalog...
1525 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1526 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1530 * Get the options for this preset...
1533 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1536 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1537 num_options
, options
)) != NULL
)
1540 * Get the print-quality for this preset...
1543 if (!strcmp(quality
, "low"))
1544 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1545 else if (!strcmp(quality
, "high"))
1546 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1548 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1551 * Ignore graphicsType "Photo" presets that are not high quality.
1554 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1555 num_options
, options
);
1557 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1558 !strcmp(graphicsType
, "Photo"))
1562 * Ignore presets for normal and draft quality where the coating
1563 * isn't "none" or "autodetect".
1566 media_front_coating
= cupsGetOption(
1567 "com.apple.print.preset.media-front-coating",
1568 num_options
, options
);
1570 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1571 media_front_coating
&&
1572 strcmp(media_front_coating
, "none") &&
1573 strcmp(media_front_coating
, "autodetect"))
1577 * Get the output mode for this preset...
1580 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1581 num_options
, options
);
1582 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1586 if (!strcmp(output_mode
, "monochrome"))
1587 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1589 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1591 else if (color_model_val
)
1593 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1594 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1596 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1599 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1602 * Save the options for this combination as needed...
1605 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1606 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1607 _ppdParseOptions(ppd_attr
->value
, 0,
1608 pc
->presets
[pwg_print_color_mode
] +
1609 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1612 cupsFreeOptions(num_options
, options
);
1614 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1617 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1618 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1619 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1622 * Try adding some common color options to create grayscale presets. These
1623 * are listed in order of popularity...
1626 const char *color_option
= NULL
, /* Color control option */
1627 *gray_choice
= NULL
; /* Choice to select grayscale */
1629 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1630 ppdFindChoice(color_model
, "Gray"))
1632 color_option
= "ColorModel";
1633 gray_choice
= "Gray";
1635 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1636 ppdFindChoice(color_model
, "grayscale"))
1638 color_option
= "HPColorMode";
1639 gray_choice
= "grayscale";
1641 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1642 ppdFindChoice(color_model
, "Mono"))
1644 color_option
= "BRMonoColor";
1645 gray_choice
= "Mono";
1647 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1648 ppdFindChoice(color_model
, "1"))
1650 color_option
= "CNIJSGrayScale";
1653 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1654 ppdFindChoice(color_model
, "True"))
1656 color_option
= "HPColorAsGray";
1657 gray_choice
= "True";
1660 if (color_option
&& gray_choice
)
1663 * Copy and convert ColorModel (output-mode) data...
1666 cups_option_t
*coption
, /* Color option */
1667 *moption
; /* Monochrome option */
1669 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1670 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1671 pwg_print_quality
++)
1673 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1676 * Copy the color options...
1679 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1680 [pwg_print_quality
];
1681 options
= calloc((size_t)num_options
, sizeof(cups_option_t
));
1685 for (i
= num_options
, moption
= options
,
1686 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1687 [pwg_print_quality
];
1689 i
--, moption
++, coption
++)
1691 moption
->name
= _cupsStrRetain(coption
->name
);
1692 moption
->value
= _cupsStrRetain(coption
->value
);
1695 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1697 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1701 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1705 * Add the grayscale option to the preset...
1708 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1709 cupsAddOption(color_option
, gray_choice
,
1710 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1711 [pwg_print_quality
],
1712 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1719 * Copy and convert Duplex (sides) data...
1722 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1723 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1724 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1725 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1726 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1730 pc
->sides_option
= strdup(duplex
->keyword
);
1732 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1736 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1737 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1738 pc
->sides_1sided
= strdup(choice
->choice
);
1739 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1740 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1741 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1742 pc
->sides_2sided_long
= strdup(choice
->choice
);
1743 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1744 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1745 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1746 !pc
->sides_2sided_short
)
1747 pc
->sides_2sided_short
= strdup(choice
->choice
);
1752 * Copy filters and pre-filters...
1755 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
1757 cupsArrayAdd(pc
->filters
,
1758 "application/vnd.cups-raw application/octet-stream 0 -");
1760 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1764 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1766 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1768 else if (ppd
->num_filters
> 0)
1770 for (i
= 0; i
< ppd
->num_filters
; i
++)
1771 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1774 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1777 * See if we have a command filter...
1780 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1782 filter
= (const char *)cupsArrayNext(pc
->filters
))
1783 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1784 _cups_isspace(filter
[28]))
1788 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1789 _cups_strcasecmp(ppd_attr
->value
, "none")))
1792 * No command filter and no cupsCommands keyword telling us not to use one.
1793 * See if this is a PostScript printer, and if so add a PostScript command
1797 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1799 filter
= (const char *)cupsArrayNext(pc
->filters
))
1800 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1801 _cups_isspace(filter
[31]))
1805 cupsArrayAdd(pc
->filters
,
1806 "application/vnd.cups-command application/postscript 100 "
1810 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1812 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
1816 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1818 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1821 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1822 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1825 * Copy the product string, if any...
1829 pc
->product
= strdup(ppd
->product
);
1832 * Copy finishings mapping data...
1835 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1838 * Have proper vendor mapping of IPP finishings values to PPD options...
1841 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1842 NULL
, NULL
, 0, NULL
,
1843 (cups_afree_func_t
)pwg_free_finishings
);
1847 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1850 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1851 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1852 &(finishings
->options
),
1853 _PPD_PARSE_OPTIONS
);
1855 cupsArrayAdd(pc
->finishings
, finishings
);
1857 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1863 * No IPP mapping data, try to map common/standard PPD keywords...
1866 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1868 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1871 * Add staple finishings...
1874 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1875 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1876 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1877 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1878 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1879 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1880 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1881 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1882 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1883 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1886 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1889 * Add (Ricoh) punch finishings...
1892 if (ppdFindChoice(ppd_option
, "Left2"))
1893 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1894 if (ppdFindChoice(ppd_option
, "Left3"))
1895 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1896 if (ppdFindChoice(ppd_option
, "Left4"))
1897 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1898 if (ppdFindChoice(ppd_option
, "Right2"))
1899 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1900 if (ppdFindChoice(ppd_option
, "Right3"))
1901 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1902 if (ppdFindChoice(ppd_option
, "Right4"))
1903 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1904 if (ppdFindChoice(ppd_option
, "Upper2"))
1905 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1906 if (ppdFindChoice(ppd_option
, "Upper3"))
1907 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1908 if (ppdFindChoice(ppd_option
, "Upper4"))
1909 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1912 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1915 * Add bind finishings...
1918 if (ppdFindChoice(ppd_option
, "Left"))
1919 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1920 if (ppdFindChoice(ppd_option
, "Right"))
1921 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1922 if (ppdFindChoice(ppd_option
, "Top"))
1923 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1924 if (ppdFindChoice(ppd_option
, "Bottom"))
1925 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1928 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1931 * Add (Adobe) fold finishings...
1934 if (ppdFindChoice(ppd_option
, "ZFold"))
1935 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1936 if (ppdFindChoice(ppd_option
, "Saddle"))
1937 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1938 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1939 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1940 if (ppdFindChoice(ppd_option
, "LeftGate"))
1941 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1942 if (ppdFindChoice(ppd_option
, "RightGate"))
1943 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1944 if (ppdFindChoice(ppd_option
, "Letter"))
1945 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1946 if (ppdFindChoice(ppd_option
, "XFold"))
1947 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1950 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1953 * Add (Ricoh) fold finishings...
1956 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1957 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1960 if (cupsArrayCount(pc
->finishings
) == 0)
1962 cupsArrayDelete(pc
->finishings
);
1963 pc
->finishings
= NULL
;
1967 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1969 pc
->templates
= cupsArrayNew3((cups_array_func_t
)_cupsArrayStrcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
1971 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1973 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1976 * Add localized text for PWG keyword to message catalog...
1979 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1982 for (lang
= langs
; lang
; lang
= lang
->next
)
1984 // See if the string is already localized...
1985 if (cupsArrayFind(lang
->strings
, &msg
))
1988 // Otherwise add the text...
1989 if (!strcmp(lang
->language
, "en"))
1992 msg
.str
= choice
->text
;
1996 // Other languauge...
1997 snprintf(ppd_name
, sizeof(ppd_name
), "%s.cupsFinishingTemplate", lang
->language
);
1998 if ((ppd_attr
= ppdFindAttr(ppd
, ppd_name
, choice
->choice
)) != NULL
)
1999 msg
.str
= ppd_attr
->text
;
2004 cupsArrayAdd(lang
->strings
, &msg
);
2013 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
2014 pc
->max_copies
= atoi(ppd_attr
->value
);
2015 else if (ppd
->manual_copies
)
2018 pc
->max_copies
= 9999;
2021 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
2022 * cupsJobPassword, and cupsMandatory.
2025 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
2026 pc
->charge_info_uri
= strdup(ppd_attr
->value
);
2028 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
2029 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
2031 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
2032 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
2034 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
2035 pc
->password
= strdup(ppd_attr
->value
);
2037 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
2038 pc
->mandatory
= cupsArrayNewStrings(ppd_attr
->value
, ' ');
2044 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
2046 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
2048 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
2049 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
2051 #ifdef HAVE_APPLICATIONSERVICES_H
2052 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
2053 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
2057 * Return the cache data...
2063 * If we get here we need to destroy the PWG mapping data and return NULL...
2068 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
2069 _ppdCacheDestroy(pc
);
2076 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
2080 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
2082 int i
; /* Looping var */
2083 pwg_map_t
*map
; /* Current map */
2084 pwg_size_t
*size
; /* Current size */
2088 * Range check input...
2095 * Free memory as needed...
2100 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2111 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2113 free(size
->map
.pwg
);
2114 free(size
->map
.ppd
);
2120 free(pc
->source_option
);
2124 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2135 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2144 free(pc
->custom_max_keyword
);
2145 free(pc
->custom_min_keyword
);
2148 cupsArrayDelete(pc
->filters
);
2149 cupsArrayDelete(pc
->prefilters
);
2150 cupsArrayDelete(pc
->finishings
);
2152 free(pc
->charge_info_uri
);
2155 cupsArrayDelete(pc
->mandatory
);
2157 cupsArrayDelete(pc
->support_files
);
2164 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2168 const char * /* O - output-bin or NULL */
2170 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2171 const char *output_bin
) /* I - PPD OutputBin string */
2173 int i
; /* Looping var */
2177 * Range check input...
2180 if (!pc
|| !output_bin
)
2184 * Look up the OutputBin string...
2188 for (i
= 0; i
< pc
->num_bins
; i
++)
2189 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
) || !_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2190 return (pc
->bins
[i
].pwg
);
2197 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2198 * IPP finishings value(s).
2201 int /* O - New number of options */
2202 _ppdCacheGetFinishingOptions(
2203 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2204 ipp_t
*job
, /* I - Job attributes or NULL */
2205 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2206 int num_options
, /* I - Number of options */
2207 cups_option_t
**options
) /* IO - Options */
2209 int i
; /* Looping var */
2210 _pwg_finishings_t
*f
, /* PWG finishings options */
2211 key
; /* Search key */
2212 ipp_attribute_t
*attr
; /* Finishings attribute */
2213 cups_option_t
*option
; /* Current finishings option */
2217 * Range check input...
2220 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2221 (!job
&& value
== IPP_FINISHINGS_NONE
))
2222 return (num_options
);
2225 * Apply finishing options...
2228 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2230 int num_values
= ippGetCount(attr
); /* Number of values */
2232 for (i
= 0; i
< num_values
; i
++)
2234 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2236 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2238 int j
; /* Another looping var */
2240 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2241 num_options
= cupsAddOption(option
->name
, option
->value
,
2242 num_options
, options
);
2246 else if (value
!= IPP_FINISHINGS_NONE
)
2250 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2252 int j
; /* Another looping var */
2254 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2255 num_options
= cupsAddOption(option
->name
, option
->value
,
2256 num_options
, options
);
2260 return (num_options
);
2265 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2269 int /* O - Number of finishings values */
2270 _ppdCacheGetFinishingValues(
2271 ppd_file_t
*ppd
, /* I - Marked PPD file */
2272 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2273 int max_values
, /* I - Maximum number of finishings values */
2274 int *values
) /* O - Finishings values */
2276 int i
, /* Looping var */
2277 num_values
= 0; /* Number of values */
2278 _pwg_finishings_t
*f
; /* Current finishings option */
2279 cups_option_t
*option
; /* Current option */
2280 ppd_choice_t
*choice
; /* Marked PPD choice */
2284 * Range check input...
2287 DEBUG_printf("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", (void *)ppd
, (void *)pc
, max_values
, (void *)values
);
2289 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2291 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2294 else if (!pc
->finishings
)
2296 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2301 * Go through the finishings options and see what is set...
2304 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2306 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2308 DEBUG_printf("_ppdCacheGetFinishingValues: Checking %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
));
2310 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2312 DEBUG_printf("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
);
2314 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2316 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2323 DEBUG_printf("_ppdCacheGetFinishingValues: Adding %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
));
2325 values
[num_values
++] = (int)f
->value
;
2327 if (num_values
>= max_values
)
2332 if (num_values
== 0)
2335 * Always have at least "finishings" = 'none'...
2338 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2339 values
[0] = IPP_FINISHINGS_NONE
;
2343 DEBUG_printf("_ppdCacheGetFinishingValues: Returning %d.", num_values
);
2345 return (num_values
);
2350 * 'ppd_inputslot_for_keyword()' - Return the PPD InputSlot associated
2351 * a keyword string, or NULL if no mapping
2354 static const char * /* O - PPD InputSlot or NULL */
2355 ppd_inputslot_for_keyword(
2356 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2357 const char *keyword
) /* I - Keyword string */
2359 int i
; /* Looping var */
2361 if (!pc
|| !keyword
)
2364 for (i
= 0; i
< pc
->num_sources
; i
++)
2365 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
) || !_cups_strcasecmp(keyword
, pc
->sources
[i
].ppd
))
2366 return (pc
->sources
[i
].ppd
);
2373 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2374 * attributes or a keyword string.
2377 const char * /* O - PPD InputSlot or NULL */
2378 _ppdCacheGetInputSlot(
2379 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2380 ipp_t
*job
, /* I - Job attributes or NULL */
2381 const char *keyword
) /* I - Keyword string or NULL */
2384 * Range check input...
2387 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2390 if (job
&& !keyword
)
2393 * Lookup the media-col attribute and any media-source found there...
2396 ipp_attribute_t
*media_col
, /* media-col attribute */
2397 *media_source
; /* media-source attribute */
2398 pwg_size_t size
; /* Dimensional size */
2399 int margins_set
; /* Were the margins set? */
2401 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2403 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2405 IPP_TAG_KEYWORD
)) != NULL
)
2408 * Use the media-source value from media-col...
2411 keyword
= ippGetString(media_source
, 0, NULL
);
2413 else if (pwgInitSize(&size
, job
, &margins_set
))
2416 * For media <= 5x7, try to ask for automatic selection so the printer can
2417 * pick the photo tray. If auto isn't available, fall back to explicitly
2418 * asking for the photo tray.
2421 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540)) {
2423 if ((match
= ppd_inputslot_for_keyword(pc
, "auto")) != NULL
)
2430 return (ppd_inputslot_for_keyword(pc
, keyword
));
2435 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2436 * attributes or a keyword string.
2439 const char * /* O - PPD MediaType or NULL */
2440 _ppdCacheGetMediaType(
2441 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2442 ipp_t
*job
, /* I - Job attributes or NULL */
2443 const char *keyword
) /* I - Keyword string or NULL */
2446 * Range check input...
2449 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2452 if (job
&& !keyword
)
2455 * Lookup the media-col attribute and any media-source found there...
2458 ipp_attribute_t
*media_col
, /* media-col attribute */
2459 *media_type
; /* media-type attribute */
2461 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2464 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2466 IPP_TAG_KEYWORD
)) == NULL
)
2467 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2468 "media-type", IPP_TAG_NAME
);
2471 keyword
= media_type
->values
[0].string
.text
;
2477 int i
; /* Looping var */
2479 for (i
= 0; i
< pc
->num_types
; i
++)
2480 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
) || !_cups_strcasecmp(keyword
, pc
->types
[i
].ppd
))
2481 return (pc
->types
[i
].ppd
);
2489 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2493 const char * /* O - PPD OutputBin or NULL */
2494 _ppdCacheGetOutputBin(
2495 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2496 const char *output_bin
) /* I - Keyword string */
2498 int i
; /* Looping var */
2502 * Range check input...
2505 if (!pc
|| !output_bin
)
2509 * Look up the OutputBin string...
2513 for (i
= 0; i
< pc
->num_bins
; i
++)
2514 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
) || !_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2515 return (pc
->bins
[i
].ppd
);
2522 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2523 * attributes or a keyword string.
2526 const char * /* O - PPD PageSize or NULL */
2527 _ppdCacheGetPageSize(
2528 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2529 ipp_t
*job
, /* I - Job attributes or NULL */
2530 const char *keyword
, /* I - Keyword string or NULL */
2531 int *exact
) /* O - 1 if exact match, 0 otherwise */
2533 int i
; /* Looping var */
2534 pwg_size_t
*size
, /* Current size */
2535 *closest
, /* Closest size */
2536 jobsize
; /* Size data from job */
2537 int margins_set
, /* Were the margins set? */
2538 dwidth
, /* Difference in width */
2539 dlength
, /* Difference in length */
2540 dleft
, /* Difference in left margins */
2541 dright
, /* Difference in right margins */
2542 dbottom
, /* Difference in bottom margins */
2543 dtop
, /* Difference in top margins */
2544 dmin
, /* Minimum difference */
2545 dclosest
; /* Closest difference */
2546 const char *ppd_name
; /* PPD media name */
2549 DEBUG_printf("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)", (void *)pc
, (void *)job
, keyword
, (void *)exact
);
2552 * Range check input...
2555 if (!pc
|| (!job
&& !keyword
))
2566 * Try getting the PPD media name from the job attributes...
2569 ipp_attribute_t
*attr
; /* Job attribute */
2571 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2572 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2573 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2577 DEBUG_printf("1_ppdCacheGetPageSize: Found attribute %s (%s)", attr
->name
, ippTagString(attr
->value_tag
));
2579 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2582 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2583 attr
->value_tag
== IPP_TAG_KEYWORD
))
2584 ppd_name
= attr
->values
[0].string
.text
;
2587 DEBUG_printf("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
);
2592 * Try looking up the named PPD size first...
2595 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2597 DEBUG_printf("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]", (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
);
2599 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2600 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2605 DEBUG_printf("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
);
2607 return (size
->map
.ppd
);
2612 if (job
&& !keyword
)
2615 * Get the size using media-col or media, with the preference being
2619 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2625 * Get the size using a media keyword...
2628 pwg_media_t
*media
; /* Media definition */
2631 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2632 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2633 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2636 jobsize
.width
= media
->width
;
2637 jobsize
.length
= media
->length
;
2642 * Now that we have the dimensions and possibly the margins, look at the
2643 * available sizes and find the match...
2647 dclosest
= 999999999;
2649 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2650 _cups_strncasecmp(ppd_name
, "custom_", 7))
2652 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2655 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2656 * is just about 176/2540ths...
2659 dwidth
= size
->width
- jobsize
.width
;
2660 dlength
= size
->length
- jobsize
.length
;
2662 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2668 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2671 dleft
= size
->left
- jobsize
.left
;
2672 dright
= size
->right
- jobsize
.right
;
2673 dtop
= size
->top
- jobsize
.top
;
2674 dbottom
= size
->bottom
- jobsize
.bottom
;
2676 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2677 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2679 dleft
= dleft
< 0 ? -dleft
: dleft
;
2680 dright
= dright
< 0 ? -dright
: dright
;
2681 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2682 dtop
= dtop
< 0 ? -dtop
: dtop
;
2683 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2685 if (dmin
< dclosest
)
2698 DEBUG_printf("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
);
2700 return (size
->map
.ppd
);
2706 DEBUG_printf("1_ppdCacheGetPageSize: Returning \"%s\" (closest)", closest
->map
.ppd
);
2708 return (closest
->map
.ppd
);
2712 * If we get here we need to check for custom page size support...
2715 if (jobsize
.width
>= pc
->custom_min_width
&&
2716 jobsize
.width
<= pc
->custom_max_width
&&
2717 jobsize
.length
>= pc
->custom_min_length
&&
2718 jobsize
.length
<= pc
->custom_max_length
)
2721 * In range, format as Custom.WWWWxLLLL (points).
2724 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2725 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2727 if (margins_set
&& exact
)
2729 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2730 dright
= pc
->custom_size
.right
- jobsize
.right
;
2731 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2732 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2734 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2735 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2741 DEBUG_printf("1_ppdCacheGetPageSize: Returning \"%s\" (custom)", pc
->custom_ppd_size
);
2743 return (pc
->custom_ppd_size
);
2747 * No custom page size support or the size is out of range - return NULL.
2750 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2757 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2760 pwg_size_t
* /* O - PWG size or NULL */
2762 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2763 const char *page_size
, /* I - PPD PageSize */
2764 ppd_size_t
*ppd_size
) /* I - PPD page size information */
2766 int i
; /* Looping var */
2767 pwg_media_t
*media
; /* Media */
2768 pwg_size_t
*size
; /* Current size */
2772 * Range check input...
2775 if (!pc
|| !page_size
)
2778 if (!_cups_strcasecmp(page_size
, "Custom") || !_cups_strncasecmp(page_size
, "Custom.", 7))
2781 * Custom size; size name can be one of the following:
2783 * Custom.WIDTHxLENGTHin - Size in inches
2784 * Custom.WIDTHxLENGTHft - Size in feet
2785 * Custom.WIDTHxLENGTHcm - Size in centimeters
2786 * Custom.WIDTHxLENGTHmm - Size in millimeters
2787 * Custom.WIDTHxLENGTHm - Size in meters
2788 * Custom.WIDTHxLENGTH[pt] - Size in points
2791 double w
, l
; /* Width and length of page */
2792 char *ptr
; /* Pointer into PageSize */
2793 struct lconv
*loc
; /* Locale data */
2798 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2799 if (!ptr
|| *ptr
!= 'x')
2802 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2806 if (!_cups_strcasecmp(ptr
, "in"))
2811 else if (!_cups_strcasecmp(ptr
, "ft"))
2816 else if (!_cups_strcasecmp(ptr
, "mm"))
2821 else if (!_cups_strcasecmp(ptr
, "cm"))
2826 else if (!_cups_strcasecmp(ptr
, "m"))
2839 w
= ppd_size
->width
* 2540.0 / 72.0;
2840 l
= ppd_size
->length
* 2540.0 / 72.0;
2844 // No custom size information...
2848 pc
->custom_size
.map
.ppd
= (char *)page_size
;
2849 pc
->custom_size
.width
= (int)w
;
2850 pc
->custom_size
.length
= (int)l
;
2852 if ((media
= pwgMediaForSize((int)w
, (int)l
)) != NULL
)
2853 pc
->custom_size
.map
.pwg
= (char *)media
->pwg
;
2855 return (&(pc
->custom_size
));
2859 * Not a custom size - look it up...
2862 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2864 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2865 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2870 * Look up standard sizes...
2873 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2875 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2876 media
= pwgMediaForPWG(page_size
);
2881 pc
->custom_size
.map
.ppd
= (char *)page_size
;
2882 pc
->custom_size
.map
.pwg
= (char *)media
->pwg
;
2883 pc
->custom_size
.width
= media
->width
;
2884 pc
->custom_size
.length
= media
->length
;
2886 return (&(pc
->custom_size
));
2894 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2898 const char * /* O - PWG media-source keyword */
2900 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2901 const char *input_slot
) /* I - PPD InputSlot */
2903 int i
; /* Looping var */
2904 pwg_map_t
*source
; /* Current source */
2908 * Range check input...
2911 if (!pc
|| !input_slot
)
2914 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2915 if (!_cups_strcasecmp(input_slot
, source
->ppd
) || !_cups_strcasecmp(input_slot
, source
->pwg
))
2916 return (source
->pwg
);
2923 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2927 const char * /* O - PWG media-type keyword */
2929 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2930 const char *media_type
) /* I - PPD MediaType */
2932 int i
; /* Looping var */
2933 pwg_map_t
*type
; /* Current type */
2937 * Range check input...
2940 if (!pc
|| !media_type
)
2943 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2944 if (!_cups_strcasecmp(media_type
, type
->ppd
) || !_cups_strcasecmp(media_type
, type
->pwg
))
2952 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2955 int /* O - 1 on success, 0 on failure */
2957 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2958 const char *filename
, /* I - File to write */
2959 ipp_t
*attrs
) /* I - Attributes to write, if any */
2961 int i
, j
, k
; /* Looping vars */
2962 cups_file_t
*fp
; /* Output file */
2963 pwg_size_t
*size
; /* Current size */
2964 pwg_map_t
*map
; /* Current map */
2965 _pwg_finishings_t
*f
; /* Current finishing option */
2966 cups_option_t
*option
; /* Current option */
2967 const char *value
; /* String value */
2968 char newfile
[1024]; /* New filename */
2972 * Range check input...
2975 if (!pc
|| !filename
)
2977 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2982 * Open the file and write with compression...
2985 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2986 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2988 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2993 * Standard header...
2996 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
3002 if (pc
->num_bins
> 0)
3004 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
3005 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
3006 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
3013 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
3014 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
3015 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
3016 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
3017 size
->bottom
, size
->right
, size
->top
);
3018 if (pc
->custom_max_width
> 0)
3019 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
3020 pc
->custom_max_width
, pc
->custom_max_length
,
3021 pc
->custom_min_width
, pc
->custom_min_length
,
3022 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
3023 pc
->custom_size
.right
, pc
->custom_size
.top
);
3029 if (pc
->source_option
)
3030 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
3032 if (pc
->num_sources
> 0)
3034 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
3035 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
3036 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
3043 if (pc
->num_types
> 0)
3045 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
3046 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
3047 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
3054 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
3056 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
3058 if (pc
->num_presets
[i
][j
])
3060 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
3061 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
3064 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
3065 cupsFilePutChar(fp
, '\n');
3074 if (pc
->sides_option
)
3075 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
3077 if (pc
->sides_1sided
)
3078 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
3080 if (pc
->sides_2sided_long
)
3081 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
3083 if (pc
->sides_2sided_short
)
3084 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
3087 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
3091 cupsFilePutConf(fp
, "Product", pc
->product
);
3093 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
3095 value
= (const char *)cupsArrayNext(pc
->filters
))
3096 cupsFilePutConf(fp
, "Filter", value
);
3098 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
3100 value
= (const char *)cupsArrayNext(pc
->prefilters
))
3101 cupsFilePutConf(fp
, "PreFilter", value
);
3103 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
3106 * Finishing options...
3109 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
3111 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
3113 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
3114 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
3115 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
3116 cupsFilePutChar(fp
, '\n');
3119 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
3120 cupsFilePutConf(fp
, "FinishingTemplate", value
);
3126 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
3129 * Accounting/quota/PIN/managed printing values...
3132 if (pc
->charge_info_uri
)
3133 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
3135 cupsFilePrintf(fp
, "JobAccountId %s\n", pc
->account_id
? "true" : "false");
3136 cupsFilePrintf(fp
, "JobAccountingUserId %s\n",
3137 pc
->accounting_user_id
? "true" : "false");
3140 cupsFilePutConf(fp
, "JobPassword", pc
->password
);
3142 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
3144 value
= (char *)cupsArrayNext(pc
->mandatory
))
3145 cupsFilePutConf(fp
, "Mandatory", value
);
3151 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
3153 value
= (char *)cupsArrayNext(pc
->support_files
))
3154 cupsFilePutConf(fp
, "SupportFile", value
);
3157 * IPP attributes, if any...
3162 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3164 attrs
->state
= IPP_STATE_IDLE
;
3165 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3169 * Close and return...
3172 if (cupsFileClose(fp
))
3179 return (!rename(newfile
, filename
));
3184 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3185 * of an IPP printer.
3188 char * /* O - PPD filename or `NULL` on error */
3189 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3190 size_t bufsize
, /* I - Size of filename buffer */
3191 ipp_t
*supported
) /* I - Get-Printer-Attributes response */
3193 const char *printer_uri
; /* Printer URI */
3194 http_t
*http
= NULL
; /* HTTP connection */
3195 cups_lang_t
*base_lang
, /* Base English language */
3196 *lang
, /* Current language information */
3197 *langs
= NULL
; /* Language (strings) files */
3198 const char *prefix
; /* Prefix string */
3199 cups_file_t
*fp
; /* PPD file */
3200 cups_array_t
*sizes
; /* Media sizes supported by printer */
3201 cups_size_t
*size
; /* Current media size */
3202 ipp_attribute_t
*attr
, /* xxx-supported */
3203 *lang_supp
, /* printer-strings-languages-supported */
3204 *defattr
, /* xxx-default */
3205 *quality
, /* print-quality-supported */
3206 *x_dim
, *y_dim
; /* Media dimensions */
3207 ipp_t
*media_col
, /* Media collection */
3208 *media_size
; /* Media size collection */
3209 char make
[256], /* Make and model */
3210 *mptr
, /* Pointer into make and model */
3211 ppdname
[PPD_MAX_NAME
],
3213 ppdtext
[PPD_MAX_TEXT
];
3214 /* PPD English text */
3215 const char *model
; /* Model name */
3216 int i
, j
, /* Looping vars */
3217 count
, /* Number of values */
3218 bottom
, /* Largest bottom margin */
3219 left
, /* Largest left margin */
3220 right
, /* Largest right margin */
3221 top
, /* Largest top margin */
3222 max_length
= 0, /* Maximum custom size */
3224 min_length
= INT_MAX
,
3225 /* Minimum custom size */
3226 min_width
= INT_MAX
,
3227 is_apple
= 0, /* Does the printer support Apple raster? */
3228 is_pdf
= 0, /* Does the printer support PDF? */
3229 is_pwg
= 0; /* Does the printer support PWG Raster? */
3230 pwg_media_t
*pwg
; /* PWG media size */
3231 int xres
, yres
; /* Resolution values */
3232 int resolutions
[1000];
3233 /* Array of resolution indices */
3234 int have_qdraft
= 0,/* Have draft quality? */
3235 have_qhigh
= 0; /* Have high quality? */
3236 char msgid
[256]; /* PWG message identifier (attr.value) */
3237 const char *keyword
; /* Keyword value */
3238 struct lconv
*loc
= localeconv();
3240 cups_array_t
*fin_options
= NULL
;
3241 /* Finishing options */
3245 * Range check input...
3251 if (!buffer
|| bufsize
< 1)
3253 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3259 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3263 if ((printer_uri
= ippGetString(ippFindAttribute(supported
, "printer-uri-supported", IPP_TAG_URI
), 0, NULL
)) == NULL
)
3265 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No printer-uri-supported attribute."), 1);
3270 * Open a temporary file for the PPD...
3273 if ((fp
= cupsCreateTempFile("ippeve", ".ppd", buffer
, bufsize
)) == NULL
)
3275 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3280 * Get a sanitized make and model...
3283 if ((attr
= ippFindAttribute(supported
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
&& ippValidateAttribute(attr
))
3286 * Sanitize the model name to only contain PPD-safe characters.
3289 cupsCopyString(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3291 for (mptr
= make
; *mptr
; mptr
++)
3293 if (*mptr
< ' ' || *mptr
>= 127 || *mptr
== '\"')
3296 * Truncate the make and model on the first bad character...
3307 * Strip trailing whitespace...
3320 * Use a default make and model if nothing remains...
3323 cupsCopyString(make
, "Unknown", sizeof(make
));
3329 * Use a default make and model...
3332 cupsCopyString(make
, "Unknown", sizeof(make
));
3335 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) || !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3338 * Normalize HP printer make and model...
3342 cupsCopyString(make
, "HP", sizeof(make
));
3344 if (!_cups_strncasecmp(model
, "HP ", 3))
3347 else if ((mptr
= strchr(make
, ' ')) != NULL
)
3350 * Separate "MAKE MODEL"...
3353 while (*mptr
&& *mptr
== ' ')
3361 * No separate model name...
3368 * Standard stuff for PPD file...
3371 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3372 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3373 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3374 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3375 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3376 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3377 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3378 cupsFilePuts(fp
, "*FileSystem: False\n");
3379 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3380 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3381 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3382 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3383 cupsFilePrintf(fp
, "*NickName: \"%s - IPP Everywhere\"\n", model
);
3384 cupsFilePrintf(fp
, "*ShortNickName: \"%s - IPP Everywhere\"\n", model
);
3386 if (ippGetBoolean(ippFindAttribute(supported
, "color-supported", IPP_TAG_BOOLEAN
), 0))
3387 cupsFilePuts(fp
, "*ColorDevice: True\n");
3389 cupsFilePuts(fp
, "*ColorDevice: False\n");
3391 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3393 cupsFilePrintf(fp
, "*APAirPrint: True\n");
3395 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3397 if ((lang_supp
= ippFindAttribute(supported
, "printer-strings-languages-supported", IPP_TAG_LANGUAGE
)) != NULL
)
3400 * List supported languages...
3403 for (i
= 0, count
= ippGetCount(lang_supp
), prefix
= "*cupsLanguages: \""; i
< count
; i
++)
3405 keyword
= ippGetString(lang_supp
, i
, NULL
);
3407 if ((lang
= cups_get_strings(&http
, printer_uri
, keyword
)) != NULL
)
3416 cupsFilePrintf(fp
, "%s%s", prefix
, keyword
);
3421 if (!strcmp(prefix
, " "))
3422 cupsFilePuts(fp
, "\"\n");
3431 // Find the English localization...
3432 for (lang
= langs
; lang
; lang
= lang
->next
)
3434 if (!strcmp(lang
->language
, "en"))
3438 base_lang
= cupsLangGet("en");
3440 if ((attr
= ippFindAttribute(supported
, "printer-more-info", IPP_TAG_URI
)) != NULL
&& ippValidateAttribute(attr
))
3441 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3443 if ((attr
= ippFindAttribute(supported
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
&& ippValidateAttribute(attr
))
3444 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3450 if (ippGetBoolean(ippFindAttribute(supported
, "job-account-id-supported", IPP_TAG_BOOLEAN
), 0))
3451 cupsFilePuts(fp
, "*cupsJobAccountId: True\n");
3453 if (ippGetBoolean(ippFindAttribute(supported
, "job-accounting-user-id-supported", IPP_TAG_BOOLEAN
), 0))
3454 cupsFilePuts(fp
, "*cupsJobAccountingUserId: True\n");
3456 if ((attr
= ippFindAttribute(supported
, "printer-privacy-policy-uri", IPP_TAG_URI
)) != NULL
&& ippValidateAttribute(attr
))
3457 cupsFilePrintf(fp
, "*cupsPrivacyURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3459 if ((attr
= ippFindAttribute(supported
, "printer-mandatory-job-attributes", IPP_TAG_KEYWORD
)) != NULL
&& ippValidateAttribute(attr
))
3461 for (i
= 0, count
= ippGetCount(attr
), prefix
= "*cupsMandatory: \""; i
< count
; i
++)
3463 keyword
= ippGetString(attr
, i
, NULL
);
3465 if (strcmp(keyword
, "attributes-charset") && strcmp(keyword
, "attributes-natural-language") && strcmp(keyword
, "printer-uri"))
3467 cupsFilePrintf(fp
, "%s%s", prefix
, keyword
);
3472 if (!strcmp(prefix
, " "))
3473 cupsFilePuts(fp
, "\"\n");
3476 if ((attr
= ippFindAttribute(supported
, "printer-requested-job-attributes", IPP_TAG_KEYWORD
)) != NULL
&& ippValidateAttribute(attr
))
3478 for (i
= 0, count
= ippGetCount(attr
), prefix
= "*cupsRequested: \""; i
< count
; i
++)
3480 keyword
= ippGetString(attr
, i
, NULL
);
3482 if (strcmp(keyword
, "attributes-charset") && strcmp(keyword
, "attributes-natural-language") && strcmp(keyword
, "printer-uri"))
3484 cupsFilePrintf(fp
, "%s%s", prefix
, keyword
);
3489 if (!strcmp(prefix
, " "))
3490 cupsFilePuts(fp
, "\"\n");
3494 * Password/PIN printing...
3497 if ((attr
= ippFindAttribute(supported
, "job-password-supported", IPP_TAG_INTEGER
)) != NULL
)
3499 char pattern
[33]; /* Password pattern */
3500 int maxlen
= ippGetInteger(attr
, 0);
3501 /* Maximum length */
3502 const char *repertoire
= ippGetString(ippFindAttribute(supported
, "job-password-repertoire-configured", IPP_TAG_KEYWORD
), 0, NULL
);
3503 /* Type of password */
3505 if (maxlen
> (int)(sizeof(pattern
) - 1))
3506 maxlen
= (int)sizeof(pattern
) - 1;
3508 if (!repertoire
|| !strcmp(repertoire
, "iana_us-ascii_digits"))
3509 memset(pattern
, '1', (size_t)maxlen
);
3510 else if (!strcmp(repertoire
, "iana_us-ascii_letters"))
3511 memset(pattern
, 'A', (size_t)maxlen
);
3512 else if (!strcmp(repertoire
, "iana_us-ascii_complex"))
3513 memset(pattern
, 'C', (size_t)maxlen
);
3514 else if (!strcmp(repertoire
, "iana_us-ascii_any"))
3515 memset(pattern
, '.', (size_t)maxlen
);
3516 else if (!strcmp(repertoire
, "iana_utf-8_digits"))
3517 memset(pattern
, 'N', (size_t)maxlen
);
3518 else if (!strcmp(repertoire
, "iana_utf-8_letters"))
3519 memset(pattern
, 'U', (size_t)maxlen
);
3521 memset(pattern
, '*', (size_t)maxlen
);
3523 pattern
[maxlen
] = '\0';
3525 cupsFilePrintf(fp
, "*cupsJobPassword: \"%s\"\n", pattern
);
3532 if ((attr
= ippFindAttribute(supported
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3534 is_apple
= ippContainsString(attr
, "image/urf") && (ippFindAttribute(supported
, "urf-supported", IPP_TAG_KEYWORD
) != NULL
);
3535 is_pdf
= ippContainsString(attr
, "application/pdf");
3536 is_pwg
= ippContainsString(attr
, "image/pwg-raster") && !is_apple
&&
3537 (ippFindAttribute(supported
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
) != NULL
) &&
3538 (ippFindAttribute(supported
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
) != NULL
);
3540 if (ippContainsString(attr
, "image/jpeg"))
3541 cupsFilePuts(fp
, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n");
3542 if (ippContainsString(attr
, "image/png"))
3543 cupsFilePuts(fp
, "*cupsFilter2: \"image/png image/png 0 -\"\n");
3547 * Don't locally filter PDF content when printing to a CUPS shared
3548 * printer, otherwise the options will be applied twice...
3551 if (ippContainsString(attr
, "application/vnd.cups-pdf"))
3552 cupsFilePuts(fp
, "*cupsFilter2: \"application/pdf application/pdf 0 -\"\n");
3554 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3557 cupsFilePuts(fp
, "*cupsManualCopies: True\n");
3559 cupsFilePuts(fp
, "*cupsFilter2: \"image/urf image/urf 100 -\"\n");
3561 cupsFilePuts(fp
, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n");
3564 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3568 * PageSize/PageRegion/ImageableArea/PaperDimension
3571 if ((attr
= ippFindAttribute(supported
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3573 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3574 if (ippGetInteger(attr
, i
) > bottom
)
3575 bottom
= ippGetInteger(attr
, i
);
3580 if ((attr
= ippFindAttribute(supported
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3582 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3583 if (ippGetInteger(attr
, i
) > left
)
3584 left
= ippGetInteger(attr
, i
);
3589 if ((attr
= ippFindAttribute(supported
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3591 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3592 if (ippGetInteger(attr
, i
) > right
)
3593 right
= ippGetInteger(attr
, i
);
3598 if ((attr
= ippFindAttribute(supported
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3600 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3601 if (ippGetInteger(attr
, i
) > top
)
3602 top
= ippGetInteger(attr
, i
);
3607 if ((defattr
= ippFindAttribute(supported
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3609 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3611 media_size
= ippGetCollection(attr
, 0);
3612 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3613 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3615 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3616 cupsCopyString(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3618 cupsCopyString(ppdname
, "Unknown", sizeof(ppdname
));
3621 cupsCopyString(ppdname
, "Unknown", sizeof(ppdname
));
3623 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(supported
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3624 cupsCopyString(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3626 cupsCopyString(ppdname
, "Unknown", sizeof(ppdname
));
3628 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, _cupsArrayFree
);
3630 if ((attr
= ippFindAttribute(supported
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3632 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3634 cups_size_t temp
; /* Current size */
3635 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3637 media_col
= ippGetCollection(attr
, i
);
3638 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3639 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3640 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3641 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3645 temp
.width
= pwg
->width
;
3646 temp
.length
= pwg
->length
;
3648 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3649 temp
.bottom
= ippGetInteger(margin
, 0);
3651 temp
.bottom
= bottom
;
3653 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3654 temp
.left
= ippGetInteger(margin
, 0);
3658 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3659 temp
.right
= ippGetInteger(margin
, 0);
3663 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3664 temp
.top
= ippGetInteger(margin
, 0);
3668 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3669 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3671 cupsCopyString(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3673 if (!cupsArrayFind(sizes
, &temp
))
3674 cupsArrayAdd(sizes
, &temp
);
3676 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3679 * Custom size - record the min/max values...
3682 int lower
, upper
; /* Range values */
3684 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3685 lower
= ippGetRange(x_dim
, 0, &upper
);
3687 lower
= upper
= ippGetInteger(x_dim
, 0);
3689 if (lower
< min_width
)
3691 if (upper
> max_width
)
3694 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3695 lower
= ippGetRange(y_dim
, 0, &upper
);
3697 lower
= upper
= ippGetInteger(y_dim
, 0);
3699 if (lower
< min_length
)
3701 if (upper
> max_length
)
3706 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(supported
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3709 * Some printers don't list custom size support in media-col-database...
3712 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3714 media_size
= ippGetCollection(attr
, i
);
3715 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3716 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3718 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3721 * Custom size - record the min/max values...
3724 int lower
, upper
; /* Range values */
3726 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3727 lower
= ippGetRange(x_dim
, 0, &upper
);
3729 lower
= upper
= ippGetInteger(x_dim
, 0);
3731 if (lower
< min_width
)
3733 if (upper
> max_width
)
3736 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3737 lower
= ippGetRange(y_dim
, 0, &upper
);
3739 lower
= upper
= ippGetInteger(y_dim
, 0);
3741 if (lower
< min_length
)
3743 if (upper
> max_length
)
3749 else if ((attr
= ippFindAttribute(supported
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3751 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3753 cups_size_t temp
; /* Current size */
3755 media_size
= ippGetCollection(attr
, i
);
3756 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3757 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3758 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3762 temp
.width
= pwg
->width
;
3763 temp
.length
= pwg
->length
;
3764 temp
.bottom
= bottom
;
3769 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3770 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3772 cupsCopyString(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3774 if (!cupsArrayFind(sizes
, &temp
))
3775 cupsArrayAdd(sizes
, &temp
);
3777 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3780 * Custom size - record the min/max values...
3783 int lower
, upper
; /* Range values */
3785 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3786 lower
= ippGetRange(x_dim
, 0, &upper
);
3788 lower
= upper
= ippGetInteger(x_dim
, 0);
3790 if (lower
< min_width
)
3792 if (upper
> max_width
)
3795 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3796 lower
= ippGetRange(y_dim
, 0, &upper
);
3798 lower
= upper
= ippGetInteger(y_dim
, 0);
3800 if (lower
< min_length
)
3802 if (upper
> max_length
)
3807 else if ((attr
= ippFindAttribute(supported
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3809 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3811 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3813 cups_size_t temp
; /* Current size */
3815 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3817 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3819 if (pwg
->width
> max_width
)
3820 max_width
= pwg
->width
;
3821 if (pwg
->length
> max_length
)
3822 max_length
= pwg
->length
;
3824 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3826 if (pwg
->width
< min_width
)
3827 min_width
= pwg
->width
;
3828 if (pwg
->length
< min_length
)
3829 min_length
= pwg
->length
;
3833 temp
.width
= pwg
->width
;
3834 temp
.length
= pwg
->length
;
3835 temp
.bottom
= bottom
;
3840 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3841 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3843 cupsCopyString(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3845 if (!cupsArrayFind(sizes
, &temp
))
3846 cupsArrayAdd(sizes
, &temp
);
3852 if (cupsArrayCount(sizes
) > 0)
3855 * List all of the standard sizes...
3858 char tleft
[256], /* Left string */
3859 tbottom
[256], /* Bottom string */
3860 tright
[256], /* Right string */
3861 ttop
[256], /* Top string */
3862 twidth
[256], /* Width string */
3863 tlength
[256]; /* Length string */
3865 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3866 "*OrderDependency: 10 AnySetup *PageSize\n"
3867 "*DefaultPageSize: %s\n", ppdname
);
3868 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3870 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3871 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3873 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3875 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3877 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3878 "*OrderDependency: 10 AnySetup *PageRegion\n"
3879 "*DefaultPageRegion: %s\n", ppdname
);
3880 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3882 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3883 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3885 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3887 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3889 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3890 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3892 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3894 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3895 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3896 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3897 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3898 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3899 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3901 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3902 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3905 cupsArrayDelete(sizes
);
3908 * Custom size support...
3911 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3913 char tmax
[256], tmin
[256]; /* Min/max values */
3915 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3916 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3917 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3918 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3920 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3922 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3923 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3924 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3926 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3927 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3928 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3930 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3931 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3932 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3933 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3938 cupsArrayDelete(sizes
);
3946 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3947 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3951 if ((attr
= ippFindAttribute(supported
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3953 int have_default
= ppdname
[0] != '\0';
3954 /* Do we have a default InputSlot? */
3955 static const char * const sources
[] =
3956 { /* Standard "media-source" strings */
4009 cupsFilePuts(fp
, "*OpenUI *InputSlot: PickOne\n"
4010 "*OrderDependency: 10 AnySetup *InputSlot\n");
4012 cupsFilePrintf(fp
, "*DefaultInputSlot: %s\n", ppdname
);
4014 for (i
= 0; i
< count
; i
++)
4016 keyword
= ippGetString(attr
, i
, NULL
);
4018 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4020 if (i
== 0 && !have_default
)
4021 cupsFilePrintf(fp
, "*DefaultInputSlot: %s\n", ppdname
);
4023 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
4025 if (!strcmp(sources
[j
], keyword
))
4027 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
4029 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, ppd_get_string(base_lang
, lang
, msgid
, ppdtext
, sizeof(ppdtext
)), j
);
4030 ppd_put_strings(fp
, langs
, "InputSlot", ppdname
, msgid
);
4035 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
4042 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
4043 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
4045 cupsCopyString(ppdname
, "Unknown", sizeof(ppdname
));
4047 if ((attr
= ippFindAttribute(supported
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
4049 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
4050 "*OrderDependency: 10 AnySetup *MediaType\n"
4051 "*DefaultMediaType: %s\n", ppdname
);
4052 for (i
= 0; i
< count
; i
++)
4054 keyword
= ippGetString(attr
, i
, NULL
);
4056 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4058 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
4060 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppd_get_string(base_lang
, lang
, msgid
, ppdtext
, sizeof(ppdtext
)), keyword
);
4061 ppd_put_strings(fp
, langs
, "MediaType", ppdname
, msgid
);
4063 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
4067 * cupsPrintQuality and DefaultResolution...
4070 quality
= ippFindAttribute(supported
, "print-quality-supported", IPP_TAG_ENUM
);
4072 if ((attr
= ippFindAttribute(supported
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4074 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4076 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4078 const char *rs
= ippGetString(attr
, i
, NULL
);
4081 if (_cups_strncasecmp(rs
, "RS", 2))
4084 lowdpi
= atoi(rs
+ 2);
4085 if ((rs
= strrchr(rs
, '-')) != NULL
)
4086 hidpi
= atoi(rs
+ 1);
4095 * Invalid "urf-supported" value...
4103 * Generate print qualities based on low and high DPIs...
4106 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4108 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4109 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4110 "*DefaultcupsPrintQuality: Normal\n");
4111 if ((lowdpi
& 1) == 0)
4113 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
/ 2);
4116 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4118 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*", lowdpi
, lowdpi
);
4122 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
);
4124 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4126 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", hidpi
, hidpi
);
4130 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4133 else if ((attr
= ippFindAttribute(supported
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4136 * Make a sorted list of resolutions.
4139 count
= ippGetCount(attr
);
4140 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4141 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4143 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4144 for (i
= 1; i
< count
; i
++)
4147 for (i
= 0; i
< (count
- 1); i
++)
4149 for (j
= i
+ 1; j
< count
; j
++)
4151 int ix
, iy
, /* First X and Y resolution */
4152 jx
, jy
, /* Second X and Y resolution */
4153 temp
; /* Swap variable */
4154 ipp_res_t units
; /* Resolution units */
4156 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4157 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4159 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4162 * Swap these two resolutions...
4165 temp
= resolutions
[i
];
4166 resolutions
[i
] = resolutions
[j
];
4167 resolutions
[j
] = temp
;
4173 * Generate print quality options...
4176 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4177 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4179 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4180 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4181 "*DefaultcupsPrintQuality: Normal\n");
4182 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4184 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4185 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4189 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4190 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4192 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4194 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4195 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4199 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4201 else if (is_apple
|| is_pwg
)
4207 if ((attr
= ippFindAttribute(supported
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4209 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4214 cupsCopyString(ppdname
, "300dpi", sizeof(ppdname
));
4217 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4219 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4220 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4221 "*DefaultcupsPrintQuality: Normal\n");
4222 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4224 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*", xres
, yres
);
4228 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4230 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4232 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4235 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4242 if ((defattr
= ippFindAttribute(supported
, "print-color-mode-default", IPP_TAG_KEYWORD
)) == NULL
)
4243 defattr
= ippFindAttribute(supported
, "output-mode-default", IPP_TAG_KEYWORD
);
4245 if ((attr
= ippFindAttribute(supported
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
4246 if ((attr
= ippFindAttribute(supported
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
4247 if ((attr
= ippFindAttribute(supported
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
4248 attr
= ippFindAttribute(supported
, "output-mode-supported", IPP_TAG_KEYWORD
);
4252 int wrote_color
= 0;
4253 const char *default_color
= NULL
; /* Default */
4255 if ((keyword
= ippGetString(defattr
, 0, NULL
)) != NULL
&&
4256 strcmp(keyword
, "auto"))
4258 if (!strcmp(keyword
, "bi-level"))
4259 default_color
= "FastGray";
4260 else if (!strcmp(keyword
, "monochrome") || !strcmp(keyword
, "auto-monochrome"))
4261 default_color
= "Gray";
4263 default_color
= "RGB";
4266 cupsFilePrintf(fp
, "*%% ColorModel from %s\n", ippGetName(attr
));
4268 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4270 keyword
= ippGetString(attr
, i
, NULL
);
4272 #define PRINTF_COLORMODEL if (!wrote_color) { cupsFilePuts(fp, "*OpenUI *ColorModel: PickOne\n*OrderDependency: 10 AnySetup *ColorModel\n"); wrote_color = 1; }
4273 #define PRINTF_COLOROPTION(name,text,cspace,bpp) cupsFilePrintf(fp, "*ColorModel %s/%s: \"<</cupsColorSpace %d/cupsBitsPerColor %d/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", name, text, cspace, bpp);
4275 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
4279 PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K
, 1)
4282 default_color
= "FastGray";
4284 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
4288 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
4290 if (!default_color
|| (!defattr
&& !strcmp(default_color
, "FastGray")))
4291 default_color
= "Gray";
4293 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
4297 if (!strcmp(keyword
, "W8-16"))
4299 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
4301 if (!default_color
|| (!defattr
&& !strcmp(default_color
, "FastGray")))
4302 default_color
= "Gray";
4305 PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW
, 16)
4307 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 6) || !strcmp(keyword
, "color"))
4311 PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB
, 8)
4314 default_color
= "RGB";
4316 // Apparently some printers only advertise color support, so make sure
4317 // we also do grayscale for these printers...
4318 if (!ippContainsString(attr
, "sgray_8") && !ippContainsString(attr
, "black_1") && !ippContainsString(attr
, "black_8") && !ippContainsString(attr
, "W8") && !ippContainsString(attr
, "W8-16"))
4319 PRINTF_COLOROPTION("Gray", _("GrayScale"), CUPS_CSPACE_SW
, 8)
4321 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
4325 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 16)
4328 default_color
= "AdobeRGB";
4330 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
4334 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 8)
4337 default_color
= "AdobeRGB";
4339 else if ((!strcasecmp(keyword
, "black_8") && !ippContainsString(attr
, "black_16")) || !strcmp(keyword
, "DEVW8"))
4343 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 8)
4345 else if (!strcasecmp(keyword
, "black_16") || !strcmp(keyword
, "DEVW16") || !strcmp(keyword
, "DEVW8-16"))
4349 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 16)
4351 else if ((!strcasecmp(keyword
, "cmyk_8") && !ippContainsString(attr
, "cmyk_16")) || !strcmp(keyword
, "DEVCMYK32"))
4355 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 8)
4357 else if (!strcasecmp(keyword
, "cmyk_16") || !strcmp(keyword
, "DEVCMYK32-64") || !strcmp(keyword
, "DEVCMYK64"))
4361 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 16)
4363 else if ((!strcasecmp(keyword
, "rgb_8") && ippContainsString(attr
, "rgb_16")) || !strcmp(keyword
, "DEVRGB24"))
4367 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 8)
4369 else if (!strcasecmp(keyword
, "rgb_16") || !strcmp(keyword
, "DEVRGB24-48") || !strcmp(keyword
, "DEVRGB48"))
4373 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 16)
4378 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
4380 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
4384 // Standard presets for color mode and quality...
4387 "*APPrinterPreset Gray_with_Paper_Auto-Detect_-_Draft/Draft B&W: \"\n"
4388 " *cupsPrintQuality Draft *ColorModel Gray\n"
4389 " com.apple.print.preset.graphicsType General\n"
4390 " com.apple.print.preset.quality low\n"
4391 " com.apple.print.preset.media-front-coating autodetect\n"
4392 " com.apple.print.preset.output-mode monochrome\"\n"
4395 "*APPrinterPreset Gray_with_Paper_Auto-Detect/Black and White: \"\n"
4396 " *cupsPrintQuality Normal *ColorModel Gray\n"
4397 " com.apple.print.preset.graphicsType General\n"
4398 " com.apple.print.preset.quality mid\n"
4399 " com.apple.print.preset.media-front-coating autodetect\n"
4400 " com.apple.print.preset.output-mode monochrome\"\n"
4402 if (strcmp(default_color
, "Gray"))
4404 "*APPrinterPreset Color_with_Paper_Auto-Detect/Color: \"\n"
4405 " *cupsPrintQuality Normal *ColorModel RGB\n"
4406 " com.apple.print.preset.graphicsType General\n"
4407 " com.apple.print.preset.quality mid\n"
4408 " com.apple.print.preset.media-front-coating autodetect\n"
4409 " com.apple.print.preset.output-mode color\"\n"
4411 if (!strcmp(default_color
, "AdobeRGB") || have_qhigh
)
4413 "*APPrinterPreset Photo_with_Paper_Auto-Detect/Photo: \"\n"
4414 " *cupsPrintQuality %s *ColorModel %s\n"
4415 " com.apple.print.preset.graphicsType Photo\n"
4416 " com.apple.print.preset.quality %s\n"
4417 " com.apple.print.preset.media-front-coating autodetect\n"
4418 " com.apple.print.preset.output-mode color\"\n"
4419 "*End\n", have_qhigh
? "High" : "Normal", default_color
, have_qhigh
? "high" : "mid");
4427 if ((attr
= ippFindAttribute(supported
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
4429 cupsFilePuts(fp
, "*OpenUI *Duplex: PickOne\n"
4430 "*OrderDependency: 10 AnySetup *Duplex\n"
4431 "*DefaultDuplex: None\n"
4432 "*Duplex None: \"<</Duplex false>>setpagedevice\"\n"
4433 "*Duplex DuplexNoTumble: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
4434 "*Duplex DuplexTumble: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
4435 "*CloseUI: *Duplex\n");
4437 if ((attr
= ippFindAttribute(supported
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4439 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4441 const char *dm
= ippGetString(attr
, i
, NULL
);
4444 if (!_cups_strcasecmp(dm
, "DM1"))
4446 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
4449 else if (!_cups_strcasecmp(dm
, "DM2"))
4451 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
4454 else if (!_cups_strcasecmp(dm
, "DM3"))
4456 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
4459 else if (!_cups_strcasecmp(dm
, "DM4"))
4461 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
4466 else if ((attr
= ippFindAttribute(supported
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
4468 keyword
= ippGetString(attr
, 0, NULL
);
4470 if (!strcmp(keyword
, "flipped"))
4471 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
4472 else if (!strcmp(keyword
, "manual-tumble"))
4473 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
4474 else if (!strcmp(keyword
, "normal"))
4475 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
4477 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
4485 if ((attr
= ippFindAttribute(supported
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
4486 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
4488 cupsCopyString(ppdname
, "Unknown", sizeof(ppdname
));
4490 if ((attr
= ippFindAttribute(supported
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 0)
4492 ipp_attribute_t
*trays
= ippFindAttribute(supported
, "printer-output-tray", IPP_TAG_STRING
);
4493 /* printer-output-tray attribute, if any */
4494 const char *tray_ptr
; /* printer-output-tray value */
4495 int tray_len
; /* Len of printer-output-tray value */
4496 char tray
[IPP_MAX_OCTETSTRING
];
4497 /* printer-output-tray string value */
4499 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
4500 "*OrderDependency: 10 AnySetup *OutputBin\n"
4501 "*DefaultOutputBin: %s\n", ppdname
);
4502 if (!strcmp(ppdname
, "FaceUp"))
4503 cupsFilePuts(fp
, "*DefaultOutputOrder: Reverse\n");
4505 cupsFilePuts(fp
, "*DefaultOutputOrder: Normal\n");
4507 for (i
= 0; i
< count
; i
++)
4509 keyword
= ippGetString(attr
, i
, NULL
);
4511 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4513 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
4515 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, ppd_get_string(base_lang
, lang
, msgid
, ppdtext
, sizeof(ppdtext
)));
4516 ppd_put_strings(fp
, langs
, "OutputBin", ppdname
, msgid
);
4518 if ((tray_ptr
= ippGetOctetString(trays
, i
, &tray_len
)) != NULL
)
4520 if (tray_len
>= (int)sizeof(tray
))
4521 tray_len
= (int)sizeof(tray
) - 1;
4523 memcpy(tray
, tray_ptr
, (size_t)tray_len
);
4524 tray
[tray_len
] = '\0';
4526 if (strstr(tray
, "stackingorder=lastToFirst;"))
4527 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
4529 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
4531 else if (!strcmp(ppdname
, "FaceUp"))
4532 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
4534 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
4536 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
4540 * Finishing options...
4543 if ((attr
= ippFindAttribute(supported
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
4545 int value
; /* Enum value */
4546 const char *ppd_keyword
; /* PPD keyword for enum */
4547 cups_array_t
*names
; /* Names we've added */
4548 static const char * const base_keywords
[] =
4549 { /* Base STD 92 keywords */
4551 "SingleAuto", /* staple */
4552 "SingleAuto", /* punch */
4554 "BindAuto", /* bind */
4555 "SaddleStitch", /* saddle-stitch */
4556 "EdgeStitchAuto", /* edge-stitch */
4560 NULL
, /* booklet-maker */
4561 NULL
, /* jog-offset */
4566 count
= ippGetCount(attr
);
4567 names
= cupsArrayNew3((cups_array_func_t
)_cupsArrayStrcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsArrayStrdup
, _cupsArrayFree
);
4568 fin_options
= cupsArrayNew((cups_array_func_t
)_cupsArrayStrcmp
, NULL
);
4571 * Staple/Bind/Stitch
4574 for (i
= 0; i
< count
; i
++)
4576 value
= ippGetInteger(attr
, i
);
4577 keyword
= ippEnumString("finishings", value
);
4579 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strcmp(keyword
, "staple") || !strcmp(keyword
, "bind"))
4585 static const char * const staple_keywords
[] =
4586 { /* StapleLocation keywords */
4588 "SingleRevLandscape",
4590 "SingleRevPortrait",
4591 "EdgeStitchPortrait",
4592 "EdgeStitchLandscape",
4593 "EdgeStitchRevPortrait",
4594 "EdgeStitchRevLandscape",
4601 "TripleRevPortrait",
4602 "TripleRevLandscape"
4604 static const char * const bind_keywords
[] =
4605 { /* StapleLocation binding keywords */
4612 cupsArrayAdd(fin_options
, "*StapleLocation");
4614 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(base_lang
, "finishings.4"));
4615 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
4616 ppd_put_strings(fp
, langs
, "Translation", "StapleLocation", "finishings.4");
4617 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
4618 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(base_lang
, "finishings.3"));
4619 ppd_put_strings(fp
, langs
, "StapleLocation", "None", "finishings.3");
4621 for (; i
< count
; i
++)
4623 value
= ippGetInteger(attr
, i
);
4624 keyword
= ippEnumString("finishings", value
);
4626 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch") && strcmp(keyword
, "staple") && strcmp(keyword
, "bind"))
4629 if (cupsArrayFind(names
, (char *)keyword
))
4630 continue; /* Already did this finishing template */
4632 cupsArrayAdd(names
, (char *)keyword
);
4634 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4636 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4637 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4638 else if (value
>= IPP_FINISHINGS_STAPLE_TOP_LEFT
&& value
<= IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
)
4639 ppd_keyword
= staple_keywords
[value
- IPP_FINISHINGS_STAPLE_TOP_LEFT
];
4640 else if (value
>= IPP_FINISHINGS_BIND_LEFT
&& value
<= IPP_FINISHINGS_BIND_BOTTOM
)
4641 ppd_keyword
= bind_keywords
[value
- IPP_FINISHINGS_BIND_LEFT
];
4648 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", ppd_keyword
, _cupsLangString(base_lang
, msgid
));
4649 ppd_put_strings(fp
, langs
, "StapleLocation", ppd_keyword
, msgid
);
4650 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, ppd_keyword
);
4653 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
4660 for (i
= 0; i
< count
; i
++)
4662 value
= ippGetInteger(attr
, i
);
4663 keyword
= ippEnumString("finishings", value
);
4665 if (!strncmp(keyword
, "cups-fold-", 10) || !strcmp(keyword
, "fold") || !strncmp(keyword
, "fold-", 5))
4671 static const char * const fold_keywords
[] =
4672 { /* FoldType keywords */
4687 cupsArrayAdd(fin_options
, "*FoldType");
4689 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(base_lang
, "finishings.10"));
4690 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
4691 ppd_put_strings(fp
, langs
, "Translation", "FoldType", "finishings.10");
4692 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
4693 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(base_lang
, "finishings.3"));
4694 ppd_put_strings(fp
, langs
, "FoldType", "None", "finishings.3");
4696 for (; i
< count
; i
++)
4698 value
= ippGetInteger(attr
, i
);
4699 keyword
= ippEnumString("finishings", value
);
4701 if (!strncmp(keyword
, "cups-fold-", 10))
4703 else if (strcmp(keyword
, "fold") && strncmp(keyword
, "fold-", 5))
4706 if (cupsArrayFind(names
, (char *)keyword
))
4707 continue; /* Already did this finishing template */
4709 cupsArrayAdd(names
, (char *)keyword
);
4711 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4713 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4714 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4715 else if (value
>= IPP_FINISHINGS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_FOLD_ENGINEERING_Z
)
4716 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_FOLD_ACCORDION
];
4717 else if (value
>= IPP_FINISHINGS_CUPS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_CUPS_FOLD_Z
)
4718 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_CUPS_FOLD_ACCORDION
];
4725 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", ppd_keyword
, _cupsLangString(base_lang
, msgid
));
4726 ppd_put_strings(fp
, langs
, "FoldType", ppd_keyword
, msgid
);
4727 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, ppd_keyword
);
4730 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4737 for (i
= 0; i
< count
; i
++)
4739 value
= ippGetInteger(attr
, i
);
4740 keyword
= ippEnumString("finishings", value
);
4742 if (!strcmp(keyword
, "punch") || !strncmp(keyword
, "cups-punch-", 11) || !strncmp(keyword
, "punch-", 6))
4748 static const char * const punch_keywords
[] =
4749 { /* PunchMedia keywords */
4751 "SingleRevLandscape",
4753 "SingleRevPortrait",
4760 "TripleRevPortrait",
4761 "TripleRevLandscape",
4767 "MultipleLandscape",
4768 "MultipleRevPortrait",
4769 "MultipleRevLandscape"
4772 cupsArrayAdd(fin_options
, "*PunchMedia");
4774 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(base_lang
, "finishings.5"));
4775 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4776 ppd_put_strings(fp
, langs
, "Translation", "PunchMedia", "finishings.5");
4777 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4778 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(base_lang
, "finishings.3"));
4779 ppd_put_strings(fp
, langs
, "PunchMedia", "None", "finishings.3");
4781 for (i
= 0; i
< count
; i
++)
4783 value
= ippGetInteger(attr
, i
);
4784 keyword
= ippEnumString("finishings", value
);
4786 if (!strncmp(keyword
, "cups-punch-", 11))
4788 else if (strcmp(keyword
, "punch") && strncmp(keyword
, "punch-", 6))
4791 if (cupsArrayFind(names
, (char *)keyword
))
4792 continue; /* Already did this finishing template */
4794 cupsArrayAdd(names
, (char *)keyword
);
4796 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4798 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4799 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4800 else if (value
>= IPP_FINISHINGS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_PUNCH_MULTIPLE_BOTTOM
)
4801 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_PUNCH_TOP_LEFT
];
4802 else if (value
>= IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_CUPS_PUNCH_QUAD_BOTTOM
)
4803 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
];
4810 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", ppd_keyword
, _cupsLangString(base_lang
, msgid
));
4811 ppd_put_strings(fp
, langs
, "PunchMedia", ppd_keyword
, msgid
);
4812 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, ppd_keyword
);
4815 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4822 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4824 cupsArrayAdd(fin_options
, "*Booklet");
4826 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(base_lang
, "finishings.13"));
4827 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4828 ppd_put_strings(fp
, langs
, "Translation", "StapleLocation", "finishings.13");
4829 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4830 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4831 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4832 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4833 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4840 for (i
= 0; i
< count
; i
++)
4842 value
= ippGetInteger(attr
, i
);
4843 keyword
= ippEnumString("finishings", value
);
4845 if (!strcmp(keyword
, "trim") || !strncmp(keyword
, "trim-", 5))
4851 static const char * const trim_keywords
[] =
4852 { /* CutMedia keywords */
4859 cupsArrayAdd(fin_options
, "*CutMedia");
4861 cupsFilePrintf(fp
, "*OpenUI *CutMedia/%s: PickOne\n", _cupsLangString(base_lang
, "finishings.11"));
4862 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *CutMedia\n");
4863 ppd_put_strings(fp
, langs
, "Translation", "CutMedia", "finishings.11");
4864 cupsFilePuts(fp
, "*DefaultCutMedia: None\n");
4865 cupsFilePrintf(fp
, "*CutMedia None/%s: \"\"\n", _cupsLangString(base_lang
, "finishings.3"));
4866 ppd_put_strings(fp
, langs
, "CutMedia", "None", "finishings.3");
4868 for (i
= 0; i
< count
; i
++)
4870 value
= ippGetInteger(attr
, i
);
4871 keyword
= ippEnumString("finishings", value
);
4873 if (strcmp(keyword
, "trim") && strncmp(keyword
, "trim-", 5))
4876 if (cupsArrayFind(names
, (char *)keyword
))
4877 continue; /* Already did this finishing template */
4879 cupsArrayAdd(names
, (char *)keyword
);
4881 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4883 if (value
== IPP_FINISHINGS_TRIM
)
4884 ppd_keyword
= "Auto";
4886 ppd_keyword
= trim_keywords
[value
- IPP_FINISHINGS_TRIM_AFTER_PAGES
];
4888 cupsFilePrintf(fp
, "*CutMedia %s/%s: \"\"\n", ppd_keyword
, _cupsLangString(base_lang
, msgid
));
4889 ppd_put_strings(fp
, langs
, "CutMedia", ppd_keyword
, msgid
);
4890 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*CutMedia %s\"\n", value
, keyword
, ppd_keyword
);
4893 cupsFilePuts(fp
, "*CloseUI: *CutMedia\n");
4896 cupsArrayDelete(names
);
4899 if ((attr
= ippFindAttribute(supported
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4901 ipp_t
*finishing_col
; /* Current finishing collection */
4902 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4903 cups_array_t
*templates
; /* Finishing templates */
4905 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickOne\n", ppd_get_string(base_lang
, lang
, "finishing-template", ppdtext
, sizeof(ppdtext
)));
4906 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4907 ppd_put_strings(fp
, langs
, "Translation", "cupsFinishingTemplate", "finishing-template");
4908 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4909 cupsFilePrintf(fp
, "*cupsFinishingTemplate none/%s: \"\"\n", _cupsLangString(lang
, "finishings.3"));
4910 ppd_put_strings(fp
, langs
, "cupsFinishingTemplate", "none", "finishings.3");
4912 templates
= cupsArrayNew((cups_array_func_t
)_cupsArrayStrcmp
, NULL
);
4913 count
= ippGetCount(attr
);
4915 for (i
= 0; i
< count
; i
++)
4917 finishing_col
= ippGetCollection(attr
, i
);
4918 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4920 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4923 if (!strcmp(keyword
, "none"))
4926 cupsArrayAdd(templates
, (void *)keyword
);
4928 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4930 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4932 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\n", ppdname
, ppd_get_string(base_lang
, lang
, msgid
, ppdtext
, sizeof(ppdtext
)));
4933 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4935 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4937 const char *name
= ippGetName(finishing_attr
);
4938 /* Member attribute name */
4940 if (strcmp(name
, "media-size"))
4941 cupsFilePrintf(fp
, "%% %s\n", name
);
4944 cupsFilePuts(fp
, "\"\n");
4945 ppd_put_strings(fp
, langs
, "cupsFinishingTemplate", ppdname
, msgid
);
4946 cupsFilePuts(fp
, "*End\n");
4949 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4951 if (cupsArrayCount(fin_options
))
4953 const char *fin_option
; /* Current finishing option */
4955 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4956 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4957 cupsFilePrintf(fp
, " %s", fin_option
);
4958 cupsFilePuts(fp
, "\"\n");
4960 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate none");
4961 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4962 cupsFilePrintf(fp
, " %s None", fin_option
);
4963 cupsFilePuts(fp
, "\"\n");
4966 cupsArrayDelete(templates
);
4969 cupsArrayDelete(fin_options
);
4975 if ((attr
= ippFindAttribute(supported
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4977 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4979 ipp_t
*preset
= ippGetCollection(attr
, i
);
4980 /* Preset collection */
4981 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
);
4983 ipp_attribute_t
*member
; /* Member attribute in preset */
4984 const char *member_name
; /* Member attribute name */
4985 char member_value
[256]; /* Member attribute value */
4987 if (!preset
|| !preset_name
)
4990 pwg_ppdize_name(preset_name
, ppdname
, sizeof(ppdname
));
4992 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", ppdname
);
4993 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4995 member_name
= ippGetName(member
);
4997 if (!member_name
|| !strcmp(member_name
, "preset-name"))
5000 if (!strcmp(member_name
, "finishings"))
5002 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
5004 const char *option
= NULL
; /* PPD option name */
5006 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
5008 if (!strcmp(keyword
, "booklet-maker"))
5013 else if (!strncmp(keyword
, "fold-", 5))
5014 option
= "FoldType";
5015 else if (!strncmp(keyword
, "punch-", 6))
5016 option
= "PunchMedia";
5017 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7) || !strcmp(keyword
, "staple") || !strcmp(keyword
, "bind"))
5018 option
= "StapleLocation";
5020 if (option
&& keyword
)
5021 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
5024 else if (!strcmp(member_name
, "finishings-col"))
5026 ipp_t
*fin_col
; /* finishings-col value */
5028 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
5030 fin_col
= ippGetCollection(member
, i
);
5032 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
5034 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
5035 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", ppdname
);
5039 else if (!strcmp(member_name
, "media"))
5042 * Map media to PageSize...
5045 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
5046 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
5048 else if (!strcmp(member_name
, "media-col"))
5050 media_col
= ippGetCollection(member
, 0);
5052 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
5054 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
5055 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
5056 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
5057 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
5060 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
5062 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
5063 cupsFilePrintf(fp
, "*InputSlot %s\n", ppdname
);
5066 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
5068 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
5069 cupsFilePrintf(fp
, "*MediaType %s\n", ppdname
);
5072 else if (!strcmp(member_name
, "print-quality"))
5075 * Map print-quality to cupsPrintQuality...
5078 int qval
= ippGetInteger(member
, 0);
5079 /* print-quality value */
5080 static const char * const qualities
[] = { "Draft", "Normal", "High" };
5081 /* cupsPrintQuality values */
5083 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
5084 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
5086 else if (!strcmp(member_name
, "output-bin"))
5088 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
5089 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
5091 else if (!strcmp(member_name
, "sides"))
5093 keyword
= ippGetString(member
, 0, NULL
);
5094 if (keyword
&& !strcmp(keyword
, "one-sided"))
5095 cupsFilePuts(fp
, "*Duplex None\n");
5096 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
5097 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
5098 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
5099 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
5104 * Add attribute name and value as-is...
5107 ippAttributeString(member
, member_value
, sizeof(member_value
));
5108 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
5112 cupsFilePuts(fp
, "\"\n*End\n");
5114 pwg_ppdize_name(preset_name
, ppdname
, sizeof(ppdname
));
5115 snprintf(msgid
, sizeof(msgid
), "preset-name.%s", preset_name
);
5116 ppd_put_strings(fp
, langs
, "APPrinterPreset", ppdname
, msgid
);
5121 * Add cupsSingleFile to support multiple files printing on printers
5122 * which don't support multiple files in its firmware...
5124 * Adding the keyword degrades printing performance (there is 1-2 seconds
5125 * pause between files).
5128 cupsFilePuts(fp
, "*cupsSingleFile: true\n");
5131 * Add localized printer-state-reasons keywords as needed...
5134 for (lang
= langs
; lang
; lang
= lang
->next
)
5136 _cups_message_t
*msg
; // Current message
5138 for (msg
= (_cups_message_t
*)cupsArrayGetFirst(lang
->strings
); msg
; msg
= (_cups_message_t
*)cupsArrayGetNext(lang
->strings
))
5140 if (!strncmp(msg
->msg
, "printer-state-reasons.", 22))
5142 if (!strcmp(lang
->language
, "en"))
5143 cupsFilePrintf(fp
, "*cupsIPPReason %s/%s: \"\"\n", msg
->msg
+ 22, msg
->str
);
5145 cupsFilePrintf(fp
, "*%s.cupsIPPReason %s/%s: \"\"\n", lang
->language
, msg
->msg
+ 22, msg
->str
);
5151 * Close up and return...
5156 for (lang
= langs
; lang
;)
5158 cups_lang_t
*next
= lang
->next
;
5160 cupsArrayDelete(lang
->strings
);
5169 * If we get here then there was a problem creating the PPD...
5176 for (lang
= langs
; lang
;)
5178 cups_lang_t
*next
= lang
->next
;
5180 cupsArrayDelete(lang
->strings
);
5189 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
5196 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
5200 const char * /* O - InputSlot name */
5201 _pwgInputSlotForSource(
5202 const char *media_source
, /* I - PWG media-source */
5203 char *name
, /* I - Name buffer */
5204 size_t namesize
) /* I - Size of name buffer */
5207 * Range check input...
5210 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
5213 if (_cups_strcasecmp(media_source
, "main"))
5214 cupsCopyString(name
, "Cassette", namesize
);
5215 else if (_cups_strcasecmp(media_source
, "alternate"))
5216 cupsCopyString(name
, "Multipurpose", namesize
);
5217 else if (_cups_strcasecmp(media_source
, "large-capacity"))
5218 cupsCopyString(name
, "LargeCapacity", namesize
);
5219 else if (_cups_strcasecmp(media_source
, "bottom"))
5220 cupsCopyString(name
, "Lower", namesize
);
5221 else if (_cups_strcasecmp(media_source
, "middle"))
5222 cupsCopyString(name
, "Middle", namesize
);
5223 else if (_cups_strcasecmp(media_source
, "top"))
5224 cupsCopyString(name
, "Upper", namesize
);
5225 else if (_cups_strcasecmp(media_source
, "rear"))
5226 cupsCopyString(name
, "Rear", namesize
);
5227 else if (_cups_strcasecmp(media_source
, "side"))
5228 cupsCopyString(name
, "Side", namesize
);
5229 else if (_cups_strcasecmp(media_source
, "envelope"))
5230 cupsCopyString(name
, "Envelope", namesize
);
5231 else if (_cups_strcasecmp(media_source
, "main-roll"))
5232 cupsCopyString(name
, "Roll", namesize
);
5233 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
5234 cupsCopyString(name
, "Roll2", namesize
);
5236 pwg_ppdize_name(media_source
, name
, namesize
);
5243 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
5247 const char * /* O - MediaType name */
5248 _pwgMediaTypeForType(
5249 const char *media_type
, /* I - PWG media-type */
5250 char *name
, /* I - Name buffer */
5251 size_t namesize
) /* I - Size of name buffer */
5254 * Range check input...
5257 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
5260 if (_cups_strcasecmp(media_type
, "auto"))
5261 cupsCopyString(name
, "Auto", namesize
);
5262 else if (_cups_strcasecmp(media_type
, "cardstock"))
5263 cupsCopyString(name
, "Cardstock", namesize
);
5264 else if (_cups_strcasecmp(media_type
, "envelope"))
5265 cupsCopyString(name
, "Envelope", namesize
);
5266 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
5267 cupsCopyString(name
, "Glossy", namesize
);
5268 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
5269 cupsCopyString(name
, "HighGloss", namesize
);
5270 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
5271 cupsCopyString(name
, "Matte", namesize
);
5272 else if (_cups_strcasecmp(media_type
, "stationery"))
5273 cupsCopyString(name
, "Plain", namesize
);
5274 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
5275 cupsCopyString(name
, "Coated", namesize
);
5276 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
5277 cupsCopyString(name
, "Inkjet", namesize
);
5278 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
5279 cupsCopyString(name
, "Letterhead", namesize
);
5280 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
5281 cupsCopyString(name
, "Preprinted", namesize
);
5282 else if (_cups_strcasecmp(media_type
, "transparency"))
5283 cupsCopyString(name
, "Transparency", namesize
);
5285 pwg_ppdize_name(media_type
, name
, namesize
);
5292 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
5295 const char * /* O - PageSize name */
5296 _pwgPageSizeForMedia(
5297 pwg_media_t
*media
, /* I - Media */
5298 char *name
, /* I - PageSize name buffer */
5299 size_t namesize
) /* I - Size of name buffer */
5301 const char *sizeptr
, /* Pointer to size in PWG name */
5302 *dimptr
; /* Pointer to dimensions in PWG name */
5306 * Range check input...
5309 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
5313 * Copy or generate a PageSize name...
5319 * Use a standard Adobe name...
5322 cupsCopyString(name
, media
->ppd
, namesize
);
5324 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
5325 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
5326 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
5327 (size_t)(dimptr
- sizeptr
) > namesize
)
5330 * Use a name of the form "wNNNhNNN"...
5333 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
5334 (int)PWG_TO_POINTS(media
->length
));
5339 * Copy the size name from class_sizename_dimensions...
5342 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
5343 name
[dimptr
- sizeptr
- 1] = '\0';
5351 * 'cups_connect()' - Connect to a URL and get the resource path.
5354 static int /* O - 1 on success, 0 on failure */
5355 cups_connect(http_t
**http
, /* IO - Current HTTP connection */
5356 const char *url
, /* I - URL to connect */
5357 char *resource
, /* I - Resource path buffer */
5358 size_t ressize
) /* I - Size of resource path buffer */
5360 char scheme
[32], /* URL scheme */
5361 userpass
[256], /* URL username:password */
5362 host
[256], /* URL host */
5363 curhost
[256]; /* Current host */
5364 int port
; /* URL port */
5365 http_encryption_t encryption
; /* Type of encryption to use */
5368 // Separate the URI...
5369 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, ressize
) < HTTP_URI_STATUS_OK
)
5372 // Use encryption as needed..
5373 if (port
== 443 || !strcmp(scheme
, "https") || !strcmp(scheme
, "ipps"))
5374 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5376 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5378 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
|| httpIsEncrypted(*http
) != (encryption
== HTTP_ENCRYPTION_ALWAYS
))
5381 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
5384 return (*http
!= NULL
);
5389 * 'cups_get_strings()' - Get the strings for the specified language.
5392 static cups_lang_t
* /* O - Language data */
5394 http_t
**http
, /* IO - Current HTTP connection */
5395 const char *printer_uri
, /* I - Printer URI */
5396 const char *language
) /* I - Language name */
5398 cups_lang_t
*lang
= NULL
; /* Language data */
5399 char resource
[256]; /* Resource path for printer */
5400 ipp_t
*request
, /* IPP request */
5401 *response
= NULL
; /* IPP response */
5402 const char *strings_uri
; /* "printer-strings-uri" value */
5403 char strings_file
[1024] = "";/* Strings filename */
5404 static int request_id
= 1000; // Request ID
5408 * Connect to the printer...
5411 if (!cups_connect(http
, printer_uri
, resource
, sizeof(resource
)))
5415 * Get the URL for the corresponding language strings...
5419 ippSetOperation(request
, IPP_OP_GET_PRINTER_ATTRIBUTES
);
5420 ippSetRequestId(request
, request_id
++);
5421 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", /*language*/NULL
, "utf-8");
5422 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", /*language*/NULL
, language
);
5423 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", /*language*/NULL
, printer_uri
);
5425 response
= cupsDoRequest(*http
, request
, resource
);
5427 if ((strings_uri
= ippGetString(ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
), 0, NULL
)) != NULL
)
5430 * Download the strings file...
5433 if (!cups_get_url(http
, strings_uri
, ".strings", strings_file
, sizeof(strings_file
)))
5437 * Allocate memory...
5440 if ((lang
= (cups_lang_t
*)calloc(1, sizeof(cups_lang_t
))) == NULL
)
5444 * Load the strings...
5447 cupsCopyString(lang
->language
, language
, sizeof(lang
->language
));
5448 lang
->strings
= _cupsMessageLoad(NULL
, strings_file
, _CUPS_MESSAGE_STRINGS
);
5449 unlink(strings_file
);
5454 ipp_attribute_t
*attr
;
5455 ipp_tag_t group_tag
= IPP_TAG_ZERO
, value_tag
;
5459 puts("No printer-strings-uri in response.");
5460 printf("Get-Printer-Attributes: %s\n", ippErrorString(ippGetStatusCode(response
)));
5461 for (attr
= ippGetFirstAttribute(response
); attr
; attr
= ippGetNextAttribute(response
))
5463 if (ippGetGroupTag(attr
) != group_tag
)
5465 group_tag
= ippGetGroupTag(attr
);
5466 puts(ippTagString(group_tag
));
5469 name
= ippGetName(attr
);
5470 value_tag
= ippGetValueTag(attr
);
5472 ippAttributeString(attr
, value
, sizeof(value
));
5474 printf(" %s %s = %s\n", name
, ippTagString(value_tag
), value
);
5481 ippDelete(response
);
5488 * 'cups_get_url()' - Get a copy of the file at the given URL.
5491 static int /* O - 1 on success, 0 on failure */
5492 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
5493 const char *url
, /* I - URL to get */
5494 const char *suffix
, /* I - Filename suffix */
5495 char *name
, /* I - Temporary filename */
5496 size_t namesize
) /* I - Size of temporary filename buffer */
5498 char resource
[256]; /* URL resource */
5499 http_status_t status
; /* Status of GET request */
5500 int fd
; /* Temporary file */
5503 if (!cups_connect(http
, url
, resource
, sizeof(resource
)))
5506 if ((fd
= cupsCreateTempFd("ippeve", suffix
, name
, namesize
)) < 0)
5509 status
= cupsGetFd(*http
, resource
, fd
);
5513 if (status
!= HTTP_STATUS_OK
)
5525 * 'ppd_get_string()' - Get a localized string.
5527 * This function looks up the msgid first in the CUPS English localization
5528 * catalog, then the printer's English localization, and finally falls back on
5529 * converting the keyword from "word-like-this" to "Words Like This".
5532 static const char * // O - Localized text
5533 ppd_get_string(cups_lang_t
*base
, // I - Base (CUPS) localization
5534 cups_lang_t
*printer
, // I - Printer localization
5535 const char *msgid
, // I - Message ID
5536 char *buffer
, // I - Temporary string buffer
5537 size_t bufsize
) // I - Size of temporary string buffer
5539 const char *text
, // Localized text
5540 *msgptr
; // Pointer into message ID
5541 char *bufptr
; // Pointer into string buffer
5544 if ((text
= _cupsLangString(base
, msgid
)) == msgid
)
5546 if ((text
= _cupsLangString(printer
, msgid
)) == msgid
)
5548 if ((msgptr
= strrchr(msgid
, '.')) != NULL
)
5556 cupsCopyString(buffer
, msgptr
, bufsize
);
5557 buffer
[0] = (char)toupper(buffer
[0] & 255);
5558 for (bufptr
= buffer
+ 1; *bufptr
; bufptr
++)
5563 bufptr
[1] = (char)toupper(bufptr
[1] & 255);
5576 // 'ppd_get_strings()' - Get the strings for a given option and choice.
5581 ppd_file_t
*ppd
, // I - PPD file
5582 cups_lang_t
*langs
, // I - Languages
5583 const char *option
, // I - PPD option keyword
5584 ppd_choice_t
*choice
, // I - PPD choice
5585 const char *pwg_msgid
) // I - PWG message ID
5587 cups_lang_t
*lang
; // Current language
5588 char ppd_name
[PPD_MAX_NAME
]; // PPD main keyword
5589 ppd_attr_t
*ppd_attr
; // PPD attribute
5590 _cups_message_t msg
; // Message
5593 msg
.msg
= (char *)pwg_msgid
;
5595 for (lang
= langs
; lang
; lang
= lang
->next
)
5597 // See if the string is already localized...
5598 if (cupsArrayFind(lang
->strings
, &msg
))
5601 // Otherwise add the text...
5602 if (!strcmp(lang
->language
, "en"))
5605 msg
.str
= choice
->text
;
5609 // Other languauge...
5610 snprintf(ppd_name
, sizeof(ppd_name
), "%s.%s", lang
->language
, option
);
5611 if ((ppd_attr
= ppdFindAttr(ppd
, ppd_name
, choice
->choice
)) != NULL
)
5612 msg
.str
= ppd_attr
->text
;
5617 cupsArrayAdd(lang
->strings
, &msg
);
5623 * 'ppd_put_strings()' - Write localization attributes to a PPD file.
5627 ppd_put_strings(cups_file_t
*fp
, /* I - PPD file */
5628 cups_lang_t
*langs
, /* I - Languages */
5629 const char *ppd_option
,/* I - PPD option */
5630 const char *ppd_choice
,/* I - PPD choice */
5631 const char *pwg_msgid
) /* I - PWG message ID */
5633 cups_lang_t
*lang
; /* Current language */
5634 const char *text
; /* Localized text */
5637 for (lang
= langs
; lang
; lang
= lang
->next
)
5639 if (strcmp(lang
->language
, "en") && (text
= _cupsLangString(lang
, pwg_msgid
)) != pwg_msgid
)
5641 // Add the first line of localized text...
5642 cupsFilePrintf(fp
, "*%s.%s %s/", lang
->language
, ppd_option
, ppd_choice
);
5643 while (*text
&& *text
!= '\n')
5645 // Escape ":" and "<"...
5646 if (*text
== ':' || *text
== '<')
5647 cupsFilePrintf(fp
, "<%02X>", *text
);
5649 cupsFilePutChar(fp
, *text
);
5653 cupsFilePuts(fp
, ": \"\"\n");
5660 * 'pwg_add_finishing()' - Add a finishings value.
5665 cups_array_t
*finishings
, /* I - Finishings array */
5666 ipp_finishings_t
template, /* I - Finishing template */
5667 const char *name
, /* I - PPD option */
5668 const char *value
) /* I - PPD choice */
5670 _pwg_finishings_t
*f
; /* New finishings value */
5673 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
5675 f
->value
= template;
5676 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
5678 cupsArrayAdd(finishings
, f
);
5684 * 'pwg_compare_finishings()' - Compare two finishings values.
5687 static int /* O - Result of comparison */
5688 pwg_compare_finishings(
5689 _pwg_finishings_t
*a
, /* I - First finishings value */
5690 _pwg_finishings_t
*b
, /* I - Second finishings value */
5691 void *data
) /* Unused */
5694 return ((int)b
->value
- (int)a
->value
);
5699 * 'pwg_compare_sizes()' - Compare two media sizes...
5702 static int /* O - Result of comparison */
5703 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
5704 cups_size_t
*b
, /* I - Second media size */
5705 void *data
) /* Unused */
5708 return (strcmp(a
->media
, b
->media
));
5713 * 'pwg_copy_size()' - Copy a media size.
5716 static cups_size_t
* /* O - New media size */
5717 pwg_copy_size(cups_size_t
*size
, /* I - Media size to copy */
5718 void *data
) /* Unused*/
5720 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
5721 /* New media size */
5724 memcpy(newsize
, size
, sizeof(cups_size_t
));
5731 * 'pwg_free_finishings()' - Free a finishings value.
5735 pwg_free_finishings(_pwg_finishings_t
*f
, /* I - Finishings value */
5736 void *data
) /* Unused */
5739 cupsFreeOptions(f
->num_options
, f
->options
);
5745 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
5749 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
5750 char *name
, /* I - Name buffer */
5751 size_t namesize
) /* I - Size of name buffer */
5753 char *ptr
, /* Pointer into name buffer */
5754 *end
; /* End of name buffer */
5757 if (!ipp
|| !_cups_isalnum(*ipp
))
5763 *name
= (char)toupper(*ipp
++);
5765 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
5767 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
5770 *ptr
++ = (char)toupper(*ipp
++ & 255);
5772 else if (*ipp
== '_' || *ipp
== '.' || *ipp
== '-' || _cups_isalnum(*ipp
))
5787 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
5791 pwg_ppdize_resolution(
5792 ipp_attribute_t
*attr
, /* I - Attribute to convert */
5793 int element
, /* I - Element to convert */
5794 int *xres
, /* O - X resolution in DPI */
5795 int *yres
, /* O - Y resolution in DPI */
5796 char *name
, /* I - Name buffer */
5797 size_t namesize
) /* I - Size of name buffer */
5799 ipp_res_t units
; /* Units for resolution */
5802 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
5804 if (units
== IPP_RES_PER_CM
)
5806 *xres
= (int)(*xres
* 2.54);
5807 *yres
= (int)(*yres
* 2.54);
5810 if (name
&& namesize
> 4)
5813 snprintf(name
, namesize
, "%ddpi", *xres
);
5815 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
5821 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
5825 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
5826 char *name
, /* I - Name buffer */
5827 size_t namesize
, /* I - Size of name buffer */
5828 const char *dashchars
)/* I - Characters to be replaced by dashes */
5830 char *ptr
, /* Pointer into name buffer */
5831 *end
; /* End of name buffer */
5832 int nodash
= 1; /* Next char in IPP name cannot be a
5833 dash (first char or after a dash) */
5836 if (_cups_islower(*ppd
))
5839 * Already lowercase name, use as-is?
5842 const char *ppdptr
; /* Pointer into PPD keyword */
5844 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
5845 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
) ||
5846 (*ppdptr
== '-' && *(ppdptr
- 1) == '-') ||
5847 (*ppdptr
== '-' && *(ppdptr
+ 1) == '\0'))
5852 cupsCopyString(name
, ppd
, namesize
);
5857 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
5859 if (_cups_isalnum(*ppd
) || *ppd
== '.' || *ppd
== '_')
5861 *ptr
++ = (char)tolower(*ppd
& 255);
5864 else if (*ppd
== '-' || strchr(dashchars
, *ppd
))
5875 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
5876 _cups_isupper(ppd
[1]) && ptr
< end
)
5881 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))
5889 /* Remove trailing dashes */
5890 while (ptr
> name
&& *(ptr
- 1) == '-')