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 int num_finishings
= 0, /* Number of finishing values */
74 finishings
[10]; /* Finishing enum values */
75 ppd_choice_t
*choice
; /* Marked choice */
76 int finishings_copies
= copies
;
77 /* Number of copies for finishings */
81 * Send standard IPP attributes...
84 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
86 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
88 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
91 if (!strcmp(keyword
, "none"))
94 * Add plain-text job-password...
97 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
102 * Add hashed job-password...
105 unsigned char hash
[64]; /* Hash of password */
106 ssize_t hashlen
; /* Length of hash */
108 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
109 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
113 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
118 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
119 keyword
= cupsGetOption("job-billing", num_options
, options
);
122 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
125 if (pc
->accounting_user_id
)
127 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
131 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
134 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
136 if (strcmp(mandatory
, "copies") &&
137 strcmp(mandatory
, "destination-uris") &&
138 strcmp(mandatory
, "finishings") &&
139 strcmp(mandatory
, "job-account-id") &&
140 strcmp(mandatory
, "job-accounting-user-id") &&
141 strcmp(mandatory
, "job-password") &&
142 strcmp(mandatory
, "job-password-encryption") &&
143 strcmp(mandatory
, "media") &&
144 strncmp(mandatory
, "media-col", 9) &&
145 strcmp(mandatory
, "multiple-document-handling") &&
146 strcmp(mandatory
, "output-bin") &&
147 strcmp(mandatory
, "print-color-mode") &&
148 strcmp(mandatory
, "print-quality") &&
149 strcmp(mandatory
, "sides") &&
150 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
152 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
154 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
159 case IPP_TAG_INTEGER
:
161 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
163 case IPP_TAG_BOOLEAN
:
164 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
168 int lower
, upper
; /* Range */
170 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
171 lower
= upper
= atoi(keyword
);
173 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
176 case IPP_TAG_STRING
:
177 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
180 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
182 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
183 keyword
= "auto-monochrome";
184 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
185 keyword
= "process-monochrome";
188 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
194 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
195 keyword
= cupsGetOption("media", num_options
, options
);
197 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
198 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
199 size
= _ppdCacheGetSize(pc
, keyword
);
201 if (size
|| media_source
|| media_type
)
204 * Add a media-col value...
207 media_col
= ippNew();
211 media_size
= ippNew();
212 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
213 "x-dimension", size
->width
);
214 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
215 "y-dimension", size
->length
);
217 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
220 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
222 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
223 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
224 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
225 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
226 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
227 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
228 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
229 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
230 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
231 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
232 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
233 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
236 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
239 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
241 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
242 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
246 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
248 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
250 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
252 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
254 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
255 keyword
= "monochrome";
261 if (keyword
&& !strcmp(keyword
, "monochrome"))
263 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
264 keyword
= "auto-monochrome";
265 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
266 keyword
= "process-monochrome";
270 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
272 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
273 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
274 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
276 if (!_cups_strcasecmp(choice
->choice
, "draft"))
277 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
278 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
279 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
280 else if (!_cups_strcasecmp(choice
->choice
, "high"))
281 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
284 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
285 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
286 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
288 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
289 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
290 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
291 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
292 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
293 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
300 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
302 if (strstr(keyword
, "uncollated"))
307 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
312 if (!_cups_strcasecmp(format
, "image/gif") ||
313 !_cups_strcasecmp(format
, "image/jp2") ||
314 !_cups_strcasecmp(format
, "image/jpeg") ||
315 !_cups_strcasecmp(format
, "image/png") ||
316 !_cups_strcasecmp(format
, "image/tiff") ||
317 !_cups_strncasecmp(format
, "image/x-", 8))
320 * Collation makes no sense for single page image formats...
325 else if (!_cups_strncasecmp(format
, "image/", 6) ||
326 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
329 * Multi-page image formats will have copies applied by the upstream
337 if (doc_handling_sup
)
339 if (!_cups_strcasecmp(keyword
, "true"))
340 collate_str
= "separate-documents-collated-copies";
342 collate_str
= "separate-documents-uncollated-copies";
344 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
346 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
348 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
353 if (i
>= doc_handling_sup
->num_values
)
358 * Map finishing options...
361 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
362 if (num_finishings
> 0)
364 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
366 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
369 * Send job-pages-per-set attribute to apply finishings correctly...
372 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
381 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
384 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
388 _ppd_cache_t
* /* O - PPD cache and mapping data */
389 _ppdCacheCreateWithFile(
390 const char *filename
, /* I - File to read */
391 ipp_t
**attrs
) /* IO - IPP attributes, if any */
393 cups_file_t
*fp
; /* File */
394 _ppd_cache_t
*pc
; /* PWG mapping data */
395 pwg_size_t
*size
; /* Current size */
396 pwg_map_t
*map
; /* Current map */
397 _pwg_finishings_t
*finishings
; /* Current finishings option */
398 int linenum
, /* Current line number */
399 num_bins
, /* Number of bins in file */
400 num_sizes
, /* Number of sizes in file */
401 num_sources
, /* Number of sources in file */
402 num_types
; /* Number of types in file */
403 char line
[2048], /* Current line */
404 *value
, /* Pointer to value in line */
405 *valueptr
, /* Pointer into value */
406 pwg_keyword
[128], /* PWG keyword */
407 ppd_keyword
[PPD_MAX_NAME
];
409 _pwg_print_color_mode_t print_color_mode
;
410 /* Print color mode for preset */
411 _pwg_print_quality_t print_quality
; /* Print quality for preset */
414 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
417 * Range check input...
425 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
433 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
435 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
440 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
443 if (!cupsFileGets(fp
, line
, sizeof(line
)))
445 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
446 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
451 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
453 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
454 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
459 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
461 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
462 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
463 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
469 * Allocate the mapping data structure...
472 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
474 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
475 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
479 pc
->max_copies
= 9999;
491 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
493 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
494 "linenum=%d", line
, value
, linenum
));
498 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
500 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
503 else if (!_cups_strcasecmp(line
, "Filter"))
506 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
507 (cups_acopy_func_t
)_cupsStrAlloc
,
508 (cups_afree_func_t
)_cupsStrFree
);
510 cupsArrayAdd(pc
->filters
, value
);
512 else if (!_cups_strcasecmp(line
, "PreFilter"))
515 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
516 (cups_acopy_func_t
)_cupsStrAlloc
,
517 (cups_afree_func_t
)_cupsStrFree
);
519 cupsArrayAdd(pc
->prefilters
, value
);
521 else if (!_cups_strcasecmp(line
, "Product"))
523 pc
->product
= _cupsStrAlloc(value
);
525 else if (!_cups_strcasecmp(line
, "SingleFile"))
527 pc
->single_file
= !_cups_strcasecmp(value
, "true");
529 else if (!_cups_strcasecmp(line
, "IPP"))
531 off_t pos
= cupsFileTell(fp
), /* Position in file */
532 length
= strtol(value
, NULL
, 10);
533 /* Length of IPP attributes */
537 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
538 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
541 else if (length
<= 0)
543 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
544 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
551 * Read IPP attributes into the provided variable...
556 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
557 *attrs
) != IPP_STATE_DATA
)
559 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
560 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
567 * Skip the IPP data entirely...
570 cupsFileSeek(fp
, pos
+ length
);
573 if (cupsFileTell(fp
) != (pos
+ length
))
575 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
576 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
580 else if (!_cups_strcasecmp(line
, "NumBins"))
584 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
585 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
589 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
591 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
592 "%d.", num_sizes
, linenum
));
593 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
597 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
599 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
601 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
605 else if (!_cups_strcasecmp(line
, "Bin"))
607 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
609 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
610 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
614 if (pc
->num_bins
>= num_bins
)
616 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
618 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
622 map
= pc
->bins
+ pc
->num_bins
;
623 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
624 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
628 else if (!_cups_strcasecmp(line
, "NumSizes"))
632 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
633 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
637 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
639 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
640 "%d.", num_sizes
, linenum
));
641 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
647 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
649 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
651 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
656 else if (!_cups_strcasecmp(line
, "Size"))
658 if (pc
->num_sizes
>= num_sizes
)
660 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
662 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
666 size
= pc
->sizes
+ pc
->num_sizes
;
668 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
669 &(size
->width
), &(size
->length
), &(size
->left
),
670 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
672 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
674 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
678 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
679 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
683 else if (!_cups_strcasecmp(line
, "CustomSize"))
685 if (pc
->custom_max_width
> 0)
687 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
689 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
693 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
694 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
695 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
696 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
697 &(pc
->custom_size
.top
)) != 8)
699 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
701 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
705 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
706 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
707 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
709 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
710 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
711 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
713 else if (!_cups_strcasecmp(line
, "SourceOption"))
715 pc
->source_option
= _cupsStrAlloc(value
);
717 else if (!_cups_strcasecmp(line
, "NumSources"))
721 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
723 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
727 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
729 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
730 "line %d.", num_sources
, linenum
));
731 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
735 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
737 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
739 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
743 else if (!_cups_strcasecmp(line
, "Source"))
745 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
747 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
749 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
753 if (pc
->num_sources
>= num_sources
)
755 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
757 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
761 map
= pc
->sources
+ pc
->num_sources
;
762 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
763 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
767 else if (!_cups_strcasecmp(line
, "NumTypes"))
771 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
772 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
776 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
778 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
779 "line %d.", num_types
, linenum
));
780 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
784 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
786 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
788 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
792 else if (!_cups_strcasecmp(line
, "Type"))
794 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
796 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
798 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
802 if (pc
->num_types
>= num_types
)
804 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
806 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
810 map
= pc
->types
+ pc
->num_types
;
811 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
812 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
816 else if (!_cups_strcasecmp(line
, "Preset"))
819 * Preset output-mode print-quality name=value ...
822 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
823 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
825 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
826 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
827 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
828 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
829 valueptr
== value
|| !*valueptr
)
831 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
833 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
837 pc
->num_presets
[print_color_mode
][print_quality
] =
838 cupsParseOptions(valueptr
, 0,
839 pc
->presets
[print_color_mode
] + print_quality
);
841 else if (!_cups_strcasecmp(line
, "SidesOption"))
842 pc
->sides_option
= _cupsStrAlloc(value
);
843 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
844 pc
->sides_1sided
= _cupsStrAlloc(value
);
845 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
846 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
847 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
848 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
849 else if (!_cups_strcasecmp(line
, "Finishings"))
853 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
855 (cups_afree_func_t
)pwg_free_finishings
);
857 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
860 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
861 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
862 &(finishings
->options
));
864 cupsArrayAdd(pc
->finishings
, finishings
);
866 else if (!_cups_strcasecmp(line
, "MaxCopies"))
867 pc
->max_copies
= atoi(value
);
868 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
869 pc
->charge_info_uri
= _cupsStrAlloc(value
);
870 else if (!_cups_strcasecmp(line
, "JobAccountId"))
871 pc
->account_id
= !_cups_strcasecmp(value
, "true");
872 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
873 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
874 else if (!_cups_strcasecmp(line
, "JobPassword"))
875 pc
->password
= _cupsStrAlloc(value
);
876 else if (!_cups_strcasecmp(line
, "Mandatory"))
879 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
881 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
883 else if (!_cups_strcasecmp(line
, "StringsURI"))
884 pc
->strings_uri
= _cupsStrAlloc(value
);
885 else if (!_cups_strcasecmp(line
, "SupportFile"))
887 if (!pc
->support_files
)
888 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
889 (cups_acopy_func_t
)_cupsStrAlloc
,
890 (cups_afree_func_t
)_cupsStrFree
);
892 cupsArrayAdd(pc
->support_files
, value
);
896 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
901 if (pc
->num_sizes
< num_sizes
)
903 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
904 pc
->num_sizes
, num_sizes
));
905 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
909 if (pc
->num_sources
< num_sources
)
911 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
912 pc
->num_sources
, num_sources
));
913 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
917 if (pc
->num_types
< num_types
)
919 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
920 pc
->num_types
, num_types
));
921 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
930 * If we get here the file was bad - free any data and return...
936 _ppdCacheDestroy(pc
);
949 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
952 _ppd_cache_t
* /* O - PPD cache and mapping data */
953 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
955 int i
, j
, k
; /* Looping vars */
956 _ppd_cache_t
*pc
; /* PWG mapping data */
957 ppd_option_t
*input_slot
, /* InputSlot option */
958 *media_type
, /* MediaType option */
959 *output_bin
, /* OutputBin option */
960 *color_model
, /* ColorModel option */
961 *duplex
; /* Duplex option */
962 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
963 pwg_map_t
*map
; /* Current source/type map */
964 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
965 int num_options
; /* Number of preset options and props */
966 cups_option_t
*options
; /* Preset options and properties */
967 ppd_size_t
*ppd_size
; /* Current PPD size */
968 pwg_size_t
*pwg_size
; /* Current PWG size */
969 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
970 /* PWG keyword string */
971 ppd_name
[PPD_MAX_NAME
];
972 /* Normalized PPD name */
973 const char *pwg_name
; /* Standard PWG media name */
974 pwg_media_t
*pwg_media
; /* PWG media data */
975 _pwg_print_color_mode_t pwg_print_color_mode
;
976 /* print-color-mode index */
977 _pwg_print_quality_t pwg_print_quality
;
978 /* print-quality index */
979 int similar
; /* Are the old and new size similar? */
980 pwg_size_t
*old_size
; /* Current old size */
981 int old_imageable
, /* Old imageable length in 2540ths */
982 old_borderless
, /* Old borderless state */
983 old_known_pwg
; /* Old PWG name is well-known */
984 int new_width
, /* New width in 2540ths */
985 new_length
, /* New length in 2540ths */
986 new_left
, /* New left margin in 2540ths */
987 new_bottom
, /* New bottom margin in 2540ths */
988 new_right
, /* New right margin in 2540ths */
989 new_top
, /* New top margin in 2540ths */
990 new_imageable
, /* New imageable length in 2540ths */
991 new_borderless
, /* New borderless state */
992 new_known_pwg
; /* New PWG name is well-known */
993 pwg_size_t
*new_size
; /* New size to add, if any */
994 const char *filter
; /* Current filter */
995 _pwg_finishings_t
*finishings
; /* Current finishings value */
998 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1001 * Range check input...
1008 * Allocate memory...
1011 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1013 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1018 * Copy and convert size data...
1021 if (ppd
->num_sizes
> 0)
1023 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1025 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1026 "pwg_size_t's.", ppd
->num_sizes
));
1030 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1035 * Don't copy over custom size...
1038 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1042 * Convert the PPD size name to the corresponding PWG keyword name.
1045 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1048 * Standard name, do we have conflicts?
1051 for (j
= 0; j
< pc
->num_sizes
; j
++)
1052 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1062 * Standard name and no conflicts, use it!
1065 pwg_name
= pwg_media
->pwg
;
1071 * Not a standard name; convert it to a PWG vendor name of the form:
1073 * pp_lowerppd_WIDTHxHEIGHTuu
1076 pwg_name
= pwg_keyword
;
1079 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1080 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1081 PWG_FROM_POINTS(ppd_size
->width
),
1082 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1086 * If we have a similar paper with non-zero margins then we only want to
1087 * keep it if it has a larger imageable area length. The NULL check is for
1088 * dimensions that are <= 0...
1091 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1092 PWG_FROM_POINTS(ppd_size
->length
),
1096 new_width
= pwg_media
->width
;
1097 new_length
= pwg_media
->length
;
1098 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1099 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1100 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1101 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1102 new_imageable
= new_length
- new_top
- new_bottom
;
1103 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1104 new_left
== 0 && new_right
== 0;
1106 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1110 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1111 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1112 old_size
->right
== 0 && old_size
->top
== 0;
1113 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1114 strncmp(old_size
->map
.pwg
, "om_", 3);
1116 similar
= old_borderless
== new_borderless
&&
1117 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1118 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1121 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1124 * The new paper has a larger imageable area so it could replace
1125 * the older paper. Regardless of the imageable area, we always
1126 * prefer the size with a well-known PWG name.
1129 new_size
= old_size
;
1130 _cupsStrFree(old_size
->map
.ppd
);
1131 _cupsStrFree(old_size
->map
.pwg
);
1138 * The paper was unique enough to deserve its own entry so add it to the
1142 new_size
= pwg_size
++;
1152 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1153 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1154 new_size
->width
= new_width
;
1155 new_size
->length
= new_length
;
1156 new_size
->left
= new_left
;
1157 new_size
->bottom
= new_bottom
;
1158 new_size
->right
= new_right
;
1159 new_size
->top
= new_top
;
1164 if (ppd
->variable_sizes
)
1167 * Generate custom size data...
1170 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1171 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1172 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1173 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1174 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1175 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1177 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1178 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1179 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1180 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1181 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1182 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1184 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1185 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1186 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1187 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1191 * Copy and convert InputSlot data...
1194 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1195 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1199 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1201 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1203 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1204 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1208 pc
->num_sources
= input_slot
->num_choices
;
1210 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1213 i
--, choice
++, map
++)
1215 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1216 !_cups_strcasecmp(choice
->choice
, "Default"))
1218 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1220 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1222 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1224 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1225 !_cups_strcasecmp(choice
->choice
, "MP") ||
1226 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1227 pwg_name
= "by-pass-tray";
1228 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1229 pwg_name
= "large-capacity";
1230 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1231 pwg_name
= "bottom";
1232 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1233 pwg_name
= "middle";
1234 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1236 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1238 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1239 pwg_name
= "main-roll";
1243 * Convert PPD name to lowercase...
1246 pwg_name
= pwg_keyword
;
1247 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1251 map
->pwg
= _cupsStrAlloc(pwg_name
);
1252 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1257 * Copy and convert MediaType data...
1260 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1262 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1264 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1265 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1269 pc
->num_types
= media_type
->num_choices
;
1271 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1274 i
--, choice
++, map
++)
1276 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1277 !_cups_strcasecmp(choice
->choice
, "Any") ||
1278 !_cups_strcasecmp(choice
->choice
, "Default"))
1280 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1281 pwg_name
= "cardstock";
1282 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1283 pwg_name
= "envelope";
1284 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1285 pwg_name
= "photographic-glossy";
1286 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1287 pwg_name
= "photographic-high-gloss";
1288 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1289 pwg_name
= "photographic-matte";
1290 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1291 pwg_name
= "stationery";
1292 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1293 pwg_name
= "stationery-coated";
1294 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1295 pwg_name
= "stationery-inkjet";
1296 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1297 pwg_name
= "stationery-letterhead";
1298 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1299 pwg_name
= "stationery-preprinted";
1300 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1301 pwg_name
= "stationery-recycled";
1302 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1303 pwg_name
= "transparency";
1307 * Convert PPD name to lowercase...
1310 pwg_name
= pwg_keyword
;
1311 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1315 map
->pwg
= _cupsStrAlloc(pwg_name
);
1316 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1321 * Copy and convert OutputBin data...
1324 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1326 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1328 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1329 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1333 pc
->num_bins
= output_bin
->num_choices
;
1335 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1338 i
--, choice
++, map
++)
1340 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1342 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1343 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1347 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1350 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1353 const char *quality
, /* com.apple.print.preset.quality value */
1354 *output_mode
, /* com.apple.print.preset.output-mode value */
1355 *color_model_val
, /* ColorModel choice */
1356 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1357 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1361 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1364 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1365 num_options
, options
)) != NULL
)
1368 * Get the print-quality for this preset...
1371 if (!strcmp(quality
, "low"))
1372 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1373 else if (!strcmp(quality
, "high"))
1374 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1376 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1379 * Ignore graphicsType "Photo" presets that are not high quality.
1382 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1383 num_options
, options
);
1385 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1386 !strcmp(graphicsType
, "Photo"))
1390 * Ignore presets for normal and draft quality where the coating
1391 * isn't "none" or "autodetect".
1394 media_front_coating
= cupsGetOption(
1395 "com.apple.print.preset.media-front-coating",
1396 num_options
, options
);
1398 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1399 media_front_coating
&&
1400 strcmp(media_front_coating
, "none") &&
1401 strcmp(media_front_coating
, "autodetect"))
1405 * Get the output mode for this preset...
1408 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1409 num_options
, options
);
1410 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1414 if (!strcmp(output_mode
, "monochrome"))
1415 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1417 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1419 else if (color_model_val
)
1421 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1422 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1424 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1427 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1430 * Save the options for this combination as needed...
1433 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1434 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1435 _ppdParseOptions(ppd_attr
->value
, 0,
1436 pc
->presets
[pwg_print_color_mode
] +
1437 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1440 cupsFreeOptions(num_options
, options
);
1442 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1445 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1446 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1447 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1450 * Try adding some common color options to create grayscale presets. These
1451 * are listed in order of popularity...
1454 const char *color_option
= NULL
, /* Color control option */
1455 *gray_choice
= NULL
; /* Choice to select grayscale */
1457 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1458 ppdFindChoice(color_model
, "Gray"))
1460 color_option
= "ColorModel";
1461 gray_choice
= "Gray";
1463 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1464 ppdFindChoice(color_model
, "grayscale"))
1466 color_option
= "HPColorMode";
1467 gray_choice
= "grayscale";
1469 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1470 ppdFindChoice(color_model
, "Mono"))
1472 color_option
= "BRMonoColor";
1473 gray_choice
= "Mono";
1475 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1476 ppdFindChoice(color_model
, "1"))
1478 color_option
= "CNIJSGrayScale";
1481 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1482 ppdFindChoice(color_model
, "True"))
1484 color_option
= "HPColorAsGray";
1485 gray_choice
= "True";
1488 if (color_option
&& gray_choice
)
1491 * Copy and convert ColorModel (output-mode) data...
1494 cups_option_t
*coption
, /* Color option */
1495 *moption
; /* Monochrome option */
1497 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1498 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1499 pwg_print_quality
++)
1501 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1504 * Copy the color options...
1507 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1508 [pwg_print_quality
];
1509 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1513 for (i
= num_options
, moption
= options
,
1514 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1515 [pwg_print_quality
];
1517 i
--, moption
++, coption
++)
1519 moption
->name
= _cupsStrRetain(coption
->name
);
1520 moption
->value
= _cupsStrRetain(coption
->value
);
1523 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1525 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1529 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1533 * Add the grayscale option to the preset...
1536 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1537 cupsAddOption(color_option
, gray_choice
,
1538 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1539 [pwg_print_quality
],
1540 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1547 * Copy and convert Duplex (sides) data...
1550 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1551 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1552 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1553 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1554 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1558 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1560 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1564 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1565 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1566 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1567 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1568 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1569 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1570 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1571 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1572 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1573 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1574 !pc
->sides_2sided_short
)
1575 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1580 * Copy filters and pre-filters...
1583 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1584 (cups_acopy_func_t
)_cupsStrAlloc
,
1585 (cups_afree_func_t
)_cupsStrFree
);
1587 cupsArrayAdd(pc
->filters
,
1588 "application/vnd.cups-raw application/octet-stream 0 -");
1590 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1594 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1596 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1598 else if (ppd
->num_filters
> 0)
1600 for (i
= 0; i
< ppd
->num_filters
; i
++)
1601 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1604 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1607 * See if we have a command filter...
1610 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1612 filter
= (const char *)cupsArrayNext(pc
->filters
))
1613 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1614 _cups_isspace(filter
[28]))
1618 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1619 _cups_strcasecmp(ppd_attr
->value
, "none")))
1622 * No command filter and no cupsCommands keyword telling us not to use one.
1623 * See if this is a PostScript printer, and if so add a PostScript command
1627 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1629 filter
= (const char *)cupsArrayNext(pc
->filters
))
1630 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1631 _cups_isspace(filter
[31]))
1635 cupsArrayAdd(pc
->filters
,
1636 "application/vnd.cups-command application/postscript 100 "
1640 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1642 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1643 (cups_acopy_func_t
)_cupsStrAlloc
,
1644 (cups_afree_func_t
)_cupsStrFree
);
1648 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1650 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1653 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1654 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1657 * Copy the product string, if any...
1661 pc
->product
= _cupsStrAlloc(ppd
->product
);
1664 * Copy finishings mapping data...
1667 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1670 * Have proper vendor mapping of IPP finishings values to PPD options...
1673 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1674 NULL
, NULL
, 0, NULL
,
1675 (cups_afree_func_t
)pwg_free_finishings
);
1679 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1682 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1683 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1684 &(finishings
->options
),
1685 _PPD_PARSE_OPTIONS
);
1687 cupsArrayAdd(pc
->finishings
, finishings
);
1689 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1695 * No IPP mapping data, try to map common/standard PPD keywords...
1698 ppd_option_t
*ppd_option
; /* PPD option */
1700 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1702 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1705 * Add staple finishings...
1708 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1709 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1710 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1711 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1712 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1713 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1714 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1715 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1716 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1717 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1720 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1723 * Add (Ricoh) punch finishings...
1726 if (ppdFindChoice(ppd_option
, "Left2"))
1727 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1728 if (ppdFindChoice(ppd_option
, "Left3"))
1729 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1730 if (ppdFindChoice(ppd_option
, "Left4"))
1731 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1732 if (ppdFindChoice(ppd_option
, "Right2"))
1733 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1734 if (ppdFindChoice(ppd_option
, "Right3"))
1735 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1736 if (ppdFindChoice(ppd_option
, "Right4"))
1737 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1738 if (ppdFindChoice(ppd_option
, "Upper2"))
1739 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1740 if (ppdFindChoice(ppd_option
, "Upper3"))
1741 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1742 if (ppdFindChoice(ppd_option
, "Upper4"))
1743 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1746 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1749 * Add bind finishings...
1752 if (ppdFindChoice(ppd_option
, "Left"))
1753 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1754 if (ppdFindChoice(ppd_option
, "Right"))
1755 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1756 if (ppdFindChoice(ppd_option
, "Top"))
1757 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1758 if (ppdFindChoice(ppd_option
, "Bottom"))
1759 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1762 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1765 * Add (Adobe) fold finishings...
1768 if (ppdFindChoice(ppd_option
, "ZFold"))
1769 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1770 if (ppdFindChoice(ppd_option
, "Saddle"))
1771 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1772 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1773 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1774 if (ppdFindChoice(ppd_option
, "LeftGate"))
1775 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1776 if (ppdFindChoice(ppd_option
, "RightGate"))
1777 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1778 if (ppdFindChoice(ppd_option
, "Letter"))
1779 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1780 if (ppdFindChoice(ppd_option
, "XFold"))
1781 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1784 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1787 * Add (Ricoh) fold finishings...
1790 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1791 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1794 if (cupsArrayCount(pc
->finishings
) == 0)
1796 cupsArrayDelete(pc
->finishings
);
1797 pc
->finishings
= NULL
;
1805 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1806 pc
->max_copies
= atoi(ppd_attr
->value
);
1807 else if (ppd
->manual_copies
)
1810 pc
->max_copies
= 9999;
1813 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1814 * cupsJobPassword, and cupsMandatory.
1817 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1818 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1820 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1821 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1823 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1824 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1826 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1827 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1829 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1830 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1833 * Strings (remote) file...
1836 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsStringsURI", NULL
)) != NULL
)
1837 pc
->strings_uri
= _cupsStrAlloc(ppd_attr
->value
);
1843 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1844 (cups_acopy_func_t
)_cupsStrAlloc
,
1845 (cups_afree_func_t
)_cupsStrFree
);
1847 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1849 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1850 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1852 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1853 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1856 * Return the cache data...
1862 * If we get here we need to destroy the PWG mapping data and return NULL...
1867 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1868 _ppdCacheDestroy(pc
);
1875 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1879 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1881 int i
; /* Looping var */
1882 pwg_map_t
*map
; /* Current map */
1883 pwg_size_t
*size
; /* Current size */
1887 * Range check input...
1894 * Free memory as needed...
1899 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1901 _cupsStrFree(map
->pwg
);
1902 _cupsStrFree(map
->ppd
);
1910 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1912 _cupsStrFree(size
->map
.pwg
);
1913 _cupsStrFree(size
->map
.ppd
);
1919 if (pc
->source_option
)
1920 _cupsStrFree(pc
->source_option
);
1924 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1926 _cupsStrFree(map
->pwg
);
1927 _cupsStrFree(map
->ppd
);
1935 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1937 _cupsStrFree(map
->pwg
);
1938 _cupsStrFree(map
->ppd
);
1944 if (pc
->custom_max_keyword
)
1945 _cupsStrFree(pc
->custom_max_keyword
);
1947 if (pc
->custom_min_keyword
)
1948 _cupsStrFree(pc
->custom_min_keyword
);
1950 _cupsStrFree(pc
->product
);
1951 cupsArrayDelete(pc
->filters
);
1952 cupsArrayDelete(pc
->prefilters
);
1953 cupsArrayDelete(pc
->finishings
);
1955 _cupsStrFree(pc
->charge_info_uri
);
1956 _cupsStrFree(pc
->password
);
1958 cupsArrayDelete(pc
->mandatory
);
1960 cupsArrayDelete(pc
->support_files
);
1967 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1971 const char * /* O - output-bin or NULL */
1973 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1974 const char *output_bin
) /* I - PPD OutputBin string */
1976 int i
; /* Looping var */
1980 * Range check input...
1983 if (!pc
|| !output_bin
)
1987 * Look up the OutputBin string...
1991 for (i
= 0; i
< pc
->num_bins
; i
++)
1992 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1993 return (pc
->bins
[i
].pwg
);
2000 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2001 * IPP finishings value(s).
2004 int /* O - New number of options */
2005 _ppdCacheGetFinishingOptions(
2006 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2007 ipp_t
*job
, /* I - Job attributes or NULL */
2008 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2009 int num_options
, /* I - Number of options */
2010 cups_option_t
**options
) /* IO - Options */
2012 int i
; /* Looping var */
2013 _pwg_finishings_t
*f
, /* PWG finishings options */
2014 key
; /* Search key */
2015 ipp_attribute_t
*attr
; /* Finishings attribute */
2016 cups_option_t
*option
; /* Current finishings option */
2020 * Range check input...
2023 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2024 (!job
&& value
== IPP_FINISHINGS_NONE
))
2025 return (num_options
);
2028 * Apply finishing options...
2031 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2033 int num_values
= ippGetCount(attr
); /* Number of values */
2035 for (i
= 0; i
< num_values
; i
++)
2037 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2039 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2041 int j
; /* Another looping var */
2043 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2044 num_options
= cupsAddOption(option
->name
, option
->value
,
2045 num_options
, options
);
2049 else if (value
!= IPP_FINISHINGS_NONE
)
2053 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2055 int j
; /* Another looping var */
2057 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2058 num_options
= cupsAddOption(option
->name
, option
->value
,
2059 num_options
, options
);
2063 return (num_options
);
2068 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2072 int /* O - Number of finishings values */
2073 _ppdCacheGetFinishingValues(
2074 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2075 int num_options
, /* I - Number of options */
2076 cups_option_t
*options
, /* I - Options */
2077 int max_values
, /* I - Maximum number of finishings values */
2078 int *values
) /* O - Finishings values */
2080 int i
, /* Looping var */
2081 num_values
= 0; /* Number of values */
2082 _pwg_finishings_t
*f
; /* Current finishings option */
2083 cups_option_t
*option
; /* Current option */
2084 const char *val
; /* Value for option */
2088 * Range check input...
2091 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2093 if (!pc
|| max_values
< 1 || !values
)
2095 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2098 else if (!pc
->finishings
)
2100 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2105 * Go through the finishings options and see what is set...
2108 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2110 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2112 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2114 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2116 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2118 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2119 _cups_strcasecmp(option
->value
, val
))
2121 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2128 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2130 values
[num_values
++] = f
->value
;
2132 if (num_values
>= max_values
)
2137 if (num_values
== 0)
2140 * Always have at least "finishings" = 'none'...
2143 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2144 values
[0] = IPP_FINISHINGS_NONE
;
2148 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2150 return (num_values
);
2155 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2156 * attributes or a keyword string.
2159 const char * /* O - PPD InputSlot or NULL */
2160 _ppdCacheGetInputSlot(
2161 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2162 ipp_t
*job
, /* I - Job attributes or NULL */
2163 const char *keyword
) /* I - Keyword string or NULL */
2166 * Range check input...
2169 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2172 if (job
&& !keyword
)
2175 * Lookup the media-col attribute and any media-source found there...
2178 ipp_attribute_t
*media_col
, /* media-col attribute */
2179 *media_source
; /* media-source attribute */
2180 pwg_size_t size
; /* Dimensional size */
2181 int margins_set
; /* Were the margins set? */
2183 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2185 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2187 IPP_TAG_KEYWORD
)) != NULL
)
2190 * Use the media-source value from media-col...
2193 keyword
= ippGetString(media_source
, 0, NULL
);
2195 else if (pwgInitSize(&size
, job
, &margins_set
))
2198 * For media <= 5x7, look for a photo tray...
2201 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2208 int i
; /* Looping var */
2210 for (i
= 0; i
< pc
->num_sources
; i
++)
2211 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2212 return (pc
->sources
[i
].ppd
);
2220 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2221 * attributes or a keyword string.
2224 const char * /* O - PPD MediaType or NULL */
2225 _ppdCacheGetMediaType(
2226 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2227 ipp_t
*job
, /* I - Job attributes or NULL */
2228 const char *keyword
) /* I - Keyword string or NULL */
2231 * Range check input...
2234 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2237 if (job
&& !keyword
)
2240 * Lookup the media-col attribute and any media-source found there...
2243 ipp_attribute_t
*media_col
, /* media-col attribute */
2244 *media_type
; /* media-type attribute */
2246 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2249 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2251 IPP_TAG_KEYWORD
)) == NULL
)
2252 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2253 "media-type", IPP_TAG_NAME
);
2256 keyword
= media_type
->values
[0].string
.text
;
2262 int i
; /* Looping var */
2264 for (i
= 0; i
< pc
->num_types
; i
++)
2265 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2266 return (pc
->types
[i
].ppd
);
2274 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2278 const char * /* O - PPD OutputBin or NULL */
2279 _ppdCacheGetOutputBin(
2280 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2281 const char *output_bin
) /* I - Keyword string */
2283 int i
; /* Looping var */
2287 * Range check input...
2290 if (!pc
|| !output_bin
)
2294 * Look up the OutputBin string...
2298 for (i
= 0; i
< pc
->num_bins
; i
++)
2299 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2300 return (pc
->bins
[i
].ppd
);
2307 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2308 * attributes or a keyword string.
2311 const char * /* O - PPD PageSize or NULL */
2312 _ppdCacheGetPageSize(
2313 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2314 ipp_t
*job
, /* I - Job attributes or NULL */
2315 const char *keyword
, /* I - Keyword string or NULL */
2316 int *exact
) /* O - 1 if exact match, 0 otherwise */
2318 int i
; /* Looping var */
2319 pwg_size_t
*size
, /* Current size */
2320 *closest
, /* Closest size */
2321 jobsize
; /* Size data from job */
2322 int margins_set
, /* Were the margins set? */
2323 dwidth
, /* Difference in width */
2324 dlength
, /* Difference in length */
2325 dleft
, /* Difference in left margins */
2326 dright
, /* Difference in right margins */
2327 dbottom
, /* Difference in bottom margins */
2328 dtop
, /* Difference in top margins */
2329 dmin
, /* Minimum difference */
2330 dclosest
; /* Closest difference */
2331 const char *ppd_name
; /* PPD media name */
2334 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2335 pc
, job
, keyword
, exact
));
2338 * Range check input...
2341 if (!pc
|| (!job
&& !keyword
))
2352 * Try getting the PPD media name from the job attributes...
2355 ipp_attribute_t
*attr
; /* Job attribute */
2357 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2358 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2359 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2363 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2364 attr
->name
, ippTagString(attr
->value_tag
)));
2366 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2369 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2370 attr
->value_tag
== IPP_TAG_KEYWORD
))
2371 ppd_name
= attr
->values
[0].string
.text
;
2374 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2379 * Try looking up the named PPD size first...
2382 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2384 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2385 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2387 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2388 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2393 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2395 return (size
->map
.ppd
);
2400 if (job
&& !keyword
)
2403 * Get the size using media-col or media, with the preference being
2407 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2413 * Get the size using a media keyword...
2416 pwg_media_t
*media
; /* Media definition */
2419 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2420 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2421 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2424 jobsize
.width
= media
->width
;
2425 jobsize
.length
= media
->length
;
2430 * Now that we have the dimensions and possibly the margins, look at the
2431 * available sizes and find the match...
2435 dclosest
= 999999999;
2437 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2438 _cups_strncasecmp(ppd_name
, "custom_", 7))
2440 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2443 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2444 * is just about 176/2540ths...
2447 dwidth
= size
->width
- jobsize
.width
;
2448 dlength
= size
->length
- jobsize
.length
;
2450 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2456 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2459 dleft
= size
->left
- jobsize
.left
;
2460 dright
= size
->right
- jobsize
.right
;
2461 dtop
= size
->top
- jobsize
.top
;
2462 dbottom
= size
->bottom
- jobsize
.bottom
;
2464 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2465 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2467 dleft
= dleft
< 0 ? -dleft
: dleft
;
2468 dright
= dright
< 0 ? -dright
: dright
;
2469 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2470 dtop
= dtop
< 0 ? -dtop
: dtop
;
2471 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2473 if (dmin
< dclosest
)
2486 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2488 return (size
->map
.ppd
);
2494 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2497 return (closest
->map
.ppd
);
2501 * If we get here we need to check for custom page size support...
2504 if (jobsize
.width
>= pc
->custom_min_width
&&
2505 jobsize
.width
<= pc
->custom_max_width
&&
2506 jobsize
.length
>= pc
->custom_min_length
&&
2507 jobsize
.length
<= pc
->custom_max_length
)
2510 * In range, format as Custom.WWWWxLLLL (points).
2513 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2514 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2516 if (margins_set
&& exact
)
2518 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2519 dright
= pc
->custom_size
.right
- jobsize
.right
;
2520 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2521 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2523 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2524 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2530 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2531 pc
->custom_ppd_size
));
2533 return (pc
->custom_ppd_size
);
2537 * No custom page size support or the size is out of range - return NULL.
2540 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2547 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2550 pwg_size_t
* /* O - PWG size or NULL */
2552 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2553 const char *page_size
) /* I - PPD PageSize */
2555 int i
; /* Looping var */
2556 pwg_media_t
*media
; /* Media */
2557 pwg_size_t
*size
; /* Current size */
2561 * Range check input...
2564 if (!pc
|| !page_size
)
2567 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2570 * Custom size; size name can be one of the following:
2572 * Custom.WIDTHxLENGTHin - Size in inches
2573 * Custom.WIDTHxLENGTHft - Size in feet
2574 * Custom.WIDTHxLENGTHcm - Size in centimeters
2575 * Custom.WIDTHxLENGTHmm - Size in millimeters
2576 * Custom.WIDTHxLENGTHm - Size in meters
2577 * Custom.WIDTHxLENGTH[pt] - Size in points
2580 double w
, l
; /* Width and length of page */
2581 char *ptr
; /* Pointer into PageSize */
2582 struct lconv
*loc
; /* Locale data */
2585 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2586 if (!ptr
|| *ptr
!= 'x')
2589 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2593 if (!_cups_strcasecmp(ptr
, "in"))
2598 else if (!_cups_strcasecmp(ptr
, "ft"))
2603 else if (!_cups_strcasecmp(ptr
, "mm"))
2608 else if (!_cups_strcasecmp(ptr
, "cm"))
2613 else if (!_cups_strcasecmp(ptr
, "m"))
2624 pc
->custom_size
.width
= (int)w
;
2625 pc
->custom_size
.length
= (int)l
;
2627 return (&(pc
->custom_size
));
2631 * Not a custom size - look it up...
2634 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2635 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2636 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2640 * Look up standard sizes...
2643 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2644 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2645 media
= pwgMediaForPWG(page_size
);
2649 pc
->custom_size
.width
= media
->width
;
2650 pc
->custom_size
.length
= media
->length
;
2652 return (&(pc
->custom_size
));
2660 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2664 const char * /* O - PWG media-source keyword */
2666 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2667 const char *input_slot
) /* I - PPD InputSlot */
2669 int i
; /* Looping var */
2670 pwg_map_t
*source
; /* Current source */
2674 * Range check input...
2677 if (!pc
|| !input_slot
)
2680 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2681 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2682 return (source
->pwg
);
2689 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2693 const char * /* O - PWG media-type keyword */
2695 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2696 const char *media_type
) /* I - PPD MediaType */
2698 int i
; /* Looping var */
2699 pwg_map_t
*type
; /* Current type */
2703 * Range check input...
2706 if (!pc
|| !media_type
)
2709 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2710 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2718 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2721 int /* O - 1 on success, 0 on failure */
2723 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2724 const char *filename
, /* I - File to write */
2725 ipp_t
*attrs
) /* I - Attributes to write, if any */
2727 int i
, j
, k
; /* Looping vars */
2728 cups_file_t
*fp
; /* Output file */
2729 pwg_size_t
*size
; /* Current size */
2730 pwg_map_t
*map
; /* Current map */
2731 _pwg_finishings_t
*f
; /* Current finishing option */
2732 cups_option_t
*option
; /* Current option */
2733 const char *value
; /* Filter/pre-filter value */
2734 char newfile
[1024]; /* New filename */
2738 * Range check input...
2741 if (!pc
|| !filename
)
2743 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2748 * Open the file and write with compression...
2751 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2752 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2754 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2759 * Standard header...
2762 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2768 if (pc
->num_bins
> 0)
2770 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2771 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2772 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2779 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2780 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2781 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2782 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2783 size
->bottom
, size
->right
, size
->top
);
2784 if (pc
->custom_max_width
> 0)
2785 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2786 pc
->custom_max_width
, pc
->custom_max_length
,
2787 pc
->custom_min_width
, pc
->custom_min_length
,
2788 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2789 pc
->custom_size
.right
, pc
->custom_size
.top
);
2795 if (pc
->source_option
)
2796 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2798 if (pc
->num_sources
> 0)
2800 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2801 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2802 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2809 if (pc
->num_types
> 0)
2811 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2812 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2813 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2820 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2821 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2822 if (pc
->num_presets
[i
][j
])
2824 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2825 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2828 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2829 cupsFilePutChar(fp
, '\n');
2836 if (pc
->sides_option
)
2837 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2839 if (pc
->sides_1sided
)
2840 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2842 if (pc
->sides_2sided_long
)
2843 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2845 if (pc
->sides_2sided_short
)
2846 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2849 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2853 cupsFilePutConf(fp
, "Product", pc
->product
);
2855 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2857 value
= (const char *)cupsArrayNext(pc
->filters
))
2858 cupsFilePutConf(fp
, "Filter", value
);
2860 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2862 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2863 cupsFilePutConf(fp
, "PreFilter", value
);
2865 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2868 * Finishing options...
2871 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2873 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2875 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2876 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2877 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2878 cupsFilePutChar(fp
, '\n');
2885 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2888 * Accounting/quota/PIN/managed printing values...
2891 if (pc
->charge_info_uri
)
2892 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2894 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2895 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2896 pc
->accounting_user_id
? "true" : "false");
2899 cupsFilePutConf(fp
, "Password", pc
->password
);
2901 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2903 value
= (char *)cupsArrayNext(pc
->mandatory
))
2904 cupsFilePutConf(fp
, "Mandatory", value
);
2907 * (Remote) strings file...
2910 if (pc
->strings_uri
)
2911 cupsFilePutConf(fp
, "StringsURI", pc
->strings_uri
);
2917 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2919 value
= (char *)cupsArrayNext(pc
->support_files
))
2920 cupsFilePutConf(fp
, "SupportFile", value
);
2923 * IPP attributes, if any...
2928 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2930 attrs
->state
= IPP_STATE_IDLE
;
2931 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2935 * Close and return...
2938 if (cupsFileClose(fp
))
2945 return (!rename(newfile
, filename
));
2950 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2951 * of an IPP printer.
2954 char * /* O - PPD filename or @code NULL@ on error */
2955 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2956 size_t bufsize
, /* I - Size of filename buffer */
2957 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2959 cups_file_t
*fp
; /* PPD file */
2960 cups_array_t
*sizes
; /* Media sizes we've added */
2961 ipp_attribute_t
*attr
, /* xxx-supported */
2962 *defattr
, /* xxx-default */
2963 *quality
, /* print-quality-supported */
2964 *x_dim
, *y_dim
; /* Media dimensions */
2965 ipp_t
*media_size
; /* Media size collection */
2966 char make
[256], /* Make and model */
2967 *model
, /* Model name */
2968 ppdname
[PPD_MAX_NAME
];
2970 int i
, j
, /* Looping vars */
2971 count
, /* Number of values */
2972 bottom
, /* Largest bottom margin */
2973 left
, /* Largest left margin */
2974 right
, /* Largest right margin */
2975 top
, /* Largest top margin */
2976 is_apple
= 0, /* Does the printer support Apple raster? */
2977 is_pdf
= 0, /* Does the printer support PDF? */
2978 is_pwg
= 0; /* Does the printer support PWG Raster? */
2979 pwg_media_t
*pwg
; /* PWG media size */
2980 int xres
, yres
; /* Resolution values */
2981 int resolutions
[1000];
2982 /* Array of resolution indices */
2983 cups_lang_t
*lang
= cupsLangDefault();
2984 /* Localization info */
2985 cups_array_t
*strings
= NULL
;/* Printer strings file */
2986 struct lconv
*loc
= localeconv();
2988 static const char * const finishings
[][2] =
2989 { /* Finishings strings */
2990 { "bale", _("Bale") },
2991 { "bind", _("Bind") },
2992 { "bind-bottom", _("Bind (Reverse Landscape)") },
2993 { "bind-left", _("Bind (Portrait)") },
2994 { "bind-right", _("Bind (Reverse Portrait)") },
2995 { "bind-top", _("Bind (Landscape)") },
2996 { "booklet-maker", _("Booklet Maker") },
2997 { "coat", _("Coat") },
2998 { "cover", _("Cover") },
2999 { "edge-stitch", _("Staple Edge") },
3000 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
3001 { "edge-stitch-left", _("Staple Edge (Portrait)") },
3002 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
3003 { "edge-stitch-top", _("Staple Edge (Landscape)") },
3004 { "fold", _("Fold") },
3005 { "fold-accordian", _("Accordian Fold") },
3006 { "fold-double-gate", _("Double Gate Fold") },
3007 { "fold-engineering-z", _("Engineering Z Fold") },
3008 { "fold-gate", _("Gate Fold") },
3009 { "fold-half", _("Half Fold") },
3010 { "fold-half-z", _("Half Z Fold") },
3011 { "fold-left-gate", _("Left Gate Fold") },
3012 { "fold-letter", _("Letter Fold") },
3013 { "fold-parallel", _("Parallel Fold") },
3014 { "fold-poster", _("Poster Fold") },
3015 { "fold-right-gate", _("Right Gate Fold") },
3016 { "fold-z", _("Z Fold") },
3017 { "jog-offset", _("Jog") },
3018 { "laminate", _("Laminate") },
3019 { "punch", _("Punch") },
3020 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3021 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3022 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3023 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3024 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3025 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3026 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3027 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3028 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3029 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3030 { "punch-top-left", _("Single Punch (Portrait)") },
3031 { "punch-top-right", _("Single Punch (Landscape)") },
3032 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3033 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3034 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3035 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3036 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3037 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3038 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3039 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3040 { "saddle-stitch", _("Saddle Stitch") },
3041 { "staple", _("Staple") },
3042 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3043 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3044 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3045 { "staple-dual-left", _("Double Staple (Portrait)") },
3046 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3047 { "staple-dual-top", _("Double Staple (Landscape)") },
3048 { "staple-top-left", _("Single Staple (Portrait)") },
3049 { "staple-top-right", _("Single Staple (Landscape)") },
3050 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3051 { "staple-triple-left", _("Triple Staple (Portrait)") },
3052 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3053 { "staple-triple-top", _("Triple Staple (Landscape)") },
3054 { "trim", _("Cut Media") }
3059 * Range check input...
3065 if (!buffer
|| bufsize
< 1)
3067 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3073 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3078 * Open a temporary file for the PPD...
3081 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3083 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3088 * Standard stuff for PPD file...
3091 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3092 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3093 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3094 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3095 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3096 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3097 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3098 cupsFilePuts(fp
, "*FileSystem: False\n");
3099 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3101 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3102 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3104 strlcpy(make
, "Unknown Printer", sizeof(make
));
3106 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3107 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3110 strlcpy(make
, "HP", sizeof(make
));
3112 else if ((model
= strchr(make
, ' ')) != NULL
)
3117 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3118 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3119 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3120 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3121 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3123 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3124 cupsFilePuts(fp
, "*ColorDevice: True\n");
3126 cupsFilePuts(fp
, "*ColorDevice: False\n");
3128 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3129 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3130 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3132 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3133 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3135 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3136 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3138 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3140 http_t
*http
= NULL
; /* Connection to printer */
3141 char stringsfile
[1024]; /* Temporary strings file */
3143 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3145 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3147 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3149 unlink(stringsfile
);
3160 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3162 is_apple
= ippContainsString(attr
, "image/urf");
3163 is_pdf
= ippContainsString(attr
, "application/pdf");
3164 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3166 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3168 const char *format
= ippGetString(attr
, i
, NULL
);
3172 * Write cupsFilter2 lines for supported formats...
3175 if (!_cups_strcasecmp(format
, "application/pdf"))
3176 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3177 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3178 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3179 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3180 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3184 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3188 * PageSize/PageRegion/ImageableArea/PaperDimension
3191 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3193 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3194 if (ippGetInteger(attr
, i
) > bottom
)
3195 bottom
= ippGetInteger(attr
, i
);
3200 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3202 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3203 if (ippGetInteger(attr
, i
) > left
)
3204 left
= ippGetInteger(attr
, i
);
3209 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3211 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3212 if (ippGetInteger(attr
, i
) > right
)
3213 right
= ippGetInteger(attr
, i
);
3218 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3220 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3221 if (ippGetInteger(attr
, i
) > top
)
3222 top
= ippGetInteger(attr
, i
);
3227 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3229 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3231 media_size
= ippGetCollection(attr
, 0);
3232 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3233 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3235 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3236 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3238 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3241 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3243 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3244 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3246 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3248 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3249 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3252 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3253 "*OrderDependency: 10 AnySetup *PageSize\n"
3254 "*DefaultPageSize: %s\n", ppdname
);
3256 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3258 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3260 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3262 media_size
= ippGetCollection(attr
, i
);
3263 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3264 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3266 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3269 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3273 char twidth
[256], /* Width string */
3274 tlength
[256]; /* Length string */
3276 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3278 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3282 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3284 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3285 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3287 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3290 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3292 cupsArrayDelete(sizes
);
3293 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3295 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3296 "*OrderDependency: 10 AnySetup *PageRegion\n"
3297 "*DefaultPageRegion: %s\n", ppdname
);
3298 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3300 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3302 media_size
= ippGetCollection(attr
, i
);
3303 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3304 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3306 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3309 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3313 char twidth
[256], /* Width string */
3314 tlength
[256]; /* Length string */
3316 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3319 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3321 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3322 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3324 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3327 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3329 cupsArrayDelete(sizes
);
3330 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3332 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3333 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3334 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3336 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3338 media_size
= ippGetCollection(attr
, i
);
3339 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3340 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3342 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3345 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3349 char tleft
[256], /* Left string */
3350 tbottom
[256], /* Bottom string */
3351 tright
[256], /* Right string */
3352 ttop
[256], /* Top string */
3353 twidth
[256], /* Width string */
3354 tlength
[256]; /* Length string */
3356 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3359 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3361 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3362 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3363 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3364 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3365 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3366 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3368 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3369 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3373 cupsArrayDelete(sizes
);
3382 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3383 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3385 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3387 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3389 static const char * const sources
[][2] =
3390 { /* "media-source" strings */
3391 { "Auto", _("Automatic") },
3392 { "Main", _("Main") },
3393 { "Alternate", _("Alternate") },
3394 { "LargeCapacity", _("Large Capacity") },
3395 { "Manual", _("Manual") },
3396 { "Envelope", _("Envelope") },
3397 { "Disc", _("Disc") },
3398 { "Photo", _("Photo") },
3399 { "Hagaki", _("Hagaki") },
3400 { "MainRoll", _("Main Roll") },
3401 { "AlternateRoll", _("Alternate Roll") },
3402 { "Top", _("Top") },
3403 { "Middle", _("Middle") },
3404 { "Bottom", _("Bottom") },
3405 { "Side", _("Side") },
3406 { "Left", _("Left") },
3407 { "Right", _("Right") },
3408 { "Center", _("Center") },
3409 { "Rear", _("Rear") },
3410 { "ByPassTray", _("Multipurpose") },
3411 { "Tray1", _("Tray 1") },
3412 { "Tray2", _("Tray 2") },
3413 { "Tray3", _("Tray 3") },
3414 { "Tray4", _("Tray 4") },
3415 { "Tray5", _("Tray 5") },
3416 { "Tray6", _("Tray 6") },
3417 { "Tray7", _("Tray 7") },
3418 { "Tray8", _("Tray 8") },
3419 { "Tray9", _("Tray 9") },
3420 { "Tray10", _("Tray 10") },
3421 { "Tray11", _("Tray 11") },
3422 { "Tray12", _("Tray 12") },
3423 { "Tray13", _("Tray 13") },
3424 { "Tray14", _("Tray 14") },
3425 { "Tray15", _("Tray 15") },
3426 { "Tray16", _("Tray 16") },
3427 { "Tray17", _("Tray 17") },
3428 { "Tray18", _("Tray 18") },
3429 { "Tray19", _("Tray 19") },
3430 { "Tray20", _("Tray 20") },
3431 { "Roll1", _("Roll 1") },
3432 { "Roll2", _("Roll 2") },
3433 { "Roll3", _("Roll 3") },
3434 { "Roll4", _("Roll 4") },
3435 { "Roll5", _("Roll 5") },
3436 { "Roll6", _("Roll 6") },
3437 { "Roll7", _("Roll 7") },
3438 { "Roll8", _("Roll 8") },
3439 { "Roll9", _("Roll 9") },
3440 { "Roll10", _("Roll 10") }
3443 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3444 "*OrderDependency: 10 AnySetup *InputSlot\n"
3445 "*DefaultInputSlot: %s\n", ppdname
);
3446 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3448 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3450 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3451 if (!strcmp(sources
[j
][0], ppdname
))
3453 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3457 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3464 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3465 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3467 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3469 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3471 static const char * const media_types
[][2] =
3472 { /* "media-type" strings */
3473 { "aluminum", _("Aluminum") },
3474 { "auto", _("Automatic") },
3475 { "back-print-film", _("Back Print Film") },
3476 { "cardboard", _("Cardboard") },
3477 { "cardstock", _("Cardstock") },
3479 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3480 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3481 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3482 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3483 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3484 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3485 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3486 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3487 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3488 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3489 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3490 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3491 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3492 { "continuous", _("Continuous") },
3493 { "continuous-long", _("Continuous Long") },
3494 { "continuous-short", _("Continuous Short") },
3495 { "disc", _("Optical Disc") },
3496 { "disc-glossy", _("Glossy Optical Disc") },
3497 { "disc-high-gloss", _("High Gloss Optical Disc") },
3498 { "disc-matte", _("Matte Optical Disc") },
3499 { "disc-satin", _("Satin Optical Disc") },
3500 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3501 { "double-wall", _("Double Wall Cardboard") },
3502 { "dry-film", _("Dry Film") },
3503 { "dvd", _("DVD") },
3504 { "embossing-foil", _("Embossing Foil") },
3505 { "end-board", _("End Board") },
3506 { "envelope", _("Envelope") },
3507 { "envelope-archival", _("Archival Envelope") },
3508 { "envelope-bond", _("Bond Envelope") },
3509 { "envelope-coated", _("Coated Envelope") },
3510 { "envelope-cotton", _("Cotton Envelope") },
3511 { "envelope-fine", _("Fine Envelope") },
3512 { "envelope-heavyweight", _("Heavyweight Envelope") },
3513 { "envelope-inkjet", _("Inkjet Envelope") },
3514 { "envelope-lightweight", _("Lightweight Envelope") },
3515 { "envelope-plain", _("Plain Envelope") },
3516 { "envelope-preprinted", _("Preprinted Envelope") },
3517 { "envelope-window", _("Windowed Envelope") },
3518 { "fabric", _("Fabric") },
3519 { "fabric-archival", _("Archival Fabric") },
3520 { "fabric-glossy", _("Glossy Fabric") },
3521 { "fabric-high-gloss", _("High Gloss Fabric") },
3522 { "fabric-matte", _("Matte Fabric") },
3523 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3524 { "fabric-waterproof", _("Waterproof Fabric") },
3525 { "film", _("Film") },
3526 { "flexo-base", _("Flexo Base") },
3527 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3528 { "flute", _("Flute") },
3529 { "foil", _("Foil") },
3530 { "full-cut-tabs", _("Full Cut Tabs") },
3531 { "glass", _("Glass") },
3532 { "glass-colored", _("Glass Colored") },
3533 { "glass-opaque", _("Glass Opaque") },
3534 { "glass-surfaced", _("Glass Surfaced") },
3535 { "glass-textured", _("Glass Textured") },
3536 { "gravure-cylinder", _("Gravure Cylinder") },
3537 { "image-setter-paper", _("Image Setter Paper") },
3538 { "imaging-cylinder", _("Imaging Cylinder") },
3539 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3540 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3541 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3542 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3543 { "labels", _("Labels") },
3544 { "labels-colored", _("Colored Labels") },
3545 { "labels-glossy", _("Glossy Labels") },
3546 { "labels-high-gloss", _("High Gloss Labels") },
3547 { "labels-inkjet", _("Inkjet Labels") },
3548 { "labels-matte", _("Matte Labels") },
3549 { "labels-permanent", _("Permanent Labels") },
3550 { "labels-satin", _("Satin Labels") },
3551 { "labels-security", _("Security Labels") },
3552 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3553 { "laminating-foil", _("Laminating Foil") },
3554 { "letterhead", _("Letterhead") },
3555 { "metal", _("Metal") },
3556 { "metal-glossy", _("Metal Glossy") },
3557 { "metal-high-gloss", _("Metal High Gloss") },
3558 { "metal-matte", _("Metal Matte") },
3559 { "metal-satin", _("Metal Satin") },
3560 { "metal-semi-gloss", _("Metal Semi Gloss") },
3561 { "mounting-tape", _("Mounting Tape") },
3562 { "multi-layer", _("Multi Layer") },
3563 { "multi-part-form", _("Multi Part Form") },
3564 { "other", _("Other") },
3565 { "paper", _("Paper") },
3566 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3567 { "photographic", _("Photo Paper") },
3568 { "photographic-archival", _("Archival Photo Paper") },
3569 { "photographic-film", _("Photo Film") },
3570 { "photographic-glossy", _("Glossy Photo Paper") },
3571 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3572 { "photographic-matte", _("Matte Photo Paper") },
3573 { "photographic-satin", _("Satin Photo Paper") },
3574 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3575 { "plastic", _("Plastic") },
3576 { "plastic-archival", _("Plastic Archival") },
3577 { "plastic-colored", _("Plastic Colored") },
3578 { "plastic-glossy", _("Plastic Glossy") },
3579 { "plastic-high-gloss", _("Plastic High Gloss") },
3580 { "plastic-matte", _("Plastic Matte") },
3581 { "plastic-satin", _("Plastic Satin") },
3582 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3583 { "plate", _("Plate") },
3584 { "polyester", _("Polyester") },
3585 { "pre-cut-tabs", _("Pre Cut Tabs") },
3586 { "roll", _("Roll") },
3587 { "screen", _("Screen") },
3588 { "screen-paged", _("Screen Paged") },
3589 { "self-adhesive", _("Self Adhesive") },
3590 { "self-adhesive-film", _("Self Adhesive Film") },
3591 { "shrink-foil", _("Shrink Foil") },
3592 { "single-face", _("Single Face") },
3593 { "single-wall", _("Single Wall Cardboard") },
3594 { "sleeve", _("Sleeve") },
3595 { "stationery", _("Plain Paper") },
3596 { "stationery-archival", _("Archival Paper") },
3597 { "stationery-coated", _("Coated Paper") },
3598 { "stationery-cotton", _("Cotton Paper") },
3599 { "stationery-fine", _("Vellum Paper") },
3600 { "stationery-heavyweight", _("Heavyweight Paper") },
3601 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3602 { "stationery-inkjet", _("Inkjet Paper") },
3603 { "stationery-letterhead", _("Letterhead") },
3604 { "stationery-lightweight", _("Lightweight Paper") },
3605 { "stationery-preprinted", _("Preprinted Paper") },
3606 { "stationery-prepunched", _("Punched Paper") },
3607 { "tab-stock", _("Tab Stock") },
3608 { "tractor", _("Tractor") },
3609 { "transfer", _("Transfer") },
3610 { "transparency", _("Transparency") },
3611 { "triple-wall", _("Triple Wall Cardboard") },
3612 { "wet-film", _("Wet Film") }
3615 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3616 "*OrderDependency: 10 AnySetup *MediaType\n"
3617 "*DefaultMediaType: %s\n", ppdname
);
3618 for (i
= 0; i
< count
; i
++)
3620 const char *keyword
= ippGetString(attr
, i
, NULL
);
3622 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3624 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3625 if (!strcmp(keyword
, media_types
[j
][0]))
3628 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3629 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3632 char msg
[256]; /* Message key */
3633 const char *str
; /* Localized string */
3635 snprintf(msg
, sizeof(msg
), "media-type.%s", keyword
);
3636 if ((str
= _cupsMessageLookup(strings
, msg
)) == msg
)
3639 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, str
, ppdname
);
3642 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3649 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3650 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3651 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3652 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3656 const char *default_color
= NULL
; /* Default */
3658 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3660 const char *keyword
= ippGetString(attr
, i
, NULL
);
3661 /* Keyword for color/bit depth */
3663 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3666 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3667 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3669 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3672 default_color
= "FastGray";
3674 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3677 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3678 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3680 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3682 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3683 default_color
= "Gray";
3685 else if (!strcasecmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3688 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3689 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3691 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3693 default_color
= "RGB";
3695 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3698 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3699 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3701 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3704 default_color
= "AdobeRGB";
3710 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3711 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3719 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3721 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3722 "*OrderDependency: 10 AnySetup *Duplex\n"
3723 "*DefaultDuplex: None\n"
3724 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3725 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3726 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3727 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3729 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3731 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3733 const char *dm
= ippGetString(attr
, i
, NULL
);
3736 if (!_cups_strcasecmp(dm
, "DM1"))
3738 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3741 else if (!_cups_strcasecmp(dm
, "DM2"))
3743 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3746 else if (!_cups_strcasecmp(dm
, "DM3"))
3748 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3751 else if (!_cups_strcasecmp(dm
, "DM4"))
3753 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3758 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3760 const char *keyword
= ippGetString(attr
, 0, NULL
);
3763 if (!strcmp(keyword
, "flipped"))
3764 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3765 else if (!strcmp(keyword
, "manual-tumble"))
3766 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3767 else if (!strcmp(keyword
, "normal"))
3768 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3770 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3778 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3779 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3781 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3783 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3785 static const char * const output_bins
[][2] =
3786 { /* "output-bin" strings */
3787 { "auto", _("Automatic") },
3788 { "bottom", _("Bottom Tray") },
3789 { "center", _("Center Tray") },
3790 { "face-down", _("Face Down") },
3791 { "face-up", _("Face Up") },
3792 { "large-capacity", _("Large Capacity Tray") },
3793 { "left", _("Left Tray") },
3794 { "mailbox-1", _("Mailbox 1") },
3795 { "mailbox-2", _("Mailbox 2") },
3796 { "mailbox-3", _("Mailbox 3") },
3797 { "mailbox-4", _("Mailbox 4") },
3798 { "mailbox-5", _("Mailbox 5") },
3799 { "mailbox-6", _("Mailbox 6") },
3800 { "mailbox-7", _("Mailbox 7") },
3801 { "mailbox-8", _("Mailbox 8") },
3802 { "mailbox-9", _("Mailbox 9") },
3803 { "mailbox-10", _("Mailbox 10") },
3804 { "middle", _("Middle") },
3805 { "my-mailbox", _("My Mailbox") },
3806 { "rear", _("Rear Tray") },
3807 { "right", _("Right Tray") },
3808 { "side", _("Side Tray") },
3809 { "stacker-1", _("Stacker 1") },
3810 { "stacker-2", _("Stacker 2") },
3811 { "stacker-3", _("Stacker 3") },
3812 { "stacker-4", _("Stacker 4") },
3813 { "stacker-5", _("Stacker 5") },
3814 { "stacker-6", _("Stacker 6") },
3815 { "stacker-7", _("Stacker 7") },
3816 { "stacker-8", _("Stacker 8") },
3817 { "stacker-9", _("Stacker 9") },
3818 { "stacker-10", _("Stacker 10") },
3819 { "top", _("Top Tray") },
3820 { "tray-1", _("Tray 1") },
3821 { "tray-2", _("Tray 2") },
3822 { "tray-3", _("Tray 3") },
3823 { "tray-4", _("Tray 4") },
3824 { "tray-5", _("Tray 5") },
3825 { "tray-6", _("Tray 6") },
3826 { "tray-7", _("Tray 7") },
3827 { "tray-8", _("Tray 8") },
3828 { "tray-9", _("Tray 9") },
3829 { "tray-10", _("Tray 10") }
3832 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3833 "*OrderDependency: 10 AnySetup *OutputBin\n"
3834 "*DefaultOutputBin: %s\n", ppdname
);
3835 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3837 if (!ippContainsString(attr
, output_bins
[i
][0]))
3840 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3842 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3844 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3848 * Finishing options...
3850 * Eventually need to re-add support for finishings-col-database, however
3851 * it is difficult to map arbitrary finishing-template values to PPD options
3852 * and have the right constraints apply (e.g. stapling vs. folding vs.
3856 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3858 const char *name
; /* String name */
3859 int value
; /* Enum value */
3860 cups_array_t
*names
; /* Names we've added */
3862 count
= ippGetCount(attr
);
3863 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3866 * Staple/Bind/Stitch
3869 for (i
= 0; i
< count
; i
++)
3871 value
= ippGetInteger(attr
, i
);
3872 name
= ippEnumString("finishings", value
);
3874 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3880 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3881 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3882 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3883 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3885 for (; i
< count
; i
++)
3887 value
= ippGetInteger(attr
, i
);
3888 name
= ippEnumString("finishings", value
);
3890 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3893 if (cupsArrayFind(names
, (char *)name
))
3894 continue; /* Already did this finishing template */
3896 cupsArrayAdd(names
, (char *)name
);
3898 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3900 if (!strcmp(finishings
[j
][0], name
))
3902 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3903 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3909 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3916 for (i
= 0; i
< count
; i
++)
3918 value
= ippGetInteger(attr
, i
);
3919 name
= ippEnumString("finishings", value
);
3921 if (!strncmp(name
, "fold-", 5))
3927 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3928 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3929 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3930 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3932 for (; i
< count
; i
++)
3934 value
= ippGetInteger(attr
, i
);
3935 name
= ippEnumString("finishings", value
);
3937 if (strncmp(name
, "fold-", 5))
3940 if (cupsArrayFind(names
, (char *)name
))
3941 continue; /* Already did this finishing template */
3943 cupsArrayAdd(names
, (char *)name
);
3945 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3947 if (!strcmp(finishings
[j
][0], name
))
3949 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3950 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
3956 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
3963 for (i
= 0; i
< count
; i
++)
3965 value
= ippGetInteger(attr
, i
);
3966 name
= ippEnumString("finishings", value
);
3968 if (!strncmp(name
, "punch-", 6))
3974 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
3975 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
3976 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
3977 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3979 for (i
= 0; i
< count
; i
++)
3981 value
= ippGetInteger(attr
, i
);
3982 name
= ippEnumString("finishings", value
);
3984 if (strncmp(name
, "punch-", 6))
3987 if (cupsArrayFind(names
, (char *)name
))
3988 continue; /* Already did this finishing template */
3990 cupsArrayAdd(names
, (char *)name
);
3992 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3994 if (!strcmp(finishings
[j
][0], name
))
3996 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3997 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
4003 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4010 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4012 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
4013 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4014 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4015 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4016 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4017 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4018 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4021 cupsArrayDelete(names
);
4025 * cupsPrintQuality and DefaultResolution...
4028 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4030 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4032 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4034 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4036 const char *rs
= ippGetString(attr
, i
, NULL
);
4039 if (_cups_strncasecmp(rs
, "RS", 2))
4042 lowdpi
= atoi(rs
+ 2);
4043 if ((rs
= strrchr(rs
, '-')) != NULL
)
4044 hidpi
= atoi(rs
+ 1);
4053 * Invalid "urf-supported" value...
4061 * Generate print qualities based on low and high DPIs...
4064 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4066 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4067 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4068 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4069 if ((lowdpi
& 1) == 0)
4070 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4071 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4072 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4073 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4074 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4075 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4076 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4079 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4082 * Make a sorted list of resolutions.
4085 count
= ippGetCount(attr
);
4086 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4087 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4089 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4090 for (i
= 1; i
< count
; i
++)
4093 for (i
= 0; i
< (count
- 1); i
++)
4095 for (j
= i
+ 1; j
< count
; j
++)
4097 int ix
, iy
, /* First X and Y resolution */
4098 jx
, jy
, /* Second X and Y resolution */
4099 temp
; /* Swap variable */
4100 ipp_res_t units
; /* Resolution units */
4102 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4103 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4105 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4108 * Swap these two resolutions...
4111 temp
= resolutions
[i
];
4112 resolutions
[i
] = resolutions
[j
];
4113 resolutions
[j
] = temp
;
4119 * Generate print quality options...
4122 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4123 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4125 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4126 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4127 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4128 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4130 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4131 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4133 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4134 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4135 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4137 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4138 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4141 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4143 else if (is_apple
|| is_pwg
)
4147 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4149 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4154 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4157 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4159 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4160 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4161 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4162 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4163 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4164 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4165 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4166 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4167 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4171 * Close up and return...
4179 * If we get here then there was a problem creating the PPD...
4188 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4195 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4199 const char * /* O - InputSlot name */
4200 _pwgInputSlotForSource(
4201 const char *media_source
, /* I - PWG media-source */
4202 char *name
, /* I - Name buffer */
4203 size_t namesize
) /* I - Size of name buffer */
4206 * Range check input...
4209 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4212 if (_cups_strcasecmp(media_source
, "main"))
4213 strlcpy(name
, "Cassette", namesize
);
4214 else if (_cups_strcasecmp(media_source
, "alternate"))
4215 strlcpy(name
, "Multipurpose", namesize
);
4216 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4217 strlcpy(name
, "LargeCapacity", namesize
);
4218 else if (_cups_strcasecmp(media_source
, "bottom"))
4219 strlcpy(name
, "Lower", namesize
);
4220 else if (_cups_strcasecmp(media_source
, "middle"))
4221 strlcpy(name
, "Middle", namesize
);
4222 else if (_cups_strcasecmp(media_source
, "top"))
4223 strlcpy(name
, "Upper", namesize
);
4224 else if (_cups_strcasecmp(media_source
, "rear"))
4225 strlcpy(name
, "Rear", namesize
);
4226 else if (_cups_strcasecmp(media_source
, "side"))
4227 strlcpy(name
, "Side", namesize
);
4228 else if (_cups_strcasecmp(media_source
, "envelope"))
4229 strlcpy(name
, "Envelope", namesize
);
4230 else if (_cups_strcasecmp(media_source
, "main-roll"))
4231 strlcpy(name
, "Roll", namesize
);
4232 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4233 strlcpy(name
, "Roll2", namesize
);
4235 pwg_ppdize_name(media_source
, name
, namesize
);
4242 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4246 const char * /* O - MediaType name */
4247 _pwgMediaTypeForType(
4248 const char *media_type
, /* I - PWG media-type */
4249 char *name
, /* I - Name buffer */
4250 size_t namesize
) /* I - Size of name buffer */
4253 * Range check input...
4256 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4259 if (_cups_strcasecmp(media_type
, "auto"))
4260 strlcpy(name
, "Auto", namesize
);
4261 else if (_cups_strcasecmp(media_type
, "cardstock"))
4262 strlcpy(name
, "Cardstock", namesize
);
4263 else if (_cups_strcasecmp(media_type
, "envelope"))
4264 strlcpy(name
, "Envelope", namesize
);
4265 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4266 strlcpy(name
, "Glossy", namesize
);
4267 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4268 strlcpy(name
, "HighGloss", namesize
);
4269 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4270 strlcpy(name
, "Matte", namesize
);
4271 else if (_cups_strcasecmp(media_type
, "stationery"))
4272 strlcpy(name
, "Plain", namesize
);
4273 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4274 strlcpy(name
, "Coated", namesize
);
4275 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4276 strlcpy(name
, "Inkjet", namesize
);
4277 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4278 strlcpy(name
, "Letterhead", namesize
);
4279 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4280 strlcpy(name
, "Preprinted", namesize
);
4281 else if (_cups_strcasecmp(media_type
, "transparency"))
4282 strlcpy(name
, "Transparency", namesize
);
4284 pwg_ppdize_name(media_type
, name
, namesize
);
4291 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4294 const char * /* O - PageSize name */
4295 _pwgPageSizeForMedia(
4296 pwg_media_t
*media
, /* I - Media */
4297 char *name
, /* I - PageSize name buffer */
4298 size_t namesize
) /* I - Size of name buffer */
4300 const char *sizeptr
, /* Pointer to size in PWG name */
4301 *dimptr
; /* Pointer to dimensions in PWG name */
4305 * Range check input...
4308 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4312 * Copy or generate a PageSize name...
4318 * Use a standard Adobe name...
4321 strlcpy(name
, media
->ppd
, namesize
);
4323 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4324 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4325 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4326 (size_t)(dimptr
- sizeptr
) > namesize
)
4329 * Use a name of the form "wNNNhNNN"...
4332 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4333 (int)PWG_TO_POINTS(media
->length
));
4338 * Copy the size name from class_sizename_dimensions...
4341 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4342 name
[dimptr
- sizeptr
- 1] = '\0';
4350 * 'cups_get_url()' - Get a copy of the file at the given URL.
4353 static int /* O - 1 on success, 0 on failure */
4354 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4355 const char *url
, /* I - URL to get */
4356 char *name
, /* I - Temporary filename */
4357 size_t namesize
) /* I - Size of temporary filename buffer */
4359 char scheme
[32], /* URL scheme */
4360 userpass
[256], /* URL username:password */
4361 host
[256], /* URL host */
4362 curhost
[256], /* Current host */
4363 resource
[256]; /* URL resource */
4364 int port
; /* URL port */
4365 http_encryption_t encryption
; /* Type of encryption to use */
4366 http_status_t status
; /* Status of GET request */
4367 int fd
; /* Temporary file */
4370 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4373 if (port
== 443 || !strcmp(scheme
, "https"))
4374 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4376 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4378 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4381 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4387 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4390 status
= cupsGetFd(*http
, resource
, fd
);
4394 if (status
!= HTTP_STATUS_OK
)
4406 * 'pwg_add_finishing()' - Add a finishings value.
4411 cups_array_t
*finishings
, /* I - Finishings array */
4412 ipp_finishings_t
template, /* I - Finishing template */
4413 const char *name
, /* I - PPD option */
4414 const char *value
) /* I - PPD choice */
4416 _pwg_finishings_t
*f
; /* New finishings value */
4419 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4421 f
->value
= template;
4422 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4424 cupsArrayAdd(finishings
, f
);
4430 * 'pwg_compare_finishings()' - Compare two finishings values.
4433 static int /* O - Result of comparison */
4434 pwg_compare_finishings(
4435 _pwg_finishings_t
*a
, /* I - First finishings value */
4436 _pwg_finishings_t
*b
) /* I - Second finishings value */
4438 return ((int)b
->value
- (int)a
->value
);
4443 * 'pwg_free_finishings()' - Free a finishings value.
4447 pwg_free_finishings(
4448 _pwg_finishings_t
*f
) /* I - Finishings value */
4450 cupsFreeOptions(f
->num_options
, f
->options
);
4456 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4460 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4461 char *name
, /* I - Name buffer */
4462 size_t namesize
) /* I - Size of name buffer */
4464 char *ptr
, /* Pointer into name buffer */
4465 *end
; /* End of name buffer */
4474 *name
= (char)toupper(*ipp
++);
4476 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4478 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4481 *ptr
++ = (char)toupper(*ipp
++ & 255);
4492 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4496 pwg_ppdize_resolution(
4497 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4498 int element
, /* I - Element to convert */
4499 int *xres
, /* O - X resolution in DPI */
4500 int *yres
, /* O - Y resolution in DPI */
4501 char *name
, /* I - Name buffer */
4502 size_t namesize
) /* I - Size of name buffer */
4504 ipp_res_t units
; /* Units for resolution */
4507 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4509 if (units
== IPP_RES_PER_CM
)
4511 *xres
= (int)(*xres
* 2.54);
4512 *yres
= (int)(*yres
* 2.54);
4515 if (name
&& namesize
> 4)
4518 snprintf(name
, namesize
, "%ddpi", *xres
);
4520 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4526 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4530 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4531 char *name
, /* I - Name buffer */
4532 size_t namesize
, /* I - Size of name buffer */
4533 const char *dashchars
)/* I - Characters to be replaced by dashes */
4535 char *ptr
, /* Pointer into name buffer */
4536 *end
; /* End of name buffer */
4539 if (_cups_islower(*ppd
))
4542 * Already lowercase name, use as-is?
4545 const char *ppdptr
; /* Pointer into PPD keyword */
4547 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4548 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4553 strlcpy(name
, ppd
, namesize
);
4558 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4560 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4561 *ptr
++ = (char)tolower(*ppd
& 255);
4562 else if (strchr(dashchars
, *ppd
))
4567 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4568 _cups_isupper(ppd
[1]) && ptr
< end
)
4570 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))