2 * PPD cache implementation for CUPS.
4 * Copyright © 2010-2018 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 * Include necessary headers...
14 #include "cups-private.h"
15 #include "ppd-private.h"
16 #include "debug-internal.h"
21 * Macro to test for two almost-equal PWG measurements.
24 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
31 static int cups_get_url(http_t
**http
, const char *url
, char *name
, size_t namesize
);
32 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
33 static void pwg_add_message(cups_array_t
*a
, const char *msg
, const char *str
);
34 static int pwg_compare_finishings(_pwg_finishings_t
*a
, _pwg_finishings_t
*b
);
35 static int pwg_compare_sizes(cups_size_t
*a
, cups_size_t
*b
);
36 static cups_size_t
*pwg_copy_size(cups_size_t
*size
);
37 static void pwg_free_finishings(_pwg_finishings_t
*f
);
38 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
39 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
40 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
41 const char *dashchars
);
45 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
47 * This functions converts PPD and CUPS-specific options to their standard IPP
48 * attributes and values and adds them to the specified IPP request.
51 int /* O - New number of copies */
53 ipp_t
*request
, /* I - IPP request */
54 ppd_file_t
*ppd
, /* I - PPD file */
55 _ppd_cache_t
*pc
, /* I - PPD cache info */
56 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
57 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
58 ipp_attribute_t
*print_color_mode_sup
,
59 /* I - Printer supports print-color-mode */
60 const char *user
, /* I - User info */
61 const char *format
, /* I - document-format value */
62 int copies
, /* I - Number of copies */
63 int num_options
, /* I - Number of options */
64 cups_option_t
*options
) /* I - Options */
66 int i
; /* Looping var */
67 const char *keyword
, /* PWG keyword */
68 *password
; /* Password string */
69 pwg_size_t
*size
; /* PWG media size */
70 ipp_t
*media_col
, /* media-col value */
71 *media_size
; /* media-size value */
72 const char *media_source
, /* media-source value */
73 *media_type
, /* media-type value */
74 *collate_str
, /* multiple-document-handling value */
75 *color_attr_name
, /* Supported color attribute */
76 *mandatory
, /* Mandatory attributes */
77 *finishing_template
; /* Finishing template */
78 int num_finishings
= 0, /* Number of finishing values */
79 finishings
[10]; /* Finishing enum values */
80 ppd_choice_t
*choice
; /* Marked choice */
81 int finishings_copies
= copies
;
82 /* Number of copies for finishings */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "finishings-col") &&
145 strcmp(mandatory
, "finishing-template") &&
146 strcmp(mandatory
, "job-account-id") &&
147 strcmp(mandatory
, "job-accounting-user-id") &&
148 strcmp(mandatory
, "job-password") &&
149 strcmp(mandatory
, "job-password-encryption") &&
150 strcmp(mandatory
, "media") &&
151 strncmp(mandatory
, "media-col", 9) &&
152 strcmp(mandatory
, "multiple-document-handling") &&
153 strcmp(mandatory
, "output-bin") &&
154 strcmp(mandatory
, "print-color-mode") &&
155 strcmp(mandatory
, "print-quality") &&
156 strcmp(mandatory
, "sides") &&
157 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
159 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
161 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
166 case IPP_TAG_INTEGER
:
168 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
170 case IPP_TAG_BOOLEAN
:
171 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
175 int lower
, upper
; /* Range */
177 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
178 lower
= upper
= atoi(keyword
);
180 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
183 case IPP_TAG_STRING
:
184 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
187 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
189 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
190 keyword
= "auto-monochrome";
191 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
192 keyword
= "process-monochrome";
195 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
201 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
202 keyword
= cupsGetOption("media", num_options
, options
);
204 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
205 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
206 size
= _ppdCacheGetSize(pc
, keyword
);
208 if (size
|| media_source
|| media_type
)
211 * Add a media-col value...
214 media_col
= ippNew();
218 media_size
= ippNew();
219 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
220 "x-dimension", size
->width
);
221 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
222 "y-dimension", size
->length
);
224 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
227 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
229 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
233 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
234 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
235 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
236 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
237 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
238 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
239 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
240 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
243 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
246 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
248 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
249 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
253 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
255 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
257 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
259 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
261 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
262 keyword
= "monochrome";
268 if (keyword
&& !strcmp(keyword
, "monochrome"))
270 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
271 keyword
= "auto-monochrome";
272 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
273 keyword
= "process-monochrome";
277 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
279 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
281 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
283 if (!_cups_strcasecmp(choice
->choice
, "draft"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
285 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
286 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
287 else if (!_cups_strcasecmp(choice
->choice
, "high"))
288 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
291 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
293 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
295 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
297 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
298 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
299 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
300 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
307 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
309 if (strstr(keyword
, "uncollated"))
314 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
319 if (!_cups_strcasecmp(format
, "image/gif") ||
320 !_cups_strcasecmp(format
, "image/jp2") ||
321 !_cups_strcasecmp(format
, "image/jpeg") ||
322 !_cups_strcasecmp(format
, "image/png") ||
323 !_cups_strcasecmp(format
, "image/tiff") ||
324 !_cups_strncasecmp(format
, "image/x-", 8))
327 * Collation makes no sense for single page image formats...
332 else if (!_cups_strncasecmp(format
, "image/", 6) ||
333 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
336 * Multi-page image formats will have copies applied by the upstream
344 if (doc_handling_sup
)
346 if (!_cups_strcasecmp(keyword
, "true"))
347 collate_str
= "separate-documents-collated-copies";
349 collate_str
= "separate-documents-uncollated-copies";
351 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
353 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
355 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
360 if (i
>= doc_handling_sup
->num_values
)
365 * Map finishing options...
368 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
369 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
371 if (finishing_template
&& strcmp(finishing_template
, "none"))
373 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
375 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
376 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
379 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
382 * Send job-pages-per-set attribute to apply finishings correctly...
385 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
390 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
391 if (num_finishings
> 0)
393 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
395 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
398 * Send job-pages-per-set attribute to apply finishings correctly...
401 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
411 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
414 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
418 _ppd_cache_t
* /* O - PPD cache and mapping data */
419 _ppdCacheCreateWithFile(
420 const char *filename
, /* I - File to read */
421 ipp_t
**attrs
) /* IO - IPP attributes, if any */
423 cups_file_t
*fp
; /* File */
424 _ppd_cache_t
*pc
; /* PWG mapping data */
425 pwg_size_t
*size
; /* Current size */
426 pwg_map_t
*map
; /* Current map */
427 _pwg_finishings_t
*finishings
; /* Current finishings option */
428 int linenum
, /* Current line number */
429 num_bins
, /* Number of bins in file */
430 num_sizes
, /* Number of sizes in file */
431 num_sources
, /* Number of sources in file */
432 num_types
; /* Number of types in file */
433 char line
[2048], /* Current line */
434 *value
, /* Pointer to value in line */
435 *valueptr
, /* Pointer into value */
436 pwg_keyword
[128], /* PWG keyword */
437 ppd_keyword
[PPD_MAX_NAME
];
439 _pwg_print_color_mode_t print_color_mode
;
440 /* Print color mode for preset */
441 _pwg_print_quality_t print_quality
; /* Print quality for preset */
444 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
447 * Range check input...
455 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
463 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
465 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
470 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
473 if (!cupsFileGets(fp
, line
, sizeof(line
)))
475 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
476 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
481 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
483 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
484 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
489 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
491 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
492 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
493 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
499 * Allocate the mapping data structure...
502 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
505 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
509 pc
->max_copies
= 9999;
521 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
523 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
524 "linenum=%d", line
, value
, linenum
));
528 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
530 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
533 else if (!_cups_strcasecmp(line
, "Filter"))
536 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
537 (cups_acopy_func_t
)_cupsStrAlloc
,
538 (cups_afree_func_t
)_cupsStrFree
);
540 cupsArrayAdd(pc
->filters
, value
);
542 else if (!_cups_strcasecmp(line
, "PreFilter"))
545 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
546 (cups_acopy_func_t
)_cupsStrAlloc
,
547 (cups_afree_func_t
)_cupsStrFree
);
549 cupsArrayAdd(pc
->prefilters
, value
);
551 else if (!_cups_strcasecmp(line
, "Product"))
553 pc
->product
= _cupsStrAlloc(value
);
555 else if (!_cups_strcasecmp(line
, "SingleFile"))
557 pc
->single_file
= !_cups_strcasecmp(value
, "true");
559 else if (!_cups_strcasecmp(line
, "IPP"))
561 off_t pos
= cupsFileTell(fp
), /* Position in file */
562 length
= strtol(value
, NULL
, 10);
563 /* Length of IPP attributes */
567 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
568 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
571 else if (length
<= 0)
573 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
574 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
581 * Read IPP attributes into the provided variable...
586 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
587 *attrs
) != IPP_STATE_DATA
)
589 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
590 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
597 * Skip the IPP data entirely...
600 cupsFileSeek(fp
, pos
+ length
);
603 if (cupsFileTell(fp
) != (pos
+ length
))
605 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
606 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
610 else if (!_cups_strcasecmp(line
, "NumBins"))
614 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
615 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
619 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
621 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
622 "%d.", num_sizes
, linenum
));
623 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
627 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
629 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
631 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
635 else if (!_cups_strcasecmp(line
, "Bin"))
637 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
639 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
640 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
644 if (pc
->num_bins
>= num_bins
)
646 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
648 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
652 map
= pc
->bins
+ pc
->num_bins
;
653 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
654 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
658 else if (!_cups_strcasecmp(line
, "NumSizes"))
662 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
663 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
667 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
669 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
670 "%d.", num_sizes
, linenum
));
671 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
677 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
679 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
681 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
686 else if (!_cups_strcasecmp(line
, "Size"))
688 if (pc
->num_sizes
>= num_sizes
)
690 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
692 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
696 size
= pc
->sizes
+ pc
->num_sizes
;
698 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
699 &(size
->width
), &(size
->length
), &(size
->left
),
700 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
702 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
704 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
708 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
709 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
713 else if (!_cups_strcasecmp(line
, "CustomSize"))
715 if (pc
->custom_max_width
> 0)
717 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
719 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
723 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
724 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
725 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
726 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
727 &(pc
->custom_size
.top
)) != 8)
729 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
731 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
735 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
736 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
737 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
739 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
740 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
741 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
743 else if (!_cups_strcasecmp(line
, "SourceOption"))
745 pc
->source_option
= _cupsStrAlloc(value
);
747 else if (!_cups_strcasecmp(line
, "NumSources"))
751 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
753 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
757 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
759 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
760 "line %d.", num_sources
, linenum
));
761 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
765 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
767 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
769 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
773 else if (!_cups_strcasecmp(line
, "Source"))
775 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
777 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
779 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
783 if (pc
->num_sources
>= num_sources
)
785 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
787 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
791 map
= pc
->sources
+ pc
->num_sources
;
792 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
793 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
797 else if (!_cups_strcasecmp(line
, "NumTypes"))
801 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
802 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
806 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
808 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
809 "line %d.", num_types
, linenum
));
810 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
814 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
816 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
818 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
822 else if (!_cups_strcasecmp(line
, "Type"))
824 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
826 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
828 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
832 if (pc
->num_types
>= num_types
)
834 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
836 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
840 map
= pc
->types
+ pc
->num_types
;
841 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
842 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
846 else if (!_cups_strcasecmp(line
, "Preset"))
849 * Preset output-mode print-quality name=value ...
852 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
853 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
855 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
856 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
857 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
858 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
859 valueptr
== value
|| !*valueptr
)
861 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
863 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
867 pc
->num_presets
[print_color_mode
][print_quality
] =
868 cupsParseOptions(valueptr
, 0,
869 pc
->presets
[print_color_mode
] + print_quality
);
871 else if (!_cups_strcasecmp(line
, "SidesOption"))
872 pc
->sides_option
= _cupsStrAlloc(value
);
873 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
874 pc
->sides_1sided
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
876 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
877 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
878 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
879 else if (!_cups_strcasecmp(line
, "Finishings"))
883 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
885 (cups_afree_func_t
)pwg_free_finishings
);
887 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
890 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
891 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
892 &(finishings
->options
));
894 cupsArrayAdd(pc
->finishings
, finishings
);
896 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
899 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
901 cupsArrayAdd(pc
->templates
, value
);
903 else if (!_cups_strcasecmp(line
, "MaxCopies"))
904 pc
->max_copies
= atoi(value
);
905 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
906 pc
->charge_info_uri
= _cupsStrAlloc(value
);
907 else if (!_cups_strcasecmp(line
, "JobAccountId"))
908 pc
->account_id
= !_cups_strcasecmp(value
, "true");
909 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
910 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
911 else if (!_cups_strcasecmp(line
, "JobPassword"))
912 pc
->password
= _cupsStrAlloc(value
);
913 else if (!_cups_strcasecmp(line
, "Mandatory"))
916 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
918 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
920 else if (!_cups_strcasecmp(line
, "SupportFile"))
922 if (!pc
->support_files
)
923 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
924 (cups_acopy_func_t
)_cupsStrAlloc
,
925 (cups_afree_func_t
)_cupsStrFree
);
927 cupsArrayAdd(pc
->support_files
, value
);
931 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
936 if (pc
->num_sizes
< num_sizes
)
938 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
939 pc
->num_sizes
, num_sizes
));
940 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
944 if (pc
->num_sources
< num_sources
)
946 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
947 pc
->num_sources
, num_sources
));
948 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
952 if (pc
->num_types
< num_types
)
954 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
955 pc
->num_types
, num_types
));
956 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
965 * If we get here the file was bad - free any data and return...
971 _ppdCacheDestroy(pc
);
984 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
987 _ppd_cache_t
* /* O - PPD cache and mapping data */
988 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
990 int i
, j
, k
; /* Looping vars */
991 _ppd_cache_t
*pc
; /* PWG mapping data */
992 ppd_option_t
*input_slot
, /* InputSlot option */
993 *media_type
, /* MediaType option */
994 *output_bin
, /* OutputBin option */
995 *color_model
, /* ColorModel option */
996 *duplex
, /* Duplex option */
997 *ppd_option
; /* Other PPD option */
998 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
999 pwg_map_t
*map
; /* Current source/type map */
1000 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1001 int num_options
; /* Number of preset options and props */
1002 cups_option_t
*options
; /* Preset options and properties */
1003 ppd_size_t
*ppd_size
; /* Current PPD size */
1004 pwg_size_t
*pwg_size
; /* Current PWG size */
1005 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1006 /* PWG keyword string */
1007 ppd_name
[PPD_MAX_NAME
];
1008 /* Normalized PPD name */
1009 const char *pwg_name
; /* Standard PWG media name */
1010 pwg_media_t
*pwg_media
; /* PWG media data */
1011 _pwg_print_color_mode_t pwg_print_color_mode
;
1012 /* print-color-mode index */
1013 _pwg_print_quality_t pwg_print_quality
;
1014 /* print-quality index */
1015 int similar
; /* Are the old and new size similar? */
1016 pwg_size_t
*old_size
; /* Current old size */
1017 int old_imageable
, /* Old imageable length in 2540ths */
1018 old_borderless
, /* Old borderless state */
1019 old_known_pwg
; /* Old PWG name is well-known */
1020 int new_width
, /* New width in 2540ths */
1021 new_length
, /* New length in 2540ths */
1022 new_left
, /* New left margin in 2540ths */
1023 new_bottom
, /* New bottom margin in 2540ths */
1024 new_right
, /* New right margin in 2540ths */
1025 new_top
, /* New top margin in 2540ths */
1026 new_imageable
, /* New imageable length in 2540ths */
1027 new_borderless
, /* New borderless state */
1028 new_known_pwg
; /* New PWG name is well-known */
1029 pwg_size_t
*new_size
; /* New size to add, if any */
1030 const char *filter
; /* Current filter */
1031 _pwg_finishings_t
*finishings
; /* Current finishings value */
1032 char msg_id
[256]; /* Message identifier */
1035 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1038 * Range check input...
1045 * Allocate memory...
1048 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1050 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1054 pc
->strings
= _cupsMessageNew(NULL
);
1057 * Copy and convert size data...
1060 if (ppd
->num_sizes
> 0)
1062 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1064 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1065 "pwg_size_t's.", ppd
->num_sizes
));
1069 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1074 * Don't copy over custom size...
1077 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1081 * Convert the PPD size name to the corresponding PWG keyword name.
1084 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1087 * Standard name, do we have conflicts?
1090 for (j
= 0; j
< pc
->num_sizes
; j
++)
1091 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1101 * Standard name and no conflicts, use it!
1104 pwg_name
= pwg_media
->pwg
;
1110 * Not a standard name; convert it to a PWG vendor name of the form:
1112 * pp_lowerppd_WIDTHxHEIGHTuu
1115 pwg_name
= pwg_keyword
;
1118 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1119 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1120 PWG_FROM_POINTS(ppd_size
->width
),
1121 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1125 * If we have a similar paper with non-zero margins then we only want to
1126 * keep it if it has a larger imageable area length. The NULL check is for
1127 * dimensions that are <= 0...
1130 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1131 PWG_FROM_POINTS(ppd_size
->length
),
1135 new_width
= pwg_media
->width
;
1136 new_length
= pwg_media
->length
;
1137 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1138 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1139 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1140 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1141 new_imageable
= new_length
- new_top
- new_bottom
;
1142 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1143 new_left
== 0 && new_right
== 0;
1145 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1149 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1150 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1151 old_size
->right
== 0 && old_size
->top
== 0;
1152 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1153 strncmp(old_size
->map
.pwg
, "om_", 3);
1155 similar
= old_borderless
== new_borderless
&&
1156 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1157 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1160 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1163 * The new paper has a larger imageable area so it could replace
1164 * the older paper. Regardless of the imageable area, we always
1165 * prefer the size with a well-known PWG name.
1168 new_size
= old_size
;
1169 _cupsStrFree(old_size
->map
.ppd
);
1170 _cupsStrFree(old_size
->map
.pwg
);
1177 * The paper was unique enough to deserve its own entry so add it to the
1181 new_size
= pwg_size
++;
1191 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1192 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1193 new_size
->width
= new_width
;
1194 new_size
->length
= new_length
;
1195 new_size
->left
= new_left
;
1196 new_size
->bottom
= new_bottom
;
1197 new_size
->right
= new_right
;
1198 new_size
->top
= new_top
;
1203 if (ppd
->variable_sizes
)
1206 * Generate custom size data...
1209 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1210 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1211 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1212 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1213 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1214 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1216 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1217 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1218 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1219 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1220 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1221 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1223 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1224 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1225 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1226 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1230 * Copy and convert InputSlot data...
1233 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1234 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1238 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1240 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1242 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1243 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1247 pc
->num_sources
= input_slot
->num_choices
;
1249 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1252 i
--, choice
++, map
++)
1254 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1255 !_cups_strcasecmp(choice
->choice
, "Default"))
1257 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1259 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1261 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1263 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1264 !_cups_strcasecmp(choice
->choice
, "MP") ||
1265 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1266 pwg_name
= "by-pass-tray";
1267 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1268 pwg_name
= "large-capacity";
1269 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1270 pwg_name
= "bottom";
1271 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1272 pwg_name
= "middle";
1273 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1275 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1277 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1278 pwg_name
= "main-roll";
1282 * Convert PPD name to lowercase...
1285 pwg_name
= pwg_keyword
;
1286 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1290 map
->pwg
= _cupsStrAlloc(pwg_name
);
1291 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1294 * Add localized text for PWG keyword to message catalog...
1297 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1298 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1303 * Copy and convert MediaType data...
1306 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1308 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1310 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1311 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1315 pc
->num_types
= media_type
->num_choices
;
1317 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1320 i
--, choice
++, map
++)
1322 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1323 !_cups_strcasecmp(choice
->choice
, "Any") ||
1324 !_cups_strcasecmp(choice
->choice
, "Default"))
1326 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1327 pwg_name
= "cardstock";
1328 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1329 pwg_name
= "envelope";
1330 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1331 pwg_name
= "photographic-glossy";
1332 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1333 pwg_name
= "photographic-high-gloss";
1334 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1335 pwg_name
= "photographic-matte";
1336 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1337 pwg_name
= "stationery";
1338 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1339 pwg_name
= "stationery-coated";
1340 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1341 pwg_name
= "stationery-inkjet";
1342 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1343 pwg_name
= "stationery-letterhead";
1344 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1345 pwg_name
= "stationery-preprinted";
1346 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1347 pwg_name
= "stationery-recycled";
1348 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1349 pwg_name
= "transparency";
1353 * Convert PPD name to lowercase...
1356 pwg_name
= pwg_keyword
;
1357 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1361 map
->pwg
= _cupsStrAlloc(pwg_name
);
1362 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1365 * Add localized text for PWG keyword to message catalog...
1368 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", pwg_name
);
1369 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1374 * Copy and convert OutputBin data...
1377 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1379 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1381 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1382 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1386 pc
->num_bins
= output_bin
->num_choices
;
1388 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1391 i
--, choice
++, map
++)
1393 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1395 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1396 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1399 * Add localized text for PWG keyword to message catalog...
1402 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_name
);
1403 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1407 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1410 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1413 const char *quality
, /* com.apple.print.preset.quality value */
1414 *output_mode
, /* com.apple.print.preset.output-mode value */
1415 *color_model_val
, /* ColorModel choice */
1416 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1417 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1422 * Add localized text for PWG keyword to message catalog...
1425 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1426 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1429 * Get the options for this preset...
1432 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1435 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1436 num_options
, options
)) != NULL
)
1439 * Get the print-quality for this preset...
1442 if (!strcmp(quality
, "low"))
1443 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1444 else if (!strcmp(quality
, "high"))
1445 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1447 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1450 * Ignore graphicsType "Photo" presets that are not high quality.
1453 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1454 num_options
, options
);
1456 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1457 !strcmp(graphicsType
, "Photo"))
1461 * Ignore presets for normal and draft quality where the coating
1462 * isn't "none" or "autodetect".
1465 media_front_coating
= cupsGetOption(
1466 "com.apple.print.preset.media-front-coating",
1467 num_options
, options
);
1469 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1470 media_front_coating
&&
1471 strcmp(media_front_coating
, "none") &&
1472 strcmp(media_front_coating
, "autodetect"))
1476 * Get the output mode for this preset...
1479 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1480 num_options
, options
);
1481 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1485 if (!strcmp(output_mode
, "monochrome"))
1486 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1488 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1490 else if (color_model_val
)
1492 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1493 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1495 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1498 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1501 * Save the options for this combination as needed...
1504 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1505 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1506 _ppdParseOptions(ppd_attr
->value
, 0,
1507 pc
->presets
[pwg_print_color_mode
] +
1508 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1511 cupsFreeOptions(num_options
, options
);
1513 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1516 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1517 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1518 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1521 * Try adding some common color options to create grayscale presets. These
1522 * are listed in order of popularity...
1525 const char *color_option
= NULL
, /* Color control option */
1526 *gray_choice
= NULL
; /* Choice to select grayscale */
1528 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1529 ppdFindChoice(color_model
, "Gray"))
1531 color_option
= "ColorModel";
1532 gray_choice
= "Gray";
1534 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1535 ppdFindChoice(color_model
, "grayscale"))
1537 color_option
= "HPColorMode";
1538 gray_choice
= "grayscale";
1540 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1541 ppdFindChoice(color_model
, "Mono"))
1543 color_option
= "BRMonoColor";
1544 gray_choice
= "Mono";
1546 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1547 ppdFindChoice(color_model
, "1"))
1549 color_option
= "CNIJSGrayScale";
1552 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1553 ppdFindChoice(color_model
, "True"))
1555 color_option
= "HPColorAsGray";
1556 gray_choice
= "True";
1559 if (color_option
&& gray_choice
)
1562 * Copy and convert ColorModel (output-mode) data...
1565 cups_option_t
*coption
, /* Color option */
1566 *moption
; /* Monochrome option */
1568 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1569 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1570 pwg_print_quality
++)
1572 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1575 * Copy the color options...
1578 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1579 [pwg_print_quality
];
1580 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1584 for (i
= num_options
, moption
= options
,
1585 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1586 [pwg_print_quality
];
1588 i
--, moption
++, coption
++)
1590 moption
->name
= _cupsStrRetain(coption
->name
);
1591 moption
->value
= _cupsStrRetain(coption
->value
);
1594 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1596 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1600 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1604 * Add the grayscale option to the preset...
1607 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1608 cupsAddOption(color_option
, gray_choice
,
1609 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1610 [pwg_print_quality
],
1611 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1618 * Copy and convert Duplex (sides) data...
1621 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1622 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1623 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1624 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1625 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1629 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1631 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1635 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1636 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1637 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1638 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1639 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1640 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1641 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1642 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1643 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1644 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1645 !pc
->sides_2sided_short
)
1646 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1651 * Copy filters and pre-filters...
1654 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1655 (cups_acopy_func_t
)_cupsStrAlloc
,
1656 (cups_afree_func_t
)_cupsStrFree
);
1658 cupsArrayAdd(pc
->filters
,
1659 "application/vnd.cups-raw application/octet-stream 0 -");
1661 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1665 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1667 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1669 else if (ppd
->num_filters
> 0)
1671 for (i
= 0; i
< ppd
->num_filters
; i
++)
1672 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1675 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1678 * See if we have a command filter...
1681 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1683 filter
= (const char *)cupsArrayNext(pc
->filters
))
1684 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1685 _cups_isspace(filter
[28]))
1689 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1690 _cups_strcasecmp(ppd_attr
->value
, "none")))
1693 * No command filter and no cupsCommands keyword telling us not to use one.
1694 * See if this is a PostScript printer, and if so add a PostScript command
1698 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1700 filter
= (const char *)cupsArrayNext(pc
->filters
))
1701 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1702 _cups_isspace(filter
[31]))
1706 cupsArrayAdd(pc
->filters
,
1707 "application/vnd.cups-command application/postscript 100 "
1711 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1713 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1714 (cups_acopy_func_t
)_cupsStrAlloc
,
1715 (cups_afree_func_t
)_cupsStrFree
);
1719 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1721 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1724 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1725 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1728 * Copy the product string, if any...
1732 pc
->product
= _cupsStrAlloc(ppd
->product
);
1735 * Copy finishings mapping data...
1738 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1741 * Have proper vendor mapping of IPP finishings values to PPD options...
1744 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1745 NULL
, NULL
, 0, NULL
,
1746 (cups_afree_func_t
)pwg_free_finishings
);
1750 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1753 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1754 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1755 &(finishings
->options
),
1756 _PPD_PARSE_OPTIONS
);
1758 cupsArrayAdd(pc
->finishings
, finishings
);
1760 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1766 * No IPP mapping data, try to map common/standard PPD keywords...
1769 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1771 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1774 * Add staple finishings...
1777 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1779 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1780 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1781 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1782 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1783 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1784 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1785 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1786 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1789 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1792 * Add (Ricoh) punch finishings...
1795 if (ppdFindChoice(ppd_option
, "Left2"))
1796 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1797 if (ppdFindChoice(ppd_option
, "Left3"))
1798 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1799 if (ppdFindChoice(ppd_option
, "Left4"))
1800 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1801 if (ppdFindChoice(ppd_option
, "Right2"))
1802 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1803 if (ppdFindChoice(ppd_option
, "Right3"))
1804 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1805 if (ppdFindChoice(ppd_option
, "Right4"))
1806 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1807 if (ppdFindChoice(ppd_option
, "Upper2"))
1808 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1809 if (ppdFindChoice(ppd_option
, "Upper3"))
1810 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1811 if (ppdFindChoice(ppd_option
, "Upper4"))
1812 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1815 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1818 * Add bind finishings...
1821 if (ppdFindChoice(ppd_option
, "Left"))
1822 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1823 if (ppdFindChoice(ppd_option
, "Right"))
1824 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1825 if (ppdFindChoice(ppd_option
, "Top"))
1826 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1827 if (ppdFindChoice(ppd_option
, "Bottom"))
1828 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1831 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1834 * Add (Adobe) fold finishings...
1837 if (ppdFindChoice(ppd_option
, "ZFold"))
1838 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1839 if (ppdFindChoice(ppd_option
, "Saddle"))
1840 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1841 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1842 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1843 if (ppdFindChoice(ppd_option
, "LeftGate"))
1844 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1845 if (ppdFindChoice(ppd_option
, "RightGate"))
1846 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1847 if (ppdFindChoice(ppd_option
, "Letter"))
1848 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1849 if (ppdFindChoice(ppd_option
, "XFold"))
1850 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1853 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1856 * Add (Ricoh) fold finishings...
1859 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1860 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1863 if (cupsArrayCount(pc
->finishings
) == 0)
1865 cupsArrayDelete(pc
->finishings
);
1866 pc
->finishings
= NULL
;
1870 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1872 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
1874 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1876 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1879 * Add localized text for PWG keyword to message catalog...
1882 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1883 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1891 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1892 pc
->max_copies
= atoi(ppd_attr
->value
);
1893 else if (ppd
->manual_copies
)
1896 pc
->max_copies
= 9999;
1899 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1900 * cupsJobPassword, and cupsMandatory.
1903 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1904 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1906 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1907 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1909 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1910 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1912 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1913 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1915 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1916 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1922 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1923 (cups_acopy_func_t
)_cupsStrAlloc
,
1924 (cups_afree_func_t
)_cupsStrFree
);
1926 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1928 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1929 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1931 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1932 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1935 * Return the cache data...
1941 * If we get here we need to destroy the PWG mapping data and return NULL...
1946 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1947 _ppdCacheDestroy(pc
);
1954 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1958 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1960 int i
; /* Looping var */
1961 pwg_map_t
*map
; /* Current map */
1962 pwg_size_t
*size
; /* Current size */
1966 * Range check input...
1973 * Free memory as needed...
1978 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1980 _cupsStrFree(map
->pwg
);
1981 _cupsStrFree(map
->ppd
);
1989 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1991 _cupsStrFree(size
->map
.pwg
);
1992 _cupsStrFree(size
->map
.ppd
);
1998 if (pc
->source_option
)
1999 _cupsStrFree(pc
->source_option
);
2003 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2005 _cupsStrFree(map
->pwg
);
2006 _cupsStrFree(map
->ppd
);
2014 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2016 _cupsStrFree(map
->pwg
);
2017 _cupsStrFree(map
->ppd
);
2023 if (pc
->custom_max_keyword
)
2024 _cupsStrFree(pc
->custom_max_keyword
);
2026 if (pc
->custom_min_keyword
)
2027 _cupsStrFree(pc
->custom_min_keyword
);
2029 _cupsStrFree(pc
->product
);
2030 cupsArrayDelete(pc
->filters
);
2031 cupsArrayDelete(pc
->prefilters
);
2032 cupsArrayDelete(pc
->finishings
);
2034 _cupsStrFree(pc
->charge_info_uri
);
2035 _cupsStrFree(pc
->password
);
2037 cupsArrayDelete(pc
->mandatory
);
2039 cupsArrayDelete(pc
->support_files
);
2041 cupsArrayDelete(pc
->strings
);
2048 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2052 const char * /* O - output-bin or NULL */
2054 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2055 const char *output_bin
) /* I - PPD OutputBin string */
2057 int i
; /* Looping var */
2061 * Range check input...
2064 if (!pc
|| !output_bin
)
2068 * Look up the OutputBin string...
2072 for (i
= 0; i
< pc
->num_bins
; i
++)
2073 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2074 return (pc
->bins
[i
].pwg
);
2081 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2082 * IPP finishings value(s).
2085 int /* O - New number of options */
2086 _ppdCacheGetFinishingOptions(
2087 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2088 ipp_t
*job
, /* I - Job attributes or NULL */
2089 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2090 int num_options
, /* I - Number of options */
2091 cups_option_t
**options
) /* IO - Options */
2093 int i
; /* Looping var */
2094 _pwg_finishings_t
*f
, /* PWG finishings options */
2095 key
; /* Search key */
2096 ipp_attribute_t
*attr
; /* Finishings attribute */
2097 cups_option_t
*option
; /* Current finishings option */
2101 * Range check input...
2104 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2105 (!job
&& value
== IPP_FINISHINGS_NONE
))
2106 return (num_options
);
2109 * Apply finishing options...
2112 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2114 int num_values
= ippGetCount(attr
); /* Number of values */
2116 for (i
= 0; i
< num_values
; i
++)
2118 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2120 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2122 int j
; /* Another looping var */
2124 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2125 num_options
= cupsAddOption(option
->name
, option
->value
,
2126 num_options
, options
);
2130 else if (value
!= IPP_FINISHINGS_NONE
)
2134 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2136 int j
; /* Another looping var */
2138 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2139 num_options
= cupsAddOption(option
->name
, option
->value
,
2140 num_options
, options
);
2144 return (num_options
);
2149 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2153 int /* O - Number of finishings values */
2154 _ppdCacheGetFinishingValues(
2155 ppd_file_t
*ppd
, /* I - Marked PPD file */
2156 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2157 int max_values
, /* I - Maximum number of finishings values */
2158 int *values
) /* O - Finishings values */
2160 int i
, /* Looping var */
2161 num_values
= 0; /* Number of values */
2162 _pwg_finishings_t
*f
; /* Current finishings option */
2163 cups_option_t
*option
; /* Current option */
2164 ppd_choice_t
*choice
; /* Marked PPD choice */
2168 * Range check input...
2171 DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd
, pc
, max_values
, values
));
2173 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2175 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2178 else if (!pc
->finishings
)
2180 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2185 * Go through the finishings options and see what is set...
2188 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2190 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2192 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2194 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2196 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2198 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2200 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2207 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2209 values
[num_values
++] = f
->value
;
2211 if (num_values
>= max_values
)
2216 if (num_values
== 0)
2219 * Always have at least "finishings" = 'none'...
2222 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2223 values
[0] = IPP_FINISHINGS_NONE
;
2227 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2229 return (num_values
);
2234 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2235 * attributes or a keyword string.
2238 const char * /* O - PPD InputSlot or NULL */
2239 _ppdCacheGetInputSlot(
2240 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2241 ipp_t
*job
, /* I - Job attributes or NULL */
2242 const char *keyword
) /* I - Keyword string or NULL */
2245 * Range check input...
2248 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2251 if (job
&& !keyword
)
2254 * Lookup the media-col attribute and any media-source found there...
2257 ipp_attribute_t
*media_col
, /* media-col attribute */
2258 *media_source
; /* media-source attribute */
2259 pwg_size_t size
; /* Dimensional size */
2260 int margins_set
; /* Were the margins set? */
2262 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2264 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2266 IPP_TAG_KEYWORD
)) != NULL
)
2269 * Use the media-source value from media-col...
2272 keyword
= ippGetString(media_source
, 0, NULL
);
2274 else if (pwgInitSize(&size
, job
, &margins_set
))
2277 * For media <= 5x7, look for a photo tray...
2280 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2287 int i
; /* Looping var */
2289 for (i
= 0; i
< pc
->num_sources
; i
++)
2290 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2291 return (pc
->sources
[i
].ppd
);
2299 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2300 * attributes or a keyword string.
2303 const char * /* O - PPD MediaType or NULL */
2304 _ppdCacheGetMediaType(
2305 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2306 ipp_t
*job
, /* I - Job attributes or NULL */
2307 const char *keyword
) /* I - Keyword string or NULL */
2310 * Range check input...
2313 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2316 if (job
&& !keyword
)
2319 * Lookup the media-col attribute and any media-source found there...
2322 ipp_attribute_t
*media_col
, /* media-col attribute */
2323 *media_type
; /* media-type attribute */
2325 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2328 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2330 IPP_TAG_KEYWORD
)) == NULL
)
2331 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2332 "media-type", IPP_TAG_NAME
);
2335 keyword
= media_type
->values
[0].string
.text
;
2341 int i
; /* Looping var */
2343 for (i
= 0; i
< pc
->num_types
; i
++)
2344 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2345 return (pc
->types
[i
].ppd
);
2353 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2357 const char * /* O - PPD OutputBin or NULL */
2358 _ppdCacheGetOutputBin(
2359 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2360 const char *output_bin
) /* I - Keyword string */
2362 int i
; /* Looping var */
2366 * Range check input...
2369 if (!pc
|| !output_bin
)
2373 * Look up the OutputBin string...
2377 for (i
= 0; i
< pc
->num_bins
; i
++)
2378 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2379 return (pc
->bins
[i
].ppd
);
2386 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2387 * attributes or a keyword string.
2390 const char * /* O - PPD PageSize or NULL */
2391 _ppdCacheGetPageSize(
2392 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2393 ipp_t
*job
, /* I - Job attributes or NULL */
2394 const char *keyword
, /* I - Keyword string or NULL */
2395 int *exact
) /* O - 1 if exact match, 0 otherwise */
2397 int i
; /* Looping var */
2398 pwg_size_t
*size
, /* Current size */
2399 *closest
, /* Closest size */
2400 jobsize
; /* Size data from job */
2401 int margins_set
, /* Were the margins set? */
2402 dwidth
, /* Difference in width */
2403 dlength
, /* Difference in length */
2404 dleft
, /* Difference in left margins */
2405 dright
, /* Difference in right margins */
2406 dbottom
, /* Difference in bottom margins */
2407 dtop
, /* Difference in top margins */
2408 dmin
, /* Minimum difference */
2409 dclosest
; /* Closest difference */
2410 const char *ppd_name
; /* PPD media name */
2413 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2414 pc
, job
, keyword
, exact
));
2417 * Range check input...
2420 if (!pc
|| (!job
&& !keyword
))
2431 * Try getting the PPD media name from the job attributes...
2434 ipp_attribute_t
*attr
; /* Job attribute */
2436 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2437 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2438 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2442 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2443 attr
->name
, ippTagString(attr
->value_tag
)));
2445 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2448 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2449 attr
->value_tag
== IPP_TAG_KEYWORD
))
2450 ppd_name
= attr
->values
[0].string
.text
;
2453 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2458 * Try looking up the named PPD size first...
2461 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2463 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2464 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2466 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2467 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2472 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2474 return (size
->map
.ppd
);
2479 if (job
&& !keyword
)
2482 * Get the size using media-col or media, with the preference being
2486 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2492 * Get the size using a media keyword...
2495 pwg_media_t
*media
; /* Media definition */
2498 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2499 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2500 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2503 jobsize
.width
= media
->width
;
2504 jobsize
.length
= media
->length
;
2509 * Now that we have the dimensions and possibly the margins, look at the
2510 * available sizes and find the match...
2514 dclosest
= 999999999;
2516 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2517 _cups_strncasecmp(ppd_name
, "custom_", 7))
2519 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2522 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2523 * is just about 176/2540ths...
2526 dwidth
= size
->width
- jobsize
.width
;
2527 dlength
= size
->length
- jobsize
.length
;
2529 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2535 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2538 dleft
= size
->left
- jobsize
.left
;
2539 dright
= size
->right
- jobsize
.right
;
2540 dtop
= size
->top
- jobsize
.top
;
2541 dbottom
= size
->bottom
- jobsize
.bottom
;
2543 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2544 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2546 dleft
= dleft
< 0 ? -dleft
: dleft
;
2547 dright
= dright
< 0 ? -dright
: dright
;
2548 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2549 dtop
= dtop
< 0 ? -dtop
: dtop
;
2550 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2552 if (dmin
< dclosest
)
2565 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2567 return (size
->map
.ppd
);
2573 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2576 return (closest
->map
.ppd
);
2580 * If we get here we need to check for custom page size support...
2583 if (jobsize
.width
>= pc
->custom_min_width
&&
2584 jobsize
.width
<= pc
->custom_max_width
&&
2585 jobsize
.length
>= pc
->custom_min_length
&&
2586 jobsize
.length
<= pc
->custom_max_length
)
2589 * In range, format as Custom.WWWWxLLLL (points).
2592 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2593 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2595 if (margins_set
&& exact
)
2597 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2598 dright
= pc
->custom_size
.right
- jobsize
.right
;
2599 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2600 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2602 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2603 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2609 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2610 pc
->custom_ppd_size
));
2612 return (pc
->custom_ppd_size
);
2616 * No custom page size support or the size is out of range - return NULL.
2619 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2626 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2629 pwg_size_t
* /* O - PWG size or NULL */
2631 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2632 const char *page_size
) /* I - PPD PageSize */
2634 int i
; /* Looping var */
2635 pwg_media_t
*media
; /* Media */
2636 pwg_size_t
*size
; /* Current size */
2640 * Range check input...
2643 if (!pc
|| !page_size
)
2646 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2649 * Custom size; size name can be one of the following:
2651 * Custom.WIDTHxLENGTHin - Size in inches
2652 * Custom.WIDTHxLENGTHft - Size in feet
2653 * Custom.WIDTHxLENGTHcm - Size in centimeters
2654 * Custom.WIDTHxLENGTHmm - Size in millimeters
2655 * Custom.WIDTHxLENGTHm - Size in meters
2656 * Custom.WIDTHxLENGTH[pt] - Size in points
2659 double w
, l
; /* Width and length of page */
2660 char *ptr
; /* Pointer into PageSize */
2661 struct lconv
*loc
; /* Locale data */
2664 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2665 if (!ptr
|| *ptr
!= 'x')
2668 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2672 if (!_cups_strcasecmp(ptr
, "in"))
2677 else if (!_cups_strcasecmp(ptr
, "ft"))
2682 else if (!_cups_strcasecmp(ptr
, "mm"))
2687 else if (!_cups_strcasecmp(ptr
, "cm"))
2692 else if (!_cups_strcasecmp(ptr
, "m"))
2703 pc
->custom_size
.width
= (int)w
;
2704 pc
->custom_size
.length
= (int)l
;
2706 return (&(pc
->custom_size
));
2710 * Not a custom size - look it up...
2713 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2714 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2715 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2719 * Look up standard sizes...
2722 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2723 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2724 media
= pwgMediaForPWG(page_size
);
2728 pc
->custom_size
.width
= media
->width
;
2729 pc
->custom_size
.length
= media
->length
;
2731 return (&(pc
->custom_size
));
2739 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2743 const char * /* O - PWG media-source keyword */
2745 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2746 const char *input_slot
) /* I - PPD InputSlot */
2748 int i
; /* Looping var */
2749 pwg_map_t
*source
; /* Current source */
2753 * Range check input...
2756 if (!pc
|| !input_slot
)
2759 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2760 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2761 return (source
->pwg
);
2768 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2772 const char * /* O - PWG media-type keyword */
2774 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2775 const char *media_type
) /* I - PPD MediaType */
2777 int i
; /* Looping var */
2778 pwg_map_t
*type
; /* Current type */
2782 * Range check input...
2785 if (!pc
|| !media_type
)
2788 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2789 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2797 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2800 int /* O - 1 on success, 0 on failure */
2802 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2803 const char *filename
, /* I - File to write */
2804 ipp_t
*attrs
) /* I - Attributes to write, if any */
2806 int i
, j
, k
; /* Looping vars */
2807 cups_file_t
*fp
; /* Output file */
2808 pwg_size_t
*size
; /* Current size */
2809 pwg_map_t
*map
; /* Current map */
2810 _pwg_finishings_t
*f
; /* Current finishing option */
2811 cups_option_t
*option
; /* Current option */
2812 const char *value
; /* String value */
2813 char newfile
[1024]; /* New filename */
2817 * Range check input...
2820 if (!pc
|| !filename
)
2822 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2827 * Open the file and write with compression...
2830 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2831 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2833 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2838 * Standard header...
2841 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2847 if (pc
->num_bins
> 0)
2849 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2850 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2851 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2858 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2859 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2860 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2861 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2862 size
->bottom
, size
->right
, size
->top
);
2863 if (pc
->custom_max_width
> 0)
2864 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2865 pc
->custom_max_width
, pc
->custom_max_length
,
2866 pc
->custom_min_width
, pc
->custom_min_length
,
2867 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2868 pc
->custom_size
.right
, pc
->custom_size
.top
);
2874 if (pc
->source_option
)
2875 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2877 if (pc
->num_sources
> 0)
2879 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2880 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2881 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2888 if (pc
->num_types
> 0)
2890 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2891 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2892 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2899 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2900 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2901 if (pc
->num_presets
[i
][j
])
2903 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2904 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2907 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2908 cupsFilePutChar(fp
, '\n');
2915 if (pc
->sides_option
)
2916 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2918 if (pc
->sides_1sided
)
2919 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2921 if (pc
->sides_2sided_long
)
2922 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2924 if (pc
->sides_2sided_short
)
2925 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2928 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2932 cupsFilePutConf(fp
, "Product", pc
->product
);
2934 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2936 value
= (const char *)cupsArrayNext(pc
->filters
))
2937 cupsFilePutConf(fp
, "Filter", value
);
2939 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2941 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2942 cupsFilePutConf(fp
, "PreFilter", value
);
2944 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2947 * Finishing options...
2950 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2952 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2954 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2955 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2956 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2957 cupsFilePutChar(fp
, '\n');
2960 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2961 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2967 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2970 * Accounting/quota/PIN/managed printing values...
2973 if (pc
->charge_info_uri
)
2974 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2976 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2977 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2978 pc
->accounting_user_id
? "true" : "false");
2981 cupsFilePutConf(fp
, "Password", pc
->password
);
2983 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2985 value
= (char *)cupsArrayNext(pc
->mandatory
))
2986 cupsFilePutConf(fp
, "Mandatory", value
);
2992 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2994 value
= (char *)cupsArrayNext(pc
->support_files
))
2995 cupsFilePutConf(fp
, "SupportFile", value
);
2998 * IPP attributes, if any...
3003 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3005 attrs
->state
= IPP_STATE_IDLE
;
3006 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3010 * Close and return...
3013 if (cupsFileClose(fp
))
3020 return (!rename(newfile
, filename
));
3025 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3026 * of an IPP printer.
3029 char * /* O - PPD filename or @code NULL@ on error */
3030 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3031 size_t bufsize
, /* I - Size of filename buffer */
3032 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3034 cups_file_t
*fp
; /* PPD file */
3035 cups_array_t
*sizes
; /* Media sizes supported by printer */
3036 cups_size_t
*size
; /* Current media size */
3037 ipp_attribute_t
*attr
, /* xxx-supported */
3038 *defattr
, /* xxx-default */
3039 *quality
, /* print-quality-supported */
3040 *x_dim
, *y_dim
; /* Media dimensions */
3041 ipp_t
*media_col
, /* Media collection */
3042 *media_size
; /* Media size collection */
3043 char make
[256], /* Make and model */
3044 *model
, /* Model name */
3045 ppdname
[PPD_MAX_NAME
];
3047 int i
, j
, /* Looping vars */
3048 count
, /* Number of values */
3049 bottom
, /* Largest bottom margin */
3050 left
, /* Largest left margin */
3051 right
, /* Largest right margin */
3052 top
, /* Largest top margin */
3053 max_length
= 0, /* Maximum custom size */
3055 min_length
= INT_MAX
,
3056 /* Minimum custom size */
3057 min_width
= INT_MAX
,
3058 is_apple
= 0, /* Does the printer support Apple raster? */
3059 is_pdf
= 0, /* Does the printer support PDF? */
3060 is_pwg
= 0; /* Does the printer support PWG Raster? */
3061 pwg_media_t
*pwg
; /* PWG media size */
3062 int xres
, yres
; /* Resolution values */
3063 int resolutions
[1000];
3064 /* Array of resolution indices */
3065 char msgid
[256]; /* Message identifier (attr.value) */
3066 const char *keyword
, /* Keyword value */
3067 *msgstr
; /* Localized string */
3068 cups_lang_t
*lang
= cupsLangDefault();
3069 /* Localization info */
3070 cups_array_t
*strings
= NULL
;/* Printer strings file */
3071 struct lconv
*loc
= localeconv();
3073 cups_array_t
*fin_options
= NULL
;
3074 /* Finishing options */
3078 * Range check input...
3084 if (!buffer
|| bufsize
< 1)
3086 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3092 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3097 * Open a temporary file for the PPD...
3100 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3102 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3107 * Standard stuff for PPD file...
3110 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3111 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3112 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3113 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3114 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3115 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3116 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3117 cupsFilePuts(fp
, "*FileSystem: False\n");
3118 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3120 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3121 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3123 strlcpy(make
, "Unknown Printer", sizeof(make
));
3125 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3126 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3129 strlcpy(make
, "HP", sizeof(make
));
3131 else if ((model
= strchr(make
, ' ')) != NULL
)
3136 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3137 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3138 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3139 cupsFilePrintf(fp
, "*NickName: \"%s - IPP Everywhere\"\n", model
);
3140 cupsFilePrintf(fp
, "*ShortNickName: \"%s - IPP Everywhere\"\n", model
);
3142 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3143 cupsFilePuts(fp
, "*ColorDevice: True\n");
3145 cupsFilePuts(fp
, "*ColorDevice: False\n");
3147 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3148 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3149 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3151 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3152 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3154 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3155 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3157 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3159 http_t
*http
= NULL
; /* Connection to printer */
3160 char stringsfile
[1024]; /* Temporary strings file */
3162 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3164 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3166 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3168 unlink(stringsfile
);
3176 * Password/PIN printing...
3179 if ((attr
= ippFindAttribute(response
, "job-password-supported", IPP_TAG_INTEGER
)) != NULL
)
3181 char pattern
[33]; /* Password pattern */
3182 int maxlen
= ippGetInteger(attr
, 0);
3183 /* Maximum length */
3184 const char *repertoire
= ippGetString(ippFindAttribute(response
, "job-password-repertoire-configured", IPP_TAG_KEYWORD
), 0, NULL
);
3185 /* Type of password */
3187 if (maxlen
> (int)(sizeof(pattern
) - 1))
3188 maxlen
= sizeof(pattern
) - 1;
3190 if (!repertoire
|| !strcmp(repertoire
, "iana_us-ascii_digits"))
3191 memset(pattern
, '1', maxlen
);
3192 else if (!strcmp(repertoire
, "iana_us-ascii_letters"))
3193 memset(pattern
, 'A', maxlen
);
3194 else if (!strcmp(repertoire
, "iana_us-ascii_complex"))
3195 memset(pattern
, 'C', maxlen
);
3196 else if (!strcmp(repertoire
, "iana_us-ascii_any"))
3197 memset(pattern
, '.', maxlen
);
3198 else if (!strcmp(repertoire
, "iana_utf-8_digits"))
3199 memset(pattern
, 'N', maxlen
);
3200 else if (!strcmp(repertoire
, "iana_utf-8_letters"))
3201 memset(pattern
, 'U', maxlen
);
3203 memset(pattern
, '*', maxlen
);
3205 pattern
[maxlen
] = '\0';
3207 cupsFilePrintf(fp
, "*cupsPassword: \"%s\"\n", pattern
);
3214 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3216 is_apple
= ippContainsString(attr
, "image/urf");
3217 is_pdf
= ippContainsString(attr
, "application/pdf");
3218 is_pwg
= ippContainsString(attr
, "image/pwg-raster") && !is_apple
;
3220 if (ippContainsString(attr
, "image/jpeg"))
3221 cupsFilePuts(fp
, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n");
3222 if (ippContainsString(attr
, "image/png"))
3223 cupsFilePuts(fp
, "*cupsFilter2: \"image/png image/png 0 -\"\n");
3227 * Don't locally filter PDF content when printing to a CUPS shared
3228 * printer, otherwise the options will be applied twice...
3231 if (ippContainsString(attr
, "application/vnd.cups-pdf"))
3232 cupsFilePuts(fp
, "*cupsFilter2: \"application/pdf application/pdf 0 -\"\n");
3234 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3237 cupsFilePuts(fp
, "*cupsFilter2: \"image/urf image/urf 100 -\"\n");
3239 cupsFilePuts(fp
, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n");
3242 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3246 * PageSize/PageRegion/ImageableArea/PaperDimension
3249 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3251 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3252 if (ippGetInteger(attr
, i
) > bottom
)
3253 bottom
= ippGetInteger(attr
, i
);
3258 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3260 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3261 if (ippGetInteger(attr
, i
) > left
)
3262 left
= ippGetInteger(attr
, i
);
3267 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3269 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3270 if (ippGetInteger(attr
, i
) > right
)
3271 right
= ippGetInteger(attr
, i
);
3276 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3278 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3279 if (ippGetInteger(attr
, i
) > top
)
3280 top
= ippGetInteger(attr
, i
);
3285 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3287 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3289 media_size
= ippGetCollection(attr
, 0);
3290 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3291 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3293 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3294 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3296 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3299 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3301 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3302 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3304 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3306 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, (cups_afree_func_t
)free
);
3308 if ((attr
= ippFindAttribute(response
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3310 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3312 cups_size_t temp
; /* Current size */
3313 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3315 media_col
= ippGetCollection(attr
, i
);
3316 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3317 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3318 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3319 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3323 temp
.width
= pwg
->width
;
3324 temp
.length
= pwg
->length
;
3326 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3327 temp
.bottom
= ippGetInteger(margin
, 0);
3329 temp
.bottom
= bottom
;
3331 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3332 temp
.left
= ippGetInteger(margin
, 0);
3336 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3337 temp
.right
= ippGetInteger(margin
, 0);
3341 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3342 temp
.top
= ippGetInteger(margin
, 0);
3346 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3347 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3349 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3351 if (!cupsArrayFind(sizes
, &temp
))
3352 cupsArrayAdd(sizes
, &temp
);
3354 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3357 * Custom size - record the min/max values...
3360 int lower
, upper
; /* Range values */
3362 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3363 lower
= ippGetRange(x_dim
, 0, &upper
);
3365 lower
= upper
= ippGetInteger(x_dim
, 0);
3367 if (lower
< min_width
)
3369 if (upper
> max_width
)
3372 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3373 lower
= ippGetRange(y_dim
, 0, &upper
);
3375 lower
= upper
= ippGetInteger(y_dim
, 0);
3377 if (lower
< min_length
)
3379 if (upper
> max_length
)
3384 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3387 * Some printers don't list custom size support in media-col-database...
3390 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3392 media_size
= ippGetCollection(attr
, i
);
3393 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3394 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3396 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3399 * Custom size - record the min/max values...
3402 int lower
, upper
; /* Range values */
3404 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3405 lower
= ippGetRange(x_dim
, 0, &upper
);
3407 lower
= upper
= ippGetInteger(x_dim
, 0);
3409 if (lower
< min_width
)
3411 if (upper
> max_width
)
3414 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3415 lower
= ippGetRange(y_dim
, 0, &upper
);
3417 lower
= upper
= ippGetInteger(y_dim
, 0);
3419 if (lower
< min_length
)
3421 if (upper
> max_length
)
3427 else if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3429 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3431 cups_size_t temp
; /* Current size */
3433 media_size
= ippGetCollection(attr
, i
);
3434 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3435 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3436 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3440 temp
.width
= pwg
->width
;
3441 temp
.length
= pwg
->length
;
3442 temp
.bottom
= bottom
;
3447 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3448 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3450 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3452 if (!cupsArrayFind(sizes
, &temp
))
3453 cupsArrayAdd(sizes
, &temp
);
3455 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3458 * Custom size - record the min/max values...
3461 int lower
, upper
; /* Range values */
3463 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3464 lower
= ippGetRange(x_dim
, 0, &upper
);
3466 lower
= upper
= ippGetInteger(x_dim
, 0);
3468 if (lower
< min_width
)
3470 if (upper
> max_width
)
3473 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3474 lower
= ippGetRange(y_dim
, 0, &upper
);
3476 lower
= upper
= ippGetInteger(y_dim
, 0);
3478 if (lower
< min_length
)
3480 if (upper
> max_length
)
3485 else if ((attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3487 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3489 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3491 cups_size_t temp
; /* Current size */
3493 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3495 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3497 if (pwg
->width
> max_width
)
3498 max_width
= pwg
->width
;
3499 if (pwg
->length
> max_length
)
3500 max_length
= pwg
->length
;
3502 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3504 if (pwg
->width
< min_width
)
3505 min_width
= pwg
->width
;
3506 if (pwg
->length
< min_length
)
3507 min_length
= pwg
->length
;
3511 temp
.width
= pwg
->width
;
3512 temp
.length
= pwg
->length
;
3513 temp
.bottom
= bottom
;
3518 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3519 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3521 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3523 if (!cupsArrayFind(sizes
, &temp
))
3524 cupsArrayAdd(sizes
, &temp
);
3530 if (cupsArrayCount(sizes
) > 0)
3533 * List all of the standard sizes...
3536 char tleft
[256], /* Left string */
3537 tbottom
[256], /* Bottom string */
3538 tright
[256], /* Right string */
3539 ttop
[256], /* Top string */
3540 twidth
[256], /* Width string */
3541 tlength
[256]; /* Length string */
3543 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3544 "*OrderDependency: 10 AnySetup *PageSize\n"
3545 "*DefaultPageSize: %s\n", ppdname
);
3546 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3548 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3549 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3551 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3553 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3555 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3556 "*OrderDependency: 10 AnySetup *PageRegion\n"
3557 "*DefaultPageRegion: %s\n", ppdname
);
3558 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3560 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3561 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3563 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3565 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3567 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3568 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3570 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3572 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3573 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3574 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3575 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3576 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3577 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3579 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3580 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3583 cupsArrayDelete(sizes
);
3586 * Custom size support...
3589 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3591 char tmax
[256], tmin
[256]; /* Min/max values */
3593 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3594 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3595 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3596 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3598 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3600 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3601 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3602 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3604 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3605 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3606 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3608 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3609 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3610 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3611 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3616 cupsArrayDelete(sizes
);
3624 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3625 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3627 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3629 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3631 static const char * const sources
[] =
3632 { /* Standard "media-source" strings */
3685 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3686 "*OrderDependency: 10 AnySetup *InputSlot\n"
3687 "*DefaultInputSlot: %s\n", ppdname
);
3688 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3690 keyword
= ippGetString(attr
, i
, NULL
);
3692 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3694 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3695 if (!strcmp(sources
[j
], keyword
))
3697 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
3698 cupsFilePrintf(fp
, "*InputSlot %s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, j
);
3699 cupsFilePrintf(fp
, "*%s.InputSlot %s/%s: \"\"\n", lang
->language
, ppdname
, _cupsLangString(lang
, msgid
));
3703 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3710 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3711 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3713 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3715 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3717 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3718 "*OrderDependency: 10 AnySetup *MediaType\n"
3719 "*DefaultMediaType: %s\n", ppdname
);
3720 for (i
= 0; i
< count
; i
++)
3722 keyword
= ippGetString(attr
, i
, NULL
);
3724 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3726 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
3727 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3728 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3731 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3732 cupsFilePrintf(fp
, "*%s.MediaType %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3734 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3741 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3742 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3743 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3744 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3748 int wrote_color
= 0;
3749 const char *default_color
= NULL
; /* Default */
3751 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3753 keyword
= ippGetString(attr
, i
, NULL
);
3755 #define PRINTF_COLORMODEL if (!wrote_color) { cupsFilePrintf(fp, "*OpenUI *ColorModel: PickOne\n*OrderDependency: 10 AnySetup *ColorModel\n*%s.Translation ColorModel/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Color Mode"))); wrote_color = 1; }
3756 #define PRINTF_COLOROPTION(name,text,cspace,bpp) { cupsFilePrintf(fp, "*ColorModel %s: \"<</cupsColorSpace %d/cupsBitsPerColor %d/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", name, cspace, bpp); cupsFilePrintf(fp, "*%s.ColorModel %s/%s: \"\"\n", lang->language, name, _cupsLangString(lang, text)); }
3758 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3762 PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K
, 1)
3765 default_color
= "FastGray";
3767 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3771 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3773 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3774 default_color
= "Gray";
3776 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
3780 if (!strcmp(keyword
, "W8-16"))
3782 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3784 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3785 default_color
= "Gray";
3788 PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW
, 16)
3790 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 7) || !strcmp(keyword
, "color"))
3794 PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB
, 8)
3796 default_color
= "RGB";
3798 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
3802 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 16)
3805 default_color
= "AdobeRGB";
3807 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
3811 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 8)
3814 default_color
= "AdobeRGB";
3816 else if ((!strcasecmp(keyword
, "black_8") && !ippContainsString(attr
, "black_16")) || !strcmp(keyword
, "DEVW8"))
3820 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 8)
3822 else if (!strcasecmp(keyword
, "black_16") || !strcmp(keyword
, "DEVW16") || !strcmp(keyword
, "DEVW8-16"))
3826 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 16)
3828 else if ((!strcasecmp(keyword
, "cmyk_8") && !ippContainsString(attr
, "cmyk_16")) || !strcmp(keyword
, "DEVCMYK32"))
3832 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 8)
3834 else if (!strcasecmp(keyword
, "cmyk_16") || !strcmp(keyword
, "DEVCMYK32-64") || !strcmp(keyword
, "DEVCMYK64"))
3838 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 16)
3840 else if ((!strcasecmp(keyword
, "rgb_8") && ippContainsString(attr
, "rgb_16")) || !strcmp(keyword
, "DEVRGB24"))
3844 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 8)
3846 else if (!strcasecmp(keyword
, "rgb_16") || !strcmp(keyword
, "DEVRGB24-48") || !strcmp(keyword
, "DEVRGB48"))
3850 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 16)
3855 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3857 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3864 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3866 cupsFilePrintf(fp
, "*OpenUI *Duplex: PickOne\n"
3867 "*OrderDependency: 10 AnySetup *Duplex\n"
3868 "*%s.Translation Duplex/%s: \"\"\n"
3869 "*DefaultDuplex: None\n"
3870 "*Duplex None: \"<</Duplex false>>setpagedevice\"\n"
3871 "*%s.Duplex None/%s: \"\"\n"
3872 "*Duplex DuplexNoTumble: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3873 "*%s.Duplex DuplexNoTumble/%s: \"\"\n"
3874 "*Duplex DuplexTumble: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3875 "*%s.Duplex DuplexTumble/%s: \"\"\n"
3876 "*CloseUI: *Duplex\n", lang
->language
, _cupsLangString(lang
, _("2-Sided Printing")), lang
->language
, _cupsLangString(lang
, _("Off (1-Sided)")), lang
->language
, _cupsLangString(lang
, _("Long-Edge (Portrait)")), lang
->language
, _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3878 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3880 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3882 const char *dm
= ippGetString(attr
, i
, NULL
);
3885 if (!_cups_strcasecmp(dm
, "DM1"))
3887 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3890 else if (!_cups_strcasecmp(dm
, "DM2"))
3892 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3895 else if (!_cups_strcasecmp(dm
, "DM3"))
3897 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3900 else if (!_cups_strcasecmp(dm
, "DM4"))
3902 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3907 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3909 keyword
= ippGetString(attr
, 0, NULL
);
3911 if (!strcmp(keyword
, "flipped"))
3912 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3913 else if (!strcmp(keyword
, "manual-tumble"))
3914 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3915 else if (!strcmp(keyword
, "normal"))
3916 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3918 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3926 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3927 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3929 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3931 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3933 ipp_attribute_t
*trays
= ippFindAttribute(response
, "printer-output-tray", IPP_TAG_STRING
);
3934 /* printer-output-tray attribute, if any */
3935 const char *tray_ptr
; /* printer-output-tray value */
3936 int tray_len
; /* Len of printer-output-tray value */
3937 char tray
[IPP_MAX_OCTETSTRING
];
3938 /* printer-output-tray string value */
3940 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3941 "*OrderDependency: 10 AnySetup *OutputBin\n"
3942 "*DefaultOutputBin: %s\n", ppdname
);
3943 if (!strcmp(ppdname
, "FaceUp"))
3944 cupsFilePuts(fp
, "*DefaultOutputOrder: Reverse\n");
3946 cupsFilePuts(fp
, "*DefaultOutputOrder: Normal\n");
3948 for (i
= 0; i
< count
; i
++)
3950 keyword
= ippGetString(attr
, i
, NULL
);
3952 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3954 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
3955 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3956 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3959 cupsFilePrintf(fp
, "*OutputBin %s: \"\"\n", ppdname
);
3960 cupsFilePrintf(fp
, "*%s.OutputBin %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3962 if ((tray_ptr
= ippGetOctetString(trays
, i
, &tray_len
)) != NULL
)
3964 if (tray_len
>= (int)sizeof(tray
))
3965 tray_len
= (int)sizeof(tray
) - 1;
3967 memcpy(tray
, tray_ptr
, tray_len
);
3968 tray
[tray_len
] = '\0';
3970 if (strstr(tray
, "stackingorder=lastToFirst;"))
3971 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
3973 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
3975 else if (!strcmp(ppdname
, "FaceUp"))
3976 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
3978 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
3980 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3984 * Finishing options...
3987 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3989 int value
; /* Enum value */
3990 cups_array_t
*names
; /* Names we've added */
3992 count
= ippGetCount(attr
);
3993 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3994 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3997 * Staple/Bind/Stitch
4000 for (i
= 0; i
< count
; i
++)
4002 value
= ippGetInteger(attr
, i
);
4003 keyword
= ippEnumString("finishings", value
);
4005 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch"))
4011 cupsArrayAdd(fin_options
, "*StapleLocation");
4013 cupsFilePuts(fp
, "*OpenUI *StapleLocation: PickOne\n");
4014 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
4015 cupsFilePrintf(fp
, "*%s.Translation StapleLocation/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Staple")));
4016 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
4017 cupsFilePuts(fp
, "*StapleLocation None: \"\"\n");
4018 cupsFilePrintf(fp
, "*%s.StapleLocation None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4020 for (; i
< count
; i
++)
4022 value
= ippGetInteger(attr
, i
);
4023 keyword
= ippEnumString("finishings", value
);
4025 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch"))
4028 if (cupsArrayFind(names
, (char *)keyword
))
4029 continue; /* Already did this finishing template */
4031 cupsArrayAdd(names
, (char *)keyword
);
4033 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4034 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4035 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4038 cupsFilePrintf(fp
, "*StapleLocation %s: \"\"\n", keyword
);
4039 cupsFilePrintf(fp
, "*%s.StapleLocation %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4040 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, keyword
);
4043 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
4050 for (i
= 0; i
< count
; i
++)
4052 value
= ippGetInteger(attr
, i
);
4053 keyword
= ippEnumString("finishings", value
);
4055 if (!strncmp(keyword
, "fold-", 5))
4061 cupsArrayAdd(fin_options
, "*FoldType");
4063 cupsFilePuts(fp
, "*OpenUI *FoldType: PickOne\n");
4064 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
4065 cupsFilePrintf(fp
, "*%s.Translation FoldType/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Fold")));
4066 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
4067 cupsFilePuts(fp
, "*FoldType None: \"\"\n");
4068 cupsFilePrintf(fp
, "*%s.FoldType None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4070 for (; i
< count
; i
++)
4072 value
= ippGetInteger(attr
, i
);
4073 keyword
= ippEnumString("finishings", value
);
4075 if (strncmp(keyword
, "fold-", 5))
4078 if (cupsArrayFind(names
, (char *)keyword
))
4079 continue; /* Already did this finishing template */
4081 cupsArrayAdd(names
, (char *)keyword
);
4083 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4084 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4085 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4088 cupsFilePrintf(fp
, "*FoldType %s: \"\"\n", keyword
);
4089 cupsFilePrintf(fp
, "*%s.FoldType %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4090 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, keyword
);
4093 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4100 for (i
= 0; i
< count
; i
++)
4102 value
= ippGetInteger(attr
, i
);
4103 keyword
= ippEnumString("finishings", value
);
4105 if (!strncmp(keyword
, "punch-", 6))
4111 cupsArrayAdd(fin_options
, "*PunchMedia");
4113 cupsFilePuts(fp
, "*OpenUI *PunchMedia: PickOne\n");
4114 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4115 cupsFilePrintf(fp
, "*%s.Translation PunchMedia/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Punch")));
4116 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4117 cupsFilePuts(fp
, "*PunchMedia None: \"\"\n");
4118 cupsFilePrintf(fp
, "*%s.PunchMedia None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4120 for (i
= 0; i
< count
; i
++)
4122 value
= ippGetInteger(attr
, i
);
4123 keyword
= ippEnumString("finishings", value
);
4125 if (strncmp(keyword
, "punch-", 6))
4128 if (cupsArrayFind(names
, (char *)keyword
))
4129 continue; /* Already did this finishing template */
4131 cupsArrayAdd(names
, (char *)keyword
);
4133 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4134 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4135 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4138 cupsFilePrintf(fp
, "*PunchMedia %s: \"\"\n", keyword
);
4139 cupsFilePrintf(fp
, "*%s.PunchMedia %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4140 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, keyword
);
4143 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4150 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4152 cupsArrayAdd(fin_options
, "*Booklet");
4154 cupsFilePuts(fp
, "*OpenUI *Booklet: Boolean\n");
4155 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4156 cupsFilePrintf(fp
, "*%s.Translation Booklet/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Booklet")));
4157 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4158 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4159 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4160 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4161 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4164 cupsArrayDelete(names
);
4167 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4169 ipp_t
*finishing_col
; /* Current finishing collection */
4170 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4171 cups_array_t
*templates
; /* Finishing templates */
4173 cupsFilePuts(fp
, "*OpenUI *cupsFinishingTemplate: PickOne\n");
4174 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4175 cupsFilePrintf(fp
, "*%s.Translation cupsFinishingTemplate/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Finishing Preset")));
4176 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4177 cupsFilePuts(fp
, "*cupsFinishingTemplate none: \"\"\n");
4178 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate none/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4180 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4181 count
= ippGetCount(attr
);
4183 for (i
= 0; i
< count
; i
++)
4185 finishing_col
= ippGetCollection(attr
, i
);
4186 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4188 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4191 if (strncmp(keyword
, "fold-", 5) && (strstr(keyword
, "-bottom") || strstr(keyword
, "-left") || strstr(keyword
, "-right") || strstr(keyword
, "-top")))
4194 cupsArrayAdd(templates
, (void *)keyword
);
4196 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4197 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4198 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4201 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s: \"\n", keyword
);
4202 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4204 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4206 const char *name
= ippGetName(finishing_attr
);
4207 /* Member attribute name */
4209 if (strcmp(name
, "media-size"))
4210 cupsFilePrintf(fp
, "%% %s\n", name
);
4213 cupsFilePuts(fp
, "\"\n");
4214 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4215 cupsFilePuts(fp
, "*End\n");
4218 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4220 if (cupsArrayCount(fin_options
))
4222 const char *fin_option
; /* Current finishing option */
4224 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4225 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4226 cupsFilePrintf(fp
, " %s", fin_option
);
4227 cupsFilePuts(fp
, "\"\n");
4229 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None");
4230 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4231 cupsFilePrintf(fp
, " %s None", fin_option
);
4232 cupsFilePuts(fp
, "\"\n");
4235 cupsArrayDelete(templates
);
4238 cupsArrayDelete(fin_options
);
4241 * cupsPrintQuality and DefaultResolution...
4244 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4246 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4248 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4250 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4252 const char *rs
= ippGetString(attr
, i
, NULL
);
4255 if (_cups_strncasecmp(rs
, "RS", 2))
4258 lowdpi
= atoi(rs
+ 2);
4259 if ((rs
= strrchr(rs
, '-')) != NULL
)
4260 hidpi
= atoi(rs
+ 1);
4269 * Invalid "urf-supported" value...
4277 * Generate print qualities based on low and high DPIs...
4280 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4282 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4283 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4284 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4285 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4286 if ((lowdpi
& 1) == 0)
4287 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
/ 2, lang
->language
, _cupsLangString(lang
, _("Draft")));
4288 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4289 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4291 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4293 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4294 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", hidpi
, hidpi
, lang
->language
, _cupsLangString(lang
, _("High")));
4295 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4298 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4301 * Make a sorted list of resolutions.
4304 count
= ippGetCount(attr
);
4305 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4306 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4308 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4309 for (i
= 1; i
< count
; i
++)
4312 for (i
= 0; i
< (count
- 1); i
++)
4314 for (j
= i
+ 1; j
< count
; j
++)
4316 int ix
, iy
, /* First X and Y resolution */
4317 jx
, jy
, /* Second X and Y resolution */
4318 temp
; /* Swap variable */
4319 ipp_res_t units
; /* Resolution units */
4321 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4322 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4324 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4327 * Swap these two resolutions...
4330 temp
= resolutions
[i
];
4331 resolutions
[i
] = resolutions
[j
];
4332 resolutions
[j
] = temp
;
4338 * Generate print quality options...
4341 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4342 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4344 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4345 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4346 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4347 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4348 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4350 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4351 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4352 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Draft/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Draft")));
4355 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4356 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4357 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Normal/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Normal")));
4359 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4361 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4362 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4363 cupsFilePrintf(fp
, "*%s.cupsPrintQuality High/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("High")));
4366 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4368 else if (is_apple
|| is_pwg
)
4372 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4374 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4379 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4382 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4384 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4385 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4386 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4387 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4388 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4389 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4391 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4393 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4394 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("High")));
4395 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4402 if ((attr
= ippFindAttribute(response
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4404 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4406 ipp_t
*preset
= ippGetCollection(attr
, i
);
4407 /* Preset collection */
4408 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
),
4410 *localized_name
; /* Localized preset name */
4411 ipp_attribute_t
*member
; /* Member attribute in preset */
4412 const char *member_name
; /* Member attribute name */
4413 char member_value
[256]; /* Member attribute value */
4415 if (!preset
|| !preset_name
)
4418 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", preset_name
);
4419 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4421 member_name
= ippGetName(member
);
4423 if (!member_name
|| !strcmp(member_name
, "preset-name"))
4426 if (!strcmp(member_name
, "finishings"))
4428 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4430 const char *option
= NULL
; /* PPD option name */
4432 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
4434 if (!strcmp(keyword
, "booklet-maker"))
4439 else if (!strncmp(keyword
, "fold-", 5))
4440 option
= "FoldType";
4441 else if (!strncmp(keyword
, "punch-", 6))
4442 option
= "PunchMedia";
4443 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7))
4444 option
= "StapleLocation";
4446 if (option
&& keyword
)
4447 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
4450 else if (!strcmp(member_name
, "finishings-col"))
4452 ipp_t
*fin_col
; /* finishings-col value */
4454 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4456 fin_col
= ippGetCollection(member
, i
);
4458 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4459 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", keyword
);
4462 else if (!strcmp(member_name
, "media"))
4465 * Map media to PageSize...
4468 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
4469 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4471 else if (!strcmp(member_name
, "media-col"))
4473 media_col
= ippGetCollection(member
, 0);
4475 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
4477 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
4478 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
4479 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
4480 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4483 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4485 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4486 cupsFilePrintf(fp
, "*InputSlot %s\n", keyword
);
4489 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4491 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4492 cupsFilePrintf(fp
, "*MediaType %s\n", keyword
);
4495 else if (!strcmp(member_name
, "print-quality"))
4498 * Map print-quality to cupsPrintQuality...
4501 int qval
= ippGetInteger(member
, 0);
4502 /* print-quality value */
4503 static const char * const qualities
[] = { "Draft", "Normal", "High" };
4504 /* cupsPrintQuality values */
4506 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
4507 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
4509 else if (!strcmp(member_name
, "output-bin"))
4511 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
4512 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
4514 else if (!strcmp(member_name
, "sides"))
4516 keyword
= ippGetString(member
, 0, NULL
);
4517 if (keyword
&& !strcmp(keyword
, "one-sided"))
4518 cupsFilePuts(fp
, "*Duplex None\n");
4519 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
4520 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
4521 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
4522 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
4527 * Add attribute name and value as-is...
4530 ippAttributeString(member
, member_value
, sizeof(member_value
));
4531 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
4535 cupsFilePuts(fp
, "\"\n*End\n");
4537 if ((localized_name
= _cupsMessageLookup(strings
, preset_name
)) != preset_name
)
4538 cupsFilePrintf(fp
, "*%s.APPrinterPreset %s/%s: \"\"\n", lang
->language
, preset_name
, localized_name
);
4543 * Close up and return...
4551 * If we get here then there was a problem creating the PPD...
4560 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4567 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4571 const char * /* O - InputSlot name */
4572 _pwgInputSlotForSource(
4573 const char *media_source
, /* I - PWG media-source */
4574 char *name
, /* I - Name buffer */
4575 size_t namesize
) /* I - Size of name buffer */
4578 * Range check input...
4581 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4584 if (_cups_strcasecmp(media_source
, "main"))
4585 strlcpy(name
, "Cassette", namesize
);
4586 else if (_cups_strcasecmp(media_source
, "alternate"))
4587 strlcpy(name
, "Multipurpose", namesize
);
4588 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4589 strlcpy(name
, "LargeCapacity", namesize
);
4590 else if (_cups_strcasecmp(media_source
, "bottom"))
4591 strlcpy(name
, "Lower", namesize
);
4592 else if (_cups_strcasecmp(media_source
, "middle"))
4593 strlcpy(name
, "Middle", namesize
);
4594 else if (_cups_strcasecmp(media_source
, "top"))
4595 strlcpy(name
, "Upper", namesize
);
4596 else if (_cups_strcasecmp(media_source
, "rear"))
4597 strlcpy(name
, "Rear", namesize
);
4598 else if (_cups_strcasecmp(media_source
, "side"))
4599 strlcpy(name
, "Side", namesize
);
4600 else if (_cups_strcasecmp(media_source
, "envelope"))
4601 strlcpy(name
, "Envelope", namesize
);
4602 else if (_cups_strcasecmp(media_source
, "main-roll"))
4603 strlcpy(name
, "Roll", namesize
);
4604 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4605 strlcpy(name
, "Roll2", namesize
);
4607 pwg_ppdize_name(media_source
, name
, namesize
);
4614 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4618 const char * /* O - MediaType name */
4619 _pwgMediaTypeForType(
4620 const char *media_type
, /* I - PWG media-type */
4621 char *name
, /* I - Name buffer */
4622 size_t namesize
) /* I - Size of name buffer */
4625 * Range check input...
4628 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4631 if (_cups_strcasecmp(media_type
, "auto"))
4632 strlcpy(name
, "Auto", namesize
);
4633 else if (_cups_strcasecmp(media_type
, "cardstock"))
4634 strlcpy(name
, "Cardstock", namesize
);
4635 else if (_cups_strcasecmp(media_type
, "envelope"))
4636 strlcpy(name
, "Envelope", namesize
);
4637 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4638 strlcpy(name
, "Glossy", namesize
);
4639 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4640 strlcpy(name
, "HighGloss", namesize
);
4641 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4642 strlcpy(name
, "Matte", namesize
);
4643 else if (_cups_strcasecmp(media_type
, "stationery"))
4644 strlcpy(name
, "Plain", namesize
);
4645 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4646 strlcpy(name
, "Coated", namesize
);
4647 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4648 strlcpy(name
, "Inkjet", namesize
);
4649 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4650 strlcpy(name
, "Letterhead", namesize
);
4651 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4652 strlcpy(name
, "Preprinted", namesize
);
4653 else if (_cups_strcasecmp(media_type
, "transparency"))
4654 strlcpy(name
, "Transparency", namesize
);
4656 pwg_ppdize_name(media_type
, name
, namesize
);
4663 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4666 const char * /* O - PageSize name */
4667 _pwgPageSizeForMedia(
4668 pwg_media_t
*media
, /* I - Media */
4669 char *name
, /* I - PageSize name buffer */
4670 size_t namesize
) /* I - Size of name buffer */
4672 const char *sizeptr
, /* Pointer to size in PWG name */
4673 *dimptr
; /* Pointer to dimensions in PWG name */
4677 * Range check input...
4680 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4684 * Copy or generate a PageSize name...
4690 * Use a standard Adobe name...
4693 strlcpy(name
, media
->ppd
, namesize
);
4695 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4696 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4697 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4698 (size_t)(dimptr
- sizeptr
) > namesize
)
4701 * Use a name of the form "wNNNhNNN"...
4704 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4705 (int)PWG_TO_POINTS(media
->length
));
4710 * Copy the size name from class_sizename_dimensions...
4713 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4714 name
[dimptr
- sizeptr
- 1] = '\0';
4722 * 'cups_get_url()' - Get a copy of the file at the given URL.
4725 static int /* O - 1 on success, 0 on failure */
4726 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4727 const char *url
, /* I - URL to get */
4728 char *name
, /* I - Temporary filename */
4729 size_t namesize
) /* I - Size of temporary filename buffer */
4731 char scheme
[32], /* URL scheme */
4732 userpass
[256], /* URL username:password */
4733 host
[256], /* URL host */
4734 curhost
[256], /* Current host */
4735 resource
[256]; /* URL resource */
4736 int port
; /* URL port */
4737 http_encryption_t encryption
; /* Type of encryption to use */
4738 http_status_t status
; /* Status of GET request */
4739 int fd
; /* Temporary file */
4742 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4745 if (port
== 443 || !strcmp(scheme
, "https"))
4746 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4748 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4750 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4753 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4759 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4762 status
= cupsGetFd(*http
, resource
, fd
);
4766 if (status
!= HTTP_STATUS_OK
)
4778 * 'pwg_add_finishing()' - Add a finishings value.
4783 cups_array_t
*finishings
, /* I - Finishings array */
4784 ipp_finishings_t
template, /* I - Finishing template */
4785 const char *name
, /* I - PPD option */
4786 const char *value
) /* I - PPD choice */
4788 _pwg_finishings_t
*f
; /* New finishings value */
4791 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4793 f
->value
= template;
4794 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4796 cupsArrayAdd(finishings
, f
);
4802 * 'pwg_add_message()' - Add a message to the PPD cached strings.
4806 pwg_add_message(cups_array_t
*a
, /* I - Message catalog */
4807 const char *msg
, /* I - Message identifier */
4808 const char *str
) /* I - Localized string */
4810 _cups_message_t
*m
; /* New message */
4813 if ((m
= calloc(1, sizeof(_cups_message_t
))) != NULL
)
4815 m
->msg
= strdup(msg
);
4816 m
->str
= strdup(str
);
4823 * 'pwg_compare_finishings()' - Compare two finishings values.
4826 static int /* O - Result of comparison */
4827 pwg_compare_finishings(
4828 _pwg_finishings_t
*a
, /* I - First finishings value */
4829 _pwg_finishings_t
*b
) /* I - Second finishings value */
4831 return ((int)b
->value
- (int)a
->value
);
4836 * 'pwg_compare_sizes()' - Compare two media sizes...
4839 static int /* O - Result of comparison */
4840 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
4841 cups_size_t
*b
) /* I - Second media size */
4843 return (strcmp(a
->media
, b
->media
));
4848 * 'pwg_copy_size()' - Copy a media size.
4851 static cups_size_t
* /* O - New media size */
4852 pwg_copy_size(cups_size_t
*size
) /* I - Media size to copy */
4854 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
4855 /* New media size */
4858 memcpy(newsize
, size
, sizeof(cups_size_t
));
4865 * 'pwg_free_finishings()' - Free a finishings value.
4869 pwg_free_finishings(
4870 _pwg_finishings_t
*f
) /* I - Finishings value */
4872 cupsFreeOptions(f
->num_options
, f
->options
);
4878 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4882 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4883 char *name
, /* I - Name buffer */
4884 size_t namesize
) /* I - Size of name buffer */
4886 char *ptr
, /* Pointer into name buffer */
4887 *end
; /* End of name buffer */
4896 *name
= (char)toupper(*ipp
++);
4898 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4900 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4903 *ptr
++ = (char)toupper(*ipp
++ & 255);
4914 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4918 pwg_ppdize_resolution(
4919 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4920 int element
, /* I - Element to convert */
4921 int *xres
, /* O - X resolution in DPI */
4922 int *yres
, /* O - Y resolution in DPI */
4923 char *name
, /* I - Name buffer */
4924 size_t namesize
) /* I - Size of name buffer */
4926 ipp_res_t units
; /* Units for resolution */
4929 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4931 if (units
== IPP_RES_PER_CM
)
4933 *xres
= (int)(*xres
* 2.54);
4934 *yres
= (int)(*yres
* 2.54);
4937 if (name
&& namesize
> 4)
4940 snprintf(name
, namesize
, "%ddpi", *xres
);
4942 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4948 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4952 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4953 char *name
, /* I - Name buffer */
4954 size_t namesize
, /* I - Size of name buffer */
4955 const char *dashchars
)/* I - Characters to be replaced by dashes */
4957 char *ptr
, /* Pointer into name buffer */
4958 *end
; /* End of name buffer */
4961 if (_cups_islower(*ppd
))
4964 * Already lowercase name, use as-is?
4967 const char *ppdptr
; /* Pointer into PPD keyword */
4969 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4970 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4975 strlcpy(name
, ppd
, namesize
);
4980 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4982 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4983 *ptr
++ = (char)tolower(*ppd
& 255);
4984 else if (strchr(dashchars
, *ppd
))
4989 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4990 _cups_isupper(ppd
[1]) && ptr
< end
)
4992 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))