2 * PPD cache implementation for CUPS.
4 * Copyright 2010-2017 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * Include necessary headers...
13 #include "cups-private.h"
14 #include "ppd-private.h"
19 * Macro to test for two almost-equal PWG measurements.
22 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
29 static int cups_get_url(http_t
**http
, const char *url
, char *name
, size_t namesize
);
30 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
31 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
32 _pwg_finishings_t
*b
);
33 static void pwg_free_finishings(_pwg_finishings_t
*f
);
34 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
35 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
36 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
37 const char *dashchars
);
41 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
43 * This functions converts PPD and CUPS-specific options to their standard IPP
44 * attributes and values and adds them to the specified IPP request.
47 int /* O - New number of copies */
49 ipp_t
*request
, /* I - IPP request */
50 ppd_file_t
*ppd
, /* I - PPD file */
51 _ppd_cache_t
*pc
, /* I - PPD cache info */
52 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
53 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
54 ipp_attribute_t
*print_color_mode_sup
,
55 /* I - Printer supports print-color-mode */
56 const char *user
, /* I - User info */
57 const char *format
, /* I - document-format value */
58 int copies
, /* I - Number of copies */
59 int num_options
, /* I - Number of options */
60 cups_option_t
*options
) /* I - Options */
62 int i
; /* Looping var */
63 const char *keyword
, /* PWG keyword */
64 *password
; /* Password string */
65 pwg_size_t
*size
; /* PWG media size */
66 ipp_t
*media_col
, /* media-col value */
67 *media_size
; /* media-size value */
68 const char *media_source
, /* media-source value */
69 *media_type
, /* media-type value */
70 *collate_str
, /* multiple-document-handling value */
71 *color_attr_name
, /* Supported color attribute */
72 *mandatory
, /* Mandatory attributes */
73 *finishing_template
; /* Finishing template */
74 int num_finishings
= 0, /* Number of finishing values */
75 finishings
[10]; /* Finishing enum values */
76 ppd_choice_t
*choice
; /* Marked choice */
77 int finishings_copies
= copies
;
78 /* Number of copies for finishings */
82 * Send standard IPP attributes...
85 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
87 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
89 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
92 if (!strcmp(keyword
, "none"))
95 * Add plain-text job-password...
98 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
103 * Add hashed job-password...
106 unsigned char hash
[64]; /* Hash of password */
107 ssize_t hashlen
; /* Length of hash */
109 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
110 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
114 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
119 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
120 keyword
= cupsGetOption("job-billing", num_options
, options
);
123 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
126 if (pc
->accounting_user_id
)
128 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
132 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
135 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
137 if (strcmp(mandatory
, "copies") &&
138 strcmp(mandatory
, "destination-uris") &&
139 strcmp(mandatory
, "finishings") &&
140 strcmp(mandatory
, "finishings-col") &&
141 strcmp(mandatory
, "finishing-template") &&
142 strcmp(mandatory
, "job-account-id") &&
143 strcmp(mandatory
, "job-accounting-user-id") &&
144 strcmp(mandatory
, "job-password") &&
145 strcmp(mandatory
, "job-password-encryption") &&
146 strcmp(mandatory
, "media") &&
147 strncmp(mandatory
, "media-col", 9) &&
148 strcmp(mandatory
, "multiple-document-handling") &&
149 strcmp(mandatory
, "output-bin") &&
150 strcmp(mandatory
, "print-color-mode") &&
151 strcmp(mandatory
, "print-quality") &&
152 strcmp(mandatory
, "sides") &&
153 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
155 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
157 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
162 case IPP_TAG_INTEGER
:
164 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
166 case IPP_TAG_BOOLEAN
:
167 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
171 int lower
, upper
; /* Range */
173 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
174 lower
= upper
= atoi(keyword
);
176 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
179 case IPP_TAG_STRING
:
180 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
183 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
185 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
186 keyword
= "auto-monochrome";
187 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
188 keyword
= "process-monochrome";
191 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
197 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
198 keyword
= cupsGetOption("media", num_options
, options
);
200 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
201 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
202 size
= _ppdCacheGetSize(pc
, keyword
);
204 if (size
|| media_source
|| media_type
)
207 * Add a media-col value...
210 media_col
= ippNew();
214 media_size
= ippNew();
215 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
216 "x-dimension", size
->width
);
217 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
218 "y-dimension", size
->length
);
220 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
223 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
225 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
226 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
227 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
229 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
233 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
234 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
235 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
239 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
242 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
244 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
245 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
249 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
251 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
253 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
255 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
257 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
258 keyword
= "monochrome";
264 if (keyword
&& !strcmp(keyword
, "monochrome"))
266 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
267 keyword
= "auto-monochrome";
268 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
269 keyword
= "process-monochrome";
273 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
275 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
276 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
277 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
279 if (!_cups_strcasecmp(choice
->choice
, "draft"))
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
281 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
283 else if (!_cups_strcasecmp(choice
->choice
, "high"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
287 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
288 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
289 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
291 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
293 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
295 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
303 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
305 if (strstr(keyword
, "uncollated"))
310 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
315 if (!_cups_strcasecmp(format
, "image/gif") ||
316 !_cups_strcasecmp(format
, "image/jp2") ||
317 !_cups_strcasecmp(format
, "image/jpeg") ||
318 !_cups_strcasecmp(format
, "image/png") ||
319 !_cups_strcasecmp(format
, "image/tiff") ||
320 !_cups_strncasecmp(format
, "image/x-", 8))
323 * Collation makes no sense for single page image formats...
328 else if (!_cups_strncasecmp(format
, "image/", 6) ||
329 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
332 * Multi-page image formats will have copies applied by the upstream
340 if (doc_handling_sup
)
342 if (!_cups_strcasecmp(keyword
, "true"))
343 collate_str
= "separate-documents-collated-copies";
345 collate_str
= "separate-documents-uncollated-copies";
347 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
349 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
351 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
356 if (i
>= doc_handling_sup
->num_values
)
361 * Map finishing options...
364 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
365 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
367 if (finishing_template
)
369 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
371 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
372 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
375 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
378 * Send job-pages-per-set attribute to apply finishings correctly...
381 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
386 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
387 if (num_finishings
> 0)
389 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
391 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
394 * Send job-pages-per-set attribute to apply finishings correctly...
397 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
407 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
410 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
414 _ppd_cache_t
* /* O - PPD cache and mapping data */
415 _ppdCacheCreateWithFile(
416 const char *filename
, /* I - File to read */
417 ipp_t
**attrs
) /* IO - IPP attributes, if any */
419 cups_file_t
*fp
; /* File */
420 _ppd_cache_t
*pc
; /* PWG mapping data */
421 pwg_size_t
*size
; /* Current size */
422 pwg_map_t
*map
; /* Current map */
423 _pwg_finishings_t
*finishings
; /* Current finishings option */
424 int linenum
, /* Current line number */
425 num_bins
, /* Number of bins in file */
426 num_sizes
, /* Number of sizes in file */
427 num_sources
, /* Number of sources in file */
428 num_types
; /* Number of types in file */
429 char line
[2048], /* Current line */
430 *value
, /* Pointer to value in line */
431 *valueptr
, /* Pointer into value */
432 pwg_keyword
[128], /* PWG keyword */
433 ppd_keyword
[PPD_MAX_NAME
];
435 _pwg_print_color_mode_t print_color_mode
;
436 /* Print color mode for preset */
437 _pwg_print_quality_t print_quality
; /* Print quality for preset */
440 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
443 * Range check input...
451 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
459 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
461 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
466 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
469 if (!cupsFileGets(fp
, line
, sizeof(line
)))
471 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
472 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
477 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
479 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
480 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
485 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
487 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
488 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
489 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
495 * Allocate the mapping data structure...
498 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
500 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
501 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
505 pc
->max_copies
= 9999;
517 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
519 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
520 "linenum=%d", line
, value
, linenum
));
524 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
526 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
529 else if (!_cups_strcasecmp(line
, "Filter"))
532 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
533 (cups_acopy_func_t
)_cupsStrAlloc
,
534 (cups_afree_func_t
)_cupsStrFree
);
536 cupsArrayAdd(pc
->filters
, value
);
538 else if (!_cups_strcasecmp(line
, "PreFilter"))
541 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
542 (cups_acopy_func_t
)_cupsStrAlloc
,
543 (cups_afree_func_t
)_cupsStrFree
);
545 cupsArrayAdd(pc
->prefilters
, value
);
547 else if (!_cups_strcasecmp(line
, "Product"))
549 pc
->product
= _cupsStrAlloc(value
);
551 else if (!_cups_strcasecmp(line
, "SingleFile"))
553 pc
->single_file
= !_cups_strcasecmp(value
, "true");
555 else if (!_cups_strcasecmp(line
, "IPP"))
557 off_t pos
= cupsFileTell(fp
), /* Position in file */
558 length
= strtol(value
, NULL
, 10);
559 /* Length of IPP attributes */
563 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
564 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
567 else if (length
<= 0)
569 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
570 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
577 * Read IPP attributes into the provided variable...
582 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
583 *attrs
) != IPP_STATE_DATA
)
585 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
586 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
593 * Skip the IPP data entirely...
596 cupsFileSeek(fp
, pos
+ length
);
599 if (cupsFileTell(fp
) != (pos
+ length
))
601 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
602 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
606 else if (!_cups_strcasecmp(line
, "NumBins"))
610 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
611 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
615 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
617 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
618 "%d.", num_sizes
, linenum
));
619 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
623 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
625 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
627 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
631 else if (!_cups_strcasecmp(line
, "Bin"))
633 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
635 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if (pc
->num_bins
>= num_bins
)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
648 map
= pc
->bins
+ pc
->num_bins
;
649 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
650 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
654 else if (!_cups_strcasecmp(line
, "NumSizes"))
658 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
659 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
663 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
665 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
666 "%d.", num_sizes
, linenum
));
667 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
675 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
677 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
682 else if (!_cups_strcasecmp(line
, "Size"))
684 if (pc
->num_sizes
>= num_sizes
)
686 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
688 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
692 size
= pc
->sizes
+ pc
->num_sizes
;
694 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
695 &(size
->width
), &(size
->length
), &(size
->left
),
696 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
698 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
700 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
704 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
705 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
709 else if (!_cups_strcasecmp(line
, "CustomSize"))
711 if (pc
->custom_max_width
> 0)
713 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
715 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
719 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
720 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
721 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
722 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
723 &(pc
->custom_size
.top
)) != 8)
725 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
727 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
731 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
732 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
733 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
735 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
736 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
737 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
739 else if (!_cups_strcasecmp(line
, "SourceOption"))
741 pc
->source_option
= _cupsStrAlloc(value
);
743 else if (!_cups_strcasecmp(line
, "NumSources"))
747 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
749 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
753 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
755 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
756 "line %d.", num_sources
, linenum
));
757 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
761 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
763 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
765 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
769 else if (!_cups_strcasecmp(line
, "Source"))
771 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
773 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
775 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
779 if (pc
->num_sources
>= num_sources
)
781 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
783 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
787 map
= pc
->sources
+ pc
->num_sources
;
788 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
789 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
793 else if (!_cups_strcasecmp(line
, "NumTypes"))
797 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
798 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
802 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
804 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
805 "line %d.", num_types
, linenum
));
806 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
810 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
812 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
814 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
818 else if (!_cups_strcasecmp(line
, "Type"))
820 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
822 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
824 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
828 if (pc
->num_types
>= num_types
)
830 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
836 map
= pc
->types
+ pc
->num_types
;
837 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
838 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
842 else if (!_cups_strcasecmp(line
, "Preset"))
845 * Preset output-mode print-quality name=value ...
848 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
849 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
851 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
852 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
853 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
854 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
855 valueptr
== value
|| !*valueptr
)
857 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
859 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
863 pc
->num_presets
[print_color_mode
][print_quality
] =
864 cupsParseOptions(valueptr
, 0,
865 pc
->presets
[print_color_mode
] + print_quality
);
867 else if (!_cups_strcasecmp(line
, "SidesOption"))
868 pc
->sides_option
= _cupsStrAlloc(value
);
869 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
870 pc
->sides_1sided
= _cupsStrAlloc(value
);
871 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
872 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
873 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
874 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "Finishings"))
879 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
881 (cups_afree_func_t
)pwg_free_finishings
);
883 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
886 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
887 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
888 &(finishings
->options
));
890 cupsArrayAdd(pc
->finishings
, finishings
);
892 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
895 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
897 cupsArrayAdd(pc
->templates
, value
);
899 else if (!_cups_strcasecmp(line
, "MaxCopies"))
900 pc
->max_copies
= atoi(value
);
901 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
902 pc
->charge_info_uri
= _cupsStrAlloc(value
);
903 else if (!_cups_strcasecmp(line
, "JobAccountId"))
904 pc
->account_id
= !_cups_strcasecmp(value
, "true");
905 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
906 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
907 else if (!_cups_strcasecmp(line
, "JobPassword"))
908 pc
->password
= _cupsStrAlloc(value
);
909 else if (!_cups_strcasecmp(line
, "Mandatory"))
912 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
914 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
916 else if (!_cups_strcasecmp(line
, "StringsURI"))
917 pc
->strings_uri
= _cupsStrAlloc(value
);
918 else if (!_cups_strcasecmp(line
, "SupportFile"))
920 if (!pc
->support_files
)
921 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
922 (cups_acopy_func_t
)_cupsStrAlloc
,
923 (cups_afree_func_t
)_cupsStrFree
);
925 cupsArrayAdd(pc
->support_files
, value
);
929 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
934 if (pc
->num_sizes
< num_sizes
)
936 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
937 pc
->num_sizes
, num_sizes
));
938 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
942 if (pc
->num_sources
< num_sources
)
944 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
945 pc
->num_sources
, num_sources
));
946 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
950 if (pc
->num_types
< num_types
)
952 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
953 pc
->num_types
, num_types
));
954 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
963 * If we get here the file was bad - free any data and return...
969 _ppdCacheDestroy(pc
);
982 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
985 _ppd_cache_t
* /* O - PPD cache and mapping data */
986 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
988 int i
, j
, k
; /* Looping vars */
989 _ppd_cache_t
*pc
; /* PWG mapping data */
990 ppd_option_t
*input_slot
, /* InputSlot option */
991 *media_type
, /* MediaType option */
992 *output_bin
, /* OutputBin option */
993 *color_model
, /* ColorModel option */
994 *duplex
, /* Duplex option */
995 *ppd_option
; /* Other PPD option */
996 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
997 pwg_map_t
*map
; /* Current source/type map */
998 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
999 int num_options
; /* Number of preset options and props */
1000 cups_option_t
*options
; /* Preset options and properties */
1001 ppd_size_t
*ppd_size
; /* Current PPD size */
1002 pwg_size_t
*pwg_size
; /* Current PWG size */
1003 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1004 /* PWG keyword string */
1005 ppd_name
[PPD_MAX_NAME
];
1006 /* Normalized PPD name */
1007 const char *pwg_name
; /* Standard PWG media name */
1008 pwg_media_t
*pwg_media
; /* PWG media data */
1009 _pwg_print_color_mode_t pwg_print_color_mode
;
1010 /* print-color-mode index */
1011 _pwg_print_quality_t pwg_print_quality
;
1012 /* print-quality index */
1013 int similar
; /* Are the old and new size similar? */
1014 pwg_size_t
*old_size
; /* Current old size */
1015 int old_imageable
, /* Old imageable length in 2540ths */
1016 old_borderless
, /* Old borderless state */
1017 old_known_pwg
; /* Old PWG name is well-known */
1018 int new_width
, /* New width in 2540ths */
1019 new_length
, /* New length in 2540ths */
1020 new_left
, /* New left margin in 2540ths */
1021 new_bottom
, /* New bottom margin in 2540ths */
1022 new_right
, /* New right margin in 2540ths */
1023 new_top
, /* New top margin in 2540ths */
1024 new_imageable
, /* New imageable length in 2540ths */
1025 new_borderless
, /* New borderless state */
1026 new_known_pwg
; /* New PWG name is well-known */
1027 pwg_size_t
*new_size
; /* New size to add, if any */
1028 const char *filter
; /* Current filter */
1029 _pwg_finishings_t
*finishings
; /* Current finishings value */
1032 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1035 * Range check input...
1042 * Allocate memory...
1045 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1047 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1052 * Copy and convert size data...
1055 if (ppd
->num_sizes
> 0)
1057 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1059 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1060 "pwg_size_t's.", ppd
->num_sizes
));
1064 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1069 * Don't copy over custom size...
1072 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1076 * Convert the PPD size name to the corresponding PWG keyword name.
1079 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1082 * Standard name, do we have conflicts?
1085 for (j
= 0; j
< pc
->num_sizes
; j
++)
1086 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1096 * Standard name and no conflicts, use it!
1099 pwg_name
= pwg_media
->pwg
;
1105 * Not a standard name; convert it to a PWG vendor name of the form:
1107 * pp_lowerppd_WIDTHxHEIGHTuu
1110 pwg_name
= pwg_keyword
;
1113 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1114 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1115 PWG_FROM_POINTS(ppd_size
->width
),
1116 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1120 * If we have a similar paper with non-zero margins then we only want to
1121 * keep it if it has a larger imageable area length. The NULL check is for
1122 * dimensions that are <= 0...
1125 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1126 PWG_FROM_POINTS(ppd_size
->length
),
1130 new_width
= pwg_media
->width
;
1131 new_length
= pwg_media
->length
;
1132 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1133 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1134 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1135 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1136 new_imageable
= new_length
- new_top
- new_bottom
;
1137 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1138 new_left
== 0 && new_right
== 0;
1140 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1144 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1145 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1146 old_size
->right
== 0 && old_size
->top
== 0;
1147 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1148 strncmp(old_size
->map
.pwg
, "om_", 3);
1150 similar
= old_borderless
== new_borderless
&&
1151 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1152 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1155 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1158 * The new paper has a larger imageable area so it could replace
1159 * the older paper. Regardless of the imageable area, we always
1160 * prefer the size with a well-known PWG name.
1163 new_size
= old_size
;
1164 _cupsStrFree(old_size
->map
.ppd
);
1165 _cupsStrFree(old_size
->map
.pwg
);
1172 * The paper was unique enough to deserve its own entry so add it to the
1176 new_size
= pwg_size
++;
1186 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1187 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1188 new_size
->width
= new_width
;
1189 new_size
->length
= new_length
;
1190 new_size
->left
= new_left
;
1191 new_size
->bottom
= new_bottom
;
1192 new_size
->right
= new_right
;
1193 new_size
->top
= new_top
;
1198 if (ppd
->variable_sizes
)
1201 * Generate custom size data...
1204 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1205 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1206 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1207 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1208 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1209 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1211 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1212 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1213 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1214 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1215 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1216 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1218 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1219 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1220 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1221 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1225 * Copy and convert InputSlot data...
1228 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1229 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1233 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1235 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1237 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1238 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1242 pc
->num_sources
= input_slot
->num_choices
;
1244 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1247 i
--, choice
++, map
++)
1249 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1250 !_cups_strcasecmp(choice
->choice
, "Default"))
1252 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1254 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1256 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1258 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1259 !_cups_strcasecmp(choice
->choice
, "MP") ||
1260 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1261 pwg_name
= "by-pass-tray";
1262 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1263 pwg_name
= "large-capacity";
1264 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1265 pwg_name
= "bottom";
1266 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1267 pwg_name
= "middle";
1268 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1270 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1272 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1273 pwg_name
= "main-roll";
1277 * Convert PPD name to lowercase...
1280 pwg_name
= pwg_keyword
;
1281 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1285 map
->pwg
= _cupsStrAlloc(pwg_name
);
1286 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1291 * Copy and convert MediaType data...
1294 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1296 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1298 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1299 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1303 pc
->num_types
= media_type
->num_choices
;
1305 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1308 i
--, choice
++, map
++)
1310 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1311 !_cups_strcasecmp(choice
->choice
, "Any") ||
1312 !_cups_strcasecmp(choice
->choice
, "Default"))
1314 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1315 pwg_name
= "cardstock";
1316 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1317 pwg_name
= "envelope";
1318 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1319 pwg_name
= "photographic-glossy";
1320 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1321 pwg_name
= "photographic-high-gloss";
1322 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1323 pwg_name
= "photographic-matte";
1324 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1325 pwg_name
= "stationery";
1326 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1327 pwg_name
= "stationery-coated";
1328 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1329 pwg_name
= "stationery-inkjet";
1330 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1331 pwg_name
= "stationery-letterhead";
1332 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1333 pwg_name
= "stationery-preprinted";
1334 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1335 pwg_name
= "stationery-recycled";
1336 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1337 pwg_name
= "transparency";
1341 * Convert PPD name to lowercase...
1344 pwg_name
= pwg_keyword
;
1345 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1349 map
->pwg
= _cupsStrAlloc(pwg_name
);
1350 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1355 * Copy and convert OutputBin data...
1358 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1360 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1362 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1363 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1367 pc
->num_bins
= output_bin
->num_choices
;
1369 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1372 i
--, choice
++, map
++)
1374 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1376 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1377 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1381 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1384 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1387 const char *quality
, /* com.apple.print.preset.quality value */
1388 *output_mode
, /* com.apple.print.preset.output-mode value */
1389 *color_model_val
, /* ColorModel choice */
1390 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1391 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1395 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1398 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1399 num_options
, options
)) != NULL
)
1402 * Get the print-quality for this preset...
1405 if (!strcmp(quality
, "low"))
1406 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1407 else if (!strcmp(quality
, "high"))
1408 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1410 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1413 * Ignore graphicsType "Photo" presets that are not high quality.
1416 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1417 num_options
, options
);
1419 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1420 !strcmp(graphicsType
, "Photo"))
1424 * Ignore presets for normal and draft quality where the coating
1425 * isn't "none" or "autodetect".
1428 media_front_coating
= cupsGetOption(
1429 "com.apple.print.preset.media-front-coating",
1430 num_options
, options
);
1432 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1433 media_front_coating
&&
1434 strcmp(media_front_coating
, "none") &&
1435 strcmp(media_front_coating
, "autodetect"))
1439 * Get the output mode for this preset...
1442 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1443 num_options
, options
);
1444 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1448 if (!strcmp(output_mode
, "monochrome"))
1449 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1451 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1453 else if (color_model_val
)
1455 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1456 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1458 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1461 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1464 * Save the options for this combination as needed...
1467 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1468 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1469 _ppdParseOptions(ppd_attr
->value
, 0,
1470 pc
->presets
[pwg_print_color_mode
] +
1471 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1474 cupsFreeOptions(num_options
, options
);
1476 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1479 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1480 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1481 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1484 * Try adding some common color options to create grayscale presets. These
1485 * are listed in order of popularity...
1488 const char *color_option
= NULL
, /* Color control option */
1489 *gray_choice
= NULL
; /* Choice to select grayscale */
1491 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1492 ppdFindChoice(color_model
, "Gray"))
1494 color_option
= "ColorModel";
1495 gray_choice
= "Gray";
1497 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1498 ppdFindChoice(color_model
, "grayscale"))
1500 color_option
= "HPColorMode";
1501 gray_choice
= "grayscale";
1503 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1504 ppdFindChoice(color_model
, "Mono"))
1506 color_option
= "BRMonoColor";
1507 gray_choice
= "Mono";
1509 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1510 ppdFindChoice(color_model
, "1"))
1512 color_option
= "CNIJSGrayScale";
1515 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1516 ppdFindChoice(color_model
, "True"))
1518 color_option
= "HPColorAsGray";
1519 gray_choice
= "True";
1522 if (color_option
&& gray_choice
)
1525 * Copy and convert ColorModel (output-mode) data...
1528 cups_option_t
*coption
, /* Color option */
1529 *moption
; /* Monochrome option */
1531 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1532 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1533 pwg_print_quality
++)
1535 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1538 * Copy the color options...
1541 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1542 [pwg_print_quality
];
1543 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1547 for (i
= num_options
, moption
= options
,
1548 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1549 [pwg_print_quality
];
1551 i
--, moption
++, coption
++)
1553 moption
->name
= _cupsStrRetain(coption
->name
);
1554 moption
->value
= _cupsStrRetain(coption
->value
);
1557 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1559 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1563 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1567 * Add the grayscale option to the preset...
1570 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1571 cupsAddOption(color_option
, gray_choice
,
1572 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1573 [pwg_print_quality
],
1574 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1581 * Copy and convert Duplex (sides) data...
1584 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1585 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1586 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1587 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1588 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1592 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1594 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1598 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1599 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1600 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1601 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1602 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1603 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1604 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1605 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1606 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1607 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1608 !pc
->sides_2sided_short
)
1609 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1614 * Copy filters and pre-filters...
1617 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1618 (cups_acopy_func_t
)_cupsStrAlloc
,
1619 (cups_afree_func_t
)_cupsStrFree
);
1621 cupsArrayAdd(pc
->filters
,
1622 "application/vnd.cups-raw application/octet-stream 0 -");
1624 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1628 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1630 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1632 else if (ppd
->num_filters
> 0)
1634 for (i
= 0; i
< ppd
->num_filters
; i
++)
1635 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1638 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1641 * See if we have a command filter...
1644 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1646 filter
= (const char *)cupsArrayNext(pc
->filters
))
1647 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1648 _cups_isspace(filter
[28]))
1652 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1653 _cups_strcasecmp(ppd_attr
->value
, "none")))
1656 * No command filter and no cupsCommands keyword telling us not to use one.
1657 * See if this is a PostScript printer, and if so add a PostScript command
1661 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1663 filter
= (const char *)cupsArrayNext(pc
->filters
))
1664 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1665 _cups_isspace(filter
[31]))
1669 cupsArrayAdd(pc
->filters
,
1670 "application/vnd.cups-command application/postscript 100 "
1674 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1676 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1677 (cups_acopy_func_t
)_cupsStrAlloc
,
1678 (cups_afree_func_t
)_cupsStrFree
);
1682 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1684 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1687 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1688 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1691 * Copy the product string, if any...
1695 pc
->product
= _cupsStrAlloc(ppd
->product
);
1698 * Copy finishings mapping data...
1701 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1704 * Have proper vendor mapping of IPP finishings values to PPD options...
1707 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1708 NULL
, NULL
, 0, NULL
,
1709 (cups_afree_func_t
)pwg_free_finishings
);
1713 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1716 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1717 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1718 &(finishings
->options
),
1719 _PPD_PARSE_OPTIONS
);
1721 cupsArrayAdd(pc
->finishings
, finishings
);
1723 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1729 * No IPP mapping data, try to map common/standard PPD keywords...
1732 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1734 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1737 * Add staple finishings...
1740 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1741 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1742 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1743 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1744 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1745 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1746 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1747 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1748 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1749 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1752 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1755 * Add (Ricoh) punch finishings...
1758 if (ppdFindChoice(ppd_option
, "Left2"))
1759 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1760 if (ppdFindChoice(ppd_option
, "Left3"))
1761 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1762 if (ppdFindChoice(ppd_option
, "Left4"))
1763 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1764 if (ppdFindChoice(ppd_option
, "Right2"))
1765 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1766 if (ppdFindChoice(ppd_option
, "Right3"))
1767 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1768 if (ppdFindChoice(ppd_option
, "Right4"))
1769 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1770 if (ppdFindChoice(ppd_option
, "Upper2"))
1771 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1772 if (ppdFindChoice(ppd_option
, "Upper3"))
1773 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1774 if (ppdFindChoice(ppd_option
, "Upper4"))
1775 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1778 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1781 * Add bind finishings...
1784 if (ppdFindChoice(ppd_option
, "Left"))
1785 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1786 if (ppdFindChoice(ppd_option
, "Right"))
1787 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1788 if (ppdFindChoice(ppd_option
, "Top"))
1789 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1790 if (ppdFindChoice(ppd_option
, "Bottom"))
1791 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1794 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1797 * Add (Adobe) fold finishings...
1800 if (ppdFindChoice(ppd_option
, "ZFold"))
1801 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1802 if (ppdFindChoice(ppd_option
, "Saddle"))
1803 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1804 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1805 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1806 if (ppdFindChoice(ppd_option
, "LeftGate"))
1807 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1808 if (ppdFindChoice(ppd_option
, "RightGate"))
1809 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1810 if (ppdFindChoice(ppd_option
, "Letter"))
1811 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1812 if (ppdFindChoice(ppd_option
, "XFold"))
1813 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1816 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1819 * Add (Ricoh) fold finishings...
1822 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1823 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1826 if (cupsArrayCount(pc
->finishings
) == 0)
1828 cupsArrayDelete(pc
->finishings
);
1829 pc
->finishings
= NULL
;
1833 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1835 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
1837 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1838 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1845 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1846 pc
->max_copies
= atoi(ppd_attr
->value
);
1847 else if (ppd
->manual_copies
)
1850 pc
->max_copies
= 9999;
1853 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1854 * cupsJobPassword, and cupsMandatory.
1857 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1858 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1860 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1861 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1863 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1864 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1866 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1867 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1869 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1870 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1873 * Strings (remote) file...
1876 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsStringsURI", NULL
)) != NULL
)
1877 pc
->strings_uri
= _cupsStrAlloc(ppd_attr
->value
);
1883 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1884 (cups_acopy_func_t
)_cupsStrAlloc
,
1885 (cups_afree_func_t
)_cupsStrFree
);
1887 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1889 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1890 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1892 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1893 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1896 * Return the cache data...
1902 * If we get here we need to destroy the PWG mapping data and return NULL...
1907 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1908 _ppdCacheDestroy(pc
);
1915 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1919 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1921 int i
; /* Looping var */
1922 pwg_map_t
*map
; /* Current map */
1923 pwg_size_t
*size
; /* Current size */
1927 * Range check input...
1934 * Free memory as needed...
1939 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1941 _cupsStrFree(map
->pwg
);
1942 _cupsStrFree(map
->ppd
);
1950 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1952 _cupsStrFree(size
->map
.pwg
);
1953 _cupsStrFree(size
->map
.ppd
);
1959 if (pc
->source_option
)
1960 _cupsStrFree(pc
->source_option
);
1964 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1966 _cupsStrFree(map
->pwg
);
1967 _cupsStrFree(map
->ppd
);
1975 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1977 _cupsStrFree(map
->pwg
);
1978 _cupsStrFree(map
->ppd
);
1984 if (pc
->custom_max_keyword
)
1985 _cupsStrFree(pc
->custom_max_keyword
);
1987 if (pc
->custom_min_keyword
)
1988 _cupsStrFree(pc
->custom_min_keyword
);
1990 _cupsStrFree(pc
->product
);
1991 cupsArrayDelete(pc
->filters
);
1992 cupsArrayDelete(pc
->prefilters
);
1993 cupsArrayDelete(pc
->finishings
);
1995 _cupsStrFree(pc
->charge_info_uri
);
1996 _cupsStrFree(pc
->password
);
1998 cupsArrayDelete(pc
->mandatory
);
2000 cupsArrayDelete(pc
->support_files
);
2007 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2011 const char * /* O - output-bin or NULL */
2013 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2014 const char *output_bin
) /* I - PPD OutputBin string */
2016 int i
; /* Looping var */
2020 * Range check input...
2023 if (!pc
|| !output_bin
)
2027 * Look up the OutputBin string...
2031 for (i
= 0; i
< pc
->num_bins
; i
++)
2032 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2033 return (pc
->bins
[i
].pwg
);
2040 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2041 * IPP finishings value(s).
2044 int /* O - New number of options */
2045 _ppdCacheGetFinishingOptions(
2046 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2047 ipp_t
*job
, /* I - Job attributes or NULL */
2048 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2049 int num_options
, /* I - Number of options */
2050 cups_option_t
**options
) /* IO - Options */
2052 int i
; /* Looping var */
2053 _pwg_finishings_t
*f
, /* PWG finishings options */
2054 key
; /* Search key */
2055 ipp_attribute_t
*attr
; /* Finishings attribute */
2056 cups_option_t
*option
; /* Current finishings option */
2060 * Range check input...
2063 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2064 (!job
&& value
== IPP_FINISHINGS_NONE
))
2065 return (num_options
);
2068 * Apply finishing options...
2071 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2073 int num_values
= ippGetCount(attr
); /* Number of values */
2075 for (i
= 0; i
< num_values
; i
++)
2077 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2079 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2081 int j
; /* Another looping var */
2083 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2084 num_options
= cupsAddOption(option
->name
, option
->value
,
2085 num_options
, options
);
2089 else if (value
!= IPP_FINISHINGS_NONE
)
2093 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2095 int j
; /* Another looping var */
2097 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2098 num_options
= cupsAddOption(option
->name
, option
->value
,
2099 num_options
, options
);
2103 return (num_options
);
2108 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2112 int /* O - Number of finishings values */
2113 _ppdCacheGetFinishingValues(
2114 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2115 int num_options
, /* I - Number of options */
2116 cups_option_t
*options
, /* I - Options */
2117 int max_values
, /* I - Maximum number of finishings values */
2118 int *values
) /* O - Finishings values */
2120 int i
, /* Looping var */
2121 num_values
= 0; /* Number of values */
2122 _pwg_finishings_t
*f
; /* Current finishings option */
2123 cups_option_t
*option
; /* Current option */
2124 const char *val
; /* Value for option */
2128 * Range check input...
2131 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2133 if (!pc
|| max_values
< 1 || !values
)
2135 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2138 else if (!pc
->finishings
)
2140 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2145 * Go through the finishings options and see what is set...
2148 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2150 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2152 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2154 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2156 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2158 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2159 _cups_strcasecmp(option
->value
, val
))
2161 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2168 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2170 values
[num_values
++] = f
->value
;
2172 if (num_values
>= max_values
)
2177 if (num_values
== 0)
2180 * Always have at least "finishings" = 'none'...
2183 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2184 values
[0] = IPP_FINISHINGS_NONE
;
2188 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2190 return (num_values
);
2195 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2196 * attributes or a keyword string.
2199 const char * /* O - PPD InputSlot or NULL */
2200 _ppdCacheGetInputSlot(
2201 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2202 ipp_t
*job
, /* I - Job attributes or NULL */
2203 const char *keyword
) /* I - Keyword string or NULL */
2206 * Range check input...
2209 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2212 if (job
&& !keyword
)
2215 * Lookup the media-col attribute and any media-source found there...
2218 ipp_attribute_t
*media_col
, /* media-col attribute */
2219 *media_source
; /* media-source attribute */
2220 pwg_size_t size
; /* Dimensional size */
2221 int margins_set
; /* Were the margins set? */
2223 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2225 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2227 IPP_TAG_KEYWORD
)) != NULL
)
2230 * Use the media-source value from media-col...
2233 keyword
= ippGetString(media_source
, 0, NULL
);
2235 else if (pwgInitSize(&size
, job
, &margins_set
))
2238 * For media <= 5x7, look for a photo tray...
2241 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2248 int i
; /* Looping var */
2250 for (i
= 0; i
< pc
->num_sources
; i
++)
2251 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2252 return (pc
->sources
[i
].ppd
);
2260 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2261 * attributes or a keyword string.
2264 const char * /* O - PPD MediaType or NULL */
2265 _ppdCacheGetMediaType(
2266 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2267 ipp_t
*job
, /* I - Job attributes or NULL */
2268 const char *keyword
) /* I - Keyword string or NULL */
2271 * Range check input...
2274 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2277 if (job
&& !keyword
)
2280 * Lookup the media-col attribute and any media-source found there...
2283 ipp_attribute_t
*media_col
, /* media-col attribute */
2284 *media_type
; /* media-type attribute */
2286 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2289 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2291 IPP_TAG_KEYWORD
)) == NULL
)
2292 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2293 "media-type", IPP_TAG_NAME
);
2296 keyword
= media_type
->values
[0].string
.text
;
2302 int i
; /* Looping var */
2304 for (i
= 0; i
< pc
->num_types
; i
++)
2305 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2306 return (pc
->types
[i
].ppd
);
2314 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2318 const char * /* O - PPD OutputBin or NULL */
2319 _ppdCacheGetOutputBin(
2320 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2321 const char *output_bin
) /* I - Keyword string */
2323 int i
; /* Looping var */
2327 * Range check input...
2330 if (!pc
|| !output_bin
)
2334 * Look up the OutputBin string...
2338 for (i
= 0; i
< pc
->num_bins
; i
++)
2339 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2340 return (pc
->bins
[i
].ppd
);
2347 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2348 * attributes or a keyword string.
2351 const char * /* O - PPD PageSize or NULL */
2352 _ppdCacheGetPageSize(
2353 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2354 ipp_t
*job
, /* I - Job attributes or NULL */
2355 const char *keyword
, /* I - Keyword string or NULL */
2356 int *exact
) /* O - 1 if exact match, 0 otherwise */
2358 int i
; /* Looping var */
2359 pwg_size_t
*size
, /* Current size */
2360 *closest
, /* Closest size */
2361 jobsize
; /* Size data from job */
2362 int margins_set
, /* Were the margins set? */
2363 dwidth
, /* Difference in width */
2364 dlength
, /* Difference in length */
2365 dleft
, /* Difference in left margins */
2366 dright
, /* Difference in right margins */
2367 dbottom
, /* Difference in bottom margins */
2368 dtop
, /* Difference in top margins */
2369 dmin
, /* Minimum difference */
2370 dclosest
; /* Closest difference */
2371 const char *ppd_name
; /* PPD media name */
2374 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2375 pc
, job
, keyword
, exact
));
2378 * Range check input...
2381 if (!pc
|| (!job
&& !keyword
))
2392 * Try getting the PPD media name from the job attributes...
2395 ipp_attribute_t
*attr
; /* Job attribute */
2397 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2398 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2399 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2403 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2404 attr
->name
, ippTagString(attr
->value_tag
)));
2406 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2409 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2410 attr
->value_tag
== IPP_TAG_KEYWORD
))
2411 ppd_name
= attr
->values
[0].string
.text
;
2414 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2419 * Try looking up the named PPD size first...
2422 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2424 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2425 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2427 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2428 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2433 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2435 return (size
->map
.ppd
);
2440 if (job
&& !keyword
)
2443 * Get the size using media-col or media, with the preference being
2447 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2453 * Get the size using a media keyword...
2456 pwg_media_t
*media
; /* Media definition */
2459 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2460 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2461 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2464 jobsize
.width
= media
->width
;
2465 jobsize
.length
= media
->length
;
2470 * Now that we have the dimensions and possibly the margins, look at the
2471 * available sizes and find the match...
2475 dclosest
= 999999999;
2477 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2478 _cups_strncasecmp(ppd_name
, "custom_", 7))
2480 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2483 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2484 * is just about 176/2540ths...
2487 dwidth
= size
->width
- jobsize
.width
;
2488 dlength
= size
->length
- jobsize
.length
;
2490 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2496 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2499 dleft
= size
->left
- jobsize
.left
;
2500 dright
= size
->right
- jobsize
.right
;
2501 dtop
= size
->top
- jobsize
.top
;
2502 dbottom
= size
->bottom
- jobsize
.bottom
;
2504 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2505 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2507 dleft
= dleft
< 0 ? -dleft
: dleft
;
2508 dright
= dright
< 0 ? -dright
: dright
;
2509 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2510 dtop
= dtop
< 0 ? -dtop
: dtop
;
2511 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2513 if (dmin
< dclosest
)
2526 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2528 return (size
->map
.ppd
);
2534 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2537 return (closest
->map
.ppd
);
2541 * If we get here we need to check for custom page size support...
2544 if (jobsize
.width
>= pc
->custom_min_width
&&
2545 jobsize
.width
<= pc
->custom_max_width
&&
2546 jobsize
.length
>= pc
->custom_min_length
&&
2547 jobsize
.length
<= pc
->custom_max_length
)
2550 * In range, format as Custom.WWWWxLLLL (points).
2553 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2554 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2556 if (margins_set
&& exact
)
2558 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2559 dright
= pc
->custom_size
.right
- jobsize
.right
;
2560 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2561 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2563 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2564 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2570 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2571 pc
->custom_ppd_size
));
2573 return (pc
->custom_ppd_size
);
2577 * No custom page size support or the size is out of range - return NULL.
2580 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2587 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2590 pwg_size_t
* /* O - PWG size or NULL */
2592 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2593 const char *page_size
) /* I - PPD PageSize */
2595 int i
; /* Looping var */
2596 pwg_media_t
*media
; /* Media */
2597 pwg_size_t
*size
; /* Current size */
2601 * Range check input...
2604 if (!pc
|| !page_size
)
2607 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2610 * Custom size; size name can be one of the following:
2612 * Custom.WIDTHxLENGTHin - Size in inches
2613 * Custom.WIDTHxLENGTHft - Size in feet
2614 * Custom.WIDTHxLENGTHcm - Size in centimeters
2615 * Custom.WIDTHxLENGTHmm - Size in millimeters
2616 * Custom.WIDTHxLENGTHm - Size in meters
2617 * Custom.WIDTHxLENGTH[pt] - Size in points
2620 double w
, l
; /* Width and length of page */
2621 char *ptr
; /* Pointer into PageSize */
2622 struct lconv
*loc
; /* Locale data */
2625 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2626 if (!ptr
|| *ptr
!= 'x')
2629 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2633 if (!_cups_strcasecmp(ptr
, "in"))
2638 else if (!_cups_strcasecmp(ptr
, "ft"))
2643 else if (!_cups_strcasecmp(ptr
, "mm"))
2648 else if (!_cups_strcasecmp(ptr
, "cm"))
2653 else if (!_cups_strcasecmp(ptr
, "m"))
2664 pc
->custom_size
.width
= (int)w
;
2665 pc
->custom_size
.length
= (int)l
;
2667 return (&(pc
->custom_size
));
2671 * Not a custom size - look it up...
2674 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2675 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2676 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2680 * Look up standard sizes...
2683 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2684 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2685 media
= pwgMediaForPWG(page_size
);
2689 pc
->custom_size
.width
= media
->width
;
2690 pc
->custom_size
.length
= media
->length
;
2692 return (&(pc
->custom_size
));
2700 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2704 const char * /* O - PWG media-source keyword */
2706 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2707 const char *input_slot
) /* I - PPD InputSlot */
2709 int i
; /* Looping var */
2710 pwg_map_t
*source
; /* Current source */
2714 * Range check input...
2717 if (!pc
|| !input_slot
)
2720 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2721 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2722 return (source
->pwg
);
2729 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2733 const char * /* O - PWG media-type keyword */
2735 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2736 const char *media_type
) /* I - PPD MediaType */
2738 int i
; /* Looping var */
2739 pwg_map_t
*type
; /* Current type */
2743 * Range check input...
2746 if (!pc
|| !media_type
)
2749 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2750 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2758 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2761 int /* O - 1 on success, 0 on failure */
2763 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2764 const char *filename
, /* I - File to write */
2765 ipp_t
*attrs
) /* I - Attributes to write, if any */
2767 int i
, j
, k
; /* Looping vars */
2768 cups_file_t
*fp
; /* Output file */
2769 pwg_size_t
*size
; /* Current size */
2770 pwg_map_t
*map
; /* Current map */
2771 _pwg_finishings_t
*f
; /* Current finishing option */
2772 cups_option_t
*option
; /* Current option */
2773 const char *value
; /* String value */
2774 char newfile
[1024]; /* New filename */
2778 * Range check input...
2781 if (!pc
|| !filename
)
2783 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2788 * Open the file and write with compression...
2791 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2792 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2794 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2799 * Standard header...
2802 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2808 if (pc
->num_bins
> 0)
2810 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2811 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2812 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2819 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2820 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2821 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2822 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2823 size
->bottom
, size
->right
, size
->top
);
2824 if (pc
->custom_max_width
> 0)
2825 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2826 pc
->custom_max_width
, pc
->custom_max_length
,
2827 pc
->custom_min_width
, pc
->custom_min_length
,
2828 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2829 pc
->custom_size
.right
, pc
->custom_size
.top
);
2835 if (pc
->source_option
)
2836 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2838 if (pc
->num_sources
> 0)
2840 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2841 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2842 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2849 if (pc
->num_types
> 0)
2851 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2852 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2853 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2860 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2861 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2862 if (pc
->num_presets
[i
][j
])
2864 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2865 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2868 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2869 cupsFilePutChar(fp
, '\n');
2876 if (pc
->sides_option
)
2877 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2879 if (pc
->sides_1sided
)
2880 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2882 if (pc
->sides_2sided_long
)
2883 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2885 if (pc
->sides_2sided_short
)
2886 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2889 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2893 cupsFilePutConf(fp
, "Product", pc
->product
);
2895 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2897 value
= (const char *)cupsArrayNext(pc
->filters
))
2898 cupsFilePutConf(fp
, "Filter", value
);
2900 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2902 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2903 cupsFilePutConf(fp
, "PreFilter", value
);
2905 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2908 * Finishing options...
2911 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2913 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2915 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2916 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2917 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2918 cupsFilePutChar(fp
, '\n');
2921 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2922 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2928 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2931 * Accounting/quota/PIN/managed printing values...
2934 if (pc
->charge_info_uri
)
2935 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2937 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2938 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2939 pc
->accounting_user_id
? "true" : "false");
2942 cupsFilePutConf(fp
, "Password", pc
->password
);
2944 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2946 value
= (char *)cupsArrayNext(pc
->mandatory
))
2947 cupsFilePutConf(fp
, "Mandatory", value
);
2950 * (Remote) strings file...
2953 if (pc
->strings_uri
)
2954 cupsFilePutConf(fp
, "StringsURI", pc
->strings_uri
);
2960 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2962 value
= (char *)cupsArrayNext(pc
->support_files
))
2963 cupsFilePutConf(fp
, "SupportFile", value
);
2966 * IPP attributes, if any...
2971 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2973 attrs
->state
= IPP_STATE_IDLE
;
2974 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2978 * Close and return...
2981 if (cupsFileClose(fp
))
2988 return (!rename(newfile
, filename
));
2993 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2994 * of an IPP printer.
2997 char * /* O - PPD filename or @code NULL@ on error */
2998 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2999 size_t bufsize
, /* I - Size of filename buffer */
3000 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3002 cups_file_t
*fp
; /* PPD file */
3003 cups_array_t
*sizes
; /* Media sizes we've added */
3004 ipp_attribute_t
*attr
, /* xxx-supported */
3005 *defattr
, /* xxx-default */
3006 *quality
, /* print-quality-supported */
3007 *x_dim
, *y_dim
; /* Media dimensions */
3008 ipp_t
*media_size
; /* Media size collection */
3009 char make
[256], /* Make and model */
3010 *model
, /* Model name */
3011 ppdname
[PPD_MAX_NAME
];
3013 int i
, j
, /* Looping vars */
3014 count
, /* Number of values */
3015 bottom
, /* Largest bottom margin */
3016 left
, /* Largest left margin */
3017 right
, /* Largest right margin */
3018 top
, /* Largest top margin */
3019 is_apple
= 0, /* Does the printer support Apple raster? */
3020 is_pdf
= 0, /* Does the printer support PDF? */
3021 is_pwg
= 0; /* Does the printer support PWG Raster? */
3022 pwg_media_t
*pwg
; /* PWG media size */
3023 int xres
, yres
; /* Resolution values */
3024 int resolutions
[1000];
3025 /* Array of resolution indices */
3026 cups_lang_t
*lang
= cupsLangDefault();
3027 /* Localization info */
3028 cups_array_t
*strings
= NULL
;/* Printer strings file */
3029 struct lconv
*loc
= localeconv();
3031 cups_array_t
*fin_options
= NULL
;
3032 /* Finishing options */
3033 static const char * const finishings
[][2] =
3034 { /* Finishings strings */
3035 { "bale", _("Bale") },
3036 { "bind", _("Bind") },
3037 { "bind-bottom", _("Bind (Reverse Landscape)") },
3038 { "bind-left", _("Bind (Portrait)") },
3039 { "bind-right", _("Bind (Reverse Portrait)") },
3040 { "bind-top", _("Bind (Landscape)") },
3041 { "booklet-maker", _("Booklet Maker") },
3042 { "coat", _("Coat") },
3043 { "cover", _("Cover") },
3044 { "edge-stitch", _("Staple Edge") },
3045 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
3046 { "edge-stitch-left", _("Staple Edge (Portrait)") },
3047 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
3048 { "edge-stitch-top", _("Staple Edge (Landscape)") },
3049 { "fold", _("Fold") },
3050 { "fold-accordian", _("Accordian Fold") },
3051 { "fold-double-gate", _("Double Gate Fold") },
3052 { "fold-engineering-z", _("Engineering Z Fold") },
3053 { "fold-gate", _("Gate Fold") },
3054 { "fold-half", _("Half Fold") },
3055 { "fold-half-z", _("Half Z Fold") },
3056 { "fold-left-gate", _("Left Gate Fold") },
3057 { "fold-letter", _("Letter Fold") },
3058 { "fold-parallel", _("Parallel Fold") },
3059 { "fold-poster", _("Poster Fold") },
3060 { "fold-right-gate", _("Right Gate Fold") },
3061 { "fold-z", _("Z Fold") },
3062 { "jog-offset", _("Jog") },
3063 { "laminate", _("Laminate") },
3064 { "punch", _("Punch") },
3065 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3066 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3067 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3068 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3069 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3070 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3071 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3072 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3073 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3074 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3075 { "punch-top-left", _("Single Punch (Portrait)") },
3076 { "punch-top-right", _("Single Punch (Landscape)") },
3077 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3078 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3079 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3080 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3081 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3082 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3083 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3084 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3085 { "saddle-stitch", _("Saddle Stitch") },
3086 { "staple", _("Staple") },
3087 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3088 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3089 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3090 { "staple-dual-left", _("Double Staple (Portrait)") },
3091 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3092 { "staple-dual-top", _("Double Staple (Landscape)") },
3093 { "staple-top-left", _("Single Staple (Portrait)") },
3094 { "staple-top-right", _("Single Staple (Landscape)") },
3095 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3096 { "staple-triple-left", _("Triple Staple (Portrait)") },
3097 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3098 { "staple-triple-top", _("Triple Staple (Landscape)") },
3099 { "trim", _("Cut Media") }
3104 * Range check input...
3110 if (!buffer
|| bufsize
< 1)
3112 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3118 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3123 * Open a temporary file for the PPD...
3126 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3128 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3133 * Standard stuff for PPD file...
3136 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3137 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3138 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3139 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3140 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3141 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3142 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3143 cupsFilePuts(fp
, "*FileSystem: False\n");
3144 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3146 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3147 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3149 strlcpy(make
, "Unknown Printer", sizeof(make
));
3151 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3152 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3155 strlcpy(make
, "HP", sizeof(make
));
3157 else if ((model
= strchr(make
, ' ')) != NULL
)
3162 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3163 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3164 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3165 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3166 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3168 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3169 cupsFilePuts(fp
, "*ColorDevice: True\n");
3171 cupsFilePuts(fp
, "*ColorDevice: False\n");
3173 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3174 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3175 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3177 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3178 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3180 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3181 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3183 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3185 http_t
*http
= NULL
; /* Connection to printer */
3186 char stringsfile
[1024]; /* Temporary strings file */
3188 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3190 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3192 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3194 unlink(stringsfile
);
3205 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3207 is_apple
= ippContainsString(attr
, "image/urf");
3208 is_pdf
= ippContainsString(attr
, "application/pdf");
3209 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3211 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3213 const char *format
= ippGetString(attr
, i
, NULL
);
3217 * Write cupsFilter2 lines for supported formats...
3220 if (!_cups_strcasecmp(format
, "application/pdf"))
3221 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3222 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3223 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3224 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3225 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3229 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3233 * PageSize/PageRegion/ImageableArea/PaperDimension
3236 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3238 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3239 if (ippGetInteger(attr
, i
) > bottom
)
3240 bottom
= ippGetInteger(attr
, i
);
3245 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3247 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3248 if (ippGetInteger(attr
, i
) > left
)
3249 left
= ippGetInteger(attr
, i
);
3254 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3256 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3257 if (ippGetInteger(attr
, i
) > right
)
3258 right
= ippGetInteger(attr
, i
);
3263 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3265 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3266 if (ippGetInteger(attr
, i
) > top
)
3267 top
= ippGetInteger(attr
, i
);
3272 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3274 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3276 media_size
= ippGetCollection(attr
, 0);
3277 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3278 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3280 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3281 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3283 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3286 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3288 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3289 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3291 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3293 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3294 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3297 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3298 "*OrderDependency: 10 AnySetup *PageSize\n"
3299 "*DefaultPageSize: %s\n", ppdname
);
3301 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3303 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3305 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3307 media_size
= ippGetCollection(attr
, i
);
3308 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3309 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3311 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3314 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3318 char twidth
[256], /* Width string */
3319 tlength
[256]; /* Length string */
3321 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3323 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3327 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3329 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3330 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3332 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3335 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3337 cupsArrayDelete(sizes
);
3338 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3340 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3341 "*OrderDependency: 10 AnySetup *PageRegion\n"
3342 "*DefaultPageRegion: %s\n", ppdname
);
3343 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3345 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3347 media_size
= ippGetCollection(attr
, i
);
3348 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3349 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3351 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3354 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3358 char twidth
[256], /* Width string */
3359 tlength
[256]; /* Length string */
3361 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3364 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3366 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3367 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3369 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3372 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3374 cupsArrayDelete(sizes
);
3375 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3377 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3378 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3379 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3381 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3383 media_size
= ippGetCollection(attr
, i
);
3384 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3385 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3387 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3390 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3394 char tleft
[256], /* Left string */
3395 tbottom
[256], /* Bottom string */
3396 tright
[256], /* Right string */
3397 ttop
[256], /* Top string */
3398 twidth
[256], /* Width string */
3399 tlength
[256]; /* Length string */
3401 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3404 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3406 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3407 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3408 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3409 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3410 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3411 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3413 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3414 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3418 cupsArrayDelete(sizes
);
3427 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3428 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3430 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3432 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3434 static const char * const sources
[][2] =
3435 { /* "media-source" strings */
3436 { "Auto", _("Automatic") },
3437 { "Main", _("Main") },
3438 { "Alternate", _("Alternate") },
3439 { "LargeCapacity", _("Large Capacity") },
3440 { "Manual", _("Manual") },
3441 { "Envelope", _("Envelope") },
3442 { "Disc", _("Disc") },
3443 { "Photo", _("Photo") },
3444 { "Hagaki", _("Hagaki") },
3445 { "MainRoll", _("Main Roll") },
3446 { "AlternateRoll", _("Alternate Roll") },
3447 { "Top", _("Top") },
3448 { "Middle", _("Middle") },
3449 { "Bottom", _("Bottom") },
3450 { "Side", _("Side") },
3451 { "Left", _("Left") },
3452 { "Right", _("Right") },
3453 { "Center", _("Center") },
3454 { "Rear", _("Rear") },
3455 { "ByPassTray", _("Multipurpose") },
3456 { "Tray1", _("Tray 1") },
3457 { "Tray2", _("Tray 2") },
3458 { "Tray3", _("Tray 3") },
3459 { "Tray4", _("Tray 4") },
3460 { "Tray5", _("Tray 5") },
3461 { "Tray6", _("Tray 6") },
3462 { "Tray7", _("Tray 7") },
3463 { "Tray8", _("Tray 8") },
3464 { "Tray9", _("Tray 9") },
3465 { "Tray10", _("Tray 10") },
3466 { "Tray11", _("Tray 11") },
3467 { "Tray12", _("Tray 12") },
3468 { "Tray13", _("Tray 13") },
3469 { "Tray14", _("Tray 14") },
3470 { "Tray15", _("Tray 15") },
3471 { "Tray16", _("Tray 16") },
3472 { "Tray17", _("Tray 17") },
3473 { "Tray18", _("Tray 18") },
3474 { "Tray19", _("Tray 19") },
3475 { "Tray20", _("Tray 20") },
3476 { "Roll1", _("Roll 1") },
3477 { "Roll2", _("Roll 2") },
3478 { "Roll3", _("Roll 3") },
3479 { "Roll4", _("Roll 4") },
3480 { "Roll5", _("Roll 5") },
3481 { "Roll6", _("Roll 6") },
3482 { "Roll7", _("Roll 7") },
3483 { "Roll8", _("Roll 8") },
3484 { "Roll9", _("Roll 9") },
3485 { "Roll10", _("Roll 10") }
3488 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3489 "*OrderDependency: 10 AnySetup *InputSlot\n"
3490 "*DefaultInputSlot: %s\n", ppdname
);
3491 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3493 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3495 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3496 if (!strcmp(sources
[j
][0], ppdname
))
3498 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3502 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3509 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3510 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3512 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3514 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3516 static const char * const media_types
[][2] =
3517 { /* "media-type" strings */
3518 { "aluminum", _("Aluminum") },
3519 { "auto", _("Automatic") },
3520 { "back-print-film", _("Back Print Film") },
3521 { "cardboard", _("Cardboard") },
3522 { "cardstock", _("Cardstock") },
3524 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3525 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3526 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3527 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3528 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3529 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3530 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3531 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3532 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3533 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3534 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3535 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3536 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3537 { "continuous", _("Continuous") },
3538 { "continuous-long", _("Continuous Long") },
3539 { "continuous-short", _("Continuous Short") },
3540 { "disc", _("Optical Disc") },
3541 { "disc-glossy", _("Glossy Optical Disc") },
3542 { "disc-high-gloss", _("High Gloss Optical Disc") },
3543 { "disc-matte", _("Matte Optical Disc") },
3544 { "disc-satin", _("Satin Optical Disc") },
3545 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3546 { "double-wall", _("Double Wall Cardboard") },
3547 { "dry-film", _("Dry Film") },
3548 { "dvd", _("DVD") },
3549 { "embossing-foil", _("Embossing Foil") },
3550 { "end-board", _("End Board") },
3551 { "envelope", _("Envelope") },
3552 { "envelope-archival", _("Archival Envelope") },
3553 { "envelope-bond", _("Bond Envelope") },
3554 { "envelope-coated", _("Coated Envelope") },
3555 { "envelope-cotton", _("Cotton Envelope") },
3556 { "envelope-fine", _("Fine Envelope") },
3557 { "envelope-heavyweight", _("Heavyweight Envelope") },
3558 { "envelope-inkjet", _("Inkjet Envelope") },
3559 { "envelope-lightweight", _("Lightweight Envelope") },
3560 { "envelope-plain", _("Plain Envelope") },
3561 { "envelope-preprinted", _("Preprinted Envelope") },
3562 { "envelope-window", _("Windowed Envelope") },
3563 { "fabric", _("Fabric") },
3564 { "fabric-archival", _("Archival Fabric") },
3565 { "fabric-glossy", _("Glossy Fabric") },
3566 { "fabric-high-gloss", _("High Gloss Fabric") },
3567 { "fabric-matte", _("Matte Fabric") },
3568 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3569 { "fabric-waterproof", _("Waterproof Fabric") },
3570 { "film", _("Film") },
3571 { "flexo-base", _("Flexo Base") },
3572 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3573 { "flute", _("Flute") },
3574 { "foil", _("Foil") },
3575 { "full-cut-tabs", _("Full Cut Tabs") },
3576 { "glass", _("Glass") },
3577 { "glass-colored", _("Glass Colored") },
3578 { "glass-opaque", _("Glass Opaque") },
3579 { "glass-surfaced", _("Glass Surfaced") },
3580 { "glass-textured", _("Glass Textured") },
3581 { "gravure-cylinder", _("Gravure Cylinder") },
3582 { "image-setter-paper", _("Image Setter Paper") },
3583 { "imaging-cylinder", _("Imaging Cylinder") },
3584 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3585 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3586 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3587 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3588 { "labels", _("Labels") },
3589 { "labels-colored", _("Colored Labels") },
3590 { "labels-glossy", _("Glossy Labels") },
3591 { "labels-high-gloss", _("High Gloss Labels") },
3592 { "labels-inkjet", _("Inkjet Labels") },
3593 { "labels-matte", _("Matte Labels") },
3594 { "labels-permanent", _("Permanent Labels") },
3595 { "labels-satin", _("Satin Labels") },
3596 { "labels-security", _("Security Labels") },
3597 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3598 { "laminating-foil", _("Laminating Foil") },
3599 { "letterhead", _("Letterhead") },
3600 { "metal", _("Metal") },
3601 { "metal-glossy", _("Metal Glossy") },
3602 { "metal-high-gloss", _("Metal High Gloss") },
3603 { "metal-matte", _("Metal Matte") },
3604 { "metal-satin", _("Metal Satin") },
3605 { "metal-semi-gloss", _("Metal Semi Gloss") },
3606 { "mounting-tape", _("Mounting Tape") },
3607 { "multi-layer", _("Multi Layer") },
3608 { "multi-part-form", _("Multi Part Form") },
3609 { "other", _("Other") },
3610 { "paper", _("Paper") },
3611 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3612 { "photographic", _("Photo Paper") },
3613 { "photographic-archival", _("Archival Photo Paper") },
3614 { "photographic-film", _("Photo Film") },
3615 { "photographic-glossy", _("Glossy Photo Paper") },
3616 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3617 { "photographic-matte", _("Matte Photo Paper") },
3618 { "photographic-satin", _("Satin Photo Paper") },
3619 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3620 { "plastic", _("Plastic") },
3621 { "plastic-archival", _("Plastic Archival") },
3622 { "plastic-colored", _("Plastic Colored") },
3623 { "plastic-glossy", _("Plastic Glossy") },
3624 { "plastic-high-gloss", _("Plastic High Gloss") },
3625 { "plastic-matte", _("Plastic Matte") },
3626 { "plastic-satin", _("Plastic Satin") },
3627 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3628 { "plate", _("Plate") },
3629 { "polyester", _("Polyester") },
3630 { "pre-cut-tabs", _("Pre Cut Tabs") },
3631 { "roll", _("Roll") },
3632 { "screen", _("Screen") },
3633 { "screen-paged", _("Screen Paged") },
3634 { "self-adhesive", _("Self Adhesive") },
3635 { "self-adhesive-film", _("Self Adhesive Film") },
3636 { "shrink-foil", _("Shrink Foil") },
3637 { "single-face", _("Single Face") },
3638 { "single-wall", _("Single Wall Cardboard") },
3639 { "sleeve", _("Sleeve") },
3640 { "stationery", _("Plain Paper") },
3641 { "stationery-archival", _("Archival Paper") },
3642 { "stationery-coated", _("Coated Paper") },
3643 { "stationery-cotton", _("Cotton Paper") },
3644 { "stationery-fine", _("Vellum Paper") },
3645 { "stationery-heavyweight", _("Heavyweight Paper") },
3646 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3647 { "stationery-inkjet", _("Inkjet Paper") },
3648 { "stationery-letterhead", _("Letterhead") },
3649 { "stationery-lightweight", _("Lightweight Paper") },
3650 { "stationery-preprinted", _("Preprinted Paper") },
3651 { "stationery-prepunched", _("Punched Paper") },
3652 { "tab-stock", _("Tab Stock") },
3653 { "tractor", _("Tractor") },
3654 { "transfer", _("Transfer") },
3655 { "transparency", _("Transparency") },
3656 { "triple-wall", _("Triple Wall Cardboard") },
3657 { "wet-film", _("Wet Film") }
3660 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3661 "*OrderDependency: 10 AnySetup *MediaType\n"
3662 "*DefaultMediaType: %s\n", ppdname
);
3663 for (i
= 0; i
< count
; i
++)
3665 const char *keyword
= ippGetString(attr
, i
, NULL
);
3667 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3669 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3670 if (!strcmp(keyword
, media_types
[j
][0]))
3673 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3674 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3677 char msg
[256]; /* Message key */
3678 const char *str
; /* Localized string */
3680 snprintf(msg
, sizeof(msg
), "media-type.%s", keyword
);
3681 if ((str
= _cupsMessageLookup(strings
, msg
)) == msg
)
3684 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, str
, ppdname
);
3687 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3694 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3695 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3696 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3697 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3701 const char *default_color
= NULL
; /* Default */
3703 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3705 const char *keyword
= ippGetString(attr
, i
, NULL
);
3706 /* Keyword for color/bit depth */
3708 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3711 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3712 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3714 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3717 default_color
= "FastGray";
3719 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3722 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3723 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3725 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3727 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3728 default_color
= "Gray";
3730 else if (!strcasecmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3733 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3734 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3736 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3738 default_color
= "RGB";
3740 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3743 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3744 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3746 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3749 default_color
= "AdobeRGB";
3755 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3756 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3764 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3766 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3767 "*OrderDependency: 10 AnySetup *Duplex\n"
3768 "*DefaultDuplex: None\n"
3769 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3770 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3771 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3772 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3774 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3776 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3778 const char *dm
= ippGetString(attr
, i
, NULL
);
3781 if (!_cups_strcasecmp(dm
, "DM1"))
3783 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3786 else if (!_cups_strcasecmp(dm
, "DM2"))
3788 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3791 else if (!_cups_strcasecmp(dm
, "DM3"))
3793 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3796 else if (!_cups_strcasecmp(dm
, "DM4"))
3798 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3803 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3805 const char *keyword
= ippGetString(attr
, 0, NULL
);
3808 if (!strcmp(keyword
, "flipped"))
3809 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3810 else if (!strcmp(keyword
, "manual-tumble"))
3811 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3812 else if (!strcmp(keyword
, "normal"))
3813 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3815 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3823 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3824 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3826 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3828 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3830 static const char * const output_bins
[][2] =
3831 { /* "output-bin" strings */
3832 { "auto", _("Automatic") },
3833 { "bottom", _("Bottom Tray") },
3834 { "center", _("Center Tray") },
3835 { "face-down", _("Face Down") },
3836 { "face-up", _("Face Up") },
3837 { "large-capacity", _("Large Capacity Tray") },
3838 { "left", _("Left Tray") },
3839 { "mailbox-1", _("Mailbox 1") },
3840 { "mailbox-2", _("Mailbox 2") },
3841 { "mailbox-3", _("Mailbox 3") },
3842 { "mailbox-4", _("Mailbox 4") },
3843 { "mailbox-5", _("Mailbox 5") },
3844 { "mailbox-6", _("Mailbox 6") },
3845 { "mailbox-7", _("Mailbox 7") },
3846 { "mailbox-8", _("Mailbox 8") },
3847 { "mailbox-9", _("Mailbox 9") },
3848 { "mailbox-10", _("Mailbox 10") },
3849 { "middle", _("Middle") },
3850 { "my-mailbox", _("My Mailbox") },
3851 { "rear", _("Rear Tray") },
3852 { "right", _("Right Tray") },
3853 { "side", _("Side Tray") },
3854 { "stacker-1", _("Stacker 1") },
3855 { "stacker-2", _("Stacker 2") },
3856 { "stacker-3", _("Stacker 3") },
3857 { "stacker-4", _("Stacker 4") },
3858 { "stacker-5", _("Stacker 5") },
3859 { "stacker-6", _("Stacker 6") },
3860 { "stacker-7", _("Stacker 7") },
3861 { "stacker-8", _("Stacker 8") },
3862 { "stacker-9", _("Stacker 9") },
3863 { "stacker-10", _("Stacker 10") },
3864 { "top", _("Top Tray") },
3865 { "tray-1", _("Tray 1") },
3866 { "tray-2", _("Tray 2") },
3867 { "tray-3", _("Tray 3") },
3868 { "tray-4", _("Tray 4") },
3869 { "tray-5", _("Tray 5") },
3870 { "tray-6", _("Tray 6") },
3871 { "tray-7", _("Tray 7") },
3872 { "tray-8", _("Tray 8") },
3873 { "tray-9", _("Tray 9") },
3874 { "tray-10", _("Tray 10") }
3877 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3878 "*OrderDependency: 10 AnySetup *OutputBin\n"
3879 "*DefaultOutputBin: %s\n", ppdname
);
3880 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3882 if (!ippContainsString(attr
, output_bins
[i
][0]))
3885 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3887 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3889 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3893 * Finishing options...
3896 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3898 const char *name
; /* String name */
3899 int value
; /* Enum value */
3900 cups_array_t
*names
; /* Names we've added */
3902 count
= ippGetCount(attr
);
3903 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3904 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3907 * Staple/Bind/Stitch
3910 for (i
= 0; i
< count
; i
++)
3912 value
= ippGetInteger(attr
, i
);
3913 name
= ippEnumString("finishings", value
);
3915 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3921 cupsArrayAdd(fin_options
, "*StapleLocation");
3923 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3924 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3925 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3926 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3928 for (; i
< count
; i
++)
3930 value
= ippGetInteger(attr
, i
);
3931 name
= ippEnumString("finishings", value
);
3933 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3936 if (cupsArrayFind(names
, (char *)name
))
3937 continue; /* Already did this finishing template */
3939 cupsArrayAdd(names
, (char *)name
);
3941 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3943 if (!strcmp(finishings
[j
][0], name
))
3945 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3946 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3952 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3959 for (i
= 0; i
< count
; i
++)
3961 value
= ippGetInteger(attr
, i
);
3962 name
= ippEnumString("finishings", value
);
3964 if (!strncmp(name
, "fold-", 5))
3970 cupsArrayAdd(fin_options
, "*FoldType");
3972 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3973 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3974 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3975 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3977 for (; i
< count
; i
++)
3979 value
= ippGetInteger(attr
, i
);
3980 name
= ippEnumString("finishings", value
);
3982 if (strncmp(name
, "fold-", 5))
3985 if (cupsArrayFind(names
, (char *)name
))
3986 continue; /* Already did this finishing template */
3988 cupsArrayAdd(names
, (char *)name
);
3990 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3992 if (!strcmp(finishings
[j
][0], name
))
3994 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3995 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
4001 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4008 for (i
= 0; i
< count
; i
++)
4010 value
= ippGetInteger(attr
, i
);
4011 name
= ippEnumString("finishings", value
);
4013 if (!strncmp(name
, "punch-", 6))
4019 cupsArrayAdd(fin_options
, "*PunchMedia");
4021 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
4022 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4023 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4024 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4026 for (i
= 0; i
< count
; i
++)
4028 value
= ippGetInteger(attr
, i
);
4029 name
= ippEnumString("finishings", value
);
4031 if (strncmp(name
, "punch-", 6))
4034 if (cupsArrayFind(names
, (char *)name
))
4035 continue; /* Already did this finishing template */
4037 cupsArrayAdd(names
, (char *)name
);
4039 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
4041 if (!strcmp(finishings
[j
][0], name
))
4043 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
4044 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
4050 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4057 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4059 cupsArrayAdd(fin_options
, "*Booklet");
4061 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
4062 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4063 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4064 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4065 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4066 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4067 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4070 cupsArrayDelete(names
);
4073 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4075 ipp_t
*finishing_col
; /* Current finishing collection */
4076 const char *template, /* Current finishing template */
4077 *loctemplate
; /* Localized template name */
4078 cups_array_t
*templates
; /* Finishing templates */
4080 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickOne\n", _cupsLangString(lang
, _("Finishing Preset")));
4081 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4082 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4083 cupsFilePrintf(fp
, "*cupsFinishingTemplate none/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4085 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4086 count
= ippGetCount(attr
);
4088 for (i
= 0; i
< count
; i
++)
4090 finishing_col
= ippGetCollection(attr
, i
);
4091 template = ippGetString(ippFindAttribute(finishing_col
, "finishing_template", IPP_TAG_ZERO
), 0, NULL
);
4093 if (!template || cupsArrayFind(templates
, (void *)template))
4096 if (strncmp(template, "fold-", 5) && (strstr(template, "-bottom") || strstr(template, "-left") || strstr(template, "-right") || strstr(template, "-top")))
4099 cupsArrayAdd(templates
, (void *)template);
4101 for (j
= 0, loctemplate
= NULL
; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
4103 if (!strcmp(finishings
[j
][0], template))
4105 loctemplate
= _cupsLangString(lang
, finishings
[j
][1]);
4112 char msg
[256]; /* Message key */
4114 snprintf(msg
, sizeof(msg
), "finishing-template.%s", template);
4115 if ((loctemplate
= _cupsMessageLookup(strings
, msg
)) == msg
)
4116 loctemplate
= template;
4119 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", template, loctemplate
);
4122 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4124 if (cupsArrayCount(fin_options
))
4126 const char *fin_option
; /* Current finishing option */
4128 cupsFilePuts(fp
, "*cupsUIConstraint finisings: \"*cupsFinishingTemplate");
4129 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4130 cupsFilePrintf(fp
, " %s", fin_option
);
4131 cupsFilePuts(fp
, "\"\n");
4133 cupsFilePuts(fp
, "*cupsUIResolver finisings: \"*cupsFinishingTemplate None");
4134 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4135 cupsFilePrintf(fp
, " %s None", fin_option
);
4136 cupsFilePuts(fp
, "\"\n");
4139 cupsArrayDelete(templates
);
4142 cupsArrayDelete(fin_options
);
4145 * cupsPrintQuality and DefaultResolution...
4148 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4150 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4152 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4154 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4156 const char *rs
= ippGetString(attr
, i
, NULL
);
4159 if (_cups_strncasecmp(rs
, "RS", 2))
4162 lowdpi
= atoi(rs
+ 2);
4163 if ((rs
= strrchr(rs
, '-')) != NULL
)
4164 hidpi
= atoi(rs
+ 1);
4173 * Invalid "urf-supported" value...
4181 * Generate print qualities based on low and high DPIs...
4184 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4186 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4187 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4188 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4189 if ((lowdpi
& 1) == 0)
4190 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4191 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4192 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4193 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4194 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4195 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4196 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4199 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4202 * Make a sorted list of resolutions.
4205 count
= ippGetCount(attr
);
4206 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4207 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4209 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4210 for (i
= 1; i
< count
; i
++)
4213 for (i
= 0; i
< (count
- 1); i
++)
4215 for (j
= i
+ 1; j
< count
; j
++)
4217 int ix
, iy
, /* First X and Y resolution */
4218 jx
, jy
, /* Second X and Y resolution */
4219 temp
; /* Swap variable */
4220 ipp_res_t units
; /* Resolution units */
4222 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4223 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4225 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4228 * Swap these two resolutions...
4231 temp
= resolutions
[i
];
4232 resolutions
[i
] = resolutions
[j
];
4233 resolutions
[j
] = temp
;
4239 * Generate print quality options...
4242 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4243 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4245 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4246 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4247 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4248 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4250 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4251 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4253 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4254 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4255 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4257 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4258 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4261 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4263 else if (is_apple
|| is_pwg
)
4267 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4269 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4274 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4277 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4279 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4280 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4281 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4282 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4283 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4284 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4285 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4286 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4287 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4291 * Close up and return...
4299 * If we get here then there was a problem creating the PPD...
4308 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4315 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4319 const char * /* O - InputSlot name */
4320 _pwgInputSlotForSource(
4321 const char *media_source
, /* I - PWG media-source */
4322 char *name
, /* I - Name buffer */
4323 size_t namesize
) /* I - Size of name buffer */
4326 * Range check input...
4329 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4332 if (_cups_strcasecmp(media_source
, "main"))
4333 strlcpy(name
, "Cassette", namesize
);
4334 else if (_cups_strcasecmp(media_source
, "alternate"))
4335 strlcpy(name
, "Multipurpose", namesize
);
4336 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4337 strlcpy(name
, "LargeCapacity", namesize
);
4338 else if (_cups_strcasecmp(media_source
, "bottom"))
4339 strlcpy(name
, "Lower", namesize
);
4340 else if (_cups_strcasecmp(media_source
, "middle"))
4341 strlcpy(name
, "Middle", namesize
);
4342 else if (_cups_strcasecmp(media_source
, "top"))
4343 strlcpy(name
, "Upper", namesize
);
4344 else if (_cups_strcasecmp(media_source
, "rear"))
4345 strlcpy(name
, "Rear", namesize
);
4346 else if (_cups_strcasecmp(media_source
, "side"))
4347 strlcpy(name
, "Side", namesize
);
4348 else if (_cups_strcasecmp(media_source
, "envelope"))
4349 strlcpy(name
, "Envelope", namesize
);
4350 else if (_cups_strcasecmp(media_source
, "main-roll"))
4351 strlcpy(name
, "Roll", namesize
);
4352 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4353 strlcpy(name
, "Roll2", namesize
);
4355 pwg_ppdize_name(media_source
, name
, namesize
);
4362 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4366 const char * /* O - MediaType name */
4367 _pwgMediaTypeForType(
4368 const char *media_type
, /* I - PWG media-type */
4369 char *name
, /* I - Name buffer */
4370 size_t namesize
) /* I - Size of name buffer */
4373 * Range check input...
4376 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4379 if (_cups_strcasecmp(media_type
, "auto"))
4380 strlcpy(name
, "Auto", namesize
);
4381 else if (_cups_strcasecmp(media_type
, "cardstock"))
4382 strlcpy(name
, "Cardstock", namesize
);
4383 else if (_cups_strcasecmp(media_type
, "envelope"))
4384 strlcpy(name
, "Envelope", namesize
);
4385 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4386 strlcpy(name
, "Glossy", namesize
);
4387 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4388 strlcpy(name
, "HighGloss", namesize
);
4389 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4390 strlcpy(name
, "Matte", namesize
);
4391 else if (_cups_strcasecmp(media_type
, "stationery"))
4392 strlcpy(name
, "Plain", namesize
);
4393 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4394 strlcpy(name
, "Coated", namesize
);
4395 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4396 strlcpy(name
, "Inkjet", namesize
);
4397 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4398 strlcpy(name
, "Letterhead", namesize
);
4399 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4400 strlcpy(name
, "Preprinted", namesize
);
4401 else if (_cups_strcasecmp(media_type
, "transparency"))
4402 strlcpy(name
, "Transparency", namesize
);
4404 pwg_ppdize_name(media_type
, name
, namesize
);
4411 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4414 const char * /* O - PageSize name */
4415 _pwgPageSizeForMedia(
4416 pwg_media_t
*media
, /* I - Media */
4417 char *name
, /* I - PageSize name buffer */
4418 size_t namesize
) /* I - Size of name buffer */
4420 const char *sizeptr
, /* Pointer to size in PWG name */
4421 *dimptr
; /* Pointer to dimensions in PWG name */
4425 * Range check input...
4428 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4432 * Copy or generate a PageSize name...
4438 * Use a standard Adobe name...
4441 strlcpy(name
, media
->ppd
, namesize
);
4443 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4444 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4445 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4446 (size_t)(dimptr
- sizeptr
) > namesize
)
4449 * Use a name of the form "wNNNhNNN"...
4452 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4453 (int)PWG_TO_POINTS(media
->length
));
4458 * Copy the size name from class_sizename_dimensions...
4461 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4462 name
[dimptr
- sizeptr
- 1] = '\0';
4470 * 'cups_get_url()' - Get a copy of the file at the given URL.
4473 static int /* O - 1 on success, 0 on failure */
4474 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4475 const char *url
, /* I - URL to get */
4476 char *name
, /* I - Temporary filename */
4477 size_t namesize
) /* I - Size of temporary filename buffer */
4479 char scheme
[32], /* URL scheme */
4480 userpass
[256], /* URL username:password */
4481 host
[256], /* URL host */
4482 curhost
[256], /* Current host */
4483 resource
[256]; /* URL resource */
4484 int port
; /* URL port */
4485 http_encryption_t encryption
; /* Type of encryption to use */
4486 http_status_t status
; /* Status of GET request */
4487 int fd
; /* Temporary file */
4490 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4493 if (port
== 443 || !strcmp(scheme
, "https"))
4494 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4496 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4498 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4501 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4507 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4510 status
= cupsGetFd(*http
, resource
, fd
);
4514 if (status
!= HTTP_STATUS_OK
)
4526 * 'pwg_add_finishing()' - Add a finishings value.
4531 cups_array_t
*finishings
, /* I - Finishings array */
4532 ipp_finishings_t
template, /* I - Finishing template */
4533 const char *name
, /* I - PPD option */
4534 const char *value
) /* I - PPD choice */
4536 _pwg_finishings_t
*f
; /* New finishings value */
4539 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4541 f
->value
= template;
4542 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4544 cupsArrayAdd(finishings
, f
);
4550 * 'pwg_compare_finishings()' - Compare two finishings values.
4553 static int /* O - Result of comparison */
4554 pwg_compare_finishings(
4555 _pwg_finishings_t
*a
, /* I - First finishings value */
4556 _pwg_finishings_t
*b
) /* I - Second finishings value */
4558 return ((int)b
->value
- (int)a
->value
);
4563 * 'pwg_free_finishings()' - Free a finishings value.
4567 pwg_free_finishings(
4568 _pwg_finishings_t
*f
) /* I - Finishings value */
4570 cupsFreeOptions(f
->num_options
, f
->options
);
4576 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4580 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4581 char *name
, /* I - Name buffer */
4582 size_t namesize
) /* I - Size of name buffer */
4584 char *ptr
, /* Pointer into name buffer */
4585 *end
; /* End of name buffer */
4594 *name
= (char)toupper(*ipp
++);
4596 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4598 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4601 *ptr
++ = (char)toupper(*ipp
++ & 255);
4612 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4616 pwg_ppdize_resolution(
4617 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4618 int element
, /* I - Element to convert */
4619 int *xres
, /* O - X resolution in DPI */
4620 int *yres
, /* O - Y resolution in DPI */
4621 char *name
, /* I - Name buffer */
4622 size_t namesize
) /* I - Size of name buffer */
4624 ipp_res_t units
; /* Units for resolution */
4627 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4629 if (units
== IPP_RES_PER_CM
)
4631 *xres
= (int)(*xres
* 2.54);
4632 *yres
= (int)(*yres
* 2.54);
4635 if (name
&& namesize
> 4)
4638 snprintf(name
, namesize
, "%ddpi", *xres
);
4640 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4646 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4650 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4651 char *name
, /* I - Name buffer */
4652 size_t namesize
, /* I - Size of name buffer */
4653 const char *dashchars
)/* I - Characters to be replaced by dashes */
4655 char *ptr
, /* Pointer into name buffer */
4656 *end
; /* End of name buffer */
4659 if (_cups_islower(*ppd
))
4662 * Already lowercase name, use as-is?
4665 const char *ppdptr
; /* Pointer into PPD keyword */
4667 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4668 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4673 strlcpy(name
, ppd
, namesize
);
4678 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4680 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4681 *ptr
++ = (char)tolower(*ppd
& 255);
4682 else if (strchr(dashchars
, *ppd
))
4687 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4688 _cups_isupper(ppd
[1]) && ptr
< end
)
4690 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))