2 * PPD cache implementation for CUPS.
4 * Copyright © 2010-2019 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 * Include necessary headers...
14 #include "cups-private.h"
15 #include "ppd-private.h"
16 #include "debug-internal.h"
21 * Macro to test for two almost-equal PWG measurements.
24 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
31 static int cups_get_url(http_t
**http
, const char *url
, char *name
, size_t namesize
);
32 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
33 static void pwg_add_message(cups_array_t
*a
, const char *msg
, const char *str
);
34 static int pwg_compare_finishings(_pwg_finishings_t
*a
, _pwg_finishings_t
*b
);
35 static int pwg_compare_sizes(cups_size_t
*a
, cups_size_t
*b
);
36 static cups_size_t
*pwg_copy_size(cups_size_t
*size
);
37 static void pwg_free_finishings(_pwg_finishings_t
*f
);
38 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
39 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
40 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
41 const char *dashchars
);
45 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
47 * This functions converts PPD and CUPS-specific options to their standard IPP
48 * attributes and values and adds them to the specified IPP request.
51 int /* O - New number of copies */
53 ipp_t
*request
, /* I - IPP request */
54 ppd_file_t
*ppd
, /* I - PPD file */
55 _ppd_cache_t
*pc
, /* I - PPD cache info */
56 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
57 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
58 ipp_attribute_t
*print_color_mode_sup
,
59 /* I - Printer supports print-color-mode */
60 const char *user
, /* I - User info */
61 const char *format
, /* I - document-format value */
62 int copies
, /* I - Number of copies */
63 int num_options
, /* I - Number of options */
64 cups_option_t
*options
) /* I - Options */
66 int i
; /* Looping var */
67 const char *keyword
, /* PWG keyword */
68 *password
; /* Password string */
69 pwg_size_t
*size
; /* PWG media size */
70 ipp_t
*media_col
, /* media-col value */
71 *media_size
; /* media-size value */
72 const char *media_source
, /* media-source value */
73 *media_type
, /* media-type value */
74 *collate_str
, /* multiple-document-handling value */
75 *color_attr_name
, /* Supported color attribute */
76 *mandatory
, /* Mandatory attributes */
77 *finishing_template
; /* Finishing template */
78 int num_finishings
= 0, /* Number of finishing values */
79 finishings
[10]; /* Finishing enum values */
80 ppd_choice_t
*choice
; /* Marked choice */
81 int finishings_copies
= copies
;
82 /* Number of copies for finishings */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "finishings-col") &&
145 strcmp(mandatory
, "finishing-template") &&
146 strcmp(mandatory
, "job-account-id") &&
147 strcmp(mandatory
, "job-accounting-user-id") &&
148 strcmp(mandatory
, "job-password") &&
149 strcmp(mandatory
, "job-password-encryption") &&
150 strcmp(mandatory
, "media") &&
151 strncmp(mandatory
, "media-col", 9) &&
152 strcmp(mandatory
, "multiple-document-handling") &&
153 strcmp(mandatory
, "output-bin") &&
154 strcmp(mandatory
, "print-color-mode") &&
155 strcmp(mandatory
, "print-quality") &&
156 strcmp(mandatory
, "sides") &&
157 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
159 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
161 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
166 case IPP_TAG_INTEGER
:
168 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
170 case IPP_TAG_BOOLEAN
:
171 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
175 int lower
, upper
; /* Range */
177 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
178 lower
= upper
= atoi(keyword
);
180 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
183 case IPP_TAG_STRING
:
184 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
187 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
189 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
190 keyword
= "auto-monochrome";
191 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
192 keyword
= "process-monochrome";
195 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
201 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
202 keyword
= cupsGetOption("media", num_options
, options
);
204 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
205 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
206 size
= _ppdCacheGetSize(pc
, keyword
);
208 if (size
|| media_source
|| media_type
)
211 * Add a media-col value...
214 media_col
= ippNew();
218 media_size
= ippNew();
219 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
220 "x-dimension", size
->width
);
221 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
222 "y-dimension", size
->length
);
224 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
227 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
229 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
233 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
234 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
235 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
236 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
237 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
238 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
239 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
240 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
243 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
246 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
248 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
249 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
253 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
255 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
257 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
259 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
261 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
262 keyword
= "monochrome";
268 if (keyword
&& !strcmp(keyword
, "monochrome"))
270 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
271 keyword
= "auto-monochrome";
272 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
273 keyword
= "process-monochrome";
277 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
279 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
281 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
283 if (!_cups_strcasecmp(choice
->choice
, "draft"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
285 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
286 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
287 else if (!_cups_strcasecmp(choice
->choice
, "high"))
288 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
291 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
293 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
295 if (pc
->sides_1sided
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
297 else if (pc
->sides_2sided_long
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
298 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
299 else if (pc
->sides_2sided_short
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
300 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
307 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
309 if (strstr(keyword
, "uncollated"))
314 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
319 if (!_cups_strcasecmp(format
, "image/gif") ||
320 !_cups_strcasecmp(format
, "image/jp2") ||
321 !_cups_strcasecmp(format
, "image/jpeg") ||
322 !_cups_strcasecmp(format
, "image/png") ||
323 !_cups_strcasecmp(format
, "image/tiff") ||
324 !_cups_strncasecmp(format
, "image/x-", 8))
327 * Collation makes no sense for single page image formats...
332 else if (!_cups_strncasecmp(format
, "image/", 6) ||
333 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
336 * Multi-page image formats will have copies applied by the upstream
344 if (doc_handling_sup
)
346 if (!_cups_strcasecmp(keyword
, "true"))
347 collate_str
= "separate-documents-collated-copies";
349 collate_str
= "separate-documents-uncollated-copies";
351 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
353 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
355 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
360 if (i
>= doc_handling_sup
->num_values
)
365 * Map finishing options...
368 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
369 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
371 if (finishing_template
&& strcmp(finishing_template
, "none"))
373 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
375 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
376 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
379 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
382 * Send job-pages-per-set attribute to apply finishings correctly...
385 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
390 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
391 if (num_finishings
> 0)
393 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
395 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
398 * Send job-pages-per-set attribute to apply finishings correctly...
401 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
411 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
414 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
418 _ppd_cache_t
* /* O - PPD cache and mapping data */
419 _ppdCacheCreateWithFile(
420 const char *filename
, /* I - File to read */
421 ipp_t
**attrs
) /* IO - IPP attributes, if any */
423 cups_file_t
*fp
; /* File */
424 _ppd_cache_t
*pc
; /* PWG mapping data */
425 pwg_size_t
*size
; /* Current size */
426 pwg_map_t
*map
; /* Current map */
427 _pwg_finishings_t
*finishings
; /* Current finishings option */
428 int linenum
, /* Current line number */
429 num_bins
, /* Number of bins in file */
430 num_sizes
, /* Number of sizes in file */
431 num_sources
, /* Number of sources in file */
432 num_types
; /* Number of types in file */
433 char line
[2048], /* Current line */
434 *value
, /* Pointer to value in line */
435 *valueptr
, /* Pointer into value */
436 pwg_keyword
[128], /* PWG keyword */
437 ppd_keyword
[PPD_MAX_NAME
];
439 _pwg_print_color_mode_t print_color_mode
;
440 /* Print color mode for preset */
441 _pwg_print_quality_t print_quality
; /* Print quality for preset */
444 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
447 * Range check input...
455 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
463 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
465 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
470 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
473 if (!cupsFileGets(fp
, line
, sizeof(line
)))
475 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
476 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
481 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
483 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
484 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
489 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
491 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
492 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
493 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
499 * Allocate the mapping data structure...
502 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
505 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
509 pc
->max_copies
= 9999;
521 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
523 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
524 "linenum=%d", line
, value
, linenum
));
528 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
530 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
533 else if (!_cups_strcasecmp(line
, "Filter"))
536 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
538 cupsArrayAdd(pc
->filters
, value
);
540 else if (!_cups_strcasecmp(line
, "PreFilter"))
543 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
545 cupsArrayAdd(pc
->prefilters
, value
);
547 else if (!_cups_strcasecmp(line
, "Product"))
549 pc
->product
= strdup(value
);
551 else if (!_cups_strcasecmp(line
, "SingleFile"))
553 pc
->single_file
= !_cups_strcasecmp(value
, "true");
555 else if (!_cups_strcasecmp(line
, "IPP"))
557 off_t pos
= cupsFileTell(fp
), /* Position in file */
558 length
= strtol(value
, NULL
, 10);
559 /* Length of IPP attributes */
563 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
564 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
567 else if (length
<= 0)
569 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
570 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
577 * Read IPP attributes into the provided variable...
582 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
583 *attrs
) != IPP_STATE_DATA
)
585 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
586 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
593 * Skip the IPP data entirely...
596 cupsFileSeek(fp
, pos
+ length
);
599 if (cupsFileTell(fp
) != (pos
+ length
))
601 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
602 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
606 else if (!_cups_strcasecmp(line
, "NumBins"))
610 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
611 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
615 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
617 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
618 "%d.", num_sizes
, linenum
));
619 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
623 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
625 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
627 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
631 else if (!_cups_strcasecmp(line
, "Bin"))
633 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
635 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if (pc
->num_bins
>= num_bins
)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
648 map
= pc
->bins
+ pc
->num_bins
;
649 map
->pwg
= strdup(pwg_keyword
);
650 map
->ppd
= strdup(ppd_keyword
);
654 else if (!_cups_strcasecmp(line
, "NumSizes"))
658 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
659 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
663 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
665 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
666 "%d.", num_sizes
, linenum
));
667 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
675 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
677 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
682 else if (!_cups_strcasecmp(line
, "Size"))
684 if (pc
->num_sizes
>= num_sizes
)
686 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
688 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
692 size
= pc
->sizes
+ pc
->num_sizes
;
694 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
695 &(size
->width
), &(size
->length
), &(size
->left
),
696 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
698 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
700 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
704 size
->map
.pwg
= strdup(pwg_keyword
);
705 size
->map
.ppd
= strdup(ppd_keyword
);
709 else if (!_cups_strcasecmp(line
, "CustomSize"))
711 if (pc
->custom_max_width
> 0)
713 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
715 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
719 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
720 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
721 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
722 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
723 &(pc
->custom_size
.top
)) != 8)
725 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
727 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
731 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
732 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
733 pc
->custom_max_keyword
= strdup(pwg_keyword
);
735 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
736 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
737 pc
->custom_min_keyword
= strdup(pwg_keyword
);
739 else if (!_cups_strcasecmp(line
, "SourceOption"))
741 pc
->source_option
= strdup(value
);
743 else if (!_cups_strcasecmp(line
, "NumSources"))
747 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
749 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
753 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
755 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
756 "line %d.", num_sources
, linenum
));
757 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
761 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
763 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
765 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
769 else if (!_cups_strcasecmp(line
, "Source"))
771 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
773 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
775 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
779 if (pc
->num_sources
>= num_sources
)
781 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
783 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
787 map
= pc
->sources
+ pc
->num_sources
;
788 map
->pwg
= strdup(pwg_keyword
);
789 map
->ppd
= strdup(ppd_keyword
);
793 else if (!_cups_strcasecmp(line
, "NumTypes"))
797 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
798 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
802 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
804 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
805 "line %d.", num_types
, linenum
));
806 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
810 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
812 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
814 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
818 else if (!_cups_strcasecmp(line
, "Type"))
820 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
822 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
824 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
828 if (pc
->num_types
>= num_types
)
830 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
836 map
= pc
->types
+ pc
->num_types
;
837 map
->pwg
= strdup(pwg_keyword
);
838 map
->ppd
= strdup(ppd_keyword
);
842 else if (!_cups_strcasecmp(line
, "Preset"))
845 * Preset output-mode print-quality name=value ...
848 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
849 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
851 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
852 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
853 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
854 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
855 valueptr
== value
|| !*valueptr
)
857 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
859 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
863 pc
->num_presets
[print_color_mode
][print_quality
] =
864 cupsParseOptions(valueptr
, 0,
865 pc
->presets
[print_color_mode
] + print_quality
);
867 else if (!_cups_strcasecmp(line
, "SidesOption"))
868 pc
->sides_option
= strdup(value
);
869 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
870 pc
->sides_1sided
= strdup(value
);
871 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
872 pc
->sides_2sided_long
= strdup(value
);
873 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
874 pc
->sides_2sided_short
= strdup(value
);
875 else if (!_cups_strcasecmp(line
, "Finishings"))
879 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
881 (cups_afree_func_t
)pwg_free_finishings
);
883 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
886 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
887 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
888 &(finishings
->options
));
890 cupsArrayAdd(pc
->finishings
, finishings
);
892 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
895 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
897 cupsArrayAdd(pc
->templates
, value
);
899 else if (!_cups_strcasecmp(line
, "MaxCopies"))
900 pc
->max_copies
= atoi(value
);
901 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
902 pc
->charge_info_uri
= strdup(value
);
903 else if (!_cups_strcasecmp(line
, "JobAccountId"))
904 pc
->account_id
= !_cups_strcasecmp(value
, "true");
905 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
906 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
907 else if (!_cups_strcasecmp(line
, "JobPassword"))
908 pc
->password
= strdup(value
);
909 else if (!_cups_strcasecmp(line
, "Mandatory"))
912 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
914 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
916 else if (!_cups_strcasecmp(line
, "SupportFile"))
918 if (!pc
->support_files
)
919 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
921 cupsArrayAdd(pc
->support_files
, value
);
925 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
930 if (pc
->num_sizes
< num_sizes
)
932 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
933 pc
->num_sizes
, num_sizes
));
934 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
938 if (pc
->num_sources
< num_sources
)
940 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
941 pc
->num_sources
, num_sources
));
942 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
946 if (pc
->num_types
< num_types
)
948 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
949 pc
->num_types
, num_types
));
950 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
959 * If we get here the file was bad - free any data and return...
965 _ppdCacheDestroy(pc
);
978 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
981 _ppd_cache_t
* /* O - PPD cache and mapping data */
982 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
984 int i
, j
, k
; /* Looping vars */
985 _ppd_cache_t
*pc
; /* PWG mapping data */
986 ppd_option_t
*input_slot
, /* InputSlot option */
987 *media_type
, /* MediaType option */
988 *output_bin
, /* OutputBin option */
989 *color_model
, /* ColorModel option */
990 *duplex
, /* Duplex option */
991 *ppd_option
; /* Other PPD option */
992 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
993 pwg_map_t
*map
; /* Current source/type map */
994 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
995 int num_options
; /* Number of preset options and props */
996 cups_option_t
*options
; /* Preset options and properties */
997 ppd_size_t
*ppd_size
; /* Current PPD size */
998 pwg_size_t
*pwg_size
; /* Current PWG size */
999 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1000 /* PWG keyword string */
1001 ppd_name
[PPD_MAX_NAME
];
1002 /* Normalized PPD name */
1003 const char *pwg_name
; /* Standard PWG media name */
1004 pwg_media_t
*pwg_media
; /* PWG media data */
1005 _pwg_print_color_mode_t pwg_print_color_mode
;
1006 /* print-color-mode index */
1007 _pwg_print_quality_t pwg_print_quality
;
1008 /* print-quality index */
1009 int similar
; /* Are the old and new size similar? */
1010 pwg_size_t
*old_size
; /* Current old size */
1011 int old_imageable
, /* Old imageable length in 2540ths */
1012 old_borderless
, /* Old borderless state */
1013 old_known_pwg
; /* Old PWG name is well-known */
1014 int new_width
, /* New width in 2540ths */
1015 new_length
, /* New length in 2540ths */
1016 new_left
, /* New left margin in 2540ths */
1017 new_bottom
, /* New bottom margin in 2540ths */
1018 new_right
, /* New right margin in 2540ths */
1019 new_top
, /* New top margin in 2540ths */
1020 new_imageable
, /* New imageable length in 2540ths */
1021 new_borderless
, /* New borderless state */
1022 new_known_pwg
; /* New PWG name is well-known */
1023 pwg_size_t
*new_size
; /* New size to add, if any */
1024 const char *filter
; /* Current filter */
1025 _pwg_finishings_t
*finishings
; /* Current finishings value */
1026 char msg_id
[256]; /* Message identifier */
1029 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1032 * Range check input...
1039 * Allocate memory...
1042 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1044 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1048 pc
->strings
= _cupsMessageNew(NULL
);
1051 * Copy and convert size data...
1054 if (ppd
->num_sizes
> 0)
1056 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1058 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1059 "pwg_size_t's.", ppd
->num_sizes
));
1063 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1068 * Don't copy over custom size...
1071 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1075 * Convert the PPD size name to the corresponding PWG keyword name.
1078 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1081 * Standard name, do we have conflicts?
1084 for (j
= 0; j
< pc
->num_sizes
; j
++)
1085 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1095 * Standard name and no conflicts, use it!
1098 pwg_name
= pwg_media
->pwg
;
1104 * Not a standard name; convert it to a PWG vendor name of the form:
1106 * pp_lowerppd_WIDTHxHEIGHTuu
1109 pwg_name
= pwg_keyword
;
1112 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1113 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1114 PWG_FROM_POINTS(ppd_size
->width
),
1115 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1119 * If we have a similar paper with non-zero margins then we only want to
1120 * keep it if it has a larger imageable area length. The NULL check is for
1121 * dimensions that are <= 0...
1124 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1125 PWG_FROM_POINTS(ppd_size
->length
),
1129 new_width
= pwg_media
->width
;
1130 new_length
= pwg_media
->length
;
1131 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1132 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1133 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1134 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1135 new_imageable
= new_length
- new_top
- new_bottom
;
1136 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1137 new_left
== 0 && new_right
== 0;
1139 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1143 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1144 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1145 old_size
->right
== 0 && old_size
->top
== 0;
1146 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1147 strncmp(old_size
->map
.pwg
, "om_", 3);
1149 similar
= old_borderless
== new_borderless
&&
1150 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1151 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1154 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1157 * The new paper has a larger imageable area so it could replace
1158 * the older paper. Regardless of the imageable area, we always
1159 * prefer the size with a well-known PWG name.
1162 new_size
= old_size
;
1163 free(old_size
->map
.ppd
);
1164 free(old_size
->map
.pwg
);
1171 * The paper was unique enough to deserve its own entry so add it to the
1175 new_size
= pwg_size
++;
1185 new_size
->map
.ppd
= strdup(ppd_size
->name
);
1186 new_size
->map
.pwg
= strdup(pwg_name
);
1187 new_size
->width
= new_width
;
1188 new_size
->length
= new_length
;
1189 new_size
->left
= new_left
;
1190 new_size
->bottom
= new_bottom
;
1191 new_size
->right
= new_right
;
1192 new_size
->top
= new_top
;
1197 if (ppd
->variable_sizes
)
1200 * Generate custom size data...
1203 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1204 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1205 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1206 pc
->custom_max_keyword
= strdup(pwg_keyword
);
1207 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1208 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1210 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1211 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1212 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1213 pc
->custom_min_keyword
= strdup(pwg_keyword
);
1214 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1215 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1217 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1218 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1219 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1220 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1224 * Copy and convert InputSlot data...
1227 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1228 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1232 pc
->source_option
= strdup(input_slot
->keyword
);
1234 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1236 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1237 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1241 pc
->num_sources
= input_slot
->num_choices
;
1243 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1246 i
--, choice
++, map
++)
1248 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1249 !_cups_strcasecmp(choice
->choice
, "Default"))
1251 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1253 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1255 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1257 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1258 !_cups_strcasecmp(choice
->choice
, "MP") ||
1259 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1260 pwg_name
= "by-pass-tray";
1261 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1262 pwg_name
= "large-capacity";
1263 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1264 pwg_name
= "bottom";
1265 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1266 pwg_name
= "middle";
1267 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1269 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1271 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1272 pwg_name
= "main-roll";
1276 * Convert PPD name to lowercase...
1279 pwg_name
= pwg_keyword
;
1280 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1284 map
->pwg
= strdup(pwg_name
);
1285 map
->ppd
= strdup(choice
->choice
);
1288 * Add localized text for PWG keyword to message catalog...
1291 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1292 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1297 * Copy and convert MediaType data...
1300 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1302 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1304 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1305 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1309 pc
->num_types
= media_type
->num_choices
;
1311 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1314 i
--, choice
++, map
++)
1316 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1317 !_cups_strcasecmp(choice
->choice
, "Any") ||
1318 !_cups_strcasecmp(choice
->choice
, "Default"))
1320 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1321 pwg_name
= "cardstock";
1322 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1323 pwg_name
= "envelope";
1324 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1325 pwg_name
= "photographic-glossy";
1326 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1327 pwg_name
= "photographic-high-gloss";
1328 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1329 pwg_name
= "photographic-matte";
1330 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1331 pwg_name
= "stationery";
1332 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1333 pwg_name
= "stationery-coated";
1334 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1335 pwg_name
= "stationery-inkjet";
1336 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1337 pwg_name
= "stationery-letterhead";
1338 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1339 pwg_name
= "stationery-preprinted";
1340 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1341 pwg_name
= "stationery-recycled";
1342 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1343 pwg_name
= "transparency";
1347 * Convert PPD name to lowercase...
1350 pwg_name
= pwg_keyword
;
1351 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1355 map
->pwg
= strdup(pwg_name
);
1356 map
->ppd
= strdup(choice
->choice
);
1359 * Add localized text for PWG keyword to message catalog...
1362 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", pwg_name
);
1363 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1368 * Copy and convert OutputBin data...
1371 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1373 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1375 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1376 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1380 pc
->num_bins
= output_bin
->num_choices
;
1382 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1385 i
--, choice
++, map
++)
1387 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1389 map
->pwg
= strdup(pwg_keyword
);
1390 map
->ppd
= strdup(choice
->choice
);
1393 * Add localized text for PWG keyword to message catalog...
1396 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_keyword
);
1397 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1401 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1404 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1407 const char *quality
, /* com.apple.print.preset.quality value */
1408 *output_mode
, /* com.apple.print.preset.output-mode value */
1409 *color_model_val
, /* ColorModel choice */
1410 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1411 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1416 * Add localized text for PWG keyword to message catalog...
1419 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1420 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1423 * Get the options for this preset...
1426 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1429 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1430 num_options
, options
)) != NULL
)
1433 * Get the print-quality for this preset...
1436 if (!strcmp(quality
, "low"))
1437 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1438 else if (!strcmp(quality
, "high"))
1439 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1441 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1444 * Ignore graphicsType "Photo" presets that are not high quality.
1447 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1448 num_options
, options
);
1450 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1451 !strcmp(graphicsType
, "Photo"))
1455 * Ignore presets for normal and draft quality where the coating
1456 * isn't "none" or "autodetect".
1459 media_front_coating
= cupsGetOption(
1460 "com.apple.print.preset.media-front-coating",
1461 num_options
, options
);
1463 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1464 media_front_coating
&&
1465 strcmp(media_front_coating
, "none") &&
1466 strcmp(media_front_coating
, "autodetect"))
1470 * Get the output mode for this preset...
1473 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1474 num_options
, options
);
1475 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1479 if (!strcmp(output_mode
, "monochrome"))
1480 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1482 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1484 else if (color_model_val
)
1486 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1487 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1489 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1492 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1495 * Save the options for this combination as needed...
1498 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1499 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1500 _ppdParseOptions(ppd_attr
->value
, 0,
1501 pc
->presets
[pwg_print_color_mode
] +
1502 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1505 cupsFreeOptions(num_options
, options
);
1507 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1510 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1511 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1512 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1515 * Try adding some common color options to create grayscale presets. These
1516 * are listed in order of popularity...
1519 const char *color_option
= NULL
, /* Color control option */
1520 *gray_choice
= NULL
; /* Choice to select grayscale */
1522 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1523 ppdFindChoice(color_model
, "Gray"))
1525 color_option
= "ColorModel";
1526 gray_choice
= "Gray";
1528 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1529 ppdFindChoice(color_model
, "grayscale"))
1531 color_option
= "HPColorMode";
1532 gray_choice
= "grayscale";
1534 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1535 ppdFindChoice(color_model
, "Mono"))
1537 color_option
= "BRMonoColor";
1538 gray_choice
= "Mono";
1540 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1541 ppdFindChoice(color_model
, "1"))
1543 color_option
= "CNIJSGrayScale";
1546 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1547 ppdFindChoice(color_model
, "True"))
1549 color_option
= "HPColorAsGray";
1550 gray_choice
= "True";
1553 if (color_option
&& gray_choice
)
1556 * Copy and convert ColorModel (output-mode) data...
1559 cups_option_t
*coption
, /* Color option */
1560 *moption
; /* Monochrome option */
1562 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1563 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1564 pwg_print_quality
++)
1566 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1569 * Copy the color options...
1572 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1573 [pwg_print_quality
];
1574 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1578 for (i
= num_options
, moption
= options
,
1579 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1580 [pwg_print_quality
];
1582 i
--, moption
++, coption
++)
1584 moption
->name
= _cupsStrRetain(coption
->name
);
1585 moption
->value
= _cupsStrRetain(coption
->value
);
1588 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1590 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1594 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1598 * Add the grayscale option to the preset...
1601 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1602 cupsAddOption(color_option
, gray_choice
,
1603 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1604 [pwg_print_quality
],
1605 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1612 * Copy and convert Duplex (sides) data...
1615 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1616 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1617 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1618 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1619 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1623 pc
->sides_option
= strdup(duplex
->keyword
);
1625 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1629 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1630 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1631 pc
->sides_1sided
= strdup(choice
->choice
);
1632 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1633 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1634 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1635 pc
->sides_2sided_long
= strdup(choice
->choice
);
1636 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1637 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1638 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1639 !pc
->sides_2sided_short
)
1640 pc
->sides_2sided_short
= strdup(choice
->choice
);
1645 * Copy filters and pre-filters...
1648 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1650 cupsArrayAdd(pc
->filters
,
1651 "application/vnd.cups-raw application/octet-stream 0 -");
1653 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1657 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1659 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1661 else if (ppd
->num_filters
> 0)
1663 for (i
= 0; i
< ppd
->num_filters
; i
++)
1664 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1667 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1670 * See if we have a command filter...
1673 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1675 filter
= (const char *)cupsArrayNext(pc
->filters
))
1676 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1677 _cups_isspace(filter
[28]))
1681 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1682 _cups_strcasecmp(ppd_attr
->value
, "none")))
1685 * No command filter and no cupsCommands keyword telling us not to use one.
1686 * See if this is a PostScript printer, and if so add a PostScript command
1690 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1692 filter
= (const char *)cupsArrayNext(pc
->filters
))
1693 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1694 _cups_isspace(filter
[31]))
1698 cupsArrayAdd(pc
->filters
,
1699 "application/vnd.cups-command application/postscript 100 "
1703 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1705 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1709 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1711 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1714 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1715 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1718 * Copy the product string, if any...
1722 pc
->product
= strdup(ppd
->product
);
1725 * Copy finishings mapping data...
1728 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1731 * Have proper vendor mapping of IPP finishings values to PPD options...
1734 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1735 NULL
, NULL
, 0, NULL
,
1736 (cups_afree_func_t
)pwg_free_finishings
);
1740 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1743 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1744 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1745 &(finishings
->options
),
1746 _PPD_PARSE_OPTIONS
);
1748 cupsArrayAdd(pc
->finishings
, finishings
);
1750 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1756 * No IPP mapping data, try to map common/standard PPD keywords...
1759 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1761 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1764 * Add staple finishings...
1767 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1768 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1769 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1770 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1771 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1772 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1773 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1774 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1775 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1779 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1782 * Add (Ricoh) punch finishings...
1785 if (ppdFindChoice(ppd_option
, "Left2"))
1786 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1787 if (ppdFindChoice(ppd_option
, "Left3"))
1788 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1789 if (ppdFindChoice(ppd_option
, "Left4"))
1790 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1791 if (ppdFindChoice(ppd_option
, "Right2"))
1792 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1793 if (ppdFindChoice(ppd_option
, "Right3"))
1794 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1795 if (ppdFindChoice(ppd_option
, "Right4"))
1796 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1797 if (ppdFindChoice(ppd_option
, "Upper2"))
1798 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1799 if (ppdFindChoice(ppd_option
, "Upper3"))
1800 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1801 if (ppdFindChoice(ppd_option
, "Upper4"))
1802 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1805 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1808 * Add bind finishings...
1811 if (ppdFindChoice(ppd_option
, "Left"))
1812 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1813 if (ppdFindChoice(ppd_option
, "Right"))
1814 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1815 if (ppdFindChoice(ppd_option
, "Top"))
1816 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1817 if (ppdFindChoice(ppd_option
, "Bottom"))
1818 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1821 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1824 * Add (Adobe) fold finishings...
1827 if (ppdFindChoice(ppd_option
, "ZFold"))
1828 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1829 if (ppdFindChoice(ppd_option
, "Saddle"))
1830 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1831 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1832 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1833 if (ppdFindChoice(ppd_option
, "LeftGate"))
1834 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1835 if (ppdFindChoice(ppd_option
, "RightGate"))
1836 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1837 if (ppdFindChoice(ppd_option
, "Letter"))
1838 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1839 if (ppdFindChoice(ppd_option
, "XFold"))
1840 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1843 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1846 * Add (Ricoh) fold finishings...
1849 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1850 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1853 if (cupsArrayCount(pc
->finishings
) == 0)
1855 cupsArrayDelete(pc
->finishings
);
1856 pc
->finishings
= NULL
;
1860 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1862 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1864 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1866 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1869 * Add localized text for PWG keyword to message catalog...
1872 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1873 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1881 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1882 pc
->max_copies
= atoi(ppd_attr
->value
);
1883 else if (ppd
->manual_copies
)
1886 pc
->max_copies
= 9999;
1889 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1890 * cupsJobPassword, and cupsMandatory.
1893 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1894 pc
->charge_info_uri
= strdup(ppd_attr
->value
);
1896 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1897 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1899 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1900 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1902 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1903 pc
->password
= strdup(ppd_attr
->value
);
1905 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1906 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1912 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1914 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1916 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1917 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1919 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1920 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1923 * Return the cache data...
1929 * If we get here we need to destroy the PWG mapping data and return NULL...
1934 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1935 _ppdCacheDestroy(pc
);
1942 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1946 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1948 int i
; /* Looping var */
1949 pwg_map_t
*map
; /* Current map */
1950 pwg_size_t
*size
; /* Current size */
1954 * Range check input...
1961 * Free memory as needed...
1966 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1977 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1979 free(size
->map
.pwg
);
1980 free(size
->map
.ppd
);
1986 free(pc
->source_option
);
1990 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2001 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2010 free(pc
->custom_max_keyword
);
2011 free(pc
->custom_min_keyword
);
2014 cupsArrayDelete(pc
->filters
);
2015 cupsArrayDelete(pc
->prefilters
);
2016 cupsArrayDelete(pc
->finishings
);
2018 free(pc
->charge_info_uri
);
2021 cupsArrayDelete(pc
->mandatory
);
2023 cupsArrayDelete(pc
->support_files
);
2025 cupsArrayDelete(pc
->strings
);
2032 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2036 const char * /* O - output-bin or NULL */
2038 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2039 const char *output_bin
) /* I - PPD OutputBin string */
2041 int i
; /* Looping var */
2045 * Range check input...
2048 if (!pc
|| !output_bin
)
2052 * Look up the OutputBin string...
2056 for (i
= 0; i
< pc
->num_bins
; i
++)
2057 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2058 return (pc
->bins
[i
].pwg
);
2065 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2066 * IPP finishings value(s).
2069 int /* O - New number of options */
2070 _ppdCacheGetFinishingOptions(
2071 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2072 ipp_t
*job
, /* I - Job attributes or NULL */
2073 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2074 int num_options
, /* I - Number of options */
2075 cups_option_t
**options
) /* IO - Options */
2077 int i
; /* Looping var */
2078 _pwg_finishings_t
*f
, /* PWG finishings options */
2079 key
; /* Search key */
2080 ipp_attribute_t
*attr
; /* Finishings attribute */
2081 cups_option_t
*option
; /* Current finishings option */
2085 * Range check input...
2088 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2089 (!job
&& value
== IPP_FINISHINGS_NONE
))
2090 return (num_options
);
2093 * Apply finishing options...
2096 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2098 int num_values
= ippGetCount(attr
); /* Number of values */
2100 for (i
= 0; i
< num_values
; i
++)
2102 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2104 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2106 int j
; /* Another looping var */
2108 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2109 num_options
= cupsAddOption(option
->name
, option
->value
,
2110 num_options
, options
);
2114 else if (value
!= IPP_FINISHINGS_NONE
)
2118 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2120 int j
; /* Another looping var */
2122 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2123 num_options
= cupsAddOption(option
->name
, option
->value
,
2124 num_options
, options
);
2128 return (num_options
);
2133 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2137 int /* O - Number of finishings values */
2138 _ppdCacheGetFinishingValues(
2139 ppd_file_t
*ppd
, /* I - Marked PPD file */
2140 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2141 int max_values
, /* I - Maximum number of finishings values */
2142 int *values
) /* O - Finishings values */
2144 int i
, /* Looping var */
2145 num_values
= 0; /* Number of values */
2146 _pwg_finishings_t
*f
; /* Current finishings option */
2147 cups_option_t
*option
; /* Current option */
2148 ppd_choice_t
*choice
; /* Marked PPD choice */
2152 * Range check input...
2155 DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd
, pc
, max_values
, values
));
2157 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2159 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2162 else if (!pc
->finishings
)
2164 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2169 * Go through the finishings options and see what is set...
2172 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2174 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2176 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
)));
2178 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2180 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2182 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2184 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2191 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
)));
2193 values
[num_values
++] = (int)f
->value
;
2195 if (num_values
>= max_values
)
2200 if (num_values
== 0)
2203 * Always have at least "finishings" = 'none'...
2206 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2207 values
[0] = IPP_FINISHINGS_NONE
;
2211 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2213 return (num_values
);
2218 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2219 * attributes or a keyword string.
2222 const char * /* O - PPD InputSlot or NULL */
2223 _ppdCacheGetInputSlot(
2224 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2225 ipp_t
*job
, /* I - Job attributes or NULL */
2226 const char *keyword
) /* I - Keyword string or NULL */
2229 * Range check input...
2232 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2235 if (job
&& !keyword
)
2238 * Lookup the media-col attribute and any media-source found there...
2241 ipp_attribute_t
*media_col
, /* media-col attribute */
2242 *media_source
; /* media-source attribute */
2243 pwg_size_t size
; /* Dimensional size */
2244 int margins_set
; /* Were the margins set? */
2246 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2248 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2250 IPP_TAG_KEYWORD
)) != NULL
)
2253 * Use the media-source value from media-col...
2256 keyword
= ippGetString(media_source
, 0, NULL
);
2258 else if (pwgInitSize(&size
, job
, &margins_set
))
2261 * For media <= 5x7, look for a photo tray...
2264 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2271 int i
; /* Looping var */
2273 for (i
= 0; i
< pc
->num_sources
; i
++)
2274 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2275 return (pc
->sources
[i
].ppd
);
2283 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2284 * attributes or a keyword string.
2287 const char * /* O - PPD MediaType or NULL */
2288 _ppdCacheGetMediaType(
2289 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2290 ipp_t
*job
, /* I - Job attributes or NULL */
2291 const char *keyword
) /* I - Keyword string or NULL */
2294 * Range check input...
2297 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2300 if (job
&& !keyword
)
2303 * Lookup the media-col attribute and any media-source found there...
2306 ipp_attribute_t
*media_col
, /* media-col attribute */
2307 *media_type
; /* media-type attribute */
2309 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2312 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2314 IPP_TAG_KEYWORD
)) == NULL
)
2315 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2316 "media-type", IPP_TAG_NAME
);
2319 keyword
= media_type
->values
[0].string
.text
;
2325 int i
; /* Looping var */
2327 for (i
= 0; i
< pc
->num_types
; i
++)
2328 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2329 return (pc
->types
[i
].ppd
);
2337 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2341 const char * /* O - PPD OutputBin or NULL */
2342 _ppdCacheGetOutputBin(
2343 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2344 const char *output_bin
) /* I - Keyword string */
2346 int i
; /* Looping var */
2350 * Range check input...
2353 if (!pc
|| !output_bin
)
2357 * Look up the OutputBin string...
2361 for (i
= 0; i
< pc
->num_bins
; i
++)
2362 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2363 return (pc
->bins
[i
].ppd
);
2370 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2371 * attributes or a keyword string.
2374 const char * /* O - PPD PageSize or NULL */
2375 _ppdCacheGetPageSize(
2376 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2377 ipp_t
*job
, /* I - Job attributes or NULL */
2378 const char *keyword
, /* I - Keyword string or NULL */
2379 int *exact
) /* O - 1 if exact match, 0 otherwise */
2381 int i
; /* Looping var */
2382 pwg_size_t
*size
, /* Current size */
2383 *closest
, /* Closest size */
2384 jobsize
; /* Size data from job */
2385 int margins_set
, /* Were the margins set? */
2386 dwidth
, /* Difference in width */
2387 dlength
, /* Difference in length */
2388 dleft
, /* Difference in left margins */
2389 dright
, /* Difference in right margins */
2390 dbottom
, /* Difference in bottom margins */
2391 dtop
, /* Difference in top margins */
2392 dmin
, /* Minimum difference */
2393 dclosest
; /* Closest difference */
2394 const char *ppd_name
; /* PPD media name */
2397 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2398 pc
, job
, keyword
, exact
));
2401 * Range check input...
2404 if (!pc
|| (!job
&& !keyword
))
2415 * Try getting the PPD media name from the job attributes...
2418 ipp_attribute_t
*attr
; /* Job attribute */
2420 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2421 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2422 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2426 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2427 attr
->name
, ippTagString(attr
->value_tag
)));
2429 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2432 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2433 attr
->value_tag
== IPP_TAG_KEYWORD
))
2434 ppd_name
= attr
->values
[0].string
.text
;
2437 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2442 * Try looking up the named PPD size first...
2445 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2447 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2448 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2450 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2451 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2456 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2458 return (size
->map
.ppd
);
2463 if (job
&& !keyword
)
2466 * Get the size using media-col or media, with the preference being
2470 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2476 * Get the size using a media keyword...
2479 pwg_media_t
*media
; /* Media definition */
2482 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2483 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2484 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2487 jobsize
.width
= media
->width
;
2488 jobsize
.length
= media
->length
;
2493 * Now that we have the dimensions and possibly the margins, look at the
2494 * available sizes and find the match...
2498 dclosest
= 999999999;
2500 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2501 _cups_strncasecmp(ppd_name
, "custom_", 7))
2503 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2506 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2507 * is just about 176/2540ths...
2510 dwidth
= size
->width
- jobsize
.width
;
2511 dlength
= size
->length
- jobsize
.length
;
2513 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2519 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2522 dleft
= size
->left
- jobsize
.left
;
2523 dright
= size
->right
- jobsize
.right
;
2524 dtop
= size
->top
- jobsize
.top
;
2525 dbottom
= size
->bottom
- jobsize
.bottom
;
2527 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2528 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2530 dleft
= dleft
< 0 ? -dleft
: dleft
;
2531 dright
= dright
< 0 ? -dright
: dright
;
2532 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2533 dtop
= dtop
< 0 ? -dtop
: dtop
;
2534 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2536 if (dmin
< dclosest
)
2549 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2551 return (size
->map
.ppd
);
2557 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2560 return (closest
->map
.ppd
);
2564 * If we get here we need to check for custom page size support...
2567 if (jobsize
.width
>= pc
->custom_min_width
&&
2568 jobsize
.width
<= pc
->custom_max_width
&&
2569 jobsize
.length
>= pc
->custom_min_length
&&
2570 jobsize
.length
<= pc
->custom_max_length
)
2573 * In range, format as Custom.WWWWxLLLL (points).
2576 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2577 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2579 if (margins_set
&& exact
)
2581 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2582 dright
= pc
->custom_size
.right
- jobsize
.right
;
2583 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2584 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2586 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2587 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2593 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2594 pc
->custom_ppd_size
));
2596 return (pc
->custom_ppd_size
);
2600 * No custom page size support or the size is out of range - return NULL.
2603 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2610 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2613 pwg_size_t
* /* O - PWG size or NULL */
2615 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2616 const char *page_size
) /* I - PPD PageSize */
2618 int i
; /* Looping var */
2619 pwg_media_t
*media
; /* Media */
2620 pwg_size_t
*size
; /* Current size */
2624 * Range check input...
2627 if (!pc
|| !page_size
)
2630 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2633 * Custom size; size name can be one of the following:
2635 * Custom.WIDTHxLENGTHin - Size in inches
2636 * Custom.WIDTHxLENGTHft - Size in feet
2637 * Custom.WIDTHxLENGTHcm - Size in centimeters
2638 * Custom.WIDTHxLENGTHmm - Size in millimeters
2639 * Custom.WIDTHxLENGTHm - Size in meters
2640 * Custom.WIDTHxLENGTH[pt] - Size in points
2643 double w
, l
; /* Width and length of page */
2644 char *ptr
; /* Pointer into PageSize */
2645 struct lconv
*loc
; /* Locale data */
2648 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2649 if (!ptr
|| *ptr
!= 'x')
2652 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2656 if (!_cups_strcasecmp(ptr
, "in"))
2661 else if (!_cups_strcasecmp(ptr
, "ft"))
2666 else if (!_cups_strcasecmp(ptr
, "mm"))
2671 else if (!_cups_strcasecmp(ptr
, "cm"))
2676 else if (!_cups_strcasecmp(ptr
, "m"))
2687 pc
->custom_size
.width
= (int)w
;
2688 pc
->custom_size
.length
= (int)l
;
2690 return (&(pc
->custom_size
));
2694 * Not a custom size - look it up...
2697 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2698 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2699 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2703 * Look up standard sizes...
2706 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2707 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2708 media
= pwgMediaForPWG(page_size
);
2712 pc
->custom_size
.width
= media
->width
;
2713 pc
->custom_size
.length
= media
->length
;
2715 return (&(pc
->custom_size
));
2723 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2727 const char * /* O - PWG media-source keyword */
2729 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2730 const char *input_slot
) /* I - PPD InputSlot */
2732 int i
; /* Looping var */
2733 pwg_map_t
*source
; /* Current source */
2737 * Range check input...
2740 if (!pc
|| !input_slot
)
2743 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2744 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2745 return (source
->pwg
);
2752 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2756 const char * /* O - PWG media-type keyword */
2758 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2759 const char *media_type
) /* I - PPD MediaType */
2761 int i
; /* Looping var */
2762 pwg_map_t
*type
; /* Current type */
2766 * Range check input...
2769 if (!pc
|| !media_type
)
2772 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2773 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2781 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2784 int /* O - 1 on success, 0 on failure */
2786 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2787 const char *filename
, /* I - File to write */
2788 ipp_t
*attrs
) /* I - Attributes to write, if any */
2790 int i
, j
, k
; /* Looping vars */
2791 cups_file_t
*fp
; /* Output file */
2792 pwg_size_t
*size
; /* Current size */
2793 pwg_map_t
*map
; /* Current map */
2794 _pwg_finishings_t
*f
; /* Current finishing option */
2795 cups_option_t
*option
; /* Current option */
2796 const char *value
; /* String value */
2797 char newfile
[1024]; /* New filename */
2801 * Range check input...
2804 if (!pc
|| !filename
)
2806 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2811 * Open the file and write with compression...
2814 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2815 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2817 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2822 * Standard header...
2825 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2831 if (pc
->num_bins
> 0)
2833 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2834 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2835 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2842 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2843 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2844 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2845 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2846 size
->bottom
, size
->right
, size
->top
);
2847 if (pc
->custom_max_width
> 0)
2848 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2849 pc
->custom_max_width
, pc
->custom_max_length
,
2850 pc
->custom_min_width
, pc
->custom_min_length
,
2851 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2852 pc
->custom_size
.right
, pc
->custom_size
.top
);
2858 if (pc
->source_option
)
2859 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2861 if (pc
->num_sources
> 0)
2863 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2864 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2865 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2872 if (pc
->num_types
> 0)
2874 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2875 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2876 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2883 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2884 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2885 if (pc
->num_presets
[i
][j
])
2887 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2888 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2891 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2892 cupsFilePutChar(fp
, '\n');
2899 if (pc
->sides_option
)
2900 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2902 if (pc
->sides_1sided
)
2903 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2905 if (pc
->sides_2sided_long
)
2906 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2908 if (pc
->sides_2sided_short
)
2909 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2912 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2916 cupsFilePutConf(fp
, "Product", pc
->product
);
2918 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2920 value
= (const char *)cupsArrayNext(pc
->filters
))
2921 cupsFilePutConf(fp
, "Filter", value
);
2923 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2925 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2926 cupsFilePutConf(fp
, "PreFilter", value
);
2928 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2931 * Finishing options...
2934 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2936 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2938 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2939 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2940 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2941 cupsFilePutChar(fp
, '\n');
2944 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2945 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2951 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2954 * Accounting/quota/PIN/managed printing values...
2957 if (pc
->charge_info_uri
)
2958 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2960 cupsFilePrintf(fp
, "JobAccountId %s\n", pc
->account_id
? "true" : "false");
2961 cupsFilePrintf(fp
, "JobAccountingUserId %s\n",
2962 pc
->accounting_user_id
? "true" : "false");
2965 cupsFilePutConf(fp
, "JobPassword", pc
->password
);
2967 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2969 value
= (char *)cupsArrayNext(pc
->mandatory
))
2970 cupsFilePutConf(fp
, "Mandatory", value
);
2976 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2978 value
= (char *)cupsArrayNext(pc
->support_files
))
2979 cupsFilePutConf(fp
, "SupportFile", value
);
2982 * IPP attributes, if any...
2987 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2989 attrs
->state
= IPP_STATE_IDLE
;
2990 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2994 * Close and return...
2997 if (cupsFileClose(fp
))
3004 return (!rename(newfile
, filename
));
3009 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3010 * of an IPP printer.
3013 char * /* O - PPD filename or @code NULL@ on error */
3014 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3015 size_t bufsize
, /* I - Size of filename buffer */
3016 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3018 cups_file_t
*fp
; /* PPD file */
3019 cups_array_t
*sizes
; /* Media sizes supported by printer */
3020 cups_size_t
*size
; /* Current media size */
3021 ipp_attribute_t
*attr
, /* xxx-supported */
3022 *defattr
, /* xxx-default */
3023 *quality
, /* print-quality-supported */
3024 *x_dim
, *y_dim
; /* Media dimensions */
3025 ipp_t
*media_col
, /* Media collection */
3026 *media_size
; /* Media size collection */
3027 char make
[256], /* Make and model */
3028 *model
, /* Model name */
3029 ppdname
[PPD_MAX_NAME
];
3031 int i
, j
, /* Looping vars */
3032 count
, /* Number of values */
3033 bottom
, /* Largest bottom margin */
3034 left
, /* Largest left margin */
3035 right
, /* Largest right margin */
3036 top
, /* Largest top margin */
3037 max_length
= 0, /* Maximum custom size */
3039 min_length
= INT_MAX
,
3040 /* Minimum custom size */
3041 min_width
= INT_MAX
,
3042 is_apple
= 0, /* Does the printer support Apple raster? */
3043 is_pdf
= 0, /* Does the printer support PDF? */
3044 is_pwg
= 0; /* Does the printer support PWG Raster? */
3045 pwg_media_t
*pwg
; /* PWG media size */
3046 int xres
, yres
; /* Resolution values */
3047 int resolutions
[1000];
3048 /* Array of resolution indices */
3049 char msgid
[256]; /* Message identifier (attr.value) */
3050 const char *keyword
, /* Keyword value */
3051 *msgstr
; /* Localized string */
3052 cups_lang_t
*lang
= cupsLangDefault();
3053 /* Localization info */
3054 cups_array_t
*strings
= NULL
;/* Printer strings file */
3055 struct lconv
*loc
= localeconv();
3057 cups_array_t
*fin_options
= NULL
;
3058 /* Finishing options */
3062 * Range check input...
3068 if (!buffer
|| bufsize
< 1)
3070 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3076 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3081 * Open a temporary file for the PPD...
3084 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3086 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3091 * Standard stuff for PPD file...
3094 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3095 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3096 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3097 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3098 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3099 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3100 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3101 cupsFilePuts(fp
, "*FileSystem: False\n");
3102 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3104 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3105 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3107 strlcpy(make
, "Unknown Printer", sizeof(make
));
3109 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3110 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3113 strlcpy(make
, "HP", sizeof(make
));
3115 else if ((model
= strchr(make
, ' ')) != NULL
)
3120 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3121 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3122 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3123 cupsFilePrintf(fp
, "*NickName: \"%s - IPP Everywhere\"\n", model
);
3124 cupsFilePrintf(fp
, "*ShortNickName: \"%s - IPP Everywhere\"\n", model
);
3126 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3127 cupsFilePuts(fp
, "*ColorDevice: True\n");
3129 cupsFilePuts(fp
, "*ColorDevice: False\n");
3131 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3132 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3133 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3135 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3136 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3138 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3139 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3141 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3143 http_t
*http
= NULL
; /* Connection to printer */
3144 char stringsfile
[1024]; /* Temporary strings file */
3146 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3148 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3150 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3152 unlink(stringsfile
);
3163 if (ippGetBoolean(ippFindAttribute(response
, "job-account-id-supported", IPP_TAG_BOOLEAN
), 0))
3164 cupsFilePuts(fp
, "*cupsJobAccountId: True\n");
3166 if (ippGetBoolean(ippFindAttribute(response
, "job-accounting-user-id-supported", IPP_TAG_BOOLEAN
), 0))
3167 cupsFilePuts(fp
, "*cupsJobAccountingUserId: True\n");
3170 * Password/PIN printing...
3173 if ((attr
= ippFindAttribute(response
, "job-password-supported", IPP_TAG_INTEGER
)) != NULL
)
3175 char pattern
[33]; /* Password pattern */
3176 int maxlen
= ippGetInteger(attr
, 0);
3177 /* Maximum length */
3178 const char *repertoire
= ippGetString(ippFindAttribute(response
, "job-password-repertoire-configured", IPP_TAG_KEYWORD
), 0, NULL
);
3179 /* Type of password */
3181 if (maxlen
> (int)(sizeof(pattern
) - 1))
3182 maxlen
= (int)sizeof(pattern
) - 1;
3184 if (!repertoire
|| !strcmp(repertoire
, "iana_us-ascii_digits"))
3185 memset(pattern
, '1', (size_t)maxlen
);
3186 else if (!strcmp(repertoire
, "iana_us-ascii_letters"))
3187 memset(pattern
, 'A', (size_t)maxlen
);
3188 else if (!strcmp(repertoire
, "iana_us-ascii_complex"))
3189 memset(pattern
, 'C', (size_t)maxlen
);
3190 else if (!strcmp(repertoire
, "iana_us-ascii_any"))
3191 memset(pattern
, '.', (size_t)maxlen
);
3192 else if (!strcmp(repertoire
, "iana_utf-8_digits"))
3193 memset(pattern
, 'N', (size_t)maxlen
);
3194 else if (!strcmp(repertoire
, "iana_utf-8_letters"))
3195 memset(pattern
, 'U', (size_t)maxlen
);
3197 memset(pattern
, '*', (size_t)maxlen
);
3199 pattern
[maxlen
] = '\0';
3201 cupsFilePrintf(fp
, "*cupsJobPassword: \"%s\"\n", pattern
);
3208 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3210 is_apple
= ippContainsString(attr
, "image/urf");
3211 is_pdf
= ippContainsString(attr
, "application/pdf");
3212 is_pwg
= ippContainsString(attr
, "image/pwg-raster") && !is_apple
;
3214 if (ippContainsString(attr
, "image/jpeg"))
3215 cupsFilePuts(fp
, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n");
3216 if (ippContainsString(attr
, "image/png"))
3217 cupsFilePuts(fp
, "*cupsFilter2: \"image/png image/png 0 -\"\n");
3221 * Don't locally filter PDF content when printing to a CUPS shared
3222 * printer, otherwise the options will be applied twice...
3225 if (ippContainsString(attr
, "application/vnd.cups-pdf"))
3226 cupsFilePuts(fp
, "*cupsFilter2: \"application/pdf application/pdf 0 -\"\n");
3228 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3231 cupsFilePuts(fp
, "*cupsManualCopies: true\n");
3233 cupsFilePuts(fp
, "*cupsFilter2: \"image/urf image/urf 100 -\"\n");
3235 cupsFilePuts(fp
, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n");
3238 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3242 * PageSize/PageRegion/ImageableArea/PaperDimension
3245 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3247 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3248 if (ippGetInteger(attr
, i
) > bottom
)
3249 bottom
= ippGetInteger(attr
, i
);
3254 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3256 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3257 if (ippGetInteger(attr
, i
) > left
)
3258 left
= ippGetInteger(attr
, i
);
3263 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3265 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3266 if (ippGetInteger(attr
, i
) > right
)
3267 right
= ippGetInteger(attr
, i
);
3272 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3274 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3275 if (ippGetInteger(attr
, i
) > top
)
3276 top
= ippGetInteger(attr
, i
);
3281 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3283 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3285 media_size
= ippGetCollection(attr
, 0);
3286 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3287 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3289 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3290 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3292 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3295 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3297 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3298 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3300 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3302 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, (cups_afree_func_t
)free
);
3304 if ((attr
= ippFindAttribute(response
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3306 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3308 cups_size_t temp
; /* Current size */
3309 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3311 media_col
= ippGetCollection(attr
, i
);
3312 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3313 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3314 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3315 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3319 temp
.width
= pwg
->width
;
3320 temp
.length
= pwg
->length
;
3322 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3323 temp
.bottom
= ippGetInteger(margin
, 0);
3325 temp
.bottom
= bottom
;
3327 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3328 temp
.left
= ippGetInteger(margin
, 0);
3332 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3333 temp
.right
= ippGetInteger(margin
, 0);
3337 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3338 temp
.top
= ippGetInteger(margin
, 0);
3342 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3343 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3345 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3347 if (!cupsArrayFind(sizes
, &temp
))
3348 cupsArrayAdd(sizes
, &temp
);
3350 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3353 * Custom size - record the min/max values...
3356 int lower
, upper
; /* Range values */
3358 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3359 lower
= ippGetRange(x_dim
, 0, &upper
);
3361 lower
= upper
= ippGetInteger(x_dim
, 0);
3363 if (lower
< min_width
)
3365 if (upper
> max_width
)
3368 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3369 lower
= ippGetRange(y_dim
, 0, &upper
);
3371 lower
= upper
= ippGetInteger(y_dim
, 0);
3373 if (lower
< min_length
)
3375 if (upper
> max_length
)
3380 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3383 * Some printers don't list custom size support in media-col-database...
3386 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3388 media_size
= ippGetCollection(attr
, i
);
3389 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3390 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3392 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3395 * Custom size - record the min/max values...
3398 int lower
, upper
; /* Range values */
3400 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3401 lower
= ippGetRange(x_dim
, 0, &upper
);
3403 lower
= upper
= ippGetInteger(x_dim
, 0);
3405 if (lower
< min_width
)
3407 if (upper
> max_width
)
3410 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3411 lower
= ippGetRange(y_dim
, 0, &upper
);
3413 lower
= upper
= ippGetInteger(y_dim
, 0);
3415 if (lower
< min_length
)
3417 if (upper
> max_length
)
3423 else if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3425 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3427 cups_size_t temp
; /* Current size */
3429 media_size
= ippGetCollection(attr
, i
);
3430 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3431 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3432 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3436 temp
.width
= pwg
->width
;
3437 temp
.length
= pwg
->length
;
3438 temp
.bottom
= bottom
;
3443 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3444 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3446 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3448 if (!cupsArrayFind(sizes
, &temp
))
3449 cupsArrayAdd(sizes
, &temp
);
3451 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3454 * Custom size - record the min/max values...
3457 int lower
, upper
; /* Range values */
3459 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3460 lower
= ippGetRange(x_dim
, 0, &upper
);
3462 lower
= upper
= ippGetInteger(x_dim
, 0);
3464 if (lower
< min_width
)
3466 if (upper
> max_width
)
3469 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3470 lower
= ippGetRange(y_dim
, 0, &upper
);
3472 lower
= upper
= ippGetInteger(y_dim
, 0);
3474 if (lower
< min_length
)
3476 if (upper
> max_length
)
3481 else if ((attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3483 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3485 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3487 cups_size_t temp
; /* Current size */
3489 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3491 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3493 if (pwg
->width
> max_width
)
3494 max_width
= pwg
->width
;
3495 if (pwg
->length
> max_length
)
3496 max_length
= pwg
->length
;
3498 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3500 if (pwg
->width
< min_width
)
3501 min_width
= pwg
->width
;
3502 if (pwg
->length
< min_length
)
3503 min_length
= pwg
->length
;
3507 temp
.width
= pwg
->width
;
3508 temp
.length
= pwg
->length
;
3509 temp
.bottom
= bottom
;
3514 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3515 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3517 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3519 if (!cupsArrayFind(sizes
, &temp
))
3520 cupsArrayAdd(sizes
, &temp
);
3526 if (cupsArrayCount(sizes
) > 0)
3529 * List all of the standard sizes...
3532 char tleft
[256], /* Left string */
3533 tbottom
[256], /* Bottom string */
3534 tright
[256], /* Right string */
3535 ttop
[256], /* Top string */
3536 twidth
[256], /* Width string */
3537 tlength
[256]; /* Length string */
3539 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3540 "*OrderDependency: 10 AnySetup *PageSize\n"
3541 "*DefaultPageSize: %s\n", ppdname
);
3542 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3544 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3545 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3547 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3549 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3551 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3552 "*OrderDependency: 10 AnySetup *PageRegion\n"
3553 "*DefaultPageRegion: %s\n", ppdname
);
3554 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3556 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3557 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3559 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3561 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3563 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3564 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3566 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3568 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3569 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3570 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3571 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3572 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3573 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3575 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3576 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3579 cupsArrayDelete(sizes
);
3582 * Custom size support...
3585 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3587 char tmax
[256], tmin
[256]; /* Min/max values */
3589 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3590 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3591 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3592 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3594 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3596 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3597 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3598 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3600 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3601 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3602 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3604 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3605 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3606 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3607 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3612 cupsArrayDelete(sizes
);
3620 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3621 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3623 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3625 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3627 static const char * const sources
[] =
3628 { /* Standard "media-source" strings */
3681 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3682 "*OrderDependency: 10 AnySetup *InputSlot\n"
3683 "*DefaultInputSlot: %s\n", ppdname
);
3684 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3686 keyword
= ippGetString(attr
, i
, NULL
);
3688 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3690 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3691 if (!strcmp(sources
[j
], keyword
))
3693 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
3694 cupsFilePrintf(fp
, "*InputSlot %s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, j
);
3695 cupsFilePrintf(fp
, "*%s.InputSlot %s/%s: \"\"\n", lang
->language
, ppdname
, _cupsLangString(lang
, msgid
));
3699 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3706 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3707 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3709 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3711 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3713 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3714 "*OrderDependency: 10 AnySetup *MediaType\n"
3715 "*DefaultMediaType: %s\n", ppdname
);
3716 for (i
= 0; i
< count
; i
++)
3718 keyword
= ippGetString(attr
, i
, NULL
);
3720 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3722 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
3723 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3724 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3727 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3728 cupsFilePrintf(fp
, "*%s.MediaType %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3730 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3737 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3738 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3739 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3740 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3744 int wrote_color
= 0;
3745 const char *default_color
= NULL
; /* Default */
3747 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3749 keyword
= ippGetString(attr
, i
, NULL
);
3751 #define PRINTF_COLORMODEL if (!wrote_color) { cupsFilePrintf(fp, "*OpenUI *ColorModel: PickOne\n*OrderDependency: 10 AnySetup *ColorModel\n*%s.Translation ColorModel/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Color Mode"))); wrote_color = 1; }
3752 #define PRINTF_COLOROPTION(name,text,cspace,bpp) { cupsFilePrintf(fp, "*ColorModel %s: \"<</cupsColorSpace %d/cupsBitsPerColor %d/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", name, cspace, bpp); cupsFilePrintf(fp, "*%s.ColorModel %s/%s: \"\"\n", lang->language, name, _cupsLangString(lang, text)); }
3754 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3758 PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K
, 1)
3761 default_color
= "FastGray";
3763 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3767 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3769 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3770 default_color
= "Gray";
3772 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
3776 if (!strcmp(keyword
, "W8-16"))
3778 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3780 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3781 default_color
= "Gray";
3784 PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW
, 16)
3786 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 7) || !strcmp(keyword
, "color"))
3790 PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB
, 8)
3792 default_color
= "RGB";
3794 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
3798 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 16)
3801 default_color
= "AdobeRGB";
3803 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
3807 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 8)
3810 default_color
= "AdobeRGB";
3812 else if ((!strcasecmp(keyword
, "black_8") && !ippContainsString(attr
, "black_16")) || !strcmp(keyword
, "DEVW8"))
3816 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 8)
3818 else if (!strcasecmp(keyword
, "black_16") || !strcmp(keyword
, "DEVW16") || !strcmp(keyword
, "DEVW8-16"))
3822 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 16)
3824 else if ((!strcasecmp(keyword
, "cmyk_8") && !ippContainsString(attr
, "cmyk_16")) || !strcmp(keyword
, "DEVCMYK32"))
3828 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 8)
3830 else if (!strcasecmp(keyword
, "cmyk_16") || !strcmp(keyword
, "DEVCMYK32-64") || !strcmp(keyword
, "DEVCMYK64"))
3834 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 16)
3836 else if ((!strcasecmp(keyword
, "rgb_8") && ippContainsString(attr
, "rgb_16")) || !strcmp(keyword
, "DEVRGB24"))
3840 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 8)
3842 else if (!strcasecmp(keyword
, "rgb_16") || !strcmp(keyword
, "DEVRGB24-48") || !strcmp(keyword
, "DEVRGB48"))
3846 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 16)
3851 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3853 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3860 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3862 cupsFilePrintf(fp
, "*OpenUI *Duplex: PickOne\n"
3863 "*OrderDependency: 10 AnySetup *Duplex\n"
3864 "*%s.Translation Duplex/%s: \"\"\n"
3865 "*DefaultDuplex: None\n"
3866 "*Duplex None: \"<</Duplex false>>setpagedevice\"\n"
3867 "*%s.Duplex None/%s: \"\"\n"
3868 "*Duplex DuplexNoTumble: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3869 "*%s.Duplex DuplexNoTumble/%s: \"\"\n"
3870 "*Duplex DuplexTumble: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3871 "*%s.Duplex DuplexTumble/%s: \"\"\n"
3872 "*CloseUI: *Duplex\n", lang
->language
, _cupsLangString(lang
, _("2-Sided Printing")), lang
->language
, _cupsLangString(lang
, _("Off (1-Sided)")), lang
->language
, _cupsLangString(lang
, _("Long-Edge (Portrait)")), lang
->language
, _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3874 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3876 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3878 const char *dm
= ippGetString(attr
, i
, NULL
);
3881 if (!_cups_strcasecmp(dm
, "DM1"))
3883 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3886 else if (!_cups_strcasecmp(dm
, "DM2"))
3888 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3891 else if (!_cups_strcasecmp(dm
, "DM3"))
3893 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3896 else if (!_cups_strcasecmp(dm
, "DM4"))
3898 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3903 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3905 keyword
= ippGetString(attr
, 0, NULL
);
3907 if (!strcmp(keyword
, "flipped"))
3908 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3909 else if (!strcmp(keyword
, "manual-tumble"))
3910 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3911 else if (!strcmp(keyword
, "normal"))
3912 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3914 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3922 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3923 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3925 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3927 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3929 ipp_attribute_t
*trays
= ippFindAttribute(response
, "printer-output-tray", IPP_TAG_STRING
);
3930 /* printer-output-tray attribute, if any */
3931 const char *tray_ptr
; /* printer-output-tray value */
3932 int tray_len
; /* Len of printer-output-tray value */
3933 char tray
[IPP_MAX_OCTETSTRING
];
3934 /* printer-output-tray string value */
3936 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3937 "*OrderDependency: 10 AnySetup *OutputBin\n"
3938 "*DefaultOutputBin: %s\n", ppdname
);
3939 if (!strcmp(ppdname
, "FaceUp"))
3940 cupsFilePuts(fp
, "*DefaultOutputOrder: Reverse\n");
3942 cupsFilePuts(fp
, "*DefaultOutputOrder: Normal\n");
3944 for (i
= 0; i
< count
; i
++)
3946 keyword
= ippGetString(attr
, i
, NULL
);
3948 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3950 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
3951 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3952 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3955 cupsFilePrintf(fp
, "*OutputBin %s: \"\"\n", ppdname
);
3956 cupsFilePrintf(fp
, "*%s.OutputBin %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3958 if ((tray_ptr
= ippGetOctetString(trays
, i
, &tray_len
)) != NULL
)
3960 if (tray_len
>= (int)sizeof(tray
))
3961 tray_len
= (int)sizeof(tray
) - 1;
3963 memcpy(tray
, tray_ptr
, (size_t)tray_len
);
3964 tray
[tray_len
] = '\0';
3966 if (strstr(tray
, "stackingorder=lastToFirst;"))
3967 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
3969 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
3971 else if (!strcmp(ppdname
, "FaceUp"))
3972 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
3974 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
3976 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3980 * Finishing options...
3983 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3985 int value
; /* Enum value */
3986 const char *ppd_keyword
; /* PPD keyword for enum */
3987 cups_array_t
*names
; /* Names we've added */
3988 static const char * const base_keywords
[] =
3989 { /* Base STD 92 keywords */
3991 "SingleAuto", /* staple */
3992 "SingleAuto", /* punch */
3994 "BindAuto", /* bind */
3995 "SaddleStitch", /* saddle-stitch */
3996 "EdgeStitchAuto", /* edge-stitch */
4000 NULL
, /* booklet-maker */
4001 NULL
, /* jog-offset */
4006 count
= ippGetCount(attr
);
4007 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
4008 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4011 * Staple/Bind/Stitch
4014 for (i
= 0; i
< count
; i
++)
4016 value
= ippGetInteger(attr
, i
);
4017 keyword
= ippEnumString("finishings", value
);
4019 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch"))
4025 static const char * const staple_keywords
[] =
4026 { /* StapleLocation keywords */
4028 "SingleRevLandscape",
4030 "SingleRevPortrait",
4031 "EdgeStitchPortrait",
4032 "EdgeStitchLandscape",
4033 "EdgeStitchRevPortrait",
4034 "EdgeStitchRevLandscape",
4041 "TripleRevPortrait",
4042 "TripleRevLandscape"
4044 static const char * const bind_keywords
[] =
4045 { /* StapleLocation binding keywords */
4052 cupsArrayAdd(fin_options
, "*StapleLocation");
4054 cupsFilePuts(fp
, "*OpenUI *StapleLocation: PickOne\n");
4055 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
4056 cupsFilePrintf(fp
, "*%s.Translation StapleLocation/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Staple")));
4057 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
4058 cupsFilePuts(fp
, "*StapleLocation None: \"\"\n");
4059 cupsFilePrintf(fp
, "*%s.StapleLocation None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4061 for (; i
< count
; i
++)
4063 value
= ippGetInteger(attr
, i
);
4064 keyword
= ippEnumString("finishings", value
);
4066 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch"))
4069 if (cupsArrayFind(names
, (char *)keyword
))
4070 continue; /* Already did this finishing template */
4072 cupsArrayAdd(names
, (char *)keyword
);
4074 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4075 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4076 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4079 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4080 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4081 else if (value
>= IPP_FINISHINGS_STAPLE_TOP_LEFT
&& value
<= IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
)
4082 ppd_keyword
= staple_keywords
[value
- IPP_FINISHINGS_STAPLE_TOP_LEFT
];
4083 else if (value
>= IPP_FINISHINGS_BIND_LEFT
&& value
<= IPP_FINISHINGS_BIND_BOTTOM
)
4084 ppd_keyword
= bind_keywords
[value
- IPP_FINISHINGS_BIND_LEFT
];
4091 cupsFilePrintf(fp
, "*StapleLocation %s: \"\"\n", ppd_keyword
);
4092 cupsFilePrintf(fp
, "*%s.StapleLocation %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4093 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, ppd_keyword
);
4096 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
4103 for (i
= 0; i
< count
; i
++)
4105 value
= ippGetInteger(attr
, i
);
4106 keyword
= ippEnumString("finishings", value
);
4108 if (!strncmp(keyword
, "cups-fold-", 10) || !strcmp(keyword
, "fold") || !strncmp(keyword
, "fold-", 5))
4114 static const char * const fold_keywords
[] =
4115 { /* FoldType keywords */
4130 cupsArrayAdd(fin_options
, "*FoldType");
4132 cupsFilePuts(fp
, "*OpenUI *FoldType: PickOne\n");
4133 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
4134 cupsFilePrintf(fp
, "*%s.Translation FoldType/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Fold")));
4135 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
4136 cupsFilePuts(fp
, "*FoldType None: \"\"\n");
4137 cupsFilePrintf(fp
, "*%s.FoldType None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4139 for (; i
< count
; i
++)
4141 value
= ippGetInteger(attr
, i
);
4142 keyword
= ippEnumString("finishings", value
);
4144 if (!strncmp(keyword
, "cups-fold-", 10))
4146 else if (strcmp(keyword
, "fold") && strncmp(keyword
, "fold-", 5))
4149 if (cupsArrayFind(names
, (char *)keyword
))
4150 continue; /* Already did this finishing template */
4152 cupsArrayAdd(names
, (char *)keyword
);
4154 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4155 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4156 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4159 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4160 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4161 else if (value
>= IPP_FINISHINGS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_FOLD_ENGINEERING_Z
)
4162 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_FOLD_ACCORDION
];
4163 else if (value
>= IPP_FINISHINGS_CUPS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_CUPS_FOLD_Z
)
4164 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_CUPS_FOLD_ACCORDION
];
4171 cupsFilePrintf(fp
, "*FoldType %s: \"\"\n", ppd_keyword
);
4172 cupsFilePrintf(fp
, "*%s.FoldType %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4173 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, ppd_keyword
);
4176 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4183 for (i
= 0; i
< count
; i
++)
4185 value
= ippGetInteger(attr
, i
);
4186 keyword
= ippEnumString("finishings", value
);
4188 if (!strncmp(keyword
, "cups-punch-", 11) || !strncmp(keyword
, "punch-", 6))
4194 static const char * const punch_keywords
[] =
4195 { /* PunchMedia keywords */
4197 "SingleRevLandscape",
4199 "SingleRevPortrait",
4206 "TripleRevPortrait",
4207 "TripleRevLandscape",
4213 "MultipleLandscape",
4214 "MultipleRevPortrait",
4215 "MultipleRevLandscape"
4218 cupsArrayAdd(fin_options
, "*PunchMedia");
4220 cupsFilePuts(fp
, "*OpenUI *PunchMedia: PickOne\n");
4221 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4222 cupsFilePrintf(fp
, "*%s.Translation PunchMedia/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Punch")));
4223 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4224 cupsFilePuts(fp
, "*PunchMedia None: \"\"\n");
4225 cupsFilePrintf(fp
, "*%s.PunchMedia None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4227 for (i
= 0; i
< count
; i
++)
4229 value
= ippGetInteger(attr
, i
);
4230 keyword
= ippEnumString("finishings", value
);
4232 if (!strncmp(keyword
, "cups-punch-", 11))
4234 else if (strncmp(keyword
, "punch-", 6))
4237 if (cupsArrayFind(names
, (char *)keyword
))
4238 continue; /* Already did this finishing template */
4240 cupsArrayAdd(names
, (char *)keyword
);
4242 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4243 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4244 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4247 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4248 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4249 else if (value
>= IPP_FINISHINGS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_PUNCH_MULTIPLE_BOTTOM
)
4250 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_PUNCH_TOP_LEFT
];
4251 else if (value
>= IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_CUPS_PUNCH_QUAD_BOTTOM
)
4252 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
];
4259 cupsFilePrintf(fp
, "*PunchMedia %s: \"\"\n", ppd_keyword
);
4260 cupsFilePrintf(fp
, "*%s.PunchMedia %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4261 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, ppd_keyword
);
4264 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4271 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4273 cupsArrayAdd(fin_options
, "*Booklet");
4275 cupsFilePuts(fp
, "*OpenUI *Booklet: Boolean\n");
4276 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4277 cupsFilePrintf(fp
, "*%s.Translation Booklet/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Booklet")));
4278 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4279 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4280 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4281 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4282 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4289 for (i
= 0; i
< count
; i
++)
4291 value
= ippGetInteger(attr
, i
);
4292 keyword
= ippEnumString("finishings", value
);
4294 if (!strcmp(keyword
, "trim") || !strncmp(keyword
, "trim-", 5))
4300 static const char * const trim_keywords
[] =
4301 { /* CutMedia keywords */
4308 cupsArrayAdd(fin_options
, "*CutMedia");
4310 cupsFilePuts(fp
, "*OpenUI *CutMedia: PickOne\n");
4311 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *CutMedia\n");
4312 cupsFilePrintf(fp
, "*%s.Translation CutMedia/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Cut")));
4313 cupsFilePuts(fp
, "*DefaultCutMedia: None\n");
4314 cupsFilePuts(fp
, "*CutMedia None: \"\"\n");
4315 cupsFilePrintf(fp
, "*%s.CutMedia None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4317 for (i
= 0; i
< count
; i
++)
4319 value
= ippGetInteger(attr
, i
);
4320 keyword
= ippEnumString("finishings", value
);
4322 if (strcmp(keyword
, "trim") && strncmp(keyword
, "trim-", 5))
4325 if (cupsArrayFind(names
, (char *)keyword
))
4326 continue; /* Already did this finishing template */
4328 cupsArrayAdd(names
, (char *)keyword
);
4330 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4331 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4332 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4335 if (value
== IPP_FINISHINGS_TRIM
)
4336 ppd_keyword
= "Auto";
4338 ppd_keyword
= trim_keywords
[value
- IPP_FINISHINGS_TRIM_AFTER_PAGES
];
4340 cupsFilePrintf(fp
, "*CutMedia %s: \"\"\n", ppd_keyword
);
4341 cupsFilePrintf(fp
, "*%s.CutMedia %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4342 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*CutMedia %s\"\n", value
, keyword
, ppd_keyword
);
4345 cupsFilePuts(fp
, "*CloseUI: *CutMedia\n");
4348 cupsArrayDelete(names
);
4351 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4353 ipp_t
*finishing_col
; /* Current finishing collection */
4354 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4355 cups_array_t
*templates
; /* Finishing templates */
4357 cupsFilePuts(fp
, "*OpenUI *cupsFinishingTemplate: PickOne\n");
4358 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4359 cupsFilePrintf(fp
, "*%s.Translation cupsFinishingTemplate/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Finishing Preset")));
4360 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4361 cupsFilePuts(fp
, "*cupsFinishingTemplate none: \"\"\n");
4362 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate none/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4364 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4365 count
= ippGetCount(attr
);
4367 for (i
= 0; i
< count
; i
++)
4369 finishing_col
= ippGetCollection(attr
, i
);
4370 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4372 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4375 if (!strcmp(keyword
, "none"))
4378 cupsArrayAdd(templates
, (void *)keyword
);
4380 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4381 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4382 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4385 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s: \"\n", keyword
);
4386 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4388 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4390 const char *name
= ippGetName(finishing_attr
);
4391 /* Member attribute name */
4393 if (strcmp(name
, "media-size"))
4394 cupsFilePrintf(fp
, "%% %s\n", name
);
4397 cupsFilePuts(fp
, "\"\n");
4398 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4399 cupsFilePuts(fp
, "*End\n");
4402 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4404 if (cupsArrayCount(fin_options
))
4406 const char *fin_option
; /* Current finishing option */
4408 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4409 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4410 cupsFilePrintf(fp
, " %s", fin_option
);
4411 cupsFilePuts(fp
, "\"\n");
4413 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None");
4414 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4415 cupsFilePrintf(fp
, " %s None", fin_option
);
4416 cupsFilePuts(fp
, "\"\n");
4419 cupsArrayDelete(templates
);
4422 cupsArrayDelete(fin_options
);
4425 * cupsPrintQuality and DefaultResolution...
4428 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4430 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4432 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4434 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4436 const char *rs
= ippGetString(attr
, i
, NULL
);
4439 if (_cups_strncasecmp(rs
, "RS", 2))
4442 lowdpi
= atoi(rs
+ 2);
4443 if ((rs
= strrchr(rs
, '-')) != NULL
)
4444 hidpi
= atoi(rs
+ 1);
4453 * Invalid "urf-supported" value...
4461 * Generate print qualities based on low and high DPIs...
4464 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4466 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4467 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4468 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4469 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4470 if ((lowdpi
& 1) == 0)
4471 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
/ 2, lang
->language
, _cupsLangString(lang
, _("Draft")));
4472 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4473 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4475 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4477 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4478 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", hidpi
, hidpi
, lang
->language
, _cupsLangString(lang
, _("High")));
4479 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4482 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4485 * Make a sorted list of resolutions.
4488 count
= ippGetCount(attr
);
4489 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4490 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4492 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4493 for (i
= 1; i
< count
; i
++)
4496 for (i
= 0; i
< (count
- 1); i
++)
4498 for (j
= i
+ 1; j
< count
; j
++)
4500 int ix
, iy
, /* First X and Y resolution */
4501 jx
, jy
, /* Second X and Y resolution */
4502 temp
; /* Swap variable */
4503 ipp_res_t units
; /* Resolution units */
4505 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4506 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4508 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4511 * Swap these two resolutions...
4514 temp
= resolutions
[i
];
4515 resolutions
[i
] = resolutions
[j
];
4516 resolutions
[j
] = temp
;
4522 * Generate print quality options...
4525 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4526 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4528 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4529 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4530 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4531 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4532 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4534 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4535 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4536 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Draft/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Draft")));
4539 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4540 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4541 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Normal/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Normal")));
4543 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4545 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4546 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4547 cupsFilePrintf(fp
, "*%s.cupsPrintQuality High/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("High")));
4550 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4552 else if (is_apple
|| is_pwg
)
4556 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4558 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4563 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4566 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4568 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4569 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4570 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4571 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4572 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4573 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4575 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4577 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4578 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("High")));
4579 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4586 if ((attr
= ippFindAttribute(response
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4588 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4590 ipp_t
*preset
= ippGetCollection(attr
, i
);
4591 /* Preset collection */
4592 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
),
4594 *localized_name
; /* Localized preset name */
4595 ipp_attribute_t
*member
; /* Member attribute in preset */
4596 const char *member_name
; /* Member attribute name */
4597 char member_value
[256]; /* Member attribute value */
4599 if (!preset
|| !preset_name
)
4602 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", preset_name
);
4603 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4605 member_name
= ippGetName(member
);
4607 if (!member_name
|| !strcmp(member_name
, "preset-name"))
4610 if (!strcmp(member_name
, "finishings"))
4612 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4614 const char *option
= NULL
; /* PPD option name */
4616 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
4618 if (!strcmp(keyword
, "booklet-maker"))
4623 else if (!strncmp(keyword
, "fold-", 5))
4624 option
= "FoldType";
4625 else if (!strncmp(keyword
, "punch-", 6))
4626 option
= "PunchMedia";
4627 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7))
4628 option
= "StapleLocation";
4630 if (option
&& keyword
)
4631 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
4634 else if (!strcmp(member_name
, "finishings-col"))
4636 ipp_t
*fin_col
; /* finishings-col value */
4638 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4640 fin_col
= ippGetCollection(member
, i
);
4642 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4643 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", keyword
);
4646 else if (!strcmp(member_name
, "media"))
4649 * Map media to PageSize...
4652 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
4653 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4655 else if (!strcmp(member_name
, "media-col"))
4657 media_col
= ippGetCollection(member
, 0);
4659 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
4661 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
4662 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
4663 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
4664 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4667 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4669 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4670 cupsFilePrintf(fp
, "*InputSlot %s\n", keyword
);
4673 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4675 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4676 cupsFilePrintf(fp
, "*MediaType %s\n", keyword
);
4679 else if (!strcmp(member_name
, "print-quality"))
4682 * Map print-quality to cupsPrintQuality...
4685 int qval
= ippGetInteger(member
, 0);
4686 /* print-quality value */
4687 static const char * const qualities
[] = { "Draft", "Normal", "High" };
4688 /* cupsPrintQuality values */
4690 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
4691 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
4693 else if (!strcmp(member_name
, "output-bin"))
4695 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
4696 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
4698 else if (!strcmp(member_name
, "sides"))
4700 keyword
= ippGetString(member
, 0, NULL
);
4701 if (keyword
&& !strcmp(keyword
, "one-sided"))
4702 cupsFilePuts(fp
, "*Duplex None\n");
4703 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
4704 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
4705 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
4706 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
4711 * Add attribute name and value as-is...
4714 ippAttributeString(member
, member_value
, sizeof(member_value
));
4715 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
4719 cupsFilePuts(fp
, "\"\n*End\n");
4721 if ((localized_name
= _cupsMessageLookup(strings
, preset_name
)) != preset_name
)
4722 cupsFilePrintf(fp
, "*%s.APPrinterPreset %s/%s: \"\"\n", lang
->language
, preset_name
, localized_name
);
4727 * Close up and return...
4735 * If we get here then there was a problem creating the PPD...
4744 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4751 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4755 const char * /* O - InputSlot name */
4756 _pwgInputSlotForSource(
4757 const char *media_source
, /* I - PWG media-source */
4758 char *name
, /* I - Name buffer */
4759 size_t namesize
) /* I - Size of name buffer */
4762 * Range check input...
4765 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4768 if (_cups_strcasecmp(media_source
, "main"))
4769 strlcpy(name
, "Cassette", namesize
);
4770 else if (_cups_strcasecmp(media_source
, "alternate"))
4771 strlcpy(name
, "Multipurpose", namesize
);
4772 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4773 strlcpy(name
, "LargeCapacity", namesize
);
4774 else if (_cups_strcasecmp(media_source
, "bottom"))
4775 strlcpy(name
, "Lower", namesize
);
4776 else if (_cups_strcasecmp(media_source
, "middle"))
4777 strlcpy(name
, "Middle", namesize
);
4778 else if (_cups_strcasecmp(media_source
, "top"))
4779 strlcpy(name
, "Upper", namesize
);
4780 else if (_cups_strcasecmp(media_source
, "rear"))
4781 strlcpy(name
, "Rear", namesize
);
4782 else if (_cups_strcasecmp(media_source
, "side"))
4783 strlcpy(name
, "Side", namesize
);
4784 else if (_cups_strcasecmp(media_source
, "envelope"))
4785 strlcpy(name
, "Envelope", namesize
);
4786 else if (_cups_strcasecmp(media_source
, "main-roll"))
4787 strlcpy(name
, "Roll", namesize
);
4788 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4789 strlcpy(name
, "Roll2", namesize
);
4791 pwg_ppdize_name(media_source
, name
, namesize
);
4798 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4802 const char * /* O - MediaType name */
4803 _pwgMediaTypeForType(
4804 const char *media_type
, /* I - PWG media-type */
4805 char *name
, /* I - Name buffer */
4806 size_t namesize
) /* I - Size of name buffer */
4809 * Range check input...
4812 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4815 if (_cups_strcasecmp(media_type
, "auto"))
4816 strlcpy(name
, "Auto", namesize
);
4817 else if (_cups_strcasecmp(media_type
, "cardstock"))
4818 strlcpy(name
, "Cardstock", namesize
);
4819 else if (_cups_strcasecmp(media_type
, "envelope"))
4820 strlcpy(name
, "Envelope", namesize
);
4821 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4822 strlcpy(name
, "Glossy", namesize
);
4823 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4824 strlcpy(name
, "HighGloss", namesize
);
4825 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4826 strlcpy(name
, "Matte", namesize
);
4827 else if (_cups_strcasecmp(media_type
, "stationery"))
4828 strlcpy(name
, "Plain", namesize
);
4829 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4830 strlcpy(name
, "Coated", namesize
);
4831 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4832 strlcpy(name
, "Inkjet", namesize
);
4833 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4834 strlcpy(name
, "Letterhead", namesize
);
4835 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4836 strlcpy(name
, "Preprinted", namesize
);
4837 else if (_cups_strcasecmp(media_type
, "transparency"))
4838 strlcpy(name
, "Transparency", namesize
);
4840 pwg_ppdize_name(media_type
, name
, namesize
);
4847 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4850 const char * /* O - PageSize name */
4851 _pwgPageSizeForMedia(
4852 pwg_media_t
*media
, /* I - Media */
4853 char *name
, /* I - PageSize name buffer */
4854 size_t namesize
) /* I - Size of name buffer */
4856 const char *sizeptr
, /* Pointer to size in PWG name */
4857 *dimptr
; /* Pointer to dimensions in PWG name */
4861 * Range check input...
4864 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4868 * Copy or generate a PageSize name...
4874 * Use a standard Adobe name...
4877 strlcpy(name
, media
->ppd
, namesize
);
4879 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4880 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4881 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4882 (size_t)(dimptr
- sizeptr
) > namesize
)
4885 * Use a name of the form "wNNNhNNN"...
4888 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4889 (int)PWG_TO_POINTS(media
->length
));
4894 * Copy the size name from class_sizename_dimensions...
4897 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4898 name
[dimptr
- sizeptr
- 1] = '\0';
4906 * 'cups_get_url()' - Get a copy of the file at the given URL.
4909 static int /* O - 1 on success, 0 on failure */
4910 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4911 const char *url
, /* I - URL to get */
4912 char *name
, /* I - Temporary filename */
4913 size_t namesize
) /* I - Size of temporary filename buffer */
4915 char scheme
[32], /* URL scheme */
4916 userpass
[256], /* URL username:password */
4917 host
[256], /* URL host */
4918 curhost
[256], /* Current host */
4919 resource
[256]; /* URL resource */
4920 int port
; /* URL port */
4921 http_encryption_t encryption
; /* Type of encryption to use */
4922 http_status_t status
; /* Status of GET request */
4923 int fd
; /* Temporary file */
4926 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4929 if (port
== 443 || !strcmp(scheme
, "https"))
4930 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4932 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4934 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4937 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4943 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4946 status
= cupsGetFd(*http
, resource
, fd
);
4950 if (status
!= HTTP_STATUS_OK
)
4962 * 'pwg_add_finishing()' - Add a finishings value.
4967 cups_array_t
*finishings
, /* I - Finishings array */
4968 ipp_finishings_t
template, /* I - Finishing template */
4969 const char *name
, /* I - PPD option */
4970 const char *value
) /* I - PPD choice */
4972 _pwg_finishings_t
*f
; /* New finishings value */
4975 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4977 f
->value
= template;
4978 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4980 cupsArrayAdd(finishings
, f
);
4986 * 'pwg_add_message()' - Add a message to the PPD cached strings.
4990 pwg_add_message(cups_array_t
*a
, /* I - Message catalog */
4991 const char *msg
, /* I - Message identifier */
4992 const char *str
) /* I - Localized string */
4994 _cups_message_t
*m
; /* New message */
4997 if ((m
= calloc(1, sizeof(_cups_message_t
))) != NULL
)
4999 m
->msg
= strdup(msg
);
5000 m
->str
= strdup(str
);
5007 * 'pwg_compare_finishings()' - Compare two finishings values.
5010 static int /* O - Result of comparison */
5011 pwg_compare_finishings(
5012 _pwg_finishings_t
*a
, /* I - First finishings value */
5013 _pwg_finishings_t
*b
) /* I - Second finishings value */
5015 return ((int)b
->value
- (int)a
->value
);
5020 * 'pwg_compare_sizes()' - Compare two media sizes...
5023 static int /* O - Result of comparison */
5024 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
5025 cups_size_t
*b
) /* I - Second media size */
5027 return (strcmp(a
->media
, b
->media
));
5032 * 'pwg_copy_size()' - Copy a media size.
5035 static cups_size_t
* /* O - New media size */
5036 pwg_copy_size(cups_size_t
*size
) /* I - Media size to copy */
5038 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
5039 /* New media size */
5042 memcpy(newsize
, size
, sizeof(cups_size_t
));
5049 * 'pwg_free_finishings()' - Free a finishings value.
5053 pwg_free_finishings(
5054 _pwg_finishings_t
*f
) /* I - Finishings value */
5056 cupsFreeOptions(f
->num_options
, f
->options
);
5062 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
5066 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
5067 char *name
, /* I - Name buffer */
5068 size_t namesize
) /* I - Size of name buffer */
5070 char *ptr
, /* Pointer into name buffer */
5071 *end
; /* End of name buffer */
5080 *name
= (char)toupper(*ipp
++);
5082 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
5084 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
5087 *ptr
++ = (char)toupper(*ipp
++ & 255);
5098 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
5102 pwg_ppdize_resolution(
5103 ipp_attribute_t
*attr
, /* I - Attribute to convert */
5104 int element
, /* I - Element to convert */
5105 int *xres
, /* O - X resolution in DPI */
5106 int *yres
, /* O - Y resolution in DPI */
5107 char *name
, /* I - Name buffer */
5108 size_t namesize
) /* I - Size of name buffer */
5110 ipp_res_t units
; /* Units for resolution */
5113 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
5115 if (units
== IPP_RES_PER_CM
)
5117 *xres
= (int)(*xres
* 2.54);
5118 *yres
= (int)(*yres
* 2.54);
5121 if (name
&& namesize
> 4)
5124 snprintf(name
, namesize
, "%ddpi", *xres
);
5126 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
5132 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
5136 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
5137 char *name
, /* I - Name buffer */
5138 size_t namesize
, /* I - Size of name buffer */
5139 const char *dashchars
)/* I - Characters to be replaced by dashes */
5141 char *ptr
, /* Pointer into name buffer */
5142 *end
; /* End of name buffer */
5145 if (_cups_islower(*ppd
))
5148 * Already lowercase name, use as-is?
5151 const char *ppdptr
; /* Pointer into PPD keyword */
5153 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
5154 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
5159 strlcpy(name
, ppd
, namesize
);
5164 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
5166 if (_cups_isalnum(*ppd
) || *ppd
== '-')
5167 *ptr
++ = (char)tolower(*ppd
& 255);
5168 else if (strchr(dashchars
, *ppd
))
5173 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
5174 _cups_isupper(ppd
[1]) && ptr
< end
)
5176 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))