2 * PPD cache implementation for CUPS.
4 * Copyright © 2010-2018 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 * Include necessary headers...
14 #include "cups-private.h"
15 #include "ppd-private.h"
20 * Macro to test for two almost-equal PWG measurements.
23 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
30 static int cups_get_url(http_t
**http
, const char *url
, char *name
, size_t namesize
);
31 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
32 static void pwg_add_message(cups_array_t
*a
, const char *msg
, const char *str
);
33 static int pwg_compare_finishings(_pwg_finishings_t
*a
, _pwg_finishings_t
*b
);
34 static int pwg_compare_sizes(cups_size_t
*a
, cups_size_t
*b
);
35 static cups_size_t
*pwg_copy_size(cups_size_t
*size
);
36 static void pwg_free_finishings(_pwg_finishings_t
*f
);
37 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
38 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
39 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
40 const char *dashchars
);
44 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
46 * This functions converts PPD and CUPS-specific options to their standard IPP
47 * attributes and values and adds them to the specified IPP request.
50 int /* O - New number of copies */
52 ipp_t
*request
, /* I - IPP request */
53 ppd_file_t
*ppd
, /* I - PPD file */
54 _ppd_cache_t
*pc
, /* I - PPD cache info */
55 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
56 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
57 ipp_attribute_t
*print_color_mode_sup
,
58 /* I - Printer supports print-color-mode */
59 const char *user
, /* I - User info */
60 const char *format
, /* I - document-format value */
61 int copies
, /* I - Number of copies */
62 int num_options
, /* I - Number of options */
63 cups_option_t
*options
) /* I - Options */
65 int i
; /* Looping var */
66 const char *keyword
, /* PWG keyword */
67 *password
; /* Password string */
68 pwg_size_t
*size
; /* PWG media size */
69 ipp_t
*media_col
, /* media-col value */
70 *media_size
; /* media-size value */
71 const char *media_source
, /* media-source value */
72 *media_type
, /* media-type value */
73 *collate_str
, /* multiple-document-handling value */
74 *color_attr_name
, /* Supported color attribute */
75 *mandatory
, /* Mandatory attributes */
76 *finishing_template
; /* Finishing template */
77 int num_finishings
= 0, /* Number of finishing values */
78 finishings
[10]; /* Finishing enum values */
79 ppd_choice_t
*choice
; /* Marked choice */
80 int finishings_copies
= copies
;
81 /* Number of copies for finishings */
85 * Send standard IPP attributes...
88 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
90 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
92 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
95 if (!strcmp(keyword
, "none"))
98 * Add plain-text job-password...
101 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
106 * Add hashed job-password...
109 unsigned char hash
[64]; /* Hash of password */
110 ssize_t hashlen
; /* Length of hash */
112 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
113 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
117 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
122 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
123 keyword
= cupsGetOption("job-billing", num_options
, options
);
126 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
129 if (pc
->accounting_user_id
)
131 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
135 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
138 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
140 if (strcmp(mandatory
, "copies") &&
141 strcmp(mandatory
, "destination-uris") &&
142 strcmp(mandatory
, "finishings") &&
143 strcmp(mandatory
, "finishings-col") &&
144 strcmp(mandatory
, "finishing-template") &&
145 strcmp(mandatory
, "job-account-id") &&
146 strcmp(mandatory
, "job-accounting-user-id") &&
147 strcmp(mandatory
, "job-password") &&
148 strcmp(mandatory
, "job-password-encryption") &&
149 strcmp(mandatory
, "media") &&
150 strncmp(mandatory
, "media-col", 9) &&
151 strcmp(mandatory
, "multiple-document-handling") &&
152 strcmp(mandatory
, "output-bin") &&
153 strcmp(mandatory
, "print-color-mode") &&
154 strcmp(mandatory
, "print-quality") &&
155 strcmp(mandatory
, "sides") &&
156 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
158 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
160 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
165 case IPP_TAG_INTEGER
:
167 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
169 case IPP_TAG_BOOLEAN
:
170 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
174 int lower
, upper
; /* Range */
176 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
177 lower
= upper
= atoi(keyword
);
179 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
182 case IPP_TAG_STRING
:
183 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
186 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
188 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
189 keyword
= "auto-monochrome";
190 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
191 keyword
= "process-monochrome";
194 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
200 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
201 keyword
= cupsGetOption("media", num_options
, options
);
203 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
204 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
205 size
= _ppdCacheGetSize(pc
, keyword
);
207 if (size
|| media_source
|| media_type
)
210 * Add a media-col value...
213 media_col
= ippNew();
217 media_size
= ippNew();
218 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
219 "x-dimension", size
->width
);
220 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
221 "y-dimension", size
->length
);
223 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
226 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
228 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
229 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
230 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
231 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
232 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
233 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
234 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
235 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
236 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
237 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
238 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
239 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
242 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
245 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
247 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
248 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
252 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
254 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
256 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
258 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
260 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
261 keyword
= "monochrome";
267 if (keyword
&& !strcmp(keyword
, "monochrome"))
269 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
270 keyword
= "auto-monochrome";
271 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
272 keyword
= "process-monochrome";
276 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
278 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
279 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
280 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
282 if (!_cups_strcasecmp(choice
->choice
, "draft"))
283 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
284 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
285 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
286 else if (!_cups_strcasecmp(choice
->choice
, "high"))
287 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
290 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
291 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
292 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
294 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
295 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
296 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
297 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
298 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
299 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
306 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
308 if (strstr(keyword
, "uncollated"))
313 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
318 if (!_cups_strcasecmp(format
, "image/gif") ||
319 !_cups_strcasecmp(format
, "image/jp2") ||
320 !_cups_strcasecmp(format
, "image/jpeg") ||
321 !_cups_strcasecmp(format
, "image/png") ||
322 !_cups_strcasecmp(format
, "image/tiff") ||
323 !_cups_strncasecmp(format
, "image/x-", 8))
326 * Collation makes no sense for single page image formats...
331 else if (!_cups_strncasecmp(format
, "image/", 6) ||
332 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
335 * Multi-page image formats will have copies applied by the upstream
343 if (doc_handling_sup
)
345 if (!_cups_strcasecmp(keyword
, "true"))
346 collate_str
= "separate-documents-collated-copies";
348 collate_str
= "separate-documents-uncollated-copies";
350 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
352 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
354 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
359 if (i
>= doc_handling_sup
->num_values
)
364 * Map finishing options...
367 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
368 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
370 if (finishing_template
)
372 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
374 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
375 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
378 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
381 * Send job-pages-per-set attribute to apply finishings correctly...
384 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
389 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
390 if (num_finishings
> 0)
392 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
394 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
397 * Send job-pages-per-set attribute to apply finishings correctly...
400 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
410 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
413 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
417 _ppd_cache_t
* /* O - PPD cache and mapping data */
418 _ppdCacheCreateWithFile(
419 const char *filename
, /* I - File to read */
420 ipp_t
**attrs
) /* IO - IPP attributes, if any */
422 cups_file_t
*fp
; /* File */
423 _ppd_cache_t
*pc
; /* PWG mapping data */
424 pwg_size_t
*size
; /* Current size */
425 pwg_map_t
*map
; /* Current map */
426 _pwg_finishings_t
*finishings
; /* Current finishings option */
427 int linenum
, /* Current line number */
428 num_bins
, /* Number of bins in file */
429 num_sizes
, /* Number of sizes in file */
430 num_sources
, /* Number of sources in file */
431 num_types
; /* Number of types in file */
432 char line
[2048], /* Current line */
433 *value
, /* Pointer to value in line */
434 *valueptr
, /* Pointer into value */
435 pwg_keyword
[128], /* PWG keyword */
436 ppd_keyword
[PPD_MAX_NAME
];
438 _pwg_print_color_mode_t print_color_mode
;
439 /* Print color mode for preset */
440 _pwg_print_quality_t print_quality
; /* Print quality for preset */
443 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
446 * Range check input...
454 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
462 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
464 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
469 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
472 if (!cupsFileGets(fp
, line
, sizeof(line
)))
474 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
475 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
480 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
482 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
483 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
488 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
490 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
491 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
492 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
498 * Allocate the mapping data structure...
501 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
503 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
504 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
508 pc
->max_copies
= 9999;
520 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
522 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
523 "linenum=%d", line
, value
, linenum
));
527 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
529 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
532 else if (!_cups_strcasecmp(line
, "Filter"))
535 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
536 (cups_acopy_func_t
)_cupsStrAlloc
,
537 (cups_afree_func_t
)_cupsStrFree
);
539 cupsArrayAdd(pc
->filters
, value
);
541 else if (!_cups_strcasecmp(line
, "PreFilter"))
544 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
545 (cups_acopy_func_t
)_cupsStrAlloc
,
546 (cups_afree_func_t
)_cupsStrFree
);
548 cupsArrayAdd(pc
->prefilters
, value
);
550 else if (!_cups_strcasecmp(line
, "Product"))
552 pc
->product
= _cupsStrAlloc(value
);
554 else if (!_cups_strcasecmp(line
, "SingleFile"))
556 pc
->single_file
= !_cups_strcasecmp(value
, "true");
558 else if (!_cups_strcasecmp(line
, "IPP"))
560 off_t pos
= cupsFileTell(fp
), /* Position in file */
561 length
= strtol(value
, NULL
, 10);
562 /* Length of IPP attributes */
566 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
567 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
570 else if (length
<= 0)
572 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
573 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
580 * Read IPP attributes into the provided variable...
585 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
586 *attrs
) != IPP_STATE_DATA
)
588 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
596 * Skip the IPP data entirely...
599 cupsFileSeek(fp
, pos
+ length
);
602 if (cupsFileTell(fp
) != (pos
+ length
))
604 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
605 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
609 else if (!_cups_strcasecmp(line
, "NumBins"))
613 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
614 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
618 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
620 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
621 "%d.", num_sizes
, linenum
));
622 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
626 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
628 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
630 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
634 else if (!_cups_strcasecmp(line
, "Bin"))
636 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
638 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
639 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
643 if (pc
->num_bins
>= num_bins
)
645 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
647 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
651 map
= pc
->bins
+ pc
->num_bins
;
652 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
653 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
657 else if (!_cups_strcasecmp(line
, "NumSizes"))
661 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
662 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
666 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
668 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
669 "%d.", num_sizes
, linenum
));
670 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
676 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
678 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
680 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
685 else if (!_cups_strcasecmp(line
, "Size"))
687 if (pc
->num_sizes
>= num_sizes
)
689 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
691 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
695 size
= pc
->sizes
+ pc
->num_sizes
;
697 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
698 &(size
->width
), &(size
->length
), &(size
->left
),
699 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
701 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
703 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
707 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
708 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
712 else if (!_cups_strcasecmp(line
, "CustomSize"))
714 if (pc
->custom_max_width
> 0)
716 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
718 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
722 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
723 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
724 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
725 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
726 &(pc
->custom_size
.top
)) != 8)
728 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
730 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
734 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
735 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
736 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
738 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
739 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
740 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
742 else if (!_cups_strcasecmp(line
, "SourceOption"))
744 pc
->source_option
= _cupsStrAlloc(value
);
746 else if (!_cups_strcasecmp(line
, "NumSources"))
750 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
758 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
759 "line %d.", num_sources
, linenum
));
760 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
764 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
766 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
768 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
772 else if (!_cups_strcasecmp(line
, "Source"))
774 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
776 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
778 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
782 if (pc
->num_sources
>= num_sources
)
784 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
786 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
790 map
= pc
->sources
+ pc
->num_sources
;
791 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
792 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
796 else if (!_cups_strcasecmp(line
, "NumTypes"))
800 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
801 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
805 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
807 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
808 "line %d.", num_types
, linenum
));
809 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
813 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
815 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
817 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
821 else if (!_cups_strcasecmp(line
, "Type"))
823 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
825 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
827 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
831 if (pc
->num_types
>= num_types
)
833 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
835 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
839 map
= pc
->types
+ pc
->num_types
;
840 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
841 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
845 else if (!_cups_strcasecmp(line
, "Preset"))
848 * Preset output-mode print-quality name=value ...
851 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
852 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
854 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
855 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
856 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
857 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
858 valueptr
== value
|| !*valueptr
)
860 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
862 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
866 pc
->num_presets
[print_color_mode
][print_quality
] =
867 cupsParseOptions(valueptr
, 0,
868 pc
->presets
[print_color_mode
] + print_quality
);
870 else if (!_cups_strcasecmp(line
, "SidesOption"))
871 pc
->sides_option
= _cupsStrAlloc(value
);
872 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
873 pc
->sides_1sided
= _cupsStrAlloc(value
);
874 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
875 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
876 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
877 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
878 else if (!_cups_strcasecmp(line
, "Finishings"))
882 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
884 (cups_afree_func_t
)pwg_free_finishings
);
886 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
889 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
890 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
891 &(finishings
->options
));
893 cupsArrayAdd(pc
->finishings
, finishings
);
895 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
898 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
900 cupsArrayAdd(pc
->templates
, value
);
902 else if (!_cups_strcasecmp(line
, "MaxCopies"))
903 pc
->max_copies
= atoi(value
);
904 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
905 pc
->charge_info_uri
= _cupsStrAlloc(value
);
906 else if (!_cups_strcasecmp(line
, "JobAccountId"))
907 pc
->account_id
= !_cups_strcasecmp(value
, "true");
908 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
909 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
910 else if (!_cups_strcasecmp(line
, "JobPassword"))
911 pc
->password
= _cupsStrAlloc(value
);
912 else if (!_cups_strcasecmp(line
, "Mandatory"))
915 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
917 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
919 else if (!_cups_strcasecmp(line
, "SupportFile"))
921 if (!pc
->support_files
)
922 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
923 (cups_acopy_func_t
)_cupsStrAlloc
,
924 (cups_afree_func_t
)_cupsStrFree
);
926 cupsArrayAdd(pc
->support_files
, value
);
930 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
935 if (pc
->num_sizes
< num_sizes
)
937 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
938 pc
->num_sizes
, num_sizes
));
939 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
943 if (pc
->num_sources
< num_sources
)
945 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
946 pc
->num_sources
, num_sources
));
947 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
951 if (pc
->num_types
< num_types
)
953 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
954 pc
->num_types
, num_types
));
955 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
964 * If we get here the file was bad - free any data and return...
970 _ppdCacheDestroy(pc
);
983 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
986 _ppd_cache_t
* /* O - PPD cache and mapping data */
987 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
989 int i
, j
, k
; /* Looping vars */
990 _ppd_cache_t
*pc
; /* PWG mapping data */
991 ppd_option_t
*input_slot
, /* InputSlot option */
992 *media_type
, /* MediaType option */
993 *output_bin
, /* OutputBin option */
994 *color_model
, /* ColorModel option */
995 *duplex
, /* Duplex option */
996 *ppd_option
; /* Other PPD option */
997 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
998 pwg_map_t
*map
; /* Current source/type map */
999 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1000 int num_options
; /* Number of preset options and props */
1001 cups_option_t
*options
; /* Preset options and properties */
1002 ppd_size_t
*ppd_size
; /* Current PPD size */
1003 pwg_size_t
*pwg_size
; /* Current PWG size */
1004 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1005 /* PWG keyword string */
1006 ppd_name
[PPD_MAX_NAME
];
1007 /* Normalized PPD name */
1008 const char *pwg_name
; /* Standard PWG media name */
1009 pwg_media_t
*pwg_media
; /* PWG media data */
1010 _pwg_print_color_mode_t pwg_print_color_mode
;
1011 /* print-color-mode index */
1012 _pwg_print_quality_t pwg_print_quality
;
1013 /* print-quality index */
1014 int similar
; /* Are the old and new size similar? */
1015 pwg_size_t
*old_size
; /* Current old size */
1016 int old_imageable
, /* Old imageable length in 2540ths */
1017 old_borderless
, /* Old borderless state */
1018 old_known_pwg
; /* Old PWG name is well-known */
1019 int new_width
, /* New width in 2540ths */
1020 new_length
, /* New length in 2540ths */
1021 new_left
, /* New left margin in 2540ths */
1022 new_bottom
, /* New bottom margin in 2540ths */
1023 new_right
, /* New right margin in 2540ths */
1024 new_top
, /* New top margin in 2540ths */
1025 new_imageable
, /* New imageable length in 2540ths */
1026 new_borderless
, /* New borderless state */
1027 new_known_pwg
; /* New PWG name is well-known */
1028 pwg_size_t
*new_size
; /* New size to add, if any */
1029 const char *filter
; /* Current filter */
1030 _pwg_finishings_t
*finishings
; /* Current finishings value */
1031 char msg_id
[256]; /* Message identifier */
1034 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1037 * Range check input...
1044 * Allocate memory...
1047 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1049 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1053 pc
->strings
= _cupsMessageNew(NULL
);
1056 * Copy and convert size data...
1059 if (ppd
->num_sizes
> 0)
1061 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1063 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1064 "pwg_size_t's.", ppd
->num_sizes
));
1068 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1073 * Don't copy over custom size...
1076 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1080 * Convert the PPD size name to the corresponding PWG keyword name.
1083 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1086 * Standard name, do we have conflicts?
1089 for (j
= 0; j
< pc
->num_sizes
; j
++)
1090 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1100 * Standard name and no conflicts, use it!
1103 pwg_name
= pwg_media
->pwg
;
1109 * Not a standard name; convert it to a PWG vendor name of the form:
1111 * pp_lowerppd_WIDTHxHEIGHTuu
1114 pwg_name
= pwg_keyword
;
1117 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1118 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1119 PWG_FROM_POINTS(ppd_size
->width
),
1120 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1124 * If we have a similar paper with non-zero margins then we only want to
1125 * keep it if it has a larger imageable area length. The NULL check is for
1126 * dimensions that are <= 0...
1129 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1130 PWG_FROM_POINTS(ppd_size
->length
),
1134 new_width
= pwg_media
->width
;
1135 new_length
= pwg_media
->length
;
1136 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1137 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1138 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1139 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1140 new_imageable
= new_length
- new_top
- new_bottom
;
1141 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1142 new_left
== 0 && new_right
== 0;
1144 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1148 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1149 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1150 old_size
->right
== 0 && old_size
->top
== 0;
1151 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1152 strncmp(old_size
->map
.pwg
, "om_", 3);
1154 similar
= old_borderless
== new_borderless
&&
1155 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1156 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1159 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1162 * The new paper has a larger imageable area so it could replace
1163 * the older paper. Regardless of the imageable area, we always
1164 * prefer the size with a well-known PWG name.
1167 new_size
= old_size
;
1168 _cupsStrFree(old_size
->map
.ppd
);
1169 _cupsStrFree(old_size
->map
.pwg
);
1176 * The paper was unique enough to deserve its own entry so add it to the
1180 new_size
= pwg_size
++;
1190 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1191 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1192 new_size
->width
= new_width
;
1193 new_size
->length
= new_length
;
1194 new_size
->left
= new_left
;
1195 new_size
->bottom
= new_bottom
;
1196 new_size
->right
= new_right
;
1197 new_size
->top
= new_top
;
1202 if (ppd
->variable_sizes
)
1205 * Generate custom size data...
1208 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1209 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1210 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1211 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1212 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1213 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1215 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1216 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1217 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1218 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1219 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1220 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1222 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1223 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1224 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1225 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1229 * Copy and convert InputSlot data...
1232 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1233 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1237 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1239 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1241 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1242 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1246 pc
->num_sources
= input_slot
->num_choices
;
1248 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1251 i
--, choice
++, map
++)
1253 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1254 !_cups_strcasecmp(choice
->choice
, "Default"))
1256 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1258 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1260 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1262 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1263 !_cups_strcasecmp(choice
->choice
, "MP") ||
1264 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1265 pwg_name
= "by-pass-tray";
1266 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1267 pwg_name
= "large-capacity";
1268 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1269 pwg_name
= "bottom";
1270 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1271 pwg_name
= "middle";
1272 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1274 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1276 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1277 pwg_name
= "main-roll";
1281 * Convert PPD name to lowercase...
1284 pwg_name
= pwg_keyword
;
1285 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1289 map
->pwg
= _cupsStrAlloc(pwg_name
);
1290 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1293 * Add localized text for PWG keyword to message catalog...
1296 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1297 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1302 * Copy and convert MediaType data...
1305 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1307 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1309 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1310 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1314 pc
->num_types
= media_type
->num_choices
;
1316 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1319 i
--, choice
++, map
++)
1321 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1322 !_cups_strcasecmp(choice
->choice
, "Any") ||
1323 !_cups_strcasecmp(choice
->choice
, "Default"))
1325 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1326 pwg_name
= "cardstock";
1327 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1328 pwg_name
= "envelope";
1329 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1330 pwg_name
= "photographic-glossy";
1331 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1332 pwg_name
= "photographic-high-gloss";
1333 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1334 pwg_name
= "photographic-matte";
1335 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1336 pwg_name
= "stationery";
1337 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1338 pwg_name
= "stationery-coated";
1339 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1340 pwg_name
= "stationery-inkjet";
1341 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1342 pwg_name
= "stationery-letterhead";
1343 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1344 pwg_name
= "stationery-preprinted";
1345 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1346 pwg_name
= "stationery-recycled";
1347 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1348 pwg_name
= "transparency";
1352 * Convert PPD name to lowercase...
1355 pwg_name
= pwg_keyword
;
1356 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1360 map
->pwg
= _cupsStrAlloc(pwg_name
);
1361 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1364 * Add localized text for PWG keyword to message catalog...
1367 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", pwg_name
);
1368 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1373 * Copy and convert OutputBin data...
1376 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1378 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1380 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1381 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1385 pc
->num_bins
= output_bin
->num_choices
;
1387 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1390 i
--, choice
++, map
++)
1392 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1394 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1395 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1398 * Add localized text for PWG keyword to message catalog...
1401 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_name
);
1402 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1406 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1409 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1412 const char *quality
, /* com.apple.print.preset.quality value */
1413 *output_mode
, /* com.apple.print.preset.output-mode value */
1414 *color_model_val
, /* ColorModel choice */
1415 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1416 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1421 * Add localized text for PWG keyword to message catalog...
1424 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1425 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1428 * Get the options for this preset...
1431 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1434 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1435 num_options
, options
)) != NULL
)
1438 * Get the print-quality for this preset...
1441 if (!strcmp(quality
, "low"))
1442 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1443 else if (!strcmp(quality
, "high"))
1444 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1446 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1449 * Ignore graphicsType "Photo" presets that are not high quality.
1452 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1453 num_options
, options
);
1455 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1456 !strcmp(graphicsType
, "Photo"))
1460 * Ignore presets for normal and draft quality where the coating
1461 * isn't "none" or "autodetect".
1464 media_front_coating
= cupsGetOption(
1465 "com.apple.print.preset.media-front-coating",
1466 num_options
, options
);
1468 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1469 media_front_coating
&&
1470 strcmp(media_front_coating
, "none") &&
1471 strcmp(media_front_coating
, "autodetect"))
1475 * Get the output mode for this preset...
1478 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1479 num_options
, options
);
1480 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1484 if (!strcmp(output_mode
, "monochrome"))
1485 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1487 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1489 else if (color_model_val
)
1491 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1492 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1494 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1497 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1500 * Save the options for this combination as needed...
1503 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1504 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1505 _ppdParseOptions(ppd_attr
->value
, 0,
1506 pc
->presets
[pwg_print_color_mode
] +
1507 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1510 cupsFreeOptions(num_options
, options
);
1512 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1515 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1516 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1517 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1520 * Try adding some common color options to create grayscale presets. These
1521 * are listed in order of popularity...
1524 const char *color_option
= NULL
, /* Color control option */
1525 *gray_choice
= NULL
; /* Choice to select grayscale */
1527 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1528 ppdFindChoice(color_model
, "Gray"))
1530 color_option
= "ColorModel";
1531 gray_choice
= "Gray";
1533 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1534 ppdFindChoice(color_model
, "grayscale"))
1536 color_option
= "HPColorMode";
1537 gray_choice
= "grayscale";
1539 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1540 ppdFindChoice(color_model
, "Mono"))
1542 color_option
= "BRMonoColor";
1543 gray_choice
= "Mono";
1545 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1546 ppdFindChoice(color_model
, "1"))
1548 color_option
= "CNIJSGrayScale";
1551 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1552 ppdFindChoice(color_model
, "True"))
1554 color_option
= "HPColorAsGray";
1555 gray_choice
= "True";
1558 if (color_option
&& gray_choice
)
1561 * Copy and convert ColorModel (output-mode) data...
1564 cups_option_t
*coption
, /* Color option */
1565 *moption
; /* Monochrome option */
1567 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1568 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1569 pwg_print_quality
++)
1571 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1574 * Copy the color options...
1577 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1578 [pwg_print_quality
];
1579 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1583 for (i
= num_options
, moption
= options
,
1584 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1585 [pwg_print_quality
];
1587 i
--, moption
++, coption
++)
1589 moption
->name
= _cupsStrRetain(coption
->name
);
1590 moption
->value
= _cupsStrRetain(coption
->value
);
1593 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1595 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1599 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1603 * Add the grayscale option to the preset...
1606 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1607 cupsAddOption(color_option
, gray_choice
,
1608 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1609 [pwg_print_quality
],
1610 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1617 * Copy and convert Duplex (sides) data...
1620 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1621 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1622 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1623 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1624 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1628 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1630 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1634 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1635 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1636 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1637 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1638 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1639 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1640 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1641 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1642 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1643 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1644 !pc
->sides_2sided_short
)
1645 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1650 * Copy filters and pre-filters...
1653 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1654 (cups_acopy_func_t
)_cupsStrAlloc
,
1655 (cups_afree_func_t
)_cupsStrFree
);
1657 cupsArrayAdd(pc
->filters
,
1658 "application/vnd.cups-raw application/octet-stream 0 -");
1660 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1664 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1666 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1668 else if (ppd
->num_filters
> 0)
1670 for (i
= 0; i
< ppd
->num_filters
; i
++)
1671 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1674 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1677 * See if we have a command filter...
1680 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1682 filter
= (const char *)cupsArrayNext(pc
->filters
))
1683 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1684 _cups_isspace(filter
[28]))
1688 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1689 _cups_strcasecmp(ppd_attr
->value
, "none")))
1692 * No command filter and no cupsCommands keyword telling us not to use one.
1693 * See if this is a PostScript printer, and if so add a PostScript command
1697 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1699 filter
= (const char *)cupsArrayNext(pc
->filters
))
1700 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1701 _cups_isspace(filter
[31]))
1705 cupsArrayAdd(pc
->filters
,
1706 "application/vnd.cups-command application/postscript 100 "
1710 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1712 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1713 (cups_acopy_func_t
)_cupsStrAlloc
,
1714 (cups_afree_func_t
)_cupsStrFree
);
1718 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1720 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1723 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1724 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1727 * Copy the product string, if any...
1731 pc
->product
= _cupsStrAlloc(ppd
->product
);
1734 * Copy finishings mapping data...
1737 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1740 * Have proper vendor mapping of IPP finishings values to PPD options...
1743 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1744 NULL
, NULL
, 0, NULL
,
1745 (cups_afree_func_t
)pwg_free_finishings
);
1749 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1752 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1753 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1754 &(finishings
->options
),
1755 _PPD_PARSE_OPTIONS
);
1757 cupsArrayAdd(pc
->finishings
, finishings
);
1759 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1765 * No IPP mapping data, try to map common/standard PPD keywords...
1768 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1770 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1773 * Add staple finishings...
1776 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1777 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1778 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1779 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1780 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1781 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1782 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1783 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1784 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1785 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1788 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1791 * Add (Ricoh) punch finishings...
1794 if (ppdFindChoice(ppd_option
, "Left2"))
1795 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1796 if (ppdFindChoice(ppd_option
, "Left3"))
1797 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1798 if (ppdFindChoice(ppd_option
, "Left4"))
1799 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1800 if (ppdFindChoice(ppd_option
, "Right2"))
1801 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1802 if (ppdFindChoice(ppd_option
, "Right3"))
1803 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1804 if (ppdFindChoice(ppd_option
, "Right4"))
1805 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1806 if (ppdFindChoice(ppd_option
, "Upper2"))
1807 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1808 if (ppdFindChoice(ppd_option
, "Upper3"))
1809 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1810 if (ppdFindChoice(ppd_option
, "Upper4"))
1811 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1814 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1817 * Add bind finishings...
1820 if (ppdFindChoice(ppd_option
, "Left"))
1821 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1822 if (ppdFindChoice(ppd_option
, "Right"))
1823 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1824 if (ppdFindChoice(ppd_option
, "Top"))
1825 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1826 if (ppdFindChoice(ppd_option
, "Bottom"))
1827 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1830 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1833 * Add (Adobe) fold finishings...
1836 if (ppdFindChoice(ppd_option
, "ZFold"))
1837 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1838 if (ppdFindChoice(ppd_option
, "Saddle"))
1839 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1840 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1841 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1842 if (ppdFindChoice(ppd_option
, "LeftGate"))
1843 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1844 if (ppdFindChoice(ppd_option
, "RightGate"))
1845 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1846 if (ppdFindChoice(ppd_option
, "Letter"))
1847 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1848 if (ppdFindChoice(ppd_option
, "XFold"))
1849 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1852 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1855 * Add (Ricoh) fold finishings...
1858 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1859 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1862 if (cupsArrayCount(pc
->finishings
) == 0)
1864 cupsArrayDelete(pc
->finishings
);
1865 pc
->finishings
= NULL
;
1869 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1871 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
1873 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1875 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1878 * Add localized text for PWG keyword to message catalog...
1881 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1882 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1890 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1891 pc
->max_copies
= atoi(ppd_attr
->value
);
1892 else if (ppd
->manual_copies
)
1895 pc
->max_copies
= 9999;
1898 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1899 * cupsJobPassword, and cupsMandatory.
1902 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1903 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1905 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1906 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1908 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1909 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1911 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1912 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1914 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1915 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1921 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1922 (cups_acopy_func_t
)_cupsStrAlloc
,
1923 (cups_afree_func_t
)_cupsStrFree
);
1925 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1927 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1928 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1930 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1931 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1934 * Return the cache data...
1940 * If we get here we need to destroy the PWG mapping data and return NULL...
1945 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1946 _ppdCacheDestroy(pc
);
1953 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1957 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1959 int i
; /* Looping var */
1960 pwg_map_t
*map
; /* Current map */
1961 pwg_size_t
*size
; /* Current size */
1965 * Range check input...
1972 * Free memory as needed...
1977 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1979 _cupsStrFree(map
->pwg
);
1980 _cupsStrFree(map
->ppd
);
1988 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1990 _cupsStrFree(size
->map
.pwg
);
1991 _cupsStrFree(size
->map
.ppd
);
1997 if (pc
->source_option
)
1998 _cupsStrFree(pc
->source_option
);
2002 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2004 _cupsStrFree(map
->pwg
);
2005 _cupsStrFree(map
->ppd
);
2013 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2015 _cupsStrFree(map
->pwg
);
2016 _cupsStrFree(map
->ppd
);
2022 if (pc
->custom_max_keyword
)
2023 _cupsStrFree(pc
->custom_max_keyword
);
2025 if (pc
->custom_min_keyword
)
2026 _cupsStrFree(pc
->custom_min_keyword
);
2028 _cupsStrFree(pc
->product
);
2029 cupsArrayDelete(pc
->filters
);
2030 cupsArrayDelete(pc
->prefilters
);
2031 cupsArrayDelete(pc
->finishings
);
2033 _cupsStrFree(pc
->charge_info_uri
);
2034 _cupsStrFree(pc
->password
);
2036 cupsArrayDelete(pc
->mandatory
);
2038 cupsArrayDelete(pc
->support_files
);
2040 cupsArrayDelete(pc
->strings
);
2047 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2051 const char * /* O - output-bin or NULL */
2053 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2054 const char *output_bin
) /* I - PPD OutputBin string */
2056 int i
; /* Looping var */
2060 * Range check input...
2063 if (!pc
|| !output_bin
)
2067 * Look up the OutputBin string...
2071 for (i
= 0; i
< pc
->num_bins
; i
++)
2072 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2073 return (pc
->bins
[i
].pwg
);
2080 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2081 * IPP finishings value(s).
2084 int /* O - New number of options */
2085 _ppdCacheGetFinishingOptions(
2086 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2087 ipp_t
*job
, /* I - Job attributes or NULL */
2088 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2089 int num_options
, /* I - Number of options */
2090 cups_option_t
**options
) /* IO - Options */
2092 int i
; /* Looping var */
2093 _pwg_finishings_t
*f
, /* PWG finishings options */
2094 key
; /* Search key */
2095 ipp_attribute_t
*attr
; /* Finishings attribute */
2096 cups_option_t
*option
; /* Current finishings option */
2100 * Range check input...
2103 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2104 (!job
&& value
== IPP_FINISHINGS_NONE
))
2105 return (num_options
);
2108 * Apply finishing options...
2111 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2113 int num_values
= ippGetCount(attr
); /* Number of values */
2115 for (i
= 0; i
< num_values
; i
++)
2117 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2119 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2121 int j
; /* Another looping var */
2123 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2124 num_options
= cupsAddOption(option
->name
, option
->value
,
2125 num_options
, options
);
2129 else if (value
!= IPP_FINISHINGS_NONE
)
2133 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2135 int j
; /* Another looping var */
2137 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2138 num_options
= cupsAddOption(option
->name
, option
->value
,
2139 num_options
, options
);
2143 return (num_options
);
2148 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2152 int /* O - Number of finishings values */
2153 _ppdCacheGetFinishingValues(
2154 ppd_file_t
*ppd
, /* I - Marked PPD file */
2155 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2156 int max_values
, /* I - Maximum number of finishings values */
2157 int *values
) /* O - Finishings values */
2159 int i
, /* Looping var */
2160 num_values
= 0; /* Number of values */
2161 _pwg_finishings_t
*f
; /* Current finishings option */
2162 cups_option_t
*option
; /* Current option */
2163 ppd_choice_t
*choice
; /* Marked PPD choice */
2167 * Range check input...
2170 DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd
, pc
, max_values
, values
));
2172 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2174 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2177 else if (!pc
->finishings
)
2179 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2184 * Go through the finishings options and see what is set...
2187 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2189 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2191 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2193 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2195 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2197 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2199 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2206 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2208 values
[num_values
++] = f
->value
;
2210 if (num_values
>= max_values
)
2215 if (num_values
== 0)
2218 * Always have at least "finishings" = 'none'...
2221 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2222 values
[0] = IPP_FINISHINGS_NONE
;
2226 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2228 return (num_values
);
2233 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2234 * attributes or a keyword string.
2237 const char * /* O - PPD InputSlot or NULL */
2238 _ppdCacheGetInputSlot(
2239 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2240 ipp_t
*job
, /* I - Job attributes or NULL */
2241 const char *keyword
) /* I - Keyword string or NULL */
2244 * Range check input...
2247 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2250 if (job
&& !keyword
)
2253 * Lookup the media-col attribute and any media-source found there...
2256 ipp_attribute_t
*media_col
, /* media-col attribute */
2257 *media_source
; /* media-source attribute */
2258 pwg_size_t size
; /* Dimensional size */
2259 int margins_set
; /* Were the margins set? */
2261 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2263 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2265 IPP_TAG_KEYWORD
)) != NULL
)
2268 * Use the media-source value from media-col...
2271 keyword
= ippGetString(media_source
, 0, NULL
);
2273 else if (pwgInitSize(&size
, job
, &margins_set
))
2276 * For media <= 5x7, look for a photo tray...
2279 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2286 int i
; /* Looping var */
2288 for (i
= 0; i
< pc
->num_sources
; i
++)
2289 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2290 return (pc
->sources
[i
].ppd
);
2298 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2299 * attributes or a keyword string.
2302 const char * /* O - PPD MediaType or NULL */
2303 _ppdCacheGetMediaType(
2304 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2305 ipp_t
*job
, /* I - Job attributes or NULL */
2306 const char *keyword
) /* I - Keyword string or NULL */
2309 * Range check input...
2312 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2315 if (job
&& !keyword
)
2318 * Lookup the media-col attribute and any media-source found there...
2321 ipp_attribute_t
*media_col
, /* media-col attribute */
2322 *media_type
; /* media-type attribute */
2324 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2327 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2329 IPP_TAG_KEYWORD
)) == NULL
)
2330 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2331 "media-type", IPP_TAG_NAME
);
2334 keyword
= media_type
->values
[0].string
.text
;
2340 int i
; /* Looping var */
2342 for (i
= 0; i
< pc
->num_types
; i
++)
2343 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2344 return (pc
->types
[i
].ppd
);
2352 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2356 const char * /* O - PPD OutputBin or NULL */
2357 _ppdCacheGetOutputBin(
2358 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2359 const char *output_bin
) /* I - Keyword string */
2361 int i
; /* Looping var */
2365 * Range check input...
2368 if (!pc
|| !output_bin
)
2372 * Look up the OutputBin string...
2376 for (i
= 0; i
< pc
->num_bins
; i
++)
2377 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2378 return (pc
->bins
[i
].ppd
);
2385 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2386 * attributes or a keyword string.
2389 const char * /* O - PPD PageSize or NULL */
2390 _ppdCacheGetPageSize(
2391 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2392 ipp_t
*job
, /* I - Job attributes or NULL */
2393 const char *keyword
, /* I - Keyword string or NULL */
2394 int *exact
) /* O - 1 if exact match, 0 otherwise */
2396 int i
; /* Looping var */
2397 pwg_size_t
*size
, /* Current size */
2398 *closest
, /* Closest size */
2399 jobsize
; /* Size data from job */
2400 int margins_set
, /* Were the margins set? */
2401 dwidth
, /* Difference in width */
2402 dlength
, /* Difference in length */
2403 dleft
, /* Difference in left margins */
2404 dright
, /* Difference in right margins */
2405 dbottom
, /* Difference in bottom margins */
2406 dtop
, /* Difference in top margins */
2407 dmin
, /* Minimum difference */
2408 dclosest
; /* Closest difference */
2409 const char *ppd_name
; /* PPD media name */
2412 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2413 pc
, job
, keyword
, exact
));
2416 * Range check input...
2419 if (!pc
|| (!job
&& !keyword
))
2430 * Try getting the PPD media name from the job attributes...
2433 ipp_attribute_t
*attr
; /* Job attribute */
2435 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2436 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2437 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2441 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2442 attr
->name
, ippTagString(attr
->value_tag
)));
2444 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2447 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2448 attr
->value_tag
== IPP_TAG_KEYWORD
))
2449 ppd_name
= attr
->values
[0].string
.text
;
2452 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2457 * Try looking up the named PPD size first...
2460 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2462 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2463 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2465 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2466 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2471 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2473 return (size
->map
.ppd
);
2478 if (job
&& !keyword
)
2481 * Get the size using media-col or media, with the preference being
2485 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2491 * Get the size using a media keyword...
2494 pwg_media_t
*media
; /* Media definition */
2497 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2498 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2499 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2502 jobsize
.width
= media
->width
;
2503 jobsize
.length
= media
->length
;
2508 * Now that we have the dimensions and possibly the margins, look at the
2509 * available sizes and find the match...
2513 dclosest
= 999999999;
2515 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2516 _cups_strncasecmp(ppd_name
, "custom_", 7))
2518 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2521 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2522 * is just about 176/2540ths...
2525 dwidth
= size
->width
- jobsize
.width
;
2526 dlength
= size
->length
- jobsize
.length
;
2528 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2534 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2537 dleft
= size
->left
- jobsize
.left
;
2538 dright
= size
->right
- jobsize
.right
;
2539 dtop
= size
->top
- jobsize
.top
;
2540 dbottom
= size
->bottom
- jobsize
.bottom
;
2542 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2543 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2545 dleft
= dleft
< 0 ? -dleft
: dleft
;
2546 dright
= dright
< 0 ? -dright
: dright
;
2547 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2548 dtop
= dtop
< 0 ? -dtop
: dtop
;
2549 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2551 if (dmin
< dclosest
)
2564 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2566 return (size
->map
.ppd
);
2572 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2575 return (closest
->map
.ppd
);
2579 * If we get here we need to check for custom page size support...
2582 if (jobsize
.width
>= pc
->custom_min_width
&&
2583 jobsize
.width
<= pc
->custom_max_width
&&
2584 jobsize
.length
>= pc
->custom_min_length
&&
2585 jobsize
.length
<= pc
->custom_max_length
)
2588 * In range, format as Custom.WWWWxLLLL (points).
2591 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2592 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2594 if (margins_set
&& exact
)
2596 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2597 dright
= pc
->custom_size
.right
- jobsize
.right
;
2598 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2599 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2601 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2602 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2608 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2609 pc
->custom_ppd_size
));
2611 return (pc
->custom_ppd_size
);
2615 * No custom page size support or the size is out of range - return NULL.
2618 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2625 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2628 pwg_size_t
* /* O - PWG size or NULL */
2630 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2631 const char *page_size
) /* I - PPD PageSize */
2633 int i
; /* Looping var */
2634 pwg_media_t
*media
; /* Media */
2635 pwg_size_t
*size
; /* Current size */
2639 * Range check input...
2642 if (!pc
|| !page_size
)
2645 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2648 * Custom size; size name can be one of the following:
2650 * Custom.WIDTHxLENGTHin - Size in inches
2651 * Custom.WIDTHxLENGTHft - Size in feet
2652 * Custom.WIDTHxLENGTHcm - Size in centimeters
2653 * Custom.WIDTHxLENGTHmm - Size in millimeters
2654 * Custom.WIDTHxLENGTHm - Size in meters
2655 * Custom.WIDTHxLENGTH[pt] - Size in points
2658 double w
, l
; /* Width and length of page */
2659 char *ptr
; /* Pointer into PageSize */
2660 struct lconv
*loc
; /* Locale data */
2663 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2664 if (!ptr
|| *ptr
!= 'x')
2667 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2671 if (!_cups_strcasecmp(ptr
, "in"))
2676 else if (!_cups_strcasecmp(ptr
, "ft"))
2681 else if (!_cups_strcasecmp(ptr
, "mm"))
2686 else if (!_cups_strcasecmp(ptr
, "cm"))
2691 else if (!_cups_strcasecmp(ptr
, "m"))
2702 pc
->custom_size
.width
= (int)w
;
2703 pc
->custom_size
.length
= (int)l
;
2705 return (&(pc
->custom_size
));
2709 * Not a custom size - look it up...
2712 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2713 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2714 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2718 * Look up standard sizes...
2721 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2722 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2723 media
= pwgMediaForPWG(page_size
);
2727 pc
->custom_size
.width
= media
->width
;
2728 pc
->custom_size
.length
= media
->length
;
2730 return (&(pc
->custom_size
));
2738 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2742 const char * /* O - PWG media-source keyword */
2744 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2745 const char *input_slot
) /* I - PPD InputSlot */
2747 int i
; /* Looping var */
2748 pwg_map_t
*source
; /* Current source */
2752 * Range check input...
2755 if (!pc
|| !input_slot
)
2758 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2759 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2760 return (source
->pwg
);
2767 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2771 const char * /* O - PWG media-type keyword */
2773 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2774 const char *media_type
) /* I - PPD MediaType */
2776 int i
; /* Looping var */
2777 pwg_map_t
*type
; /* Current type */
2781 * Range check input...
2784 if (!pc
|| !media_type
)
2787 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2788 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2796 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2799 int /* O - 1 on success, 0 on failure */
2801 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2802 const char *filename
, /* I - File to write */
2803 ipp_t
*attrs
) /* I - Attributes to write, if any */
2805 int i
, j
, k
; /* Looping vars */
2806 cups_file_t
*fp
; /* Output file */
2807 pwg_size_t
*size
; /* Current size */
2808 pwg_map_t
*map
; /* Current map */
2809 _pwg_finishings_t
*f
; /* Current finishing option */
2810 cups_option_t
*option
; /* Current option */
2811 const char *value
; /* String value */
2812 char newfile
[1024]; /* New filename */
2816 * Range check input...
2819 if (!pc
|| !filename
)
2821 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2826 * Open the file and write with compression...
2829 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2830 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2837 * Standard header...
2840 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2846 if (pc
->num_bins
> 0)
2848 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2849 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2850 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2857 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2858 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2859 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2860 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2861 size
->bottom
, size
->right
, size
->top
);
2862 if (pc
->custom_max_width
> 0)
2863 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2864 pc
->custom_max_width
, pc
->custom_max_length
,
2865 pc
->custom_min_width
, pc
->custom_min_length
,
2866 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2867 pc
->custom_size
.right
, pc
->custom_size
.top
);
2873 if (pc
->source_option
)
2874 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2876 if (pc
->num_sources
> 0)
2878 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2879 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2880 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2887 if (pc
->num_types
> 0)
2889 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2890 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2891 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2898 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2899 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2900 if (pc
->num_presets
[i
][j
])
2902 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2903 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2906 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2907 cupsFilePutChar(fp
, '\n');
2914 if (pc
->sides_option
)
2915 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2917 if (pc
->sides_1sided
)
2918 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2920 if (pc
->sides_2sided_long
)
2921 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2923 if (pc
->sides_2sided_short
)
2924 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2927 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2931 cupsFilePutConf(fp
, "Product", pc
->product
);
2933 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2935 value
= (const char *)cupsArrayNext(pc
->filters
))
2936 cupsFilePutConf(fp
, "Filter", value
);
2938 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2940 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2941 cupsFilePutConf(fp
, "PreFilter", value
);
2943 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2946 * Finishing options...
2949 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2951 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2953 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2954 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2955 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2956 cupsFilePutChar(fp
, '\n');
2959 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2960 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2966 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2969 * Accounting/quota/PIN/managed printing values...
2972 if (pc
->charge_info_uri
)
2973 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2975 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2976 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2977 pc
->accounting_user_id
? "true" : "false");
2980 cupsFilePutConf(fp
, "Password", pc
->password
);
2982 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2984 value
= (char *)cupsArrayNext(pc
->mandatory
))
2985 cupsFilePutConf(fp
, "Mandatory", value
);
2991 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2993 value
= (char *)cupsArrayNext(pc
->support_files
))
2994 cupsFilePutConf(fp
, "SupportFile", value
);
2997 * IPP attributes, if any...
3002 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3004 attrs
->state
= IPP_STATE_IDLE
;
3005 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3009 * Close and return...
3012 if (cupsFileClose(fp
))
3019 return (!rename(newfile
, filename
));
3024 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3025 * of an IPP printer.
3028 char * /* O - PPD filename or @code NULL@ on error */
3029 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3030 size_t bufsize
, /* I - Size of filename buffer */
3031 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3033 cups_file_t
*fp
; /* PPD file */
3034 cups_array_t
*sizes
; /* Media sizes supported by printer */
3035 cups_size_t
*size
; /* Current media size */
3036 ipp_attribute_t
*attr
, /* xxx-supported */
3037 *defattr
, /* xxx-default */
3038 *quality
, /* print-quality-supported */
3039 *x_dim
, *y_dim
; /* Media dimensions */
3040 ipp_t
*media_col
, /* Media collection */
3041 *media_size
; /* Media size collection */
3042 char make
[256], /* Make and model */
3043 *model
, /* Model name */
3044 ppdname
[PPD_MAX_NAME
];
3046 int i
, j
, /* Looping vars */
3047 count
, /* Number of values */
3048 bottom
, /* Largest bottom margin */
3049 left
, /* Largest left margin */
3050 right
, /* Largest right margin */
3051 top
, /* Largest top margin */
3052 max_length
= 0, /* Maximum custom size */
3054 min_length
= INT_MAX
,
3055 /* Minimum custom size */
3056 min_width
= INT_MAX
,
3057 is_apple
= 0, /* Does the printer support Apple raster? */
3058 is_pdf
= 0, /* Does the printer support PDF? */
3059 is_pwg
= 0; /* Does the printer support PWG Raster? */
3060 pwg_media_t
*pwg
; /* PWG media size */
3061 int xres
, yres
; /* Resolution values */
3062 int resolutions
[1000];
3063 /* Array of resolution indices */
3064 char msgid
[256]; /* Message identifier (attr.value) */
3065 const char *keyword
, /* Keyword value */
3066 *msgstr
; /* Localized string */
3067 cups_lang_t
*lang
= cupsLangDefault();
3068 /* Localization info */
3069 cups_array_t
*strings
= NULL
;/* Printer strings file */
3070 struct lconv
*loc
= localeconv();
3072 cups_array_t
*fin_options
= NULL
;
3073 /* Finishing options */
3077 * Range check input...
3083 if (!buffer
|| bufsize
< 1)
3085 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3091 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3096 * Open a temporary file for the PPD...
3099 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3101 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3106 * Standard stuff for PPD file...
3109 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3110 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3111 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3112 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3113 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3114 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3115 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3116 cupsFilePuts(fp
, "*FileSystem: False\n");
3117 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3119 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3120 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3122 strlcpy(make
, "Unknown Printer", sizeof(make
));
3124 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3125 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3128 strlcpy(make
, "HP", sizeof(make
));
3130 else if ((model
= strchr(make
, ' ')) != NULL
)
3135 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3136 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3137 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3138 cupsFilePrintf(fp
, "*NickName: \"%s - IPP Everywhere\"\n", model
);
3139 cupsFilePrintf(fp
, "*ShortNickName: \"%s - IPP Everywhere\"\n", model
);
3141 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3142 cupsFilePuts(fp
, "*ColorDevice: True\n");
3144 cupsFilePuts(fp
, "*ColorDevice: False\n");
3146 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3147 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3148 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3150 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3151 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3153 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3154 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3156 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3158 http_t
*http
= NULL
; /* Connection to printer */
3159 char stringsfile
[1024]; /* Temporary strings file */
3161 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3163 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3165 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3167 unlink(stringsfile
);
3175 * Password/PIN printing...
3178 if ((attr
= ippFindAttribute(response
, "job-password-supported", IPP_TAG_INTEGER
)) != NULL
)
3180 char pattern
[33]; /* Password pattern */
3181 int maxlen
= ippGetInteger(attr
, 0);
3182 /* Maximum length */
3183 const char *repertoire
= ippGetString(ippFindAttribute(response
, "job-password-repertoire-configured", IPP_TAG_KEYWORD
), 0, NULL
);
3184 /* Type of password */
3186 if (maxlen
> (int)(sizeof(pattern
) - 1))
3187 maxlen
= sizeof(pattern
) - 1;
3189 if (!repertoire
|| !strcmp(repertoire
, "iana_us-ascii_digits"))
3190 memset(pattern
, '1', maxlen
);
3191 else if (!strcmp(repertoire
, "iana_us-ascii_letters"))
3192 memset(pattern
, 'A', maxlen
);
3193 else if (!strcmp(repertoire
, "iana_us-ascii_complex"))
3194 memset(pattern
, 'C', maxlen
);
3195 else if (!strcmp(repertoire
, "iana_us-ascii_any"))
3196 memset(pattern
, '.', maxlen
);
3197 else if (!strcmp(repertoire
, "iana_utf-8_digits"))
3198 memset(pattern
, 'N', maxlen
);
3199 else if (!strcmp(repertoire
, "iana_utf-8_letters"))
3200 memset(pattern
, 'U', maxlen
);
3202 memset(pattern
, '*', maxlen
);
3204 pattern
[maxlen
] = '\0';
3206 cupsFilePrintf(fp
, "*cupsPassword: \"%s\"\n", pattern
);
3213 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3215 is_apple
= ippContainsString(attr
, "image/urf");
3216 is_pdf
= ippContainsString(attr
, "application/pdf");
3217 is_pwg
= ippContainsString(attr
, "image/pwg-raster") && !is_apple
;
3219 if (ippContainsString(attr
, "image/jpeg"))
3220 cupsFilePuts(fp
, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n");
3221 if (ippContainsString(attr
, "image/png"))
3222 cupsFilePuts(fp
, "*cupsFilter2: \"image/png image/png 0 -\"\n");
3224 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3226 cupsFilePuts(fp
, "*cupsFilter2: \"image/urf image/urf 100 -\"\n");
3228 cupsFilePuts(fp
, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n");
3231 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3235 * PageSize/PageRegion/ImageableArea/PaperDimension
3238 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3240 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3241 if (ippGetInteger(attr
, i
) > bottom
)
3242 bottom
= ippGetInteger(attr
, i
);
3247 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3249 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3250 if (ippGetInteger(attr
, i
) > left
)
3251 left
= ippGetInteger(attr
, i
);
3256 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3258 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3259 if (ippGetInteger(attr
, i
) > right
)
3260 right
= ippGetInteger(attr
, i
);
3265 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3267 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3268 if (ippGetInteger(attr
, i
) > top
)
3269 top
= ippGetInteger(attr
, i
);
3274 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3276 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3278 media_size
= ippGetCollection(attr
, 0);
3279 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3280 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3282 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3283 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3285 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3288 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3290 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3291 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3293 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3295 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, (cups_afree_func_t
)free
);
3297 if ((attr
= ippFindAttribute(response
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3299 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3301 cups_size_t temp
; /* Current size */
3302 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3304 media_col
= ippGetCollection(attr
, i
);
3305 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3306 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3307 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3308 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3312 temp
.width
= pwg
->width
;
3313 temp
.length
= pwg
->length
;
3315 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3316 temp
.bottom
= ippGetInteger(margin
, 0);
3318 temp
.bottom
= bottom
;
3320 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3321 temp
.left
= ippGetInteger(margin
, 0);
3325 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3326 temp
.right
= ippGetInteger(margin
, 0);
3330 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3331 temp
.top
= ippGetInteger(margin
, 0);
3335 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3336 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3338 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3340 if (!cupsArrayFind(sizes
, &temp
))
3341 cupsArrayAdd(sizes
, &temp
);
3343 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3346 * Custom size - record the min/max values...
3349 int lower
, upper
; /* Range values */
3351 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3352 lower
= ippGetRange(x_dim
, 0, &upper
);
3354 lower
= upper
= ippGetInteger(x_dim
, 0);
3356 if (lower
< min_width
)
3358 if (upper
> max_width
)
3361 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3362 lower
= ippGetRange(y_dim
, 0, &upper
);
3364 lower
= upper
= ippGetInteger(y_dim
, 0);
3366 if (lower
< min_length
)
3368 if (upper
> max_length
)
3373 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3376 * Some printers don't list custom size support in media-col-database...
3379 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3381 media_size
= ippGetCollection(attr
, i
);
3382 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3383 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3385 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3388 * Custom size - record the min/max values...
3391 int lower
, upper
; /* Range values */
3393 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3394 lower
= ippGetRange(x_dim
, 0, &upper
);
3396 lower
= upper
= ippGetInteger(x_dim
, 0);
3398 if (lower
< min_width
)
3400 if (upper
> max_width
)
3403 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3404 lower
= ippGetRange(y_dim
, 0, &upper
);
3406 lower
= upper
= ippGetInteger(y_dim
, 0);
3408 if (lower
< min_length
)
3410 if (upper
> max_length
)
3416 else if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3418 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3420 cups_size_t temp
; /* Current size */
3422 media_size
= ippGetCollection(attr
, i
);
3423 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3424 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3425 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3429 temp
.width
= pwg
->width
;
3430 temp
.length
= pwg
->length
;
3431 temp
.bottom
= bottom
;
3436 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3437 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3439 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3441 if (!cupsArrayFind(sizes
, &temp
))
3442 cupsArrayAdd(sizes
, &temp
);
3444 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3447 * Custom size - record the min/max values...
3450 int lower
, upper
; /* Range values */
3452 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3453 lower
= ippGetRange(x_dim
, 0, &upper
);
3455 lower
= upper
= ippGetInteger(x_dim
, 0);
3457 if (lower
< min_width
)
3459 if (upper
> max_width
)
3462 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3463 lower
= ippGetRange(y_dim
, 0, &upper
);
3465 lower
= upper
= ippGetInteger(y_dim
, 0);
3467 if (lower
< min_length
)
3469 if (upper
> max_length
)
3474 else if ((attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3476 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3478 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3480 cups_size_t temp
; /* Current size */
3482 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3484 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3486 if (pwg
->width
> max_width
)
3487 max_width
= pwg
->width
;
3488 if (pwg
->length
> max_length
)
3489 max_length
= pwg
->length
;
3491 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3493 if (pwg
->width
< min_width
)
3494 min_width
= pwg
->width
;
3495 if (pwg
->length
< min_length
)
3496 min_length
= pwg
->length
;
3500 temp
.width
= pwg
->width
;
3501 temp
.length
= pwg
->length
;
3502 temp
.bottom
= bottom
;
3507 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3508 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3510 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3512 if (!cupsArrayFind(sizes
, &temp
))
3513 cupsArrayAdd(sizes
, &temp
);
3519 if (cupsArrayCount(sizes
) > 0)
3522 * List all of the standard sizes...
3525 char tleft
[256], /* Left string */
3526 tbottom
[256], /* Bottom string */
3527 tright
[256], /* Right string */
3528 ttop
[256], /* Top string */
3529 twidth
[256], /* Width string */
3530 tlength
[256]; /* Length string */
3532 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3533 "*OrderDependency: 10 AnySetup *PageSize\n"
3534 "*DefaultPageSize: %s\n", ppdname
);
3535 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3537 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3538 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3540 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3542 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3544 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3545 "*OrderDependency: 10 AnySetup *PageRegion\n"
3546 "*DefaultPageRegion: %s\n", ppdname
);
3547 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3549 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3550 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3552 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3554 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3556 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3557 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3559 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3561 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3562 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3563 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3564 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3565 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3566 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3568 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3569 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3572 cupsArrayDelete(sizes
);
3575 * Custom size support...
3578 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3580 char tmax
[256], tmin
[256]; /* Min/max values */
3582 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3583 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3584 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3585 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3587 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3589 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3590 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3591 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3593 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3594 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3595 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3597 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3598 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3599 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3600 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3605 cupsArrayDelete(sizes
);
3613 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3614 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3616 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3618 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3620 static const char * const sources
[] =
3621 { /* Standard "media-source" strings */
3674 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3675 "*OrderDependency: 10 AnySetup *InputSlot\n"
3676 "*DefaultInputSlot: %s\n", ppdname
);
3677 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3679 keyword
= ippGetString(attr
, i
, NULL
);
3681 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3683 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3684 if (!strcmp(sources
[j
], keyword
))
3686 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
3687 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, msgid
), j
);
3691 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3698 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3699 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3701 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3703 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3705 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3706 "*OrderDependency: 10 AnySetup *MediaType\n"
3707 "*DefaultMediaType: %s\n", ppdname
);
3708 for (i
= 0; i
< count
; i
++)
3710 keyword
= ippGetString(attr
, i
, NULL
);
3712 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3714 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
3715 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3716 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3719 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, msgstr
, ppdname
);
3721 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3728 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3729 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3730 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3731 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3735 int wrote_color
= 0;
3736 const char *default_color
= NULL
; /* Default */
3738 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3740 keyword
= ippGetString(attr
, i
, NULL
);
3742 #define PRINTF_COLORMODEL if (!wrote_color) { cupsFilePrintf(fp, "*OpenUI *ColorModel/%s: PickOne\n*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang, _("Color Mode"))); wrote_color = 1; }
3743 #define PRINTF_COLOROPTION(name,text,cspace,bpp) cupsFilePrintf(fp, "*ColorModel %s/%s: \"<</cupsColorSpace %d/cupsBitsPerColor %d/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", name, _cupsLangString(lang, text), cspace, bpp)
3745 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3749 PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K
, 1);
3752 default_color
= "FastGray";
3754 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3758 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8);
3760 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3761 default_color
= "Gray";
3763 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
3767 if (!strcmp(keyword
, "W8-16"))
3769 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8);
3771 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3772 default_color
= "Gray";
3775 PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW
, 16);
3777 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 7) || !strcmp(keyword
, "color"))
3781 PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB
, 8);
3783 default_color
= "RGB";
3785 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
3789 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 16);
3792 default_color
= "AdobeRGB";
3794 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
3798 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 8);
3801 default_color
= "AdobeRGB";
3803 else if ((!strcasecmp(keyword
, "black_8") && !ippContainsString(attr
, "black_16")) || !strcmp(keyword
, "DEVW8"))
3807 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 8);
3809 else if (!strcasecmp(keyword
, "black_16") || !strcmp(keyword
, "DEVW16") || !strcmp(keyword
, "DEVW8-16"))
3813 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 16);
3815 else if ((!strcasecmp(keyword
, "cmyk_8") && !ippContainsString(attr
, "cmyk_16")) || !strcmp(keyword
, "DEVCMYK32"))
3819 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 8);
3821 else if (!strcasecmp(keyword
, "cmyk_16") || !strcmp(keyword
, "DEVCMYK32-64") || !strcmp(keyword
, "DEVCMYK64"))
3825 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 16);
3827 else if ((!strcasecmp(keyword
, "rgb_8") && ippContainsString(attr
, "rgb_16")) || !strcmp(keyword
, "DEVRGB24"))
3831 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 8);
3833 else if (!strcasecmp(keyword
, "rgb_16") || !strcmp(keyword
, "DEVRGB24-48") || !strcmp(keyword
, "DEVRGB48"))
3837 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 16);
3842 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3844 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3851 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3853 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3854 "*OrderDependency: 10 AnySetup *Duplex\n"
3855 "*DefaultDuplex: None\n"
3856 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3857 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3858 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3859 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3861 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3863 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3865 const char *dm
= ippGetString(attr
, i
, NULL
);
3868 if (!_cups_strcasecmp(dm
, "DM1"))
3870 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3873 else if (!_cups_strcasecmp(dm
, "DM2"))
3875 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3878 else if (!_cups_strcasecmp(dm
, "DM3"))
3880 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3883 else if (!_cups_strcasecmp(dm
, "DM4"))
3885 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3890 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3892 keyword
= ippGetString(attr
, 0, NULL
);
3894 if (!strcmp(keyword
, "flipped"))
3895 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3896 else if (!strcmp(keyword
, "manual-tumble"))
3897 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3898 else if (!strcmp(keyword
, "normal"))
3899 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3901 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3909 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3910 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3912 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3914 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3916 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3917 "*OrderDependency: 10 AnySetup *OutputBin\n"
3918 "*DefaultOutputBin: %s\n", ppdname
);
3919 for (i
= 0; i
< count
; i
++)
3921 keyword
= ippGetString(attr
, i
, NULL
);
3923 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3925 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
3926 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3927 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3930 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, msgstr
);
3932 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3936 * Finishing options...
3939 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3941 int value
; /* Enum value */
3942 cups_array_t
*names
; /* Names we've added */
3944 count
= ippGetCount(attr
);
3945 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3946 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3949 * Staple/Bind/Stitch
3952 for (i
= 0; i
< count
; i
++)
3954 value
= ippGetInteger(attr
, i
);
3955 keyword
= ippEnumString("finishings", value
);
3957 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch"))
3963 cupsArrayAdd(fin_options
, "*StapleLocation");
3965 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3966 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3967 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3968 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3970 for (; i
< count
; i
++)
3972 value
= ippGetInteger(attr
, i
);
3973 keyword
= ippEnumString("finishings", value
);
3975 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch"))
3978 if (cupsArrayFind(names
, (char *)keyword
))
3979 continue; /* Already did this finishing template */
3981 cupsArrayAdd(names
, (char *)keyword
);
3983 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
3984 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3985 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3988 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", keyword
, msgstr
);
3989 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, keyword
);
3992 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3999 for (i
= 0; i
< count
; i
++)
4001 value
= ippGetInteger(attr
, i
);
4002 keyword
= ippEnumString("finishings", value
);
4004 if (!strncmp(keyword
, "fold-", 5))
4010 cupsArrayAdd(fin_options
, "*FoldType");
4012 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
4013 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
4014 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
4015 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4017 for (; i
< count
; i
++)
4019 value
= ippGetInteger(attr
, i
);
4020 keyword
= ippEnumString("finishings", value
);
4022 if (strncmp(keyword
, "fold-", 5))
4025 if (cupsArrayFind(names
, (char *)keyword
))
4026 continue; /* Already did this finishing template */
4028 cupsArrayAdd(names
, (char *)keyword
);
4030 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4031 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4032 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4035 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", keyword
, msgstr
);
4036 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, keyword
);
4039 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4046 for (i
= 0; i
< count
; i
++)
4048 value
= ippGetInteger(attr
, i
);
4049 keyword
= ippEnumString("finishings", value
);
4051 if (!strncmp(keyword
, "punch-", 6))
4057 cupsArrayAdd(fin_options
, "*PunchMedia");
4059 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
4060 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4061 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4062 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4064 for (i
= 0; i
< count
; i
++)
4066 value
= ippGetInteger(attr
, i
);
4067 keyword
= ippEnumString("finishings", value
);
4069 if (strncmp(keyword
, "punch-", 6))
4072 if (cupsArrayFind(names
, (char *)keyword
))
4073 continue; /* Already did this finishing template */
4075 cupsArrayAdd(names
, (char *)keyword
);
4077 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4078 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4079 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4082 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", keyword
, msgstr
);
4083 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, keyword
);
4086 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4093 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4095 cupsArrayAdd(fin_options
, "*Booklet");
4097 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
4098 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4099 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4100 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4101 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4102 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4103 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4106 cupsArrayDelete(names
);
4109 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4111 ipp_t
*finishing_col
; /* Current finishing collection */
4112 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4113 cups_array_t
*templates
; /* Finishing templates */
4115 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickOne\n", _cupsLangString(lang
, _("Finishing Preset")));
4116 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4117 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4118 cupsFilePrintf(fp
, "*cupsFinishingTemplate none/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4120 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4121 count
= ippGetCount(attr
);
4123 for (i
= 0; i
< count
; i
++)
4125 finishing_col
= ippGetCollection(attr
, i
);
4126 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4128 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4131 if (strncmp(keyword
, "fold-", 5) && (strstr(keyword
, "-bottom") || strstr(keyword
, "-left") || strstr(keyword
, "-right") || strstr(keyword
, "-top")))
4134 cupsArrayAdd(templates
, (void *)keyword
);
4136 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4137 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4138 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4141 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\n", keyword
, msgstr
);
4142 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4144 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4146 const char *name
= ippGetName(finishing_attr
);
4147 /* Member attribute name */
4149 if (strcmp(name
, "media-size"))
4150 cupsFilePrintf(fp
, "%% %s\n", name
);
4153 cupsFilePuts(fp
, "\"\n");
4154 cupsFilePuts(fp
, "*End\n");
4157 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4159 if (cupsArrayCount(fin_options
))
4161 const char *fin_option
; /* Current finishing option */
4163 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4164 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4165 cupsFilePrintf(fp
, " %s", fin_option
);
4166 cupsFilePuts(fp
, "\"\n");
4168 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None");
4169 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4170 cupsFilePrintf(fp
, " %s None", fin_option
);
4171 cupsFilePuts(fp
, "\"\n");
4174 cupsArrayDelete(templates
);
4177 cupsArrayDelete(fin_options
);
4180 * cupsPrintQuality and DefaultResolution...
4183 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4185 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4187 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4189 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4191 const char *rs
= ippGetString(attr
, i
, NULL
);
4194 if (_cups_strncasecmp(rs
, "RS", 2))
4197 lowdpi
= atoi(rs
+ 2);
4198 if ((rs
= strrchr(rs
, '-')) != NULL
)
4199 hidpi
= atoi(rs
+ 1);
4208 * Invalid "urf-supported" value...
4216 * Generate print qualities based on low and high DPIs...
4219 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4221 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4222 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4223 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4224 if ((lowdpi
& 1) == 0)
4225 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4226 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4227 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4228 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4229 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4230 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4231 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4234 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4237 * Make a sorted list of resolutions.
4240 count
= ippGetCount(attr
);
4241 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4242 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4244 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4245 for (i
= 1; i
< count
; i
++)
4248 for (i
= 0; i
< (count
- 1); i
++)
4250 for (j
= i
+ 1; j
< count
; j
++)
4252 int ix
, iy
, /* First X and Y resolution */
4253 jx
, jy
, /* Second X and Y resolution */
4254 temp
; /* Swap variable */
4255 ipp_res_t units
; /* Resolution units */
4257 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4258 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4260 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4263 * Swap these two resolutions...
4266 temp
= resolutions
[i
];
4267 resolutions
[i
] = resolutions
[j
];
4268 resolutions
[j
] = temp
;
4274 * Generate print quality options...
4277 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4278 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4280 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4281 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4282 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4283 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4285 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4286 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4288 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4289 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4290 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4292 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4293 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4296 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4298 else if (is_apple
|| is_pwg
)
4302 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4304 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4309 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4312 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4314 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4315 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4316 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4317 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4318 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4319 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4320 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4321 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4322 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4329 if ((attr
= ippFindAttribute(response
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4331 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4333 ipp_t
*preset
= ippGetCollection(attr
, i
);
4334 /* Preset collection */
4335 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
),
4337 *localized_name
; /* Localized preset name */
4338 ipp_attribute_t
*member
; /* Member attribute in preset */
4339 const char *member_name
; /* Member attribute name */
4340 char member_value
[256]; /* Member attribute value */
4342 if (!preset
|| !preset_name
)
4345 if ((localized_name
= _cupsMessageLookup(strings
, preset_name
)) == preset_name
)
4346 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", preset_name
);
4348 cupsFilePrintf(fp
, "*APPrinterPreset %s/%s: \"\n", preset_name
, localized_name
);
4350 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4352 member_name
= ippGetName(member
);
4354 if (!member_name
|| !strcmp(member_name
, "preset-name"))
4357 if (!strcmp(member_name
, "finishings"))
4359 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4361 const char *option
= NULL
; /* PPD option name */
4363 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
4365 if (!strcmp(keyword
, "booklet-maker"))
4370 else if (!strncmp(keyword
, "fold-", 5))
4371 option
= "FoldType";
4372 else if (!strncmp(keyword
, "punch-", 6))
4373 option
= "PunchMedia";
4374 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7))
4375 option
= "StapleLocation";
4377 if (option
&& keyword
)
4378 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
4381 else if (!strcmp(member_name
, "finishings-col"))
4383 ipp_t
*fin_col
; /* finishings-col value */
4385 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4387 fin_col
= ippGetCollection(member
, i
);
4389 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4390 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", keyword
);
4393 else if (!strcmp(member_name
, "media"))
4396 * Map media to PageSize...
4399 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
4400 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4402 else if (!strcmp(member_name
, "media-col"))
4404 media_col
= ippGetCollection(member
, 0);
4406 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
4408 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
4409 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
4410 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
4411 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4414 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4416 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4417 cupsFilePrintf(fp
, "*InputSlot %s\n", keyword
);
4420 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4422 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4423 cupsFilePrintf(fp
, "*MediaType %s\n", keyword
);
4426 else if (!strcmp(member_name
, "print-quality"))
4429 * Map print-quality to cupsPrintQuality...
4432 int qval
= ippGetInteger(member
, 0);
4433 /* print-quality value */
4434 static const char * const qualities
[] = { "Draft", "Normal", "High" };
4435 /* cupsPrintQuality values */
4437 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
4438 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
4440 else if (!strcmp(member_name
, "output-bin"))
4442 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
4443 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
4445 else if (!strcmp(member_name
, "sides"))
4447 keyword
= ippGetString(member
, 0, NULL
);
4448 if (keyword
&& !strcmp(keyword
, "one-sided"))
4449 cupsFilePuts(fp
, "*Duplex None\n");
4450 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
4451 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
4452 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
4453 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
4458 * Add attribute name and value as-is...
4461 ippAttributeString(member
, member_value
, sizeof(member_value
));
4462 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
4466 cupsFilePuts(fp
, "\"\n*End\n");
4471 * Close up and return...
4479 * If we get here then there was a problem creating the PPD...
4488 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4495 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4499 const char * /* O - InputSlot name */
4500 _pwgInputSlotForSource(
4501 const char *media_source
, /* I - PWG media-source */
4502 char *name
, /* I - Name buffer */
4503 size_t namesize
) /* I - Size of name buffer */
4506 * Range check input...
4509 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4512 if (_cups_strcasecmp(media_source
, "main"))
4513 strlcpy(name
, "Cassette", namesize
);
4514 else if (_cups_strcasecmp(media_source
, "alternate"))
4515 strlcpy(name
, "Multipurpose", namesize
);
4516 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4517 strlcpy(name
, "LargeCapacity", namesize
);
4518 else if (_cups_strcasecmp(media_source
, "bottom"))
4519 strlcpy(name
, "Lower", namesize
);
4520 else if (_cups_strcasecmp(media_source
, "middle"))
4521 strlcpy(name
, "Middle", namesize
);
4522 else if (_cups_strcasecmp(media_source
, "top"))
4523 strlcpy(name
, "Upper", namesize
);
4524 else if (_cups_strcasecmp(media_source
, "rear"))
4525 strlcpy(name
, "Rear", namesize
);
4526 else if (_cups_strcasecmp(media_source
, "side"))
4527 strlcpy(name
, "Side", namesize
);
4528 else if (_cups_strcasecmp(media_source
, "envelope"))
4529 strlcpy(name
, "Envelope", namesize
);
4530 else if (_cups_strcasecmp(media_source
, "main-roll"))
4531 strlcpy(name
, "Roll", namesize
);
4532 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4533 strlcpy(name
, "Roll2", namesize
);
4535 pwg_ppdize_name(media_source
, name
, namesize
);
4542 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4546 const char * /* O - MediaType name */
4547 _pwgMediaTypeForType(
4548 const char *media_type
, /* I - PWG media-type */
4549 char *name
, /* I - Name buffer */
4550 size_t namesize
) /* I - Size of name buffer */
4553 * Range check input...
4556 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4559 if (_cups_strcasecmp(media_type
, "auto"))
4560 strlcpy(name
, "Auto", namesize
);
4561 else if (_cups_strcasecmp(media_type
, "cardstock"))
4562 strlcpy(name
, "Cardstock", namesize
);
4563 else if (_cups_strcasecmp(media_type
, "envelope"))
4564 strlcpy(name
, "Envelope", namesize
);
4565 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4566 strlcpy(name
, "Glossy", namesize
);
4567 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4568 strlcpy(name
, "HighGloss", namesize
);
4569 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4570 strlcpy(name
, "Matte", namesize
);
4571 else if (_cups_strcasecmp(media_type
, "stationery"))
4572 strlcpy(name
, "Plain", namesize
);
4573 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4574 strlcpy(name
, "Coated", namesize
);
4575 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4576 strlcpy(name
, "Inkjet", namesize
);
4577 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4578 strlcpy(name
, "Letterhead", namesize
);
4579 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4580 strlcpy(name
, "Preprinted", namesize
);
4581 else if (_cups_strcasecmp(media_type
, "transparency"))
4582 strlcpy(name
, "Transparency", namesize
);
4584 pwg_ppdize_name(media_type
, name
, namesize
);
4591 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4594 const char * /* O - PageSize name */
4595 _pwgPageSizeForMedia(
4596 pwg_media_t
*media
, /* I - Media */
4597 char *name
, /* I - PageSize name buffer */
4598 size_t namesize
) /* I - Size of name buffer */
4600 const char *sizeptr
, /* Pointer to size in PWG name */
4601 *dimptr
; /* Pointer to dimensions in PWG name */
4605 * Range check input...
4608 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4612 * Copy or generate a PageSize name...
4618 * Use a standard Adobe name...
4621 strlcpy(name
, media
->ppd
, namesize
);
4623 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4624 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4625 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4626 (size_t)(dimptr
- sizeptr
) > namesize
)
4629 * Use a name of the form "wNNNhNNN"...
4632 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4633 (int)PWG_TO_POINTS(media
->length
));
4638 * Copy the size name from class_sizename_dimensions...
4641 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4642 name
[dimptr
- sizeptr
- 1] = '\0';
4650 * 'cups_get_url()' - Get a copy of the file at the given URL.
4653 static int /* O - 1 on success, 0 on failure */
4654 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4655 const char *url
, /* I - URL to get */
4656 char *name
, /* I - Temporary filename */
4657 size_t namesize
) /* I - Size of temporary filename buffer */
4659 char scheme
[32], /* URL scheme */
4660 userpass
[256], /* URL username:password */
4661 host
[256], /* URL host */
4662 curhost
[256], /* Current host */
4663 resource
[256]; /* URL resource */
4664 int port
; /* URL port */
4665 http_encryption_t encryption
; /* Type of encryption to use */
4666 http_status_t status
; /* Status of GET request */
4667 int fd
; /* Temporary file */
4670 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4673 if (port
== 443 || !strcmp(scheme
, "https"))
4674 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4676 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4678 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4681 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4687 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4690 status
= cupsGetFd(*http
, resource
, fd
);
4694 if (status
!= HTTP_STATUS_OK
)
4706 * 'pwg_add_finishing()' - Add a finishings value.
4711 cups_array_t
*finishings
, /* I - Finishings array */
4712 ipp_finishings_t
template, /* I - Finishing template */
4713 const char *name
, /* I - PPD option */
4714 const char *value
) /* I - PPD choice */
4716 _pwg_finishings_t
*f
; /* New finishings value */
4719 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4721 f
->value
= template;
4722 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4724 cupsArrayAdd(finishings
, f
);
4730 * 'pwg_add_message()' - Add a message to the PPD cached strings.
4734 pwg_add_message(cups_array_t
*a
, /* I - Message catalog */
4735 const char *msg
, /* I - Message identifier */
4736 const char *str
) /* I - Localized string */
4738 _cups_message_t
*m
; /* New message */
4741 if ((m
= calloc(1, sizeof(_cups_message_t
))) != NULL
)
4743 m
->msg
= strdup(msg
);
4744 m
->str
= strdup(str
);
4751 * 'pwg_compare_finishings()' - Compare two finishings values.
4754 static int /* O - Result of comparison */
4755 pwg_compare_finishings(
4756 _pwg_finishings_t
*a
, /* I - First finishings value */
4757 _pwg_finishings_t
*b
) /* I - Second finishings value */
4759 return ((int)b
->value
- (int)a
->value
);
4764 * 'pwg_compare_sizes()' - Compare two media sizes...
4767 static int /* O - Result of comparison */
4768 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
4769 cups_size_t
*b
) /* I - Second media size */
4771 return (strcmp(a
->media
, b
->media
));
4776 * 'pwg_copy_size()' - Copy a media size.
4779 static cups_size_t
* /* O - New media size */
4780 pwg_copy_size(cups_size_t
*size
) /* I - Media size to copy */
4782 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
4783 /* New media size */
4786 memcpy(newsize
, size
, sizeof(cups_size_t
));
4793 * 'pwg_free_finishings()' - Free a finishings value.
4797 pwg_free_finishings(
4798 _pwg_finishings_t
*f
) /* I - Finishings value */
4800 cupsFreeOptions(f
->num_options
, f
->options
);
4806 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4810 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4811 char *name
, /* I - Name buffer */
4812 size_t namesize
) /* I - Size of name buffer */
4814 char *ptr
, /* Pointer into name buffer */
4815 *end
; /* End of name buffer */
4824 *name
= (char)toupper(*ipp
++);
4826 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4828 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4831 *ptr
++ = (char)toupper(*ipp
++ & 255);
4842 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4846 pwg_ppdize_resolution(
4847 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4848 int element
, /* I - Element to convert */
4849 int *xres
, /* O - X resolution in DPI */
4850 int *yres
, /* O - Y resolution in DPI */
4851 char *name
, /* I - Name buffer */
4852 size_t namesize
) /* I - Size of name buffer */
4854 ipp_res_t units
; /* Units for resolution */
4857 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4859 if (units
== IPP_RES_PER_CM
)
4861 *xres
= (int)(*xres
* 2.54);
4862 *yres
= (int)(*yres
* 2.54);
4865 if (name
&& namesize
> 4)
4868 snprintf(name
, namesize
, "%ddpi", *xres
);
4870 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4876 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4880 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4881 char *name
, /* I - Name buffer */
4882 size_t namesize
, /* I - Size of name buffer */
4883 const char *dashchars
)/* I - Characters to be replaced by dashes */
4885 char *ptr
, /* Pointer into name buffer */
4886 *end
; /* End of name buffer */
4889 if (_cups_islower(*ppd
))
4892 * Already lowercase name, use as-is?
4895 const char *ppdptr
; /* Pointer into PPD keyword */
4897 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4898 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4903 strlcpy(name
, ppd
, namesize
);
4908 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4910 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4911 *ptr
++ = (char)tolower(*ppd
& 255);
4912 else if (strchr(dashchars
, *ppd
))
4917 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4918 _cups_isupper(ppd
[1]) && ptr
< end
)
4920 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))