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 */
83 job_pages
= 0, /* job-pages value */
84 number_up
= 1; /* number-up value */
85 const char *value
; /* Option value */
89 * Send standard IPP attributes...
92 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
94 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
96 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
99 if (!strcmp(keyword
, "none"))
102 * Add plain-text job-password...
105 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
110 * Add hashed job-password...
113 unsigned char hash
[64]; /* Hash of password */
114 ssize_t hashlen
; /* Length of hash */
116 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
117 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
121 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
126 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
127 keyword
= cupsGetOption("job-billing", num_options
, options
);
130 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
133 if (pc
->accounting_user_id
)
135 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
139 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
142 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
144 if (strcmp(mandatory
, "copies") &&
145 strcmp(mandatory
, "destination-uris") &&
146 strcmp(mandatory
, "finishings") &&
147 strcmp(mandatory
, "finishings-col") &&
148 strcmp(mandatory
, "finishing-template") &&
149 strcmp(mandatory
, "job-account-id") &&
150 strcmp(mandatory
, "job-accounting-user-id") &&
151 strcmp(mandatory
, "job-password") &&
152 strcmp(mandatory
, "job-password-encryption") &&
153 strcmp(mandatory
, "media") &&
154 strncmp(mandatory
, "media-col", 9) &&
155 strcmp(mandatory
, "multiple-document-handling") &&
156 strcmp(mandatory
, "output-bin") &&
157 strcmp(mandatory
, "print-color-mode") &&
158 strcmp(mandatory
, "print-quality") &&
159 strcmp(mandatory
, "sides") &&
160 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
162 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
164 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
169 case IPP_TAG_INTEGER
:
171 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
173 case IPP_TAG_BOOLEAN
:
174 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
178 int lower
, upper
; /* Range */
180 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
181 lower
= upper
= atoi(keyword
);
183 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
186 case IPP_TAG_STRING
:
187 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
190 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
192 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
193 keyword
= "auto-monochrome";
194 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
195 keyword
= "process-monochrome";
198 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
204 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
205 keyword
= cupsGetOption("media", num_options
, options
);
207 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
208 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
209 size
= _ppdCacheGetSize(pc
, keyword
);
211 if (size
|| media_source
|| media_type
)
214 * Add a media-col value...
217 media_col
= ippNew();
221 media_size
= ippNew();
222 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
223 "x-dimension", size
->width
);
224 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
225 "y-dimension", size
->length
);
227 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
230 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
232 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
233 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
234 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
235 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
236 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
237 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
238 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
239 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
240 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
241 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
242 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
243 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
246 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
249 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
251 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
252 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
256 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
258 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
260 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
262 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
264 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
265 keyword
= "monochrome";
271 if (keyword
&& !strcmp(keyword
, "monochrome"))
273 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
274 keyword
= "auto-monochrome";
275 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
276 keyword
= "process-monochrome";
280 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
282 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
283 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
284 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
286 if (!_cups_strcasecmp(choice
->choice
, "draft"))
287 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
288 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
289 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
290 else if (!_cups_strcasecmp(choice
->choice
, "high"))
291 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
294 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
295 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
296 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
298 if (pc
->sides_1sided
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
299 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
300 else if (pc
->sides_2sided_long
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
301 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
302 else if (pc
->sides_2sided_short
&& !_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
303 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
310 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
312 if (strstr(keyword
, "uncollated"))
317 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
322 if (!_cups_strcasecmp(format
, "image/gif") ||
323 !_cups_strcasecmp(format
, "image/jp2") ||
324 !_cups_strcasecmp(format
, "image/jpeg") ||
325 !_cups_strcasecmp(format
, "image/png") ||
326 !_cups_strcasecmp(format
, "image/tiff") ||
327 !_cups_strncasecmp(format
, "image/x-", 8))
330 * Collation makes no sense for single page image formats...
335 else if (!_cups_strncasecmp(format
, "image/", 6) ||
336 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
339 * Multi-page image formats will have copies applied by the upstream
347 if (doc_handling_sup
)
349 if (!_cups_strcasecmp(keyword
, "true"))
350 collate_str
= "separate-documents-collated-copies";
352 collate_str
= "separate-documents-uncollated-copies";
354 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
356 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
358 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
363 if (i
>= doc_handling_sup
->num_values
)
368 * Map finishing options...
371 if (copies
!= finishings_copies
)
373 // Figure out the proper job-pages-per-set value...
374 if ((value
= cupsGetOption("job-pages", num_options
, options
)) == NULL
)
375 value
= cupsGetOption("com.apple.print.PrintSettings.PMTotalBeginPages..n.", num_options
, options
);
378 job_pages
= atoi(value
);
380 // Adjust for number-up
381 if ((value
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
382 number_up
= atoi(value
);
384 job_pages
= (job_pages
+ number_up
- 1) / number_up
;
386 // When duplex printing, raster data will include an extra (blank) page to
387 // make the total number of pages even. Make sure this is reflected in the
389 if ((job_pages
& 1) && (keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
&& strcmp(keyword
, "one-sided"))
393 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
394 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
396 if (finishing_template
&& strcmp(finishing_template
, "none"))
398 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
400 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
401 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
404 if (copies
!= finishings_copies
&& job_pages
> 0)
407 * Send job-pages-per-set attribute to apply finishings correctly...
410 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", job_pages
);
415 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
416 if (num_finishings
> 0)
418 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
420 if (copies
!= finishings_copies
&& job_pages
> 0)
423 * Send job-pages-per-set attribute to apply finishings correctly...
426 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", job_pages
);
436 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
439 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
443 _ppd_cache_t
* /* O - PPD cache and mapping data */
444 _ppdCacheCreateWithFile(
445 const char *filename
, /* I - File to read */
446 ipp_t
**attrs
) /* IO - IPP attributes, if any */
448 cups_file_t
*fp
; /* File */
449 _ppd_cache_t
*pc
; /* PWG mapping data */
450 pwg_size_t
*size
; /* Current size */
451 pwg_map_t
*map
; /* Current map */
452 _pwg_finishings_t
*finishings
; /* Current finishings option */
453 int linenum
, /* Current line number */
454 num_bins
, /* Number of bins in file */
455 num_sizes
, /* Number of sizes in file */
456 num_sources
, /* Number of sources in file */
457 num_types
; /* Number of types in file */
458 char line
[2048], /* Current line */
459 *value
, /* Pointer to value in line */
460 *valueptr
, /* Pointer into value */
461 pwg_keyword
[128], /* PWG keyword */
462 ppd_keyword
[PPD_MAX_NAME
];
464 _pwg_print_color_mode_t print_color_mode
;
465 /* Print color mode for preset */
466 _pwg_print_quality_t print_quality
; /* Print quality for preset */
469 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
472 * Range check input...
480 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
488 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
490 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
495 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
498 if (!cupsFileGets(fp
, line
, sizeof(line
)))
500 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
501 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
506 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
508 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
509 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
514 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
516 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
517 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
518 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
524 * Allocate the mapping data structure...
527 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
529 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
530 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
534 pc
->max_copies
= 9999;
546 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
548 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
549 "linenum=%d", line
, value
, linenum
));
553 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
555 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
558 else if (!_cups_strcasecmp(line
, "Filter"))
561 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
563 cupsArrayAdd(pc
->filters
, value
);
565 else if (!_cups_strcasecmp(line
, "PreFilter"))
568 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
570 cupsArrayAdd(pc
->prefilters
, value
);
572 else if (!_cups_strcasecmp(line
, "Product"))
574 pc
->product
= strdup(value
);
576 else if (!_cups_strcasecmp(line
, "SingleFile"))
578 pc
->single_file
= !_cups_strcasecmp(value
, "true");
580 else if (!_cups_strcasecmp(line
, "IPP"))
582 off_t pos
= cupsFileTell(fp
), /* Position in file */
583 length
= strtol(value
, NULL
, 10);
584 /* Length of IPP attributes */
588 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
592 else if (length
<= 0)
594 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
595 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
602 * Read IPP attributes into the provided variable...
607 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
608 *attrs
) != IPP_STATE_DATA
)
610 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
611 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
618 * Skip the IPP data entirely...
621 cupsFileSeek(fp
, pos
+ length
);
624 if (cupsFileTell(fp
) != (pos
+ length
))
626 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
627 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
631 else if (!_cups_strcasecmp(line
, "NumBins"))
635 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
643 "%d.", num_sizes
, linenum
));
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
648 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
650 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
652 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
656 else if (!_cups_strcasecmp(line
, "Bin"))
658 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
660 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 if (pc
->num_bins
>= num_bins
)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 map
= pc
->bins
+ pc
->num_bins
;
674 map
->pwg
= strdup(pwg_keyword
);
675 map
->ppd
= strdup(ppd_keyword
);
679 else if (!_cups_strcasecmp(line
, "NumSizes"))
683 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
684 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
688 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
690 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
691 "%d.", num_sizes
, linenum
));
692 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
698 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
700 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
702 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
707 else if (!_cups_strcasecmp(line
, "Size"))
709 if (pc
->num_sizes
>= num_sizes
)
711 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
713 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
717 size
= pc
->sizes
+ pc
->num_sizes
;
719 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
720 &(size
->width
), &(size
->length
), &(size
->left
),
721 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
723 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
725 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
729 size
->map
.pwg
= strdup(pwg_keyword
);
730 size
->map
.ppd
= strdup(ppd_keyword
);
734 else if (!_cups_strcasecmp(line
, "CustomSize"))
736 if (pc
->custom_max_width
> 0)
738 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
740 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
744 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
745 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
746 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
747 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
748 &(pc
->custom_size
.top
)) != 8)
750 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
757 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
758 pc
->custom_max_keyword
= strdup(pwg_keyword
);
760 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
761 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
762 pc
->custom_min_keyword
= strdup(pwg_keyword
);
764 else if (!_cups_strcasecmp(line
, "SourceOption"))
766 pc
->source_option
= strdup(value
);
768 else if (!_cups_strcasecmp(line
, "NumSources"))
772 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
774 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
778 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
780 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
781 "line %d.", num_sources
, linenum
));
782 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
786 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
788 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
790 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
794 else if (!_cups_strcasecmp(line
, "Source"))
796 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
798 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
800 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
804 if (pc
->num_sources
>= num_sources
)
806 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
808 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
812 map
= pc
->sources
+ pc
->num_sources
;
813 map
->pwg
= strdup(pwg_keyword
);
814 map
->ppd
= strdup(ppd_keyword
);
818 else if (!_cups_strcasecmp(line
, "NumTypes"))
822 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
823 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
827 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
829 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
830 "line %d.", num_types
, linenum
));
831 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
835 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
837 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
839 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
843 else if (!_cups_strcasecmp(line
, "Type"))
845 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
847 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
849 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
853 if (pc
->num_types
>= num_types
)
855 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
857 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
861 map
= pc
->types
+ pc
->num_types
;
862 map
->pwg
= strdup(pwg_keyword
);
863 map
->ppd
= strdup(ppd_keyword
);
867 else if (!_cups_strcasecmp(line
, "Preset"))
870 * Preset output-mode print-quality name=value ...
873 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
874 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
876 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
877 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
878 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
879 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
880 valueptr
== value
|| !*valueptr
)
882 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
884 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
888 pc
->num_presets
[print_color_mode
][print_quality
] =
889 cupsParseOptions(valueptr
, 0,
890 pc
->presets
[print_color_mode
] + print_quality
);
892 else if (!_cups_strcasecmp(line
, "SidesOption"))
893 pc
->sides_option
= strdup(value
);
894 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
895 pc
->sides_1sided
= strdup(value
);
896 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
897 pc
->sides_2sided_long
= strdup(value
);
898 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
899 pc
->sides_2sided_short
= strdup(value
);
900 else if (!_cups_strcasecmp(line
, "Finishings"))
904 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
906 (cups_afree_func_t
)pwg_free_finishings
);
908 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
911 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
912 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
913 &(finishings
->options
));
915 cupsArrayAdd(pc
->finishings
, finishings
);
917 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
920 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
922 cupsArrayAdd(pc
->templates
, value
);
924 else if (!_cups_strcasecmp(line
, "MaxCopies"))
925 pc
->max_copies
= atoi(value
);
926 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
927 pc
->charge_info_uri
= strdup(value
);
928 else if (!_cups_strcasecmp(line
, "JobAccountId"))
929 pc
->account_id
= !_cups_strcasecmp(value
, "true");
930 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
931 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
932 else if (!_cups_strcasecmp(line
, "JobPassword"))
933 pc
->password
= strdup(value
);
934 else if (!_cups_strcasecmp(line
, "Mandatory"))
937 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
939 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
941 else if (!_cups_strcasecmp(line
, "SupportFile"))
943 if (!pc
->support_files
)
944 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
946 cupsArrayAdd(pc
->support_files
, value
);
950 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
955 if (pc
->num_sizes
< num_sizes
)
957 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
958 pc
->num_sizes
, num_sizes
));
959 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
963 if (pc
->num_sources
< num_sources
)
965 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
966 pc
->num_sources
, num_sources
));
967 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
971 if (pc
->num_types
< num_types
)
973 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
974 pc
->num_types
, num_types
));
975 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
984 * If we get here the file was bad - free any data and return...
990 _ppdCacheDestroy(pc
);
1003 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1006 _ppd_cache_t
* /* O - PPD cache and mapping data */
1007 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
1009 int i
, j
, k
; /* Looping vars */
1010 _ppd_cache_t
*pc
; /* PWG mapping data */
1011 ppd_option_t
*input_slot
, /* InputSlot option */
1012 *media_type
, /* MediaType option */
1013 *output_bin
, /* OutputBin option */
1014 *color_model
, /* ColorModel option */
1015 *duplex
, /* Duplex option */
1016 *ppd_option
; /* Other PPD option */
1017 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1018 pwg_map_t
*map
; /* Current source/type map */
1019 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1020 int num_options
; /* Number of preset options and props */
1021 cups_option_t
*options
; /* Preset options and properties */
1022 ppd_size_t
*ppd_size
; /* Current PPD size */
1023 pwg_size_t
*pwg_size
; /* Current PWG size */
1024 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1025 /* PWG keyword string */
1026 ppd_name
[PPD_MAX_NAME
];
1027 /* Normalized PPD name */
1028 const char *pwg_name
; /* Standard PWG media name */
1029 pwg_media_t
*pwg_media
; /* PWG media data */
1030 _pwg_print_color_mode_t pwg_print_color_mode
;
1031 /* print-color-mode index */
1032 _pwg_print_quality_t pwg_print_quality
;
1033 /* print-quality index */
1034 int similar
; /* Are the old and new size similar? */
1035 pwg_size_t
*old_size
; /* Current old size */
1036 int old_imageable
, /* Old imageable length in 2540ths */
1037 old_borderless
, /* Old borderless state */
1038 old_known_pwg
; /* Old PWG name is well-known */
1039 int new_width
, /* New width in 2540ths */
1040 new_length
, /* New length in 2540ths */
1041 new_left
, /* New left margin in 2540ths */
1042 new_bottom
, /* New bottom margin in 2540ths */
1043 new_right
, /* New right margin in 2540ths */
1044 new_top
, /* New top margin in 2540ths */
1045 new_imageable
, /* New imageable length in 2540ths */
1046 new_borderless
, /* New borderless state */
1047 new_known_pwg
; /* New PWG name is well-known */
1048 pwg_size_t
*new_size
; /* New size to add, if any */
1049 const char *filter
; /* Current filter */
1050 _pwg_finishings_t
*finishings
; /* Current finishings value */
1051 char msg_id
[256]; /* Message identifier */
1054 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1057 * Range check input...
1064 * Allocate memory...
1067 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1069 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1073 pc
->strings
= _cupsMessageNew(NULL
);
1076 * Copy and convert size data...
1079 if (ppd
->num_sizes
> 0)
1081 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1083 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1084 "pwg_size_t's.", ppd
->num_sizes
));
1088 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1093 * Don't copy over custom size...
1096 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1100 * Convert the PPD size name to the corresponding PWG keyword name.
1103 if ((pwg_media
= pwgMediaForSize(PWG_FROM_POINTS(ppd_size
->width
), PWG_FROM_POINTS(ppd_size
->length
))) != NULL
)
1106 * Standard name, do we have conflicts?
1109 for (j
= 0; j
< pc
->num_sizes
; j
++)
1110 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1120 * Standard name and no conflicts, use it!
1123 pwg_name
= pwg_media
->pwg
;
1129 * Not a standard name; convert it to a PWG vendor name of the form:
1131 * pp_lowerppd_WIDTHxHEIGHTuu
1134 pwg_name
= pwg_keyword
;
1137 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1138 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1139 PWG_FROM_POINTS(ppd_size
->width
),
1140 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1144 * If we have a similar paper with non-zero margins then we only want to
1145 * keep it if it has a larger imageable area length. The NULL check is for
1146 * dimensions that are <= 0...
1149 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1150 PWG_FROM_POINTS(ppd_size
->length
),
1154 new_width
= pwg_media
->width
;
1155 new_length
= pwg_media
->length
;
1156 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1157 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1158 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1159 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1160 new_imageable
= new_length
- new_top
- new_bottom
;
1161 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1162 new_left
== 0 && new_right
== 0;
1164 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1168 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1169 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1170 old_size
->right
== 0 && old_size
->top
== 0;
1171 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1172 strncmp(old_size
->map
.pwg
, "om_", 3);
1174 similar
= old_borderless
== new_borderless
&&
1175 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1176 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1179 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1182 * The new paper has a larger imageable area so it could replace
1183 * the older paper. Regardless of the imageable area, we always
1184 * prefer the size with a well-known PWG name.
1187 new_size
= old_size
;
1188 free(old_size
->map
.ppd
);
1189 free(old_size
->map
.pwg
);
1196 * The paper was unique enough to deserve its own entry so add it to the
1200 new_size
= pwg_size
++;
1210 new_size
->map
.ppd
= strdup(ppd_size
->name
);
1211 new_size
->map
.pwg
= strdup(pwg_name
);
1212 new_size
->width
= new_width
;
1213 new_size
->length
= new_length
;
1214 new_size
->left
= new_left
;
1215 new_size
->bottom
= new_bottom
;
1216 new_size
->right
= new_right
;
1217 new_size
->top
= new_top
;
1222 if (ppd
->variable_sizes
)
1225 * Generate custom size data...
1228 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1229 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1230 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1231 pc
->custom_max_keyword
= strdup(pwg_keyword
);
1232 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1233 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1235 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1236 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1237 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1238 pc
->custom_min_keyword
= strdup(pwg_keyword
);
1239 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1240 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1242 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1243 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1244 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1245 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1249 * Copy and convert InputSlot data...
1252 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1253 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1257 pc
->source_option
= strdup(input_slot
->keyword
);
1259 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1261 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1262 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1266 pc
->num_sources
= input_slot
->num_choices
;
1268 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1271 i
--, choice
++, map
++)
1273 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1274 !_cups_strcasecmp(choice
->choice
, "Default"))
1276 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1278 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1280 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1282 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1283 !_cups_strcasecmp(choice
->choice
, "MP") ||
1284 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1285 pwg_name
= "by-pass-tray";
1286 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1287 pwg_name
= "large-capacity";
1288 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1289 pwg_name
= "bottom";
1290 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1291 pwg_name
= "middle";
1292 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1294 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1296 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1297 pwg_name
= "main-roll";
1301 * Convert PPD name to lowercase...
1304 pwg_name
= pwg_keyword
;
1305 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1309 map
->pwg
= strdup(pwg_name
);
1310 map
->ppd
= strdup(choice
->choice
);
1313 * Add localized text for PWG keyword to message catalog...
1316 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1317 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1322 * Copy and convert MediaType data...
1325 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1327 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1329 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1330 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1334 pc
->num_types
= media_type
->num_choices
;
1336 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1339 i
--, choice
++, map
++)
1341 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1342 !_cups_strcasecmp(choice
->choice
, "Any") ||
1343 !_cups_strcasecmp(choice
->choice
, "Default"))
1345 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1346 pwg_name
= "cardstock";
1347 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1348 pwg_name
= "envelope";
1349 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1350 pwg_name
= "photographic-glossy";
1351 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1352 pwg_name
= "photographic-high-gloss";
1353 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1354 pwg_name
= "photographic-matte";
1355 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1356 pwg_name
= "stationery";
1357 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1358 pwg_name
= "stationery-coated";
1359 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1360 pwg_name
= "stationery-inkjet";
1361 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1362 pwg_name
= "stationery-letterhead";
1363 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1364 pwg_name
= "stationery-preprinted";
1365 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1366 pwg_name
= "stationery-recycled";
1367 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1368 pwg_name
= "transparency";
1372 * Convert PPD name to lowercase...
1375 pwg_name
= pwg_keyword
;
1376 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1380 map
->pwg
= strdup(pwg_name
);
1381 map
->ppd
= strdup(choice
->choice
);
1384 * Add localized text for PWG keyword to message catalog...
1387 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", pwg_name
);
1388 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1393 * Copy and convert OutputBin data...
1396 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1398 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1400 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1401 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1405 pc
->num_bins
= output_bin
->num_choices
;
1407 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1410 i
--, choice
++, map
++)
1412 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1414 map
->pwg
= strdup(pwg_keyword
);
1415 map
->ppd
= strdup(choice
->choice
);
1418 * Add localized text for PWG keyword to message catalog...
1421 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_keyword
);
1422 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1426 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1429 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1432 const char *quality
, /* com.apple.print.preset.quality value */
1433 *output_mode
, /* com.apple.print.preset.output-mode value */
1434 *color_model_val
, /* ColorModel choice */
1435 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1436 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1441 * Add localized text for PWG keyword to message catalog...
1444 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1445 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1448 * Get the options for this preset...
1451 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1454 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1455 num_options
, options
)) != NULL
)
1458 * Get the print-quality for this preset...
1461 if (!strcmp(quality
, "low"))
1462 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1463 else if (!strcmp(quality
, "high"))
1464 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1466 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1469 * Ignore graphicsType "Photo" presets that are not high quality.
1472 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1473 num_options
, options
);
1475 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1476 !strcmp(graphicsType
, "Photo"))
1480 * Ignore presets for normal and draft quality where the coating
1481 * isn't "none" or "autodetect".
1484 media_front_coating
= cupsGetOption(
1485 "com.apple.print.preset.media-front-coating",
1486 num_options
, options
);
1488 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1489 media_front_coating
&&
1490 strcmp(media_front_coating
, "none") &&
1491 strcmp(media_front_coating
, "autodetect"))
1495 * Get the output mode for this preset...
1498 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1499 num_options
, options
);
1500 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1504 if (!strcmp(output_mode
, "monochrome"))
1505 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1507 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1509 else if (color_model_val
)
1511 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1512 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1514 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1517 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1520 * Save the options for this combination as needed...
1523 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1524 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1525 _ppdParseOptions(ppd_attr
->value
, 0,
1526 pc
->presets
[pwg_print_color_mode
] +
1527 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1530 cupsFreeOptions(num_options
, options
);
1532 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1535 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1536 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1537 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1540 * Try adding some common color options to create grayscale presets. These
1541 * are listed in order of popularity...
1544 const char *color_option
= NULL
, /* Color control option */
1545 *gray_choice
= NULL
; /* Choice to select grayscale */
1547 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1548 ppdFindChoice(color_model
, "Gray"))
1550 color_option
= "ColorModel";
1551 gray_choice
= "Gray";
1553 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1554 ppdFindChoice(color_model
, "grayscale"))
1556 color_option
= "HPColorMode";
1557 gray_choice
= "grayscale";
1559 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1560 ppdFindChoice(color_model
, "Mono"))
1562 color_option
= "BRMonoColor";
1563 gray_choice
= "Mono";
1565 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1566 ppdFindChoice(color_model
, "1"))
1568 color_option
= "CNIJSGrayScale";
1571 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1572 ppdFindChoice(color_model
, "True"))
1574 color_option
= "HPColorAsGray";
1575 gray_choice
= "True";
1578 if (color_option
&& gray_choice
)
1581 * Copy and convert ColorModel (output-mode) data...
1584 cups_option_t
*coption
, /* Color option */
1585 *moption
; /* Monochrome option */
1587 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1588 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1589 pwg_print_quality
++)
1591 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1594 * Copy the color options...
1597 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1598 [pwg_print_quality
];
1599 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1603 for (i
= num_options
, moption
= options
,
1604 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1605 [pwg_print_quality
];
1607 i
--, moption
++, coption
++)
1609 moption
->name
= _cupsStrRetain(coption
->name
);
1610 moption
->value
= _cupsStrRetain(coption
->value
);
1613 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1615 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1619 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1623 * Add the grayscale option to the preset...
1626 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1627 cupsAddOption(color_option
, gray_choice
,
1628 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1629 [pwg_print_quality
],
1630 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1637 * Copy and convert Duplex (sides) data...
1640 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1641 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1642 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1643 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1644 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1648 pc
->sides_option
= strdup(duplex
->keyword
);
1650 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1654 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1655 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1656 pc
->sides_1sided
= strdup(choice
->choice
);
1657 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1658 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1659 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1660 pc
->sides_2sided_long
= strdup(choice
->choice
);
1661 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1662 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1663 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1664 !pc
->sides_2sided_short
)
1665 pc
->sides_2sided_short
= strdup(choice
->choice
);
1670 * Copy filters and pre-filters...
1673 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1675 cupsArrayAdd(pc
->filters
,
1676 "application/vnd.cups-raw application/octet-stream 0 -");
1678 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1682 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1684 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1686 else if (ppd
->num_filters
> 0)
1688 for (i
= 0; i
< ppd
->num_filters
; i
++)
1689 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1692 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1695 * See if we have a command filter...
1698 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1700 filter
= (const char *)cupsArrayNext(pc
->filters
))
1701 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1702 _cups_isspace(filter
[28]))
1706 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1707 _cups_strcasecmp(ppd_attr
->value
, "none")))
1710 * No command filter and no cupsCommands keyword telling us not to use one.
1711 * See if this is a PostScript printer, and if so add a PostScript command
1715 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1717 filter
= (const char *)cupsArrayNext(pc
->filters
))
1718 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1719 _cups_isspace(filter
[31]))
1723 cupsArrayAdd(pc
->filters
,
1724 "application/vnd.cups-command application/postscript 100 "
1728 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1730 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1734 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1736 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1739 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1740 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1743 * Copy the product string, if any...
1747 pc
->product
= strdup(ppd
->product
);
1750 * Copy finishings mapping data...
1753 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1756 * Have proper vendor mapping of IPP finishings values to PPD options...
1759 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1760 NULL
, NULL
, 0, NULL
,
1761 (cups_afree_func_t
)pwg_free_finishings
);
1765 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1768 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1769 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1770 &(finishings
->options
),
1771 _PPD_PARSE_OPTIONS
);
1773 cupsArrayAdd(pc
->finishings
, finishings
);
1775 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1781 * No IPP mapping data, try to map common/standard PPD keywords...
1784 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1786 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1789 * Add staple finishings...
1792 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1793 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1794 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1795 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1796 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1797 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1798 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1799 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1800 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1801 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1804 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1807 * Add (Ricoh) punch finishings...
1810 if (ppdFindChoice(ppd_option
, "Left2"))
1811 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1812 if (ppdFindChoice(ppd_option
, "Left3"))
1813 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1814 if (ppdFindChoice(ppd_option
, "Left4"))
1815 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1816 if (ppdFindChoice(ppd_option
, "Right2"))
1817 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1818 if (ppdFindChoice(ppd_option
, "Right3"))
1819 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1820 if (ppdFindChoice(ppd_option
, "Right4"))
1821 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1822 if (ppdFindChoice(ppd_option
, "Upper2"))
1823 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1824 if (ppdFindChoice(ppd_option
, "Upper3"))
1825 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1826 if (ppdFindChoice(ppd_option
, "Upper4"))
1827 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1830 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1833 * Add bind finishings...
1836 if (ppdFindChoice(ppd_option
, "Left"))
1837 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1838 if (ppdFindChoice(ppd_option
, "Right"))
1839 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1840 if (ppdFindChoice(ppd_option
, "Top"))
1841 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1842 if (ppdFindChoice(ppd_option
, "Bottom"))
1843 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1846 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1849 * Add (Adobe) fold finishings...
1852 if (ppdFindChoice(ppd_option
, "ZFold"))
1853 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1854 if (ppdFindChoice(ppd_option
, "Saddle"))
1855 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1856 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1857 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1858 if (ppdFindChoice(ppd_option
, "LeftGate"))
1859 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1860 if (ppdFindChoice(ppd_option
, "RightGate"))
1861 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1862 if (ppdFindChoice(ppd_option
, "Letter"))
1863 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1864 if (ppdFindChoice(ppd_option
, "XFold"))
1865 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1868 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1871 * Add (Ricoh) fold finishings...
1874 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1875 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1878 if (cupsArrayCount(pc
->finishings
) == 0)
1880 cupsArrayDelete(pc
->finishings
);
1881 pc
->finishings
= NULL
;
1885 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1887 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1889 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1891 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1894 * Add localized text for PWG keyword to message catalog...
1897 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1898 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1906 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1907 pc
->max_copies
= atoi(ppd_attr
->value
);
1908 else if (ppd
->manual_copies
)
1911 pc
->max_copies
= 9999;
1914 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1915 * cupsJobPassword, and cupsMandatory.
1918 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1919 pc
->charge_info_uri
= strdup(ppd_attr
->value
);
1921 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1922 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1924 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1925 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1927 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1928 pc
->password
= strdup(ppd_attr
->value
);
1930 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1931 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1937 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
1939 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1941 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1942 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1944 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1945 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1948 * Return the cache data...
1954 * If we get here we need to destroy the PWG mapping data and return NULL...
1959 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1960 _ppdCacheDestroy(pc
);
1967 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1971 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1973 int i
; /* Looping var */
1974 pwg_map_t
*map
; /* Current map */
1975 pwg_size_t
*size
; /* Current size */
1979 * Range check input...
1986 * Free memory as needed...
1991 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2002 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2004 free(size
->map
.pwg
);
2005 free(size
->map
.ppd
);
2011 free(pc
->source_option
);
2015 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2026 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2035 free(pc
->custom_max_keyword
);
2036 free(pc
->custom_min_keyword
);
2039 cupsArrayDelete(pc
->filters
);
2040 cupsArrayDelete(pc
->prefilters
);
2041 cupsArrayDelete(pc
->finishings
);
2043 free(pc
->charge_info_uri
);
2046 cupsArrayDelete(pc
->mandatory
);
2048 cupsArrayDelete(pc
->support_files
);
2050 cupsArrayDelete(pc
->strings
);
2057 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2061 const char * /* O - output-bin or NULL */
2063 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2064 const char *output_bin
) /* I - PPD OutputBin string */
2066 int i
; /* Looping var */
2070 * Range check input...
2073 if (!pc
|| !output_bin
)
2077 * Look up the OutputBin string...
2081 for (i
= 0; i
< pc
->num_bins
; i
++)
2082 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2083 return (pc
->bins
[i
].pwg
);
2090 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2091 * IPP finishings value(s).
2094 int /* O - New number of options */
2095 _ppdCacheGetFinishingOptions(
2096 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2097 ipp_t
*job
, /* I - Job attributes or NULL */
2098 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2099 int num_options
, /* I - Number of options */
2100 cups_option_t
**options
) /* IO - Options */
2102 int i
; /* Looping var */
2103 _pwg_finishings_t
*f
, /* PWG finishings options */
2104 key
; /* Search key */
2105 ipp_attribute_t
*attr
; /* Finishings attribute */
2106 cups_option_t
*option
; /* Current finishings option */
2110 * Range check input...
2113 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2114 (!job
&& value
== IPP_FINISHINGS_NONE
))
2115 return (num_options
);
2118 * Apply finishing options...
2121 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2123 int num_values
= ippGetCount(attr
); /* Number of values */
2125 for (i
= 0; i
< num_values
; i
++)
2127 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2129 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2131 int j
; /* Another looping var */
2133 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2134 num_options
= cupsAddOption(option
->name
, option
->value
,
2135 num_options
, options
);
2139 else if (value
!= IPP_FINISHINGS_NONE
)
2143 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2145 int j
; /* Another looping var */
2147 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2148 num_options
= cupsAddOption(option
->name
, option
->value
,
2149 num_options
, options
);
2153 return (num_options
);
2158 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2162 int /* O - Number of finishings values */
2163 _ppdCacheGetFinishingValues(
2164 ppd_file_t
*ppd
, /* I - Marked PPD file */
2165 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2166 int max_values
, /* I - Maximum number of finishings values */
2167 int *values
) /* O - Finishings values */
2169 int i
, /* Looping var */
2170 num_values
= 0; /* Number of values */
2171 _pwg_finishings_t
*f
; /* Current finishings option */
2172 cups_option_t
*option
; /* Current option */
2173 ppd_choice_t
*choice
; /* Marked PPD choice */
2177 * Range check input...
2180 DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd
, pc
, max_values
, values
));
2182 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2184 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2187 else if (!pc
->finishings
)
2189 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2194 * Go through the finishings options and see what is set...
2197 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2199 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2201 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
)));
2203 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2205 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2207 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2209 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2216 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", (int)f
->value
, ippEnumString("finishings", (int)f
->value
)));
2218 values
[num_values
++] = (int)f
->value
;
2220 if (num_values
>= max_values
)
2225 if (num_values
== 0)
2228 * Always have at least "finishings" = 'none'...
2231 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2232 values
[0] = IPP_FINISHINGS_NONE
;
2236 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2238 return (num_values
);
2243 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2244 * attributes or a keyword string.
2247 const char * /* O - PPD InputSlot or NULL */
2248 _ppdCacheGetInputSlot(
2249 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2250 ipp_t
*job
, /* I - Job attributes or NULL */
2251 const char *keyword
) /* I - Keyword string or NULL */
2254 * Range check input...
2257 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2260 if (job
&& !keyword
)
2263 * Lookup the media-col attribute and any media-source found there...
2266 ipp_attribute_t
*media_col
, /* media-col attribute */
2267 *media_source
; /* media-source attribute */
2268 pwg_size_t size
; /* Dimensional size */
2269 int margins_set
; /* Were the margins set? */
2271 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2273 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2275 IPP_TAG_KEYWORD
)) != NULL
)
2278 * Use the media-source value from media-col...
2281 keyword
= ippGetString(media_source
, 0, NULL
);
2283 else if (pwgInitSize(&size
, job
, &margins_set
))
2286 * For media <= 5x7, look for a photo tray...
2289 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2296 int i
; /* Looping var */
2298 for (i
= 0; i
< pc
->num_sources
; i
++)
2299 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2300 return (pc
->sources
[i
].ppd
);
2308 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2309 * attributes or a keyword string.
2312 const char * /* O - PPD MediaType or NULL */
2313 _ppdCacheGetMediaType(
2314 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2315 ipp_t
*job
, /* I - Job attributes or NULL */
2316 const char *keyword
) /* I - Keyword string or NULL */
2319 * Range check input...
2322 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2325 if (job
&& !keyword
)
2328 * Lookup the media-col attribute and any media-source found there...
2331 ipp_attribute_t
*media_col
, /* media-col attribute */
2332 *media_type
; /* media-type attribute */
2334 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2337 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2339 IPP_TAG_KEYWORD
)) == NULL
)
2340 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2341 "media-type", IPP_TAG_NAME
);
2344 keyword
= media_type
->values
[0].string
.text
;
2350 int i
; /* Looping var */
2352 for (i
= 0; i
< pc
->num_types
; i
++)
2353 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2354 return (pc
->types
[i
].ppd
);
2362 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2366 const char * /* O - PPD OutputBin or NULL */
2367 _ppdCacheGetOutputBin(
2368 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2369 const char *output_bin
) /* I - Keyword string */
2371 int i
; /* Looping var */
2375 * Range check input...
2378 if (!pc
|| !output_bin
)
2382 * Look up the OutputBin string...
2386 for (i
= 0; i
< pc
->num_bins
; i
++)
2387 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2388 return (pc
->bins
[i
].ppd
);
2395 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2396 * attributes or a keyword string.
2399 const char * /* O - PPD PageSize or NULL */
2400 _ppdCacheGetPageSize(
2401 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2402 ipp_t
*job
, /* I - Job attributes or NULL */
2403 const char *keyword
, /* I - Keyword string or NULL */
2404 int *exact
) /* O - 1 if exact match, 0 otherwise */
2406 int i
; /* Looping var */
2407 pwg_size_t
*size
, /* Current size */
2408 *closest
, /* Closest size */
2409 jobsize
; /* Size data from job */
2410 int margins_set
, /* Were the margins set? */
2411 dwidth
, /* Difference in width */
2412 dlength
, /* Difference in length */
2413 dleft
, /* Difference in left margins */
2414 dright
, /* Difference in right margins */
2415 dbottom
, /* Difference in bottom margins */
2416 dtop
, /* Difference in top margins */
2417 dmin
, /* Minimum difference */
2418 dclosest
; /* Closest difference */
2419 const char *ppd_name
; /* PPD media name */
2422 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2423 pc
, job
, keyword
, exact
));
2426 * Range check input...
2429 if (!pc
|| (!job
&& !keyword
))
2440 * Try getting the PPD media name from the job attributes...
2443 ipp_attribute_t
*attr
; /* Job attribute */
2445 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2446 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2447 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2451 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2452 attr
->name
, ippTagString(attr
->value_tag
)));
2454 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2457 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2458 attr
->value_tag
== IPP_TAG_KEYWORD
))
2459 ppd_name
= attr
->values
[0].string
.text
;
2462 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2467 * Try looking up the named PPD size first...
2470 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2472 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2473 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2475 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2476 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2481 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2483 return (size
->map
.ppd
);
2488 if (job
&& !keyword
)
2491 * Get the size using media-col or media, with the preference being
2495 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2501 * Get the size using a media keyword...
2504 pwg_media_t
*media
; /* Media definition */
2507 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2508 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2509 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2512 jobsize
.width
= media
->width
;
2513 jobsize
.length
= media
->length
;
2518 * Now that we have the dimensions and possibly the margins, look at the
2519 * available sizes and find the match...
2523 dclosest
= 999999999;
2525 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2526 _cups_strncasecmp(ppd_name
, "custom_", 7))
2528 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2531 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2532 * is just about 176/2540ths...
2535 dwidth
= size
->width
- jobsize
.width
;
2536 dlength
= size
->length
- jobsize
.length
;
2538 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2544 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2547 dleft
= size
->left
- jobsize
.left
;
2548 dright
= size
->right
- jobsize
.right
;
2549 dtop
= size
->top
- jobsize
.top
;
2550 dbottom
= size
->bottom
- jobsize
.bottom
;
2552 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2553 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2555 dleft
= dleft
< 0 ? -dleft
: dleft
;
2556 dright
= dright
< 0 ? -dright
: dright
;
2557 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2558 dtop
= dtop
< 0 ? -dtop
: dtop
;
2559 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2561 if (dmin
< dclosest
)
2574 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2576 return (size
->map
.ppd
);
2582 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2585 return (closest
->map
.ppd
);
2589 * If we get here we need to check for custom page size support...
2592 if (jobsize
.width
>= pc
->custom_min_width
&&
2593 jobsize
.width
<= pc
->custom_max_width
&&
2594 jobsize
.length
>= pc
->custom_min_length
&&
2595 jobsize
.length
<= pc
->custom_max_length
)
2598 * In range, format as Custom.WWWWxLLLL (points).
2601 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2602 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2604 if (margins_set
&& exact
)
2606 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2607 dright
= pc
->custom_size
.right
- jobsize
.right
;
2608 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2609 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2611 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2612 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2618 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2619 pc
->custom_ppd_size
));
2621 return (pc
->custom_ppd_size
);
2625 * No custom page size support or the size is out of range - return NULL.
2628 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2635 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2638 pwg_size_t
* /* O - PWG size or NULL */
2640 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2641 const char *page_size
) /* I - PPD PageSize */
2643 int i
; /* Looping var */
2644 pwg_media_t
*media
; /* Media */
2645 pwg_size_t
*size
; /* Current size */
2649 * Range check input...
2652 if (!pc
|| !page_size
)
2655 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2658 * Custom size; size name can be one of the following:
2660 * Custom.WIDTHxLENGTHin - Size in inches
2661 * Custom.WIDTHxLENGTHft - Size in feet
2662 * Custom.WIDTHxLENGTHcm - Size in centimeters
2663 * Custom.WIDTHxLENGTHmm - Size in millimeters
2664 * Custom.WIDTHxLENGTHm - Size in meters
2665 * Custom.WIDTHxLENGTH[pt] - Size in points
2668 double w
, l
; /* Width and length of page */
2669 char *ptr
; /* Pointer into PageSize */
2670 struct lconv
*loc
; /* Locale data */
2673 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2674 if (!ptr
|| *ptr
!= 'x')
2677 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2681 if (!_cups_strcasecmp(ptr
, "in"))
2686 else if (!_cups_strcasecmp(ptr
, "ft"))
2691 else if (!_cups_strcasecmp(ptr
, "mm"))
2696 else if (!_cups_strcasecmp(ptr
, "cm"))
2701 else if (!_cups_strcasecmp(ptr
, "m"))
2712 pc
->custom_size
.width
= (int)w
;
2713 pc
->custom_size
.length
= (int)l
;
2715 return (&(pc
->custom_size
));
2719 * Not a custom size - look it up...
2722 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2723 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2724 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2728 * Look up standard sizes...
2731 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2732 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2733 media
= pwgMediaForPWG(page_size
);
2737 pc
->custom_size
.width
= media
->width
;
2738 pc
->custom_size
.length
= media
->length
;
2740 return (&(pc
->custom_size
));
2748 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2752 const char * /* O - PWG media-source keyword */
2754 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2755 const char *input_slot
) /* I - PPD InputSlot */
2757 int i
; /* Looping var */
2758 pwg_map_t
*source
; /* Current source */
2762 * Range check input...
2765 if (!pc
|| !input_slot
)
2768 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2769 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2770 return (source
->pwg
);
2777 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2781 const char * /* O - PWG media-type keyword */
2783 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2784 const char *media_type
) /* I - PPD MediaType */
2786 int i
; /* Looping var */
2787 pwg_map_t
*type
; /* Current type */
2791 * Range check input...
2794 if (!pc
|| !media_type
)
2797 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2798 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2806 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2809 int /* O - 1 on success, 0 on failure */
2811 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2812 const char *filename
, /* I - File to write */
2813 ipp_t
*attrs
) /* I - Attributes to write, if any */
2815 int i
, j
, k
; /* Looping vars */
2816 cups_file_t
*fp
; /* Output file */
2817 pwg_size_t
*size
; /* Current size */
2818 pwg_map_t
*map
; /* Current map */
2819 _pwg_finishings_t
*f
; /* Current finishing option */
2820 cups_option_t
*option
; /* Current option */
2821 const char *value
; /* String value */
2822 char newfile
[1024]; /* New filename */
2826 * Range check input...
2829 if (!pc
|| !filename
)
2831 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2836 * Open the file and write with compression...
2839 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2840 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2842 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2847 * Standard header...
2850 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2856 if (pc
->num_bins
> 0)
2858 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2859 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2860 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2867 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2868 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2869 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2870 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2871 size
->bottom
, size
->right
, size
->top
);
2872 if (pc
->custom_max_width
> 0)
2873 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2874 pc
->custom_max_width
, pc
->custom_max_length
,
2875 pc
->custom_min_width
, pc
->custom_min_length
,
2876 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2877 pc
->custom_size
.right
, pc
->custom_size
.top
);
2883 if (pc
->source_option
)
2884 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2886 if (pc
->num_sources
> 0)
2888 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2889 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2890 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2897 if (pc
->num_types
> 0)
2899 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2900 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2901 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2908 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2909 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2910 if (pc
->num_presets
[i
][j
])
2912 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2913 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2916 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2917 cupsFilePutChar(fp
, '\n');
2924 if (pc
->sides_option
)
2925 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2927 if (pc
->sides_1sided
)
2928 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2930 if (pc
->sides_2sided_long
)
2931 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2933 if (pc
->sides_2sided_short
)
2934 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2937 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2941 cupsFilePutConf(fp
, "Product", pc
->product
);
2943 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2945 value
= (const char *)cupsArrayNext(pc
->filters
))
2946 cupsFilePutConf(fp
, "Filter", value
);
2948 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2950 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2951 cupsFilePutConf(fp
, "PreFilter", value
);
2953 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2956 * Finishing options...
2959 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2961 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2963 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2964 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2965 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2966 cupsFilePutChar(fp
, '\n');
2969 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2970 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2976 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2979 * Accounting/quota/PIN/managed printing values...
2982 if (pc
->charge_info_uri
)
2983 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2985 cupsFilePrintf(fp
, "JobAccountId %s\n", pc
->account_id
? "true" : "false");
2986 cupsFilePrintf(fp
, "JobAccountingUserId %s\n",
2987 pc
->accounting_user_id
? "true" : "false");
2990 cupsFilePutConf(fp
, "JobPassword", pc
->password
);
2992 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2994 value
= (char *)cupsArrayNext(pc
->mandatory
))
2995 cupsFilePutConf(fp
, "Mandatory", value
);
3001 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
3003 value
= (char *)cupsArrayNext(pc
->support_files
))
3004 cupsFilePutConf(fp
, "SupportFile", value
);
3007 * IPP attributes, if any...
3012 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3014 attrs
->state
= IPP_STATE_IDLE
;
3015 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3019 * Close and return...
3022 if (cupsFileClose(fp
))
3029 return (!rename(newfile
, filename
));
3034 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3035 * of an IPP printer.
3038 char * /* O - PPD filename or @code NULL@ on error */
3039 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3040 size_t bufsize
, /* I - Size of filename buffer */
3041 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3043 cups_file_t
*fp
; /* PPD file */
3044 cups_array_t
*sizes
; /* Media sizes supported by printer */
3045 cups_size_t
*size
; /* Current media size */
3046 ipp_attribute_t
*attr
, /* xxx-supported */
3047 *defattr
, /* xxx-default */
3048 *quality
, /* print-quality-supported */
3049 *x_dim
, *y_dim
; /* Media dimensions */
3050 ipp_t
*media_col
, /* Media collection */
3051 *media_size
; /* Media size collection */
3052 char make
[256], /* Make and model */
3053 *model
, /* Model name */
3054 ppdname
[PPD_MAX_NAME
];
3056 int i
, j
, /* Looping vars */
3057 count
, /* Number of values */
3058 bottom
, /* Largest bottom margin */
3059 left
, /* Largest left margin */
3060 right
, /* Largest right margin */
3061 top
, /* Largest top margin */
3062 max_length
= 0, /* Maximum custom size */
3064 min_length
= INT_MAX
,
3065 /* Minimum custom size */
3066 min_width
= INT_MAX
,
3067 is_apple
= 0, /* Does the printer support Apple raster? */
3068 is_pdf
= 0, /* Does the printer support PDF? */
3069 is_pwg
= 0; /* Does the printer support PWG Raster? */
3070 pwg_media_t
*pwg
; /* PWG media size */
3071 int xres
, yres
; /* Resolution values */
3072 int resolutions
[1000];
3073 /* Array of resolution indices */
3074 char msgid
[256]; /* Message identifier (attr.value) */
3075 const char *keyword
, /* Keyword value */
3076 *msgstr
; /* Localized string */
3077 cups_lang_t
*lang
= cupsLangDefault();
3078 /* Localization info */
3079 cups_array_t
*strings
= NULL
;/* Printer strings file */
3080 struct lconv
*loc
= localeconv();
3082 cups_array_t
*fin_options
= NULL
;
3083 /* Finishing options */
3087 * Range check input...
3093 if (!buffer
|| bufsize
< 1)
3095 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3101 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3106 * Open a temporary file for the PPD...
3109 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3111 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3116 * Standard stuff for PPD file...
3119 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3120 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3121 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3122 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3123 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3124 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3125 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3126 cupsFilePuts(fp
, "*FileSystem: False\n");
3127 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3129 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3130 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3132 strlcpy(make
, "Unknown Printer", sizeof(make
));
3134 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3135 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3138 strlcpy(make
, "HP", sizeof(make
));
3140 else if ((model
= strchr(make
, ' ')) != NULL
)
3145 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3146 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3147 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3148 cupsFilePrintf(fp
, "*NickName: \"%s - IPP Everywhere\"\n", model
);
3149 cupsFilePrintf(fp
, "*ShortNickName: \"%s - IPP Everywhere\"\n", model
);
3151 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3152 cupsFilePuts(fp
, "*ColorDevice: True\n");
3154 cupsFilePuts(fp
, "*ColorDevice: False\n");
3156 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3157 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3158 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3160 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3161 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3163 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3164 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3166 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3168 http_t
*http
= NULL
; /* Connection to printer */
3169 char stringsfile
[1024]; /* Temporary strings file */
3171 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3173 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3175 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3177 unlink(stringsfile
);
3188 if (ippGetBoolean(ippFindAttribute(response
, "job-account-id-supported", IPP_TAG_BOOLEAN
), 0))
3189 cupsFilePuts(fp
, "*cupsJobAccountId: True\n");
3191 if (ippGetBoolean(ippFindAttribute(response
, "job-accounting-user-id-supported", IPP_TAG_BOOLEAN
), 0))
3192 cupsFilePuts(fp
, "*cupsJobAccountingUserId: True\n");
3195 * Password/PIN printing...
3198 if ((attr
= ippFindAttribute(response
, "job-password-supported", IPP_TAG_INTEGER
)) != NULL
)
3200 char pattern
[33]; /* Password pattern */
3201 int maxlen
= ippGetInteger(attr
, 0);
3202 /* Maximum length */
3203 const char *repertoire
= ippGetString(ippFindAttribute(response
, "job-password-repertoire-configured", IPP_TAG_KEYWORD
), 0, NULL
);
3204 /* Type of password */
3206 if (maxlen
> (int)(sizeof(pattern
) - 1))
3207 maxlen
= (int)sizeof(pattern
) - 1;
3209 if (!repertoire
|| !strcmp(repertoire
, "iana_us-ascii_digits"))
3210 memset(pattern
, '1', (size_t)maxlen
);
3211 else if (!strcmp(repertoire
, "iana_us-ascii_letters"))
3212 memset(pattern
, 'A', (size_t)maxlen
);
3213 else if (!strcmp(repertoire
, "iana_us-ascii_complex"))
3214 memset(pattern
, 'C', (size_t)maxlen
);
3215 else if (!strcmp(repertoire
, "iana_us-ascii_any"))
3216 memset(pattern
, '.', (size_t)maxlen
);
3217 else if (!strcmp(repertoire
, "iana_utf-8_digits"))
3218 memset(pattern
, 'N', (size_t)maxlen
);
3219 else if (!strcmp(repertoire
, "iana_utf-8_letters"))
3220 memset(pattern
, 'U', (size_t)maxlen
);
3222 memset(pattern
, '*', (size_t)maxlen
);
3224 pattern
[maxlen
] = '\0';
3226 cupsFilePrintf(fp
, "*cupsJobPassword: \"%s\"\n", pattern
);
3233 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3235 is_apple
= ippContainsString(attr
, "image/urf");
3236 is_pdf
= ippContainsString(attr
, "application/pdf");
3237 is_pwg
= ippContainsString(attr
, "image/pwg-raster") && !is_apple
;
3239 if (ippContainsString(attr
, "image/jpeg"))
3240 cupsFilePuts(fp
, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n");
3241 if (ippContainsString(attr
, "image/png"))
3242 cupsFilePuts(fp
, "*cupsFilter2: \"image/png image/png 0 -\"\n");
3246 * Don't locally filter PDF content when printing to a CUPS shared
3247 * printer, otherwise the options will be applied twice...
3250 if (ippContainsString(attr
, "application/vnd.cups-pdf"))
3251 cupsFilePuts(fp
, "*cupsFilter2: \"application/pdf application/pdf 0 -\"\n");
3253 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3256 cupsFilePuts(fp
, "*cupsManualCopies: True\n");
3258 cupsFilePuts(fp
, "*cupsFilter2: \"image/urf image/urf 100 -\"\n");
3260 cupsFilePuts(fp
, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n");
3263 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3267 * PageSize/PageRegion/ImageableArea/PaperDimension
3270 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3272 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3273 if (ippGetInteger(attr
, i
) > bottom
)
3274 bottom
= ippGetInteger(attr
, i
);
3279 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3281 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3282 if (ippGetInteger(attr
, i
) > left
)
3283 left
= ippGetInteger(attr
, i
);
3288 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3290 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3291 if (ippGetInteger(attr
, i
) > right
)
3292 right
= ippGetInteger(attr
, i
);
3297 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3299 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3300 if (ippGetInteger(attr
, i
) > top
)
3301 top
= ippGetInteger(attr
, i
);
3306 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3308 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3310 media_size
= ippGetCollection(attr
, 0);
3311 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3312 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3314 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3315 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3317 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3320 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3322 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3323 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3325 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3327 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, (cups_afree_func_t
)free
);
3329 if ((attr
= ippFindAttribute(response
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3331 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3333 cups_size_t temp
; /* Current size */
3334 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3336 media_col
= ippGetCollection(attr
, i
);
3337 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3338 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3339 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3340 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3344 temp
.width
= pwg
->width
;
3345 temp
.length
= pwg
->length
;
3347 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3348 temp
.bottom
= ippGetInteger(margin
, 0);
3350 temp
.bottom
= bottom
;
3352 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3353 temp
.left
= ippGetInteger(margin
, 0);
3357 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3358 temp
.right
= ippGetInteger(margin
, 0);
3362 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3363 temp
.top
= ippGetInteger(margin
, 0);
3367 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3368 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3370 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3372 if (!cupsArrayFind(sizes
, &temp
))
3373 cupsArrayAdd(sizes
, &temp
);
3375 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3378 * Custom size - record the min/max values...
3381 int lower
, upper
; /* Range values */
3383 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3384 lower
= ippGetRange(x_dim
, 0, &upper
);
3386 lower
= upper
= ippGetInteger(x_dim
, 0);
3388 if (lower
< min_width
)
3390 if (upper
> max_width
)
3393 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3394 lower
= ippGetRange(y_dim
, 0, &upper
);
3396 lower
= upper
= ippGetInteger(y_dim
, 0);
3398 if (lower
< min_length
)
3400 if (upper
> max_length
)
3405 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3408 * Some printers don't list custom size support in media-col-database...
3411 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3413 media_size
= ippGetCollection(attr
, i
);
3414 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3415 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3417 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3420 * Custom size - record the min/max values...
3423 int lower
, upper
; /* Range values */
3425 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3426 lower
= ippGetRange(x_dim
, 0, &upper
);
3428 lower
= upper
= ippGetInteger(x_dim
, 0);
3430 if (lower
< min_width
)
3432 if (upper
> max_width
)
3435 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3436 lower
= ippGetRange(y_dim
, 0, &upper
);
3438 lower
= upper
= ippGetInteger(y_dim
, 0);
3440 if (lower
< min_length
)
3442 if (upper
> max_length
)
3448 else if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3450 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3452 cups_size_t temp
; /* Current size */
3454 media_size
= ippGetCollection(attr
, i
);
3455 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3456 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3457 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3461 temp
.width
= pwg
->width
;
3462 temp
.length
= pwg
->length
;
3463 temp
.bottom
= bottom
;
3468 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3469 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3471 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3473 if (!cupsArrayFind(sizes
, &temp
))
3474 cupsArrayAdd(sizes
, &temp
);
3476 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3479 * Custom size - record the min/max values...
3482 int lower
, upper
; /* Range values */
3484 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3485 lower
= ippGetRange(x_dim
, 0, &upper
);
3487 lower
= upper
= ippGetInteger(x_dim
, 0);
3489 if (lower
< min_width
)
3491 if (upper
> max_width
)
3494 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3495 lower
= ippGetRange(y_dim
, 0, &upper
);
3497 lower
= upper
= ippGetInteger(y_dim
, 0);
3499 if (lower
< min_length
)
3501 if (upper
> max_length
)
3506 else if ((attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3508 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3510 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3512 cups_size_t temp
; /* Current size */
3514 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3516 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3518 if (pwg
->width
> max_width
)
3519 max_width
= pwg
->width
;
3520 if (pwg
->length
> max_length
)
3521 max_length
= pwg
->length
;
3523 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3525 if (pwg
->width
< min_width
)
3526 min_width
= pwg
->width
;
3527 if (pwg
->length
< min_length
)
3528 min_length
= pwg
->length
;
3532 temp
.width
= pwg
->width
;
3533 temp
.length
= pwg
->length
;
3534 temp
.bottom
= bottom
;
3539 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3540 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3542 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3544 if (!cupsArrayFind(sizes
, &temp
))
3545 cupsArrayAdd(sizes
, &temp
);
3551 if (cupsArrayCount(sizes
) > 0)
3554 * List all of the standard sizes...
3557 char tleft
[256], /* Left string */
3558 tbottom
[256], /* Bottom string */
3559 tright
[256], /* Right string */
3560 ttop
[256], /* Top string */
3561 twidth
[256], /* Width string */
3562 tlength
[256]; /* Length string */
3564 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3565 "*OrderDependency: 10 AnySetup *PageSize\n"
3566 "*DefaultPageSize: %s\n", ppdname
);
3567 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3569 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3570 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3572 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3574 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3576 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3577 "*OrderDependency: 10 AnySetup *PageRegion\n"
3578 "*DefaultPageRegion: %s\n", ppdname
);
3579 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3581 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3582 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3584 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3586 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3588 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3589 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3591 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3593 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3594 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3595 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3596 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3597 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3598 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3600 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3601 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3604 cupsArrayDelete(sizes
);
3607 * Custom size support...
3610 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3612 char tmax
[256], tmin
[256]; /* Min/max values */
3614 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3615 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3616 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3617 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3619 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3621 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3622 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3623 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3625 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3626 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3627 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3629 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3630 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3631 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3632 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3637 cupsArrayDelete(sizes
);
3645 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3646 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3650 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3652 int have_default
= ppdname
[0] != '\0';
3653 /* Do we have a default InputSlot? */
3654 static const char * const sources
[] =
3655 { /* Standard "media-source" strings */
3708 cupsFilePuts(fp
, "*OpenUI *InputSlot: PickOne\n"
3709 "*OrderDependency: 10 AnySetup *InputSlot\n");
3711 cupsFilePrintf(fp
, "*DefaultInputSlot: %s\n", ppdname
);
3713 for (i
= 0; i
< count
; i
++)
3715 keyword
= ippGetString(attr
, i
, NULL
);
3717 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3719 if (i
== 0 && !have_default
)
3720 cupsFilePrintf(fp
, "*DefaultInputSlot: %s\n", ppdname
);
3722 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3723 if (!strcmp(sources
[j
], keyword
))
3725 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
3727 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3728 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3731 cupsFilePrintf(fp
, "*InputSlot %s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, j
);
3732 cupsFilePrintf(fp
, "*%s.InputSlot %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3736 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3743 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3744 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3746 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3748 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3750 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3751 "*OrderDependency: 10 AnySetup *MediaType\n"
3752 "*DefaultMediaType: %s\n", ppdname
);
3753 for (i
= 0; i
< count
; i
++)
3755 keyword
= ippGetString(attr
, i
, NULL
);
3757 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3759 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
3760 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3761 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3764 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3765 cupsFilePrintf(fp
, "*%s.MediaType %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
3767 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3774 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3775 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3776 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3777 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3781 int wrote_color
= 0;
3782 const char *default_color
= NULL
; /* Default */
3784 cupsFilePrintf(fp
, "*%% ColorModel from %s\n", ippGetName(attr
));
3786 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3788 keyword
= ippGetString(attr
, i
, NULL
);
3790 #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; }
3791 #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)); }
3793 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3797 PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K
, 1)
3800 default_color
= "FastGray";
3802 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3806 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3808 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3809 default_color
= "Gray";
3811 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
3815 if (!strcmp(keyword
, "W8-16"))
3817 PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW
, 8)
3819 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3820 default_color
= "Gray";
3823 PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW
, 16)
3825 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 7) || !strcmp(keyword
, "color"))
3829 PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB
, 8)
3831 default_color
= "RGB";
3833 // Apparently some printers only advertise color support, so make sure
3834 // we also do grayscale for these printers...
3835 if (!ippContainsString(attr
, "sgray_8") && !ippContainsString(attr
, "black_1") && !ippContainsString(attr
, "black_8") && !ippContainsString(attr
, "W8") && !ippContainsString(attr
, "W8-16"))
3836 PRINTF_COLOROPTION("Gray", _("GrayScale"), CUPS_CSPACE_SW
, 8)
3838 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
3842 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 16)
3845 default_color
= "AdobeRGB";
3847 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
3851 PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB
, 8)
3854 default_color
= "AdobeRGB";
3856 else if ((!strcasecmp(keyword
, "black_8") && !ippContainsString(attr
, "black_16")) || !strcmp(keyword
, "DEVW8"))
3860 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 8)
3862 else if (!strcasecmp(keyword
, "black_16") || !strcmp(keyword
, "DEVW16") || !strcmp(keyword
, "DEVW8-16"))
3866 PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W
, 16)
3868 else if ((!strcasecmp(keyword
, "cmyk_8") && !ippContainsString(attr
, "cmyk_16")) || !strcmp(keyword
, "DEVCMYK32"))
3872 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 8)
3874 else if (!strcasecmp(keyword
, "cmyk_16") || !strcmp(keyword
, "DEVCMYK32-64") || !strcmp(keyword
, "DEVCMYK64"))
3878 PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK
, 16)
3880 else if ((!strcasecmp(keyword
, "rgb_8") && ippContainsString(attr
, "rgb_16")) || !strcmp(keyword
, "DEVRGB24"))
3884 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 8)
3886 else if (!strcasecmp(keyword
, "rgb_16") || !strcmp(keyword
, "DEVRGB24-48") || !strcmp(keyword
, "DEVRGB48"))
3890 PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB
, 16)
3895 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3897 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3904 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3906 cupsFilePrintf(fp
, "*OpenUI *Duplex: PickOne\n"
3907 "*OrderDependency: 10 AnySetup *Duplex\n"
3908 "*%s.Translation Duplex/%s: \"\"\n"
3909 "*DefaultDuplex: None\n"
3910 "*Duplex None: \"<</Duplex false>>setpagedevice\"\n"
3911 "*%s.Duplex None/%s: \"\"\n"
3912 "*Duplex DuplexNoTumble: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3913 "*%s.Duplex DuplexNoTumble/%s: \"\"\n"
3914 "*Duplex DuplexTumble: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3915 "*%s.Duplex DuplexTumble/%s: \"\"\n"
3916 "*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)")));
3918 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3920 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3922 const char *dm
= ippGetString(attr
, i
, NULL
);
3925 if (!_cups_strcasecmp(dm
, "DM1"))
3927 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3930 else if (!_cups_strcasecmp(dm
, "DM2"))
3932 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3935 else if (!_cups_strcasecmp(dm
, "DM3"))
3937 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3940 else if (!_cups_strcasecmp(dm
, "DM4"))
3942 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3947 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3949 keyword
= ippGetString(attr
, 0, NULL
);
3951 if (!strcmp(keyword
, "flipped"))
3952 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3953 else if (!strcmp(keyword
, "manual-tumble"))
3954 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3955 else if (!strcmp(keyword
, "normal"))
3956 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3958 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3966 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3967 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3969 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3971 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 0)
3973 ipp_attribute_t
*trays
= ippFindAttribute(response
, "printer-output-tray", IPP_TAG_STRING
);
3974 /* printer-output-tray attribute, if any */
3975 const char *tray_ptr
; /* printer-output-tray value */
3976 int tray_len
; /* Len of printer-output-tray value */
3977 char tray
[IPP_MAX_OCTETSTRING
];
3978 /* printer-output-tray string value */
3980 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3981 "*OrderDependency: 10 AnySetup *OutputBin\n"
3982 "*DefaultOutputBin: %s\n", ppdname
);
3983 if (!strcmp(ppdname
, "FaceUp"))
3984 cupsFilePuts(fp
, "*DefaultOutputOrder: Reverse\n");
3986 cupsFilePuts(fp
, "*DefaultOutputOrder: Normal\n");
3988 for (i
= 0; i
< count
; i
++)
3990 keyword
= ippGetString(attr
, i
, NULL
);
3992 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3994 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
3995 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3996 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3999 cupsFilePrintf(fp
, "*OutputBin %s: \"\"\n", ppdname
);
4000 cupsFilePrintf(fp
, "*%s.OutputBin %s/%s: \"\"\n", lang
->language
, ppdname
, msgstr
);
4002 if ((tray_ptr
= ippGetOctetString(trays
, i
, &tray_len
)) != NULL
)
4004 if (tray_len
>= (int)sizeof(tray
))
4005 tray_len
= (int)sizeof(tray
) - 1;
4007 memcpy(tray
, tray_ptr
, (size_t)tray_len
);
4008 tray
[tray_len
] = '\0';
4010 if (strstr(tray
, "stackingorder=lastToFirst;"))
4011 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
4013 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
4015 else if (!strcmp(ppdname
, "FaceUp"))
4016 cupsFilePrintf(fp
, "*PageStackOrder %s: Reverse\n", ppdname
);
4018 cupsFilePrintf(fp
, "*PageStackOrder %s: Normal\n", ppdname
);
4020 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
4024 * Finishing options...
4027 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
4029 int value
; /* Enum value */
4030 const char *ppd_keyword
; /* PPD keyword for enum */
4031 cups_array_t
*names
; /* Names we've added */
4032 static const char * const base_keywords
[] =
4033 { /* Base STD 92 keywords */
4035 "SingleAuto", /* staple */
4036 "SingleAuto", /* punch */
4038 "BindAuto", /* bind */
4039 "SaddleStitch", /* saddle-stitch */
4040 "EdgeStitchAuto", /* edge-stitch */
4044 NULL
, /* booklet-maker */
4045 NULL
, /* jog-offset */
4050 count
= ippGetCount(attr
);
4051 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
4052 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4055 * Staple/Bind/Stitch
4058 for (i
= 0; i
< count
; i
++)
4060 value
= ippGetInteger(attr
, i
);
4061 keyword
= ippEnumString("finishings", value
);
4063 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch"))
4069 static const char * const staple_keywords
[] =
4070 { /* StapleLocation keywords */
4072 "SingleRevLandscape",
4074 "SingleRevPortrait",
4075 "EdgeStitchPortrait",
4076 "EdgeStitchLandscape",
4077 "EdgeStitchRevPortrait",
4078 "EdgeStitchRevLandscape",
4085 "TripleRevPortrait",
4086 "TripleRevLandscape"
4088 static const char * const bind_keywords
[] =
4089 { /* StapleLocation binding keywords */
4096 cupsArrayAdd(fin_options
, "*StapleLocation");
4098 cupsFilePuts(fp
, "*OpenUI *StapleLocation: PickOne\n");
4099 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
4100 cupsFilePrintf(fp
, "*%s.Translation StapleLocation/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Staple")));
4101 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
4102 cupsFilePuts(fp
, "*StapleLocation None: \"\"\n");
4103 cupsFilePrintf(fp
, "*%s.StapleLocation None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4105 for (; i
< count
; i
++)
4107 value
= ippGetInteger(attr
, i
);
4108 keyword
= ippEnumString("finishings", value
);
4110 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch"))
4113 if (cupsArrayFind(names
, (char *)keyword
))
4114 continue; /* Already did this finishing template */
4116 cupsArrayAdd(names
, (char *)keyword
);
4118 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4119 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4120 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4123 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4124 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4125 else if (value
>= IPP_FINISHINGS_STAPLE_TOP_LEFT
&& value
<= IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
)
4126 ppd_keyword
= staple_keywords
[value
- IPP_FINISHINGS_STAPLE_TOP_LEFT
];
4127 else if (value
>= IPP_FINISHINGS_BIND_LEFT
&& value
<= IPP_FINISHINGS_BIND_BOTTOM
)
4128 ppd_keyword
= bind_keywords
[value
- IPP_FINISHINGS_BIND_LEFT
];
4135 cupsFilePrintf(fp
, "*StapleLocation %s: \"\"\n", ppd_keyword
);
4136 cupsFilePrintf(fp
, "*%s.StapleLocation %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4137 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, ppd_keyword
);
4140 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
4147 for (i
= 0; i
< count
; i
++)
4149 value
= ippGetInteger(attr
, i
);
4150 keyword
= ippEnumString("finishings", value
);
4152 if (!strncmp(keyword
, "cups-fold-", 10) || !strcmp(keyword
, "fold") || !strncmp(keyword
, "fold-", 5))
4158 static const char * const fold_keywords
[] =
4159 { /* FoldType keywords */
4174 cupsArrayAdd(fin_options
, "*FoldType");
4176 cupsFilePuts(fp
, "*OpenUI *FoldType: PickOne\n");
4177 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
4178 cupsFilePrintf(fp
, "*%s.Translation FoldType/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Fold")));
4179 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
4180 cupsFilePuts(fp
, "*FoldType None: \"\"\n");
4181 cupsFilePrintf(fp
, "*%s.FoldType None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4183 for (; i
< count
; i
++)
4185 value
= ippGetInteger(attr
, i
);
4186 keyword
= ippEnumString("finishings", value
);
4188 if (!strncmp(keyword
, "cups-fold-", 10))
4190 else if (strcmp(keyword
, "fold") && strncmp(keyword
, "fold-", 5))
4193 if (cupsArrayFind(names
, (char *)keyword
))
4194 continue; /* Already did this finishing template */
4196 cupsArrayAdd(names
, (char *)keyword
);
4198 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4199 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4200 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4203 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4204 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4205 else if (value
>= IPP_FINISHINGS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_FOLD_ENGINEERING_Z
)
4206 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_FOLD_ACCORDION
];
4207 else if (value
>= IPP_FINISHINGS_CUPS_FOLD_ACCORDION
&& value
<= IPP_FINISHINGS_CUPS_FOLD_Z
)
4208 ppd_keyword
= fold_keywords
[value
- IPP_FINISHINGS_CUPS_FOLD_ACCORDION
];
4215 cupsFilePrintf(fp
, "*FoldType %s: \"\"\n", ppd_keyword
);
4216 cupsFilePrintf(fp
, "*%s.FoldType %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4217 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, ppd_keyword
);
4220 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4227 for (i
= 0; i
< count
; i
++)
4229 value
= ippGetInteger(attr
, i
);
4230 keyword
= ippEnumString("finishings", value
);
4232 if (!strncmp(keyword
, "cups-punch-", 11) || !strncmp(keyword
, "punch-", 6))
4238 static const char * const punch_keywords
[] =
4239 { /* PunchMedia keywords */
4241 "SingleRevLandscape",
4243 "SingleRevPortrait",
4250 "TripleRevPortrait",
4251 "TripleRevLandscape",
4257 "MultipleLandscape",
4258 "MultipleRevPortrait",
4259 "MultipleRevLandscape"
4262 cupsArrayAdd(fin_options
, "*PunchMedia");
4264 cupsFilePuts(fp
, "*OpenUI *PunchMedia: PickOne\n");
4265 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4266 cupsFilePrintf(fp
, "*%s.Translation PunchMedia/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Punch")));
4267 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4268 cupsFilePuts(fp
, "*PunchMedia None: \"\"\n");
4269 cupsFilePrintf(fp
, "*%s.PunchMedia None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4271 for (i
= 0; i
< count
; i
++)
4273 value
= ippGetInteger(attr
, i
);
4274 keyword
= ippEnumString("finishings", value
);
4276 if (!strncmp(keyword
, "cups-punch-", 11))
4278 else if (strncmp(keyword
, "punch-", 6))
4281 if (cupsArrayFind(names
, (char *)keyword
))
4282 continue; /* Already did this finishing template */
4284 cupsArrayAdd(names
, (char *)keyword
);
4286 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4287 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4288 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4291 if (value
>= IPP_FINISHINGS_NONE
&& value
<= IPP_FINISHINGS_LAMINATE
)
4292 ppd_keyword
= base_keywords
[value
- IPP_FINISHINGS_NONE
];
4293 else if (value
>= IPP_FINISHINGS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_PUNCH_MULTIPLE_BOTTOM
)
4294 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_PUNCH_TOP_LEFT
];
4295 else if (value
>= IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
&& value
<= IPP_FINISHINGS_CUPS_PUNCH_QUAD_BOTTOM
)
4296 ppd_keyword
= punch_keywords
[value
- IPP_FINISHINGS_CUPS_PUNCH_TOP_LEFT
];
4303 cupsFilePrintf(fp
, "*PunchMedia %s: \"\"\n", ppd_keyword
);
4304 cupsFilePrintf(fp
, "*%s.PunchMedia %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4305 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, ppd_keyword
);
4308 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4315 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4317 cupsArrayAdd(fin_options
, "*Booklet");
4319 cupsFilePuts(fp
, "*OpenUI *Booklet: Boolean\n");
4320 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4321 cupsFilePrintf(fp
, "*%s.Translation Booklet/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Booklet")));
4322 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4323 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4324 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4325 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4326 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4333 for (i
= 0; i
< count
; i
++)
4335 value
= ippGetInteger(attr
, i
);
4336 keyword
= ippEnumString("finishings", value
);
4338 if (!strcmp(keyword
, "trim") || !strncmp(keyword
, "trim-", 5))
4344 static const char * const trim_keywords
[] =
4345 { /* CutMedia keywords */
4352 cupsArrayAdd(fin_options
, "*CutMedia");
4354 cupsFilePuts(fp
, "*OpenUI *CutMedia: PickOne\n");
4355 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *CutMedia\n");
4356 cupsFilePrintf(fp
, "*%s.Translation CutMedia/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Cut")));
4357 cupsFilePuts(fp
, "*DefaultCutMedia: None\n");
4358 cupsFilePuts(fp
, "*CutMedia None: \"\"\n");
4359 cupsFilePrintf(fp
, "*%s.CutMedia None/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4361 for (i
= 0; i
< count
; i
++)
4363 value
= ippGetInteger(attr
, i
);
4364 keyword
= ippEnumString("finishings", value
);
4366 if (strcmp(keyword
, "trim") && strncmp(keyword
, "trim-", 5))
4369 if (cupsArrayFind(names
, (char *)keyword
))
4370 continue; /* Already did this finishing template */
4372 cupsArrayAdd(names
, (char *)keyword
);
4374 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4375 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4376 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4379 if (value
== IPP_FINISHINGS_TRIM
)
4380 ppd_keyword
= "Auto";
4382 ppd_keyword
= trim_keywords
[value
- IPP_FINISHINGS_TRIM_AFTER_PAGES
];
4384 cupsFilePrintf(fp
, "*CutMedia %s: \"\"\n", ppd_keyword
);
4385 cupsFilePrintf(fp
, "*%s.CutMedia %s/%s: \"\"\n", lang
->language
, ppd_keyword
, msgstr
);
4386 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*CutMedia %s\"\n", value
, keyword
, ppd_keyword
);
4389 cupsFilePuts(fp
, "*CloseUI: *CutMedia\n");
4392 cupsArrayDelete(names
);
4395 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4397 ipp_t
*finishing_col
; /* Current finishing collection */
4398 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4399 cups_array_t
*templates
; /* Finishing templates */
4401 cupsFilePuts(fp
, "*OpenUI *cupsFinishingTemplate: PickOne\n");
4402 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4403 cupsFilePrintf(fp
, "*%s.Translation cupsFinishingTemplate/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Finishing Preset")));
4404 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4405 cupsFilePuts(fp
, "*cupsFinishingTemplate none: \"\"\n");
4406 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate none/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("None")));
4408 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4409 count
= ippGetCount(attr
);
4411 for (i
= 0; i
< count
; i
++)
4413 finishing_col
= ippGetCollection(attr
, i
);
4414 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4416 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4419 if (!strcmp(keyword
, "none"))
4422 cupsArrayAdd(templates
, (void *)keyword
);
4424 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4425 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4426 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4429 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s: \"\n", keyword
);
4430 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4432 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4434 const char *name
= ippGetName(finishing_attr
);
4435 /* Member attribute name */
4437 if (strcmp(name
, "media-size"))
4438 cupsFilePrintf(fp
, "%% %s\n", name
);
4441 cupsFilePuts(fp
, "\"\n");
4442 cupsFilePrintf(fp
, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang
->language
, keyword
, msgstr
);
4443 cupsFilePuts(fp
, "*End\n");
4446 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4448 if (cupsArrayCount(fin_options
))
4450 const char *fin_option
; /* Current finishing option */
4452 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4453 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4454 cupsFilePrintf(fp
, " %s", fin_option
);
4455 cupsFilePuts(fp
, "\"\n");
4457 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None");
4458 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4459 cupsFilePrintf(fp
, " %s None", fin_option
);
4460 cupsFilePuts(fp
, "\"\n");
4463 cupsArrayDelete(templates
);
4466 cupsArrayDelete(fin_options
);
4469 * cupsPrintQuality and DefaultResolution...
4472 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4474 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4476 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4478 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4480 const char *rs
= ippGetString(attr
, i
, NULL
);
4483 if (_cups_strncasecmp(rs
, "RS", 2))
4486 lowdpi
= atoi(rs
+ 2);
4487 if ((rs
= strrchr(rs
, '-')) != NULL
)
4488 hidpi
= atoi(rs
+ 1);
4497 * Invalid "urf-supported" value...
4505 * Generate print qualities based on low and high DPIs...
4508 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4510 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4511 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4512 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4513 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4514 if ((lowdpi
& 1) == 0)
4515 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
/ 2, lang
->language
, _cupsLangString(lang
, _("Draft")));
4516 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4517 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4519 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", lowdpi
, lowdpi
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4521 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4522 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", hidpi
, hidpi
, lang
->language
, _cupsLangString(lang
, _("High")));
4523 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4526 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4529 * Make a sorted list of resolutions.
4532 count
= ippGetCount(attr
);
4533 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4534 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4536 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4537 for (i
= 1; i
< count
; i
++)
4540 for (i
= 0; i
< (count
- 1); i
++)
4542 for (j
= i
+ 1; j
< count
; j
++)
4544 int ix
, iy
, /* First X and Y resolution */
4545 jx
, jy
, /* Second X and Y resolution */
4546 temp
; /* Swap variable */
4547 ipp_res_t units
; /* Resolution units */
4549 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4550 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4552 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4555 * Swap these two resolutions...
4558 temp
= resolutions
[i
];
4559 resolutions
[i
] = resolutions
[j
];
4560 resolutions
[j
] = temp
;
4566 * Generate print quality options...
4569 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4570 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4572 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4573 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4574 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4575 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4576 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4578 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4579 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4580 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Draft/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Draft")));
4583 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4584 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4585 cupsFilePrintf(fp
, "*%s.cupsPrintQuality Normal/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("Normal")));
4587 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4589 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4590 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
4591 cupsFilePrintf(fp
, "*%s.cupsPrintQuality High/%s: \"\"\n", lang
->language
, _cupsLangString(lang
, _("High")));
4594 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4596 else if (is_apple
|| is_pwg
)
4600 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4602 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4607 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4610 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4612 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality: PickOne\n"
4613 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4614 "*%s.Translation cupsPrintQuality/%s: \"\"\n"
4615 "*DefaultcupsPrintQuality: Normal\n", lang
->language
, _cupsLangString(lang
, _("Print Quality")));
4616 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4617 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Draft")));
4619 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("Normal")));
4621 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4622 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", xres
, yres
, lang
->language
, _cupsLangString(lang
, _("High")));
4623 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4630 if ((attr
= ippFindAttribute(response
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4632 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4634 ipp_t
*preset
= ippGetCollection(attr
, i
);
4635 /* Preset collection */
4636 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
),
4638 *localized_name
; /* Localized preset name */
4639 ipp_attribute_t
*member
; /* Member attribute in preset */
4640 const char *member_name
; /* Member attribute name */
4641 char member_value
[256]; /* Member attribute value */
4643 if (!preset
|| !preset_name
)
4646 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", preset_name
);
4647 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4649 member_name
= ippGetName(member
);
4651 if (!member_name
|| !strcmp(member_name
, "preset-name"))
4654 if (!strcmp(member_name
, "finishings"))
4656 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4658 const char *option
= NULL
; /* PPD option name */
4660 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
4662 if (!strcmp(keyword
, "booklet-maker"))
4667 else if (!strncmp(keyword
, "fold-", 5))
4668 option
= "FoldType";
4669 else if (!strncmp(keyword
, "punch-", 6))
4670 option
= "PunchMedia";
4671 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7))
4672 option
= "StapleLocation";
4674 if (option
&& keyword
)
4675 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
4678 else if (!strcmp(member_name
, "finishings-col"))
4680 ipp_t
*fin_col
; /* finishings-col value */
4682 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4684 fin_col
= ippGetCollection(member
, i
);
4686 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4687 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", keyword
);
4690 else if (!strcmp(member_name
, "media"))
4693 * Map media to PageSize...
4696 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
4697 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4699 else if (!strcmp(member_name
, "media-col"))
4701 media_col
= ippGetCollection(member
, 0);
4703 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
4705 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
4706 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
4707 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
4708 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4711 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4713 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4714 cupsFilePrintf(fp
, "*InputSlot %s\n", keyword
);
4717 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4719 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4720 cupsFilePrintf(fp
, "*MediaType %s\n", keyword
);
4723 else if (!strcmp(member_name
, "print-quality"))
4726 * Map print-quality to cupsPrintQuality...
4729 int qval
= ippGetInteger(member
, 0);
4730 /* print-quality value */
4731 static const char * const qualities
[] = { "Draft", "Normal", "High" };
4732 /* cupsPrintQuality values */
4734 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
4735 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
4737 else if (!strcmp(member_name
, "output-bin"))
4739 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
4740 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
4742 else if (!strcmp(member_name
, "sides"))
4744 keyword
= ippGetString(member
, 0, NULL
);
4745 if (keyword
&& !strcmp(keyword
, "one-sided"))
4746 cupsFilePuts(fp
, "*Duplex None\n");
4747 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
4748 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
4749 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
4750 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
4755 * Add attribute name and value as-is...
4758 ippAttributeString(member
, member_value
, sizeof(member_value
));
4759 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
4763 cupsFilePuts(fp
, "\"\n*End\n");
4765 if ((localized_name
= _cupsMessageLookup(strings
, preset_name
)) != preset_name
)
4766 cupsFilePrintf(fp
, "*%s.APPrinterPreset %s/%s: \"\"\n", lang
->language
, preset_name
, localized_name
);
4771 * Close up and return...
4779 * If we get here then there was a problem creating the PPD...
4788 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4795 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4799 const char * /* O - InputSlot name */
4800 _pwgInputSlotForSource(
4801 const char *media_source
, /* I - PWG media-source */
4802 char *name
, /* I - Name buffer */
4803 size_t namesize
) /* I - Size of name buffer */
4806 * Range check input...
4809 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4812 if (_cups_strcasecmp(media_source
, "main"))
4813 strlcpy(name
, "Cassette", namesize
);
4814 else if (_cups_strcasecmp(media_source
, "alternate"))
4815 strlcpy(name
, "Multipurpose", namesize
);
4816 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4817 strlcpy(name
, "LargeCapacity", namesize
);
4818 else if (_cups_strcasecmp(media_source
, "bottom"))
4819 strlcpy(name
, "Lower", namesize
);
4820 else if (_cups_strcasecmp(media_source
, "middle"))
4821 strlcpy(name
, "Middle", namesize
);
4822 else if (_cups_strcasecmp(media_source
, "top"))
4823 strlcpy(name
, "Upper", namesize
);
4824 else if (_cups_strcasecmp(media_source
, "rear"))
4825 strlcpy(name
, "Rear", namesize
);
4826 else if (_cups_strcasecmp(media_source
, "side"))
4827 strlcpy(name
, "Side", namesize
);
4828 else if (_cups_strcasecmp(media_source
, "envelope"))
4829 strlcpy(name
, "Envelope", namesize
);
4830 else if (_cups_strcasecmp(media_source
, "main-roll"))
4831 strlcpy(name
, "Roll", namesize
);
4832 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4833 strlcpy(name
, "Roll2", namesize
);
4835 pwg_ppdize_name(media_source
, name
, namesize
);
4842 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4846 const char * /* O - MediaType name */
4847 _pwgMediaTypeForType(
4848 const char *media_type
, /* I - PWG media-type */
4849 char *name
, /* I - Name buffer */
4850 size_t namesize
) /* I - Size of name buffer */
4853 * Range check input...
4856 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4859 if (_cups_strcasecmp(media_type
, "auto"))
4860 strlcpy(name
, "Auto", namesize
);
4861 else if (_cups_strcasecmp(media_type
, "cardstock"))
4862 strlcpy(name
, "Cardstock", namesize
);
4863 else if (_cups_strcasecmp(media_type
, "envelope"))
4864 strlcpy(name
, "Envelope", namesize
);
4865 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4866 strlcpy(name
, "Glossy", namesize
);
4867 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4868 strlcpy(name
, "HighGloss", namesize
);
4869 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4870 strlcpy(name
, "Matte", namesize
);
4871 else if (_cups_strcasecmp(media_type
, "stationery"))
4872 strlcpy(name
, "Plain", namesize
);
4873 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4874 strlcpy(name
, "Coated", namesize
);
4875 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4876 strlcpy(name
, "Inkjet", namesize
);
4877 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4878 strlcpy(name
, "Letterhead", namesize
);
4879 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4880 strlcpy(name
, "Preprinted", namesize
);
4881 else if (_cups_strcasecmp(media_type
, "transparency"))
4882 strlcpy(name
, "Transparency", namesize
);
4884 pwg_ppdize_name(media_type
, name
, namesize
);
4891 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4894 const char * /* O - PageSize name */
4895 _pwgPageSizeForMedia(
4896 pwg_media_t
*media
, /* I - Media */
4897 char *name
, /* I - PageSize name buffer */
4898 size_t namesize
) /* I - Size of name buffer */
4900 const char *sizeptr
, /* Pointer to size in PWG name */
4901 *dimptr
; /* Pointer to dimensions in PWG name */
4905 * Range check input...
4908 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4912 * Copy or generate a PageSize name...
4918 * Use a standard Adobe name...
4921 strlcpy(name
, media
->ppd
, namesize
);
4923 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4924 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4925 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4926 (size_t)(dimptr
- sizeptr
) > namesize
)
4929 * Use a name of the form "wNNNhNNN"...
4932 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4933 (int)PWG_TO_POINTS(media
->length
));
4938 * Copy the size name from class_sizename_dimensions...
4941 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4942 name
[dimptr
- sizeptr
- 1] = '\0';
4950 * 'cups_get_url()' - Get a copy of the file at the given URL.
4953 static int /* O - 1 on success, 0 on failure */
4954 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4955 const char *url
, /* I - URL to get */
4956 char *name
, /* I - Temporary filename */
4957 size_t namesize
) /* I - Size of temporary filename buffer */
4959 char scheme
[32], /* URL scheme */
4960 userpass
[256], /* URL username:password */
4961 host
[256], /* URL host */
4962 curhost
[256], /* Current host */
4963 resource
[256]; /* URL resource */
4964 int port
; /* URL port */
4965 http_encryption_t encryption
; /* Type of encryption to use */
4966 http_status_t status
; /* Status of GET request */
4967 int fd
; /* Temporary file */
4970 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4973 if (port
== 443 || !strcmp(scheme
, "https"))
4974 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4976 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4978 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4981 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4987 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4990 status
= cupsGetFd(*http
, resource
, fd
);
4994 if (status
!= HTTP_STATUS_OK
)
5006 * 'pwg_add_finishing()' - Add a finishings value.
5011 cups_array_t
*finishings
, /* I - Finishings array */
5012 ipp_finishings_t
template, /* I - Finishing template */
5013 const char *name
, /* I - PPD option */
5014 const char *value
) /* I - PPD choice */
5016 _pwg_finishings_t
*f
; /* New finishings value */
5019 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
5021 f
->value
= template;
5022 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
5024 cupsArrayAdd(finishings
, f
);
5030 * 'pwg_add_message()' - Add a message to the PPD cached strings.
5034 pwg_add_message(cups_array_t
*a
, /* I - Message catalog */
5035 const char *msg
, /* I - Message identifier */
5036 const char *str
) /* I - Localized string */
5038 _cups_message_t
*m
; /* New message */
5041 if ((m
= calloc(1, sizeof(_cups_message_t
))) != NULL
)
5043 m
->msg
= strdup(msg
);
5044 m
->str
= strdup(str
);
5051 * 'pwg_compare_finishings()' - Compare two finishings values.
5054 static int /* O - Result of comparison */
5055 pwg_compare_finishings(
5056 _pwg_finishings_t
*a
, /* I - First finishings value */
5057 _pwg_finishings_t
*b
) /* I - Second finishings value */
5059 return ((int)b
->value
- (int)a
->value
);
5064 * 'pwg_compare_sizes()' - Compare two media sizes...
5067 static int /* O - Result of comparison */
5068 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
5069 cups_size_t
*b
) /* I - Second media size */
5071 return (strcmp(a
->media
, b
->media
));
5076 * 'pwg_copy_size()' - Copy a media size.
5079 static cups_size_t
* /* O - New media size */
5080 pwg_copy_size(cups_size_t
*size
) /* I - Media size to copy */
5082 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
5083 /* New media size */
5086 memcpy(newsize
, size
, sizeof(cups_size_t
));
5093 * 'pwg_free_finishings()' - Free a finishings value.
5097 pwg_free_finishings(
5098 _pwg_finishings_t
*f
) /* I - Finishings value */
5100 cupsFreeOptions(f
->num_options
, f
->options
);
5106 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
5110 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
5111 char *name
, /* I - Name buffer */
5112 size_t namesize
) /* I - Size of name buffer */
5114 char *ptr
, /* Pointer into name buffer */
5115 *end
; /* End of name buffer */
5124 *name
= (char)toupper(*ipp
++);
5126 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
5128 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
5131 *ptr
++ = (char)toupper(*ipp
++ & 255);
5142 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
5146 pwg_ppdize_resolution(
5147 ipp_attribute_t
*attr
, /* I - Attribute to convert */
5148 int element
, /* I - Element to convert */
5149 int *xres
, /* O - X resolution in DPI */
5150 int *yres
, /* O - Y resolution in DPI */
5151 char *name
, /* I - Name buffer */
5152 size_t namesize
) /* I - Size of name buffer */
5154 ipp_res_t units
; /* Units for resolution */
5157 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
5159 if (units
== IPP_RES_PER_CM
)
5161 *xres
= (int)(*xres
* 2.54);
5162 *yres
= (int)(*yres
* 2.54);
5165 if (name
&& namesize
> 4)
5168 snprintf(name
, namesize
, "%ddpi", *xres
);
5170 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
5176 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
5180 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
5181 char *name
, /* I - Name buffer */
5182 size_t namesize
, /* I - Size of name buffer */
5183 const char *dashchars
)/* I - Characters to be replaced by dashes */
5185 char *ptr
, /* Pointer into name buffer */
5186 *end
; /* End of name buffer */
5187 int nodash
= 1; /* Next char in IPP name cannot be a
5188 dash (first char or after a dash) */
5191 if (_cups_islower(*ppd
))
5194 * Already lowercase name, use as-is?
5197 const char *ppdptr
; /* Pointer into PPD keyword */
5199 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
5200 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
) ||
5201 (*ppdptr
== '-' && *(ppdptr
- 1) == '-') ||
5202 (*ppdptr
== '-' && *(ppdptr
+ 1) == '\0'))
5207 strlcpy(name
, ppd
, namesize
);
5212 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
5214 if (_cups_isalnum(*ppd
))
5216 *ptr
++ = (char)tolower(*ppd
& 255);
5219 else if (*ppd
== '-' || strchr(dashchars
, *ppd
))
5235 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
5236 _cups_isupper(ppd
[1]) && ptr
< end
)
5241 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))
5249 /* Remove trailing dashes */
5250 while (ptr
> name
&& *(ptr
- 1) == '-')