2 * PPD cache implementation for CUPS.
4 * Copyright 2010-2017 by Apple Inc.
6 * These coded instructions, statements, and computer programs are the
7 * property of Apple Inc. and are protected by Federal copyright
8 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
9 * which should have been included with this file. If this file is
10 * file is missing or damaged, see the license at "http://www.cups.org/".
12 * This file is subject to the Apple OS-Developed Software exception.
16 * Include necessary headers...
19 #include "cups-private.h"
20 #include "ppd-private.h"
25 * Macro to test for two almost-equal PWG measurements.
28 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
35 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
36 _pwg_finishings_t
*b
);
37 static void pwg_free_finishings(_pwg_finishings_t
*f
);
38 static void pwg_free_material(_pwg_material_t
*m
);
39 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
40 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
41 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
42 const char *dashchars
);
46 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
48 * This functions converts PPD and CUPS-specific options to their standard IPP
49 * attributes and values and adds them to the specified IPP request.
52 int /* O - New number of copies */
53 _cupsConvertOptions(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
,
57 /* I - media-col-supported values */
58 ipp_attribute_t
*doc_handling_sup
,
59 /* I - multiple-document-handling-supported values */
60 ipp_attribute_t
*print_color_mode_sup
,
61 /* I - Printer supports print-color-mode */
62 const char *user
, /* I - User info */
63 const char *format
, /* I - document-format value */
64 int copies
, /* I - Number of copies */
65 int num_options
, /* I - Number of options */
66 cups_option_t
*options
) /* I - Options */
68 int i
; /* Looping var */
69 const char *keyword
, /* PWG keyword */
70 *password
; /* Password string */
71 pwg_size_t
*size
; /* PWG media size */
72 ipp_t
*media_col
, /* media-col value */
73 *media_size
; /* media-size value */
74 const char *media_source
, /* media-source value */
75 *media_type
, /* media-type value */
76 *collate_str
, /* multiple-document-handling value */
77 *color_attr_name
, /* Supported color attribute */
78 *mandatory
; /* Mandatory attributes */
79 int num_finishings
= 0, /* Number of finishing values */
80 finishings
[10]; /* Finishing enum values */
81 ppd_choice_t
*choice
; /* Marked choice */
85 * Send standard IPP attributes...
88 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
90 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
92 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
95 if (!strcmp(keyword
, "none"))
98 * Add plain-text job-password...
101 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
106 * Add hashed job-password...
109 unsigned char hash
[64]; /* Hash of password */
110 ssize_t hashlen
; /* Length of hash */
112 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
113 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
117 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
122 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
123 keyword
= cupsGetOption("job-billing", num_options
, options
);
126 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
129 if (pc
->accounting_user_id
)
131 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
135 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
138 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
140 if (strcmp(mandatory
, "copies") &&
141 strcmp(mandatory
, "destination-uris") &&
142 strcmp(mandatory
, "finishings") &&
143 strcmp(mandatory
, "job-account-id") &&
144 strcmp(mandatory
, "job-accounting-user-id") &&
145 strcmp(mandatory
, "job-password") &&
146 strcmp(mandatory
, "job-password-encryption") &&
147 strcmp(mandatory
, "media") &&
148 strncmp(mandatory
, "media-col", 9) &&
149 strcmp(mandatory
, "multiple-document-handling") &&
150 strcmp(mandatory
, "output-bin") &&
151 strcmp(mandatory
, "print-color-mode") &&
152 strcmp(mandatory
, "print-quality") &&
153 strcmp(mandatory
, "sides") &&
154 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
156 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
158 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
163 case IPP_TAG_INTEGER
:
165 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
167 case IPP_TAG_BOOLEAN
:
168 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
172 int lower
, upper
; /* Range */
174 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
175 lower
= upper
= atoi(keyword
);
177 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
180 case IPP_TAG_STRING
:
181 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
184 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
186 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
187 keyword
= "auto-monochrome";
188 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
189 keyword
= "process-monochrome";
192 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
198 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
199 keyword
= cupsGetOption("media", num_options
, options
);
201 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
204 * Add a media-col value...
207 media_size
= ippNew();
208 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
209 "x-dimension", size
->width
);
210 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
211 "y-dimension", size
->length
);
213 media_col
= ippNew();
214 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
216 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
219 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
223 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
225 if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
226 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
227 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
229 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
231 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
233 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
234 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
235 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && media_type
)
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
239 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
242 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
244 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
245 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
249 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
251 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
253 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
255 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
257 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
258 keyword
= "monochrome";
264 if (keyword
&& !strcmp(keyword
, "monochrome"))
266 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
267 keyword
= "auto-monochrome";
268 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
269 keyword
= "process-monochrome";
273 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
275 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
276 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
277 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
279 if (!_cups_strcasecmp(choice
->choice
, "draft"))
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
281 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
283 else if (!_cups_strcasecmp(choice
->choice
, "high"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
287 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
288 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
289 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
291 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
293 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
295 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
303 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
305 if (strstr(keyword
, "uncollated"))
310 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
315 if (!_cups_strcasecmp(format
, "image/gif") ||
316 !_cups_strcasecmp(format
, "image/jp2") ||
317 !_cups_strcasecmp(format
, "image/jpeg") ||
318 !_cups_strcasecmp(format
, "image/png") ||
319 !_cups_strcasecmp(format
, "image/tiff") ||
320 !_cups_strncasecmp(format
, "image/x-", 8))
323 * Collation makes no sense for single page image formats...
328 else if (!_cups_strncasecmp(format
, "image/", 6) ||
329 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
332 * Multi-page image formats will have copies applied by the upstream
340 if (doc_handling_sup
)
342 if (!_cups_strcasecmp(keyword
, "true"))
343 collate_str
= "separate-documents-collated-copies";
345 collate_str
= "separate-documents-uncollated-copies";
347 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
349 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
351 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
356 if (i
>= doc_handling_sup
->num_values
)
361 * Map finishing options...
364 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
365 if (num_finishings
> 0)
367 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
369 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
372 * Send job-pages-per-set attribute to apply finishings correctly...
375 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
384 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
387 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
391 _ppd_cache_t
* /* O - PPD cache and mapping data */
392 _ppdCacheCreateWithFile(
393 const char *filename
, /* I - File to read */
394 ipp_t
**attrs
) /* IO - IPP attributes, if any */
396 cups_file_t
*fp
; /* File */
397 _ppd_cache_t
*pc
; /* PWG mapping data */
398 pwg_size_t
*size
; /* Current size */
399 pwg_map_t
*map
; /* Current map */
400 _pwg_finishings_t
*finishings
; /* Current finishings option */
401 int linenum
, /* Current line number */
402 num_bins
, /* Number of bins in file */
403 num_sizes
, /* Number of sizes in file */
404 num_sources
, /* Number of sources in file */
405 num_types
; /* Number of types in file */
406 char line
[2048], /* Current line */
407 *value
, /* Pointer to value in line */
408 *valueptr
, /* Pointer into value */
409 pwg_keyword
[128], /* PWG keyword */
410 ppd_keyword
[PPD_MAX_NAME
];
412 _pwg_print_color_mode_t print_color_mode
;
413 /* Print color mode for preset */
414 _pwg_print_quality_t print_quality
; /* Print quality for preset */
417 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
420 * Range check input...
428 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
436 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
438 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
443 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
446 if (!cupsFileGets(fp
, line
, sizeof(line
)))
448 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
449 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
454 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
456 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
457 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
462 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
464 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
465 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
466 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
472 * Allocate the mapping data structure...
475 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
477 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
478 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
482 pc
->max_copies
= 9999;
494 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
496 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
497 "linenum=%d", line
, value
, linenum
));
501 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
503 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
506 else if (!_cups_strcasecmp(line
, "3D"))
508 pc
->cups_3d
= _cupsStrAlloc(value
);
510 else if (!_cups_strcasecmp(line
, "LayerOrder"))
512 pc
->cups_layer_order
= _cupsStrAlloc(value
);
514 else if (!_cups_strcasecmp(line
, "Accuracy"))
516 sscanf(value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
518 else if (!_cups_strcasecmp(line
, "Volume"))
520 sscanf(value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
522 else if (!_cups_strcasecmp(line
, "Material"))
525 * Material key "name" name=value ... name=value
528 if ((valueptr
= strchr(value
, ' ')) != NULL
)
530 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
534 material
->key
= _cupsStrAlloc(value
);
536 if (*valueptr
== '\"')
538 value
= valueptr
+ 1;
539 if ((valueptr
= strchr(value
, '\"')) != NULL
)
542 material
->name
= _cupsStrAlloc(value
);
543 material
->num_props
= cupsParseOptions(valueptr
, 0, &material
->props
);
548 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
550 cupsArrayAdd(pc
->materials
, material
);
553 else if (!_cups_strcasecmp(line
, "Filter"))
556 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
557 (cups_acopy_func_t
)_cupsStrAlloc
,
558 (cups_afree_func_t
)_cupsStrFree
);
560 cupsArrayAdd(pc
->filters
, value
);
562 else if (!_cups_strcasecmp(line
, "PreFilter"))
565 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
566 (cups_acopy_func_t
)_cupsStrAlloc
,
567 (cups_afree_func_t
)_cupsStrFree
);
569 cupsArrayAdd(pc
->prefilters
, value
);
571 else if (!_cups_strcasecmp(line
, "Product"))
573 pc
->product
= _cupsStrAlloc(value
);
575 else if (!_cups_strcasecmp(line
, "SingleFile"))
577 pc
->single_file
= !_cups_strcasecmp(value
, "true");
579 else if (!_cups_strcasecmp(line
, "IPP"))
581 off_t pos
= cupsFileTell(fp
), /* Position in file */
582 length
= strtol(value
, NULL
, 10);
583 /* Length of IPP attributes */
587 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
588 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
591 else if (length
<= 0)
593 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
594 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
601 * Read IPP attributes into the provided variable...
606 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
607 *attrs
) != IPP_STATE_DATA
)
609 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
610 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
617 * Skip the IPP data entirely...
620 cupsFileSeek(fp
, pos
+ length
);
623 if (cupsFileTell(fp
) != (pos
+ length
))
625 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
626 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
630 else if (!_cups_strcasecmp(line
, "NumBins"))
634 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
635 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
639 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
641 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
642 "%d.", num_sizes
, linenum
));
643 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
647 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
649 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
651 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
655 else if (!_cups_strcasecmp(line
, "Bin"))
657 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
659 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
660 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
664 if (pc
->num_bins
>= num_bins
)
666 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
668 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
672 map
= pc
->bins
+ pc
->num_bins
;
673 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
674 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
678 else if (!_cups_strcasecmp(line
, "NumSizes"))
682 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
683 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
687 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
689 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
690 "%d.", num_sizes
, linenum
));
691 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
697 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
699 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
701 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
706 else if (!_cups_strcasecmp(line
, "Size"))
708 if (pc
->num_sizes
>= num_sizes
)
710 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
712 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
716 size
= pc
->sizes
+ pc
->num_sizes
;
718 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
719 &(size
->width
), &(size
->length
), &(size
->left
),
720 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
722 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
724 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
728 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
729 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
733 else if (!_cups_strcasecmp(line
, "CustomSize"))
735 if (pc
->custom_max_width
> 0)
737 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
739 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
743 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
744 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
745 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
746 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
747 &(pc
->custom_size
.top
)) != 8)
749 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
751 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
755 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
756 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
757 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
759 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
760 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
761 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
763 else if (!_cups_strcasecmp(line
, "SourceOption"))
765 pc
->source_option
= _cupsStrAlloc(value
);
767 else if (!_cups_strcasecmp(line
, "NumSources"))
771 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
773 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
777 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
779 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
780 "line %d.", num_sources
, linenum
));
781 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
785 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
787 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
789 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
793 else if (!_cups_strcasecmp(line
, "Source"))
795 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
797 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
799 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
803 if (pc
->num_sources
>= num_sources
)
805 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
807 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
811 map
= pc
->sources
+ pc
->num_sources
;
812 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
813 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
817 else if (!_cups_strcasecmp(line
, "NumTypes"))
821 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
822 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
826 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
828 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
829 "line %d.", num_types
, linenum
));
830 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
834 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
836 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
838 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
842 else if (!_cups_strcasecmp(line
, "Type"))
844 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
846 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
848 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
852 if (pc
->num_types
>= num_types
)
854 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
856 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
860 map
= pc
->types
+ pc
->num_types
;
861 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
862 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
866 else if (!_cups_strcasecmp(line
, "Preset"))
869 * Preset output-mode print-quality name=value ...
872 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
873 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
875 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
876 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
877 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
878 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
879 valueptr
== value
|| !*valueptr
)
881 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
883 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
887 pc
->num_presets
[print_color_mode
][print_quality
] =
888 cupsParseOptions(valueptr
, 0,
889 pc
->presets
[print_color_mode
] + print_quality
);
891 else if (!_cups_strcasecmp(line
, "SidesOption"))
892 pc
->sides_option
= _cupsStrAlloc(value
);
893 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
894 pc
->sides_1sided
= _cupsStrAlloc(value
);
895 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
896 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
897 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
898 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
899 else if (!_cups_strcasecmp(line
, "Finishings"))
903 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
905 (cups_afree_func_t
)pwg_free_finishings
);
907 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
910 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
911 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
912 &(finishings
->options
));
914 cupsArrayAdd(pc
->finishings
, finishings
);
916 else if (!_cups_strcasecmp(line
, "MaxCopies"))
917 pc
->max_copies
= atoi(value
);
918 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
919 pc
->charge_info_uri
= _cupsStrAlloc(value
);
920 else if (!_cups_strcasecmp(line
, "JobAccountId"))
921 pc
->account_id
= !_cups_strcasecmp(value
, "true");
922 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
923 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
924 else if (!_cups_strcasecmp(line
, "JobPassword"))
925 pc
->password
= _cupsStrAlloc(value
);
926 else if (!_cups_strcasecmp(line
, "Mandatory"))
929 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
931 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
933 else if (!_cups_strcasecmp(line
, "SupportFile"))
935 if (!pc
->support_files
)
936 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
937 (cups_acopy_func_t
)_cupsStrAlloc
,
938 (cups_afree_func_t
)_cupsStrFree
);
940 cupsArrayAdd(pc
->support_files
, value
);
944 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
949 if (pc
->num_sizes
< num_sizes
)
951 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
952 pc
->num_sizes
, num_sizes
));
953 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
957 if (pc
->num_sources
< num_sources
)
959 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
960 pc
->num_sources
, num_sources
));
961 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
965 if (pc
->num_types
< num_types
)
967 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
968 pc
->num_types
, num_types
));
969 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
978 * If we get here the file was bad - free any data and return...
984 _ppdCacheDestroy(pc
);
997 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1000 _ppd_cache_t
* /* O - PPD cache and mapping data */
1001 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
1003 int i
, j
, k
; /* Looping vars */
1004 _ppd_cache_t
*pc
; /* PWG mapping data */
1005 ppd_option_t
*input_slot
, /* InputSlot option */
1006 *media_type
, /* MediaType option */
1007 *output_bin
, /* OutputBin option */
1008 *color_model
, /* ColorModel option */
1009 *duplex
; /* Duplex option */
1010 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1011 pwg_map_t
*map
; /* Current source/type map */
1012 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1013 int num_options
; /* Number of preset options and props */
1014 cups_option_t
*options
; /* Preset options and properties */
1015 ppd_size_t
*ppd_size
; /* Current PPD size */
1016 pwg_size_t
*pwg_size
; /* Current PWG size */
1017 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1018 /* PWG keyword string */
1019 ppd_name
[PPD_MAX_NAME
];
1020 /* Normalized PPD name */
1021 const char *pwg_name
; /* Standard PWG media name */
1022 pwg_media_t
*pwg_media
; /* PWG media data */
1023 _pwg_print_color_mode_t pwg_print_color_mode
;
1024 /* print-color-mode index */
1025 _pwg_print_quality_t pwg_print_quality
;
1026 /* print-quality index */
1027 int similar
; /* Are the old and new size similar? */
1028 pwg_size_t
*old_size
; /* Current old size */
1029 int old_imageable
, /* Old imageable length in 2540ths */
1030 old_borderless
, /* Old borderless state */
1031 old_known_pwg
; /* Old PWG name is well-known */
1032 int new_width
, /* New width in 2540ths */
1033 new_length
, /* New length in 2540ths */
1034 new_left
, /* New left margin in 2540ths */
1035 new_bottom
, /* New bottom margin in 2540ths */
1036 new_right
, /* New right margin in 2540ths */
1037 new_top
, /* New top margin in 2540ths */
1038 new_imageable
, /* New imageable length in 2540ths */
1039 new_borderless
, /* New borderless state */
1040 new_known_pwg
; /* New PWG name is well-known */
1041 pwg_size_t
*new_size
; /* New size to add, if any */
1042 const char *filter
; /* Current filter */
1043 _pwg_finishings_t
*finishings
; /* Current finishings value */
1046 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1049 * Range check input...
1056 * Allocate memory...
1059 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1061 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1066 * Copy and convert size data...
1069 if (ppd
->num_sizes
> 0)
1071 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1073 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1074 "pwg_size_t's.", ppd
->num_sizes
));
1078 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1083 * Don't copy over custom size...
1086 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1090 * Convert the PPD size name to the corresponding PWG keyword name.
1093 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1096 * Standard name, do we have conflicts?
1099 for (j
= 0; j
< pc
->num_sizes
; j
++)
1100 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1110 * Standard name and no conflicts, use it!
1113 pwg_name
= pwg_media
->pwg
;
1119 * Not a standard name; convert it to a PWG vendor name of the form:
1121 * pp_lowerppd_WIDTHxHEIGHTuu
1124 pwg_name
= pwg_keyword
;
1127 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1128 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1129 PWG_FROM_POINTS(ppd_size
->width
),
1130 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1134 * If we have a similar paper with non-zero margins then we only want to
1135 * keep it if it has a larger imageable area length. The NULL check is for
1136 * dimensions that are <= 0...
1139 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1140 PWG_FROM_POINTS(ppd_size
->length
),
1144 new_width
= pwg_media
->width
;
1145 new_length
= pwg_media
->length
;
1146 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1147 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1148 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1149 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1150 new_imageable
= new_length
- new_top
- new_bottom
;
1151 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1152 new_left
== 0 && new_right
== 0;
1154 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1158 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1159 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1160 old_size
->right
== 0 && old_size
->top
== 0;
1161 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1162 strncmp(old_size
->map
.pwg
, "om_", 3);
1164 similar
= old_borderless
== new_borderless
&&
1165 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1166 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1169 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1172 * The new paper has a larger imageable area so it could replace
1173 * the older paper. Regardless of the imageable area, we always
1174 * prefer the size with a well-known PWG name.
1177 new_size
= old_size
;
1178 _cupsStrFree(old_size
->map
.ppd
);
1179 _cupsStrFree(old_size
->map
.pwg
);
1186 * The paper was unique enough to deserve its own entry so add it to the
1190 new_size
= pwg_size
++;
1200 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1201 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1202 new_size
->width
= new_width
;
1203 new_size
->length
= new_length
;
1204 new_size
->left
= new_left
;
1205 new_size
->bottom
= new_bottom
;
1206 new_size
->right
= new_right
;
1207 new_size
->top
= new_top
;
1212 if (ppd
->variable_sizes
)
1215 * Generate custom size data...
1218 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1219 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1220 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1221 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1222 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1223 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1225 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1226 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1227 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1228 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1229 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1230 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1232 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1233 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1234 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1235 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1239 * Copy and convert InputSlot data...
1242 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1243 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1247 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1249 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1251 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1252 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1256 pc
->num_sources
= input_slot
->num_choices
;
1258 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1261 i
--, choice
++, map
++)
1263 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1264 !_cups_strcasecmp(choice
->choice
, "Default"))
1266 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1268 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1270 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1272 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1273 !_cups_strcasecmp(choice
->choice
, "MP") ||
1274 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1275 pwg_name
= "by-pass-tray";
1276 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1277 pwg_name
= "large-capacity";
1278 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1279 pwg_name
= "bottom";
1280 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1281 pwg_name
= "middle";
1282 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1284 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1286 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1287 pwg_name
= "main-roll";
1291 * Convert PPD name to lowercase...
1294 pwg_name
= pwg_keyword
;
1295 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1299 map
->pwg
= _cupsStrAlloc(pwg_name
);
1300 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1305 * Copy and convert MediaType data...
1308 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1310 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1312 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1313 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1317 pc
->num_types
= media_type
->num_choices
;
1319 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1322 i
--, choice
++, map
++)
1324 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1325 !_cups_strcasecmp(choice
->choice
, "Any") ||
1326 !_cups_strcasecmp(choice
->choice
, "Default"))
1328 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1329 pwg_name
= "cardstock";
1330 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1331 pwg_name
= "envelope";
1332 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1333 pwg_name
= "photographic-glossy";
1334 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1335 pwg_name
= "photographic-high-gloss";
1336 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1337 pwg_name
= "photographic-matte";
1338 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1339 pwg_name
= "stationery";
1340 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1341 pwg_name
= "stationery-coated";
1342 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1343 pwg_name
= "stationery-inkjet";
1344 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1345 pwg_name
= "stationery-letterhead";
1346 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1347 pwg_name
= "stationery-preprinted";
1348 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1349 pwg_name
= "stationery-recycled";
1350 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1351 pwg_name
= "transparency";
1355 * Convert PPD name to lowercase...
1358 pwg_name
= pwg_keyword
;
1359 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1363 map
->pwg
= _cupsStrAlloc(pwg_name
);
1364 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1369 * Copy and convert OutputBin data...
1372 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1374 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1376 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1377 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1381 pc
->num_bins
= output_bin
->num_choices
;
1383 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1386 i
--, choice
++, map
++)
1388 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1390 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1391 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1395 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1398 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1401 const char *quality
, /* com.apple.print.preset.quality value */
1402 *output_mode
, /* com.apple.print.preset.output-mode value */
1403 *color_model_val
, /* ColorModel choice */
1404 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1405 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1409 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1412 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1413 num_options
, options
)) != NULL
)
1416 * Get the print-quality for this preset...
1419 if (!strcmp(quality
, "low"))
1420 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1421 else if (!strcmp(quality
, "high"))
1422 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1424 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1427 * Ignore graphicsType "Photo" presets that are not high quality.
1430 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1431 num_options
, options
);
1433 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1434 !strcmp(graphicsType
, "Photo"))
1438 * Ignore presets for normal and draft quality where the coating
1439 * isn't "none" or "autodetect".
1442 media_front_coating
= cupsGetOption(
1443 "com.apple.print.preset.media-front-coating",
1444 num_options
, options
);
1446 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1447 media_front_coating
&&
1448 strcmp(media_front_coating
, "none") &&
1449 strcmp(media_front_coating
, "autodetect"))
1453 * Get the output mode for this preset...
1456 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1457 num_options
, options
);
1458 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1462 if (!strcmp(output_mode
, "monochrome"))
1463 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1465 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1467 else if (color_model_val
)
1469 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1470 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1472 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1475 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1478 * Save the options for this combination as needed...
1481 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1482 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1483 _ppdParseOptions(ppd_attr
->value
, 0,
1484 pc
->presets
[pwg_print_color_mode
] +
1485 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1488 cupsFreeOptions(num_options
, options
);
1490 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1493 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1494 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1495 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1498 * Try adding some common color options to create grayscale presets. These
1499 * are listed in order of popularity...
1502 const char *color_option
= NULL
, /* Color control option */
1503 *gray_choice
= NULL
; /* Choice to select grayscale */
1505 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1506 ppdFindChoice(color_model
, "Gray"))
1508 color_option
= "ColorModel";
1509 gray_choice
= "Gray";
1511 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1512 ppdFindChoice(color_model
, "grayscale"))
1514 color_option
= "HPColorMode";
1515 gray_choice
= "grayscale";
1517 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1518 ppdFindChoice(color_model
, "Mono"))
1520 color_option
= "BRMonoColor";
1521 gray_choice
= "Mono";
1523 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1524 ppdFindChoice(color_model
, "1"))
1526 color_option
= "CNIJSGrayScale";
1529 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1530 ppdFindChoice(color_model
, "True"))
1532 color_option
= "HPColorAsGray";
1533 gray_choice
= "True";
1536 if (color_option
&& gray_choice
)
1539 * Copy and convert ColorModel (output-mode) data...
1542 cups_option_t
*coption
, /* Color option */
1543 *moption
; /* Monochrome option */
1545 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1546 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1547 pwg_print_quality
++)
1549 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1552 * Copy the color options...
1555 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1556 [pwg_print_quality
];
1557 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1561 for (i
= num_options
, moption
= options
,
1562 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1563 [pwg_print_quality
];
1565 i
--, moption
++, coption
++)
1567 moption
->name
= _cupsStrRetain(coption
->name
);
1568 moption
->value
= _cupsStrRetain(coption
->value
);
1571 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1573 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1577 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1581 * Add the grayscale option to the preset...
1584 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1585 cupsAddOption(color_option
, gray_choice
,
1586 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1587 [pwg_print_quality
],
1588 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1595 * Copy and convert Duplex (sides) data...
1598 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1599 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1600 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1601 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1602 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1606 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1608 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1612 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1613 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1614 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1615 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1616 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1617 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1618 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1619 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1620 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1621 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1622 !pc
->sides_2sided_short
)
1623 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1628 * Copy filters and pre-filters...
1631 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1632 (cups_acopy_func_t
)_cupsStrAlloc
,
1633 (cups_afree_func_t
)_cupsStrFree
);
1635 cupsArrayAdd(pc
->filters
,
1636 "application/vnd.cups-raw application/octet-stream 0 -");
1638 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1642 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1644 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1646 else if (ppd
->num_filters
> 0)
1648 for (i
= 0; i
< ppd
->num_filters
; i
++)
1649 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1652 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1655 * See if we have a command filter...
1658 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1660 filter
= (const char *)cupsArrayNext(pc
->filters
))
1661 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1662 _cups_isspace(filter
[28]))
1666 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1667 _cups_strcasecmp(ppd_attr
->value
, "none")))
1670 * No command filter and no cupsCommands keyword telling us not to use one.
1671 * See if this is a PostScript printer, and if so add a PostScript command
1675 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1677 filter
= (const char *)cupsArrayNext(pc
->filters
))
1678 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1679 _cups_isspace(filter
[31]))
1683 cupsArrayAdd(pc
->filters
,
1684 "application/vnd.cups-command application/postscript 100 "
1688 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1690 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1691 (cups_acopy_func_t
)_cupsStrAlloc
,
1692 (cups_afree_func_t
)_cupsStrFree
);
1696 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1698 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1701 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1702 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1705 * Copy the product string, if any...
1709 pc
->product
= _cupsStrAlloc(ppd
->product
);
1712 * Copy finishings mapping data...
1715 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1717 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1718 NULL
, NULL
, 0, NULL
,
1719 (cups_afree_func_t
)pwg_free_finishings
);
1723 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1726 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1727 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1728 &(finishings
->options
),
1729 _PPD_PARSE_OPTIONS
);
1731 cupsArrayAdd(pc
->finishings
, finishings
);
1733 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1741 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1742 pc
->max_copies
= atoi(ppd_attr
->value
);
1743 else if (ppd
->manual_copies
)
1746 pc
->max_copies
= 9999;
1749 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1750 * cupsJobPassword, and cupsMandatory.
1753 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1754 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1756 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1757 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1759 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1760 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1762 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1763 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1765 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1766 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1772 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1773 (cups_acopy_func_t
)_cupsStrAlloc
,
1774 (cups_afree_func_t
)_cupsStrFree
);
1776 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1778 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1779 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1781 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1782 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1788 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1789 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1791 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1792 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1794 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1795 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1797 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1798 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1800 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1802 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1805 * *cupsMaterial key/name: "name=value ... name=value"
1808 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1810 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1811 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1812 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1815 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1817 cupsArrayAdd(pc
->materials
, material
);
1821 * Return the cache data...
1827 * If we get here we need to destroy the PWG mapping data and return NULL...
1832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1833 _ppdCacheDestroy(pc
);
1840 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1844 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1846 int i
; /* Looping var */
1847 pwg_map_t
*map
; /* Current map */
1848 pwg_size_t
*size
; /* Current size */
1852 * Range check input...
1859 * Free memory as needed...
1864 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1866 _cupsStrFree(map
->pwg
);
1867 _cupsStrFree(map
->ppd
);
1875 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1877 _cupsStrFree(size
->map
.pwg
);
1878 _cupsStrFree(size
->map
.ppd
);
1884 if (pc
->source_option
)
1885 _cupsStrFree(pc
->source_option
);
1889 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1891 _cupsStrFree(map
->pwg
);
1892 _cupsStrFree(map
->ppd
);
1900 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1902 _cupsStrFree(map
->pwg
);
1903 _cupsStrFree(map
->ppd
);
1909 if (pc
->custom_max_keyword
)
1910 _cupsStrFree(pc
->custom_max_keyword
);
1912 if (pc
->custom_min_keyword
)
1913 _cupsStrFree(pc
->custom_min_keyword
);
1915 _cupsStrFree(pc
->product
);
1916 cupsArrayDelete(pc
->filters
);
1917 cupsArrayDelete(pc
->prefilters
);
1918 cupsArrayDelete(pc
->finishings
);
1920 _cupsStrFree(pc
->charge_info_uri
);
1921 _cupsStrFree(pc
->password
);
1923 cupsArrayDelete(pc
->mandatory
);
1925 cupsArrayDelete(pc
->support_files
);
1927 _cupsStrFree(pc
->cups_3d
);
1928 _cupsStrFree(pc
->cups_layer_order
);
1930 cupsArrayDelete(pc
->materials
);
1937 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1941 const char * /* O - output-bin or NULL */
1943 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1944 const char *output_bin
) /* I - PPD OutputBin string */
1946 int i
; /* Looping var */
1950 * Range check input...
1953 if (!pc
|| !output_bin
)
1957 * Look up the OutputBin string...
1961 for (i
= 0; i
< pc
->num_bins
; i
++)
1962 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1963 return (pc
->bins
[i
].pwg
);
1970 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1971 * IPP finishings value(s).
1974 int /* O - New number of options */
1975 _ppdCacheGetFinishingOptions(
1976 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1977 ipp_t
*job
, /* I - Job attributes or NULL */
1978 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1979 int num_options
, /* I - Number of options */
1980 cups_option_t
**options
) /* IO - Options */
1982 int i
; /* Looping var */
1983 _pwg_finishings_t
*f
, /* PWG finishings options */
1984 key
; /* Search key */
1985 ipp_attribute_t
*attr
; /* Finishings attribute */
1986 cups_option_t
*option
; /* Current finishings option */
1990 * Range check input...
1993 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1994 (!job
&& value
== IPP_FINISHINGS_NONE
))
1995 return (num_options
);
1998 * Apply finishing options...
2001 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2003 int num_values
= ippGetCount(attr
); /* Number of values */
2005 for (i
= 0; i
< num_values
; i
++)
2007 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2009 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2011 int j
; /* Another looping var */
2013 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2014 num_options
= cupsAddOption(option
->name
, option
->value
,
2015 num_options
, options
);
2019 else if (value
!= IPP_FINISHINGS_NONE
)
2023 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2025 int j
; /* Another looping var */
2027 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2028 num_options
= cupsAddOption(option
->name
, option
->value
,
2029 num_options
, options
);
2033 return (num_options
);
2038 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2042 int /* O - Number of finishings values */
2043 _ppdCacheGetFinishingValues(
2044 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2045 int num_options
, /* I - Number of options */
2046 cups_option_t
*options
, /* I - Options */
2047 int max_values
, /* I - Maximum number of finishings values */
2048 int *values
) /* O - Finishings values */
2050 int i
, /* Looping var */
2051 num_values
= 0; /* Number of values */
2052 _pwg_finishings_t
*f
; /* Current finishings option */
2053 cups_option_t
*option
; /* Current option */
2054 const char *val
; /* Value for option */
2058 * Range check input...
2061 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2063 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2065 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2070 * Go through the finishings options and see what is set...
2073 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2075 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2077 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2079 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2081 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2083 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2084 _cups_strcasecmp(option
->value
, val
))
2086 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2093 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2095 values
[num_values
++] = f
->value
;
2097 if (num_values
>= max_values
)
2102 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2104 return (num_values
);
2109 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2110 * attributes or a keyword string.
2113 const char * /* O - PPD InputSlot or NULL */
2114 _ppdCacheGetInputSlot(
2115 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2116 ipp_t
*job
, /* I - Job attributes or NULL */
2117 const char *keyword
) /* I - Keyword string or NULL */
2120 * Range check input...
2123 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2126 if (job
&& !keyword
)
2129 * Lookup the media-col attribute and any media-source found there...
2132 ipp_attribute_t
*media_col
, /* media-col attribute */
2133 *media_source
; /* media-source attribute */
2134 pwg_size_t size
; /* Dimensional size */
2135 int margins_set
; /* Were the margins set? */
2137 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2139 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2141 IPP_TAG_KEYWORD
)) != NULL
)
2144 * Use the media-source value from media-col...
2147 keyword
= ippGetString(media_source
, 0, NULL
);
2149 else if (pwgInitSize(&size
, job
, &margins_set
))
2152 * For media <= 5x7, look for a photo tray...
2155 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2162 int i
; /* Looping var */
2164 for (i
= 0; i
< pc
->num_sources
; i
++)
2165 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2166 return (pc
->sources
[i
].ppd
);
2174 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2175 * attributes or a keyword string.
2178 const char * /* O - PPD MediaType or NULL */
2179 _ppdCacheGetMediaType(
2180 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2181 ipp_t
*job
, /* I - Job attributes or NULL */
2182 const char *keyword
) /* I - Keyword string or NULL */
2185 * Range check input...
2188 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2191 if (job
&& !keyword
)
2194 * Lookup the media-col attribute and any media-source found there...
2197 ipp_attribute_t
*media_col
, /* media-col attribute */
2198 *media_type
; /* media-type attribute */
2200 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2203 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2205 IPP_TAG_KEYWORD
)) == NULL
)
2206 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2207 "media-type", IPP_TAG_NAME
);
2210 keyword
= media_type
->values
[0].string
.text
;
2216 int i
; /* Looping var */
2218 for (i
= 0; i
< pc
->num_types
; i
++)
2219 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2220 return (pc
->types
[i
].ppd
);
2228 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2232 const char * /* O - PPD OutputBin or NULL */
2233 _ppdCacheGetOutputBin(
2234 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2235 const char *output_bin
) /* I - Keyword string */
2237 int i
; /* Looping var */
2241 * Range check input...
2244 if (!pc
|| !output_bin
)
2248 * Look up the OutputBin string...
2252 for (i
= 0; i
< pc
->num_bins
; i
++)
2253 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2254 return (pc
->bins
[i
].ppd
);
2261 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2262 * attributes or a keyword string.
2265 const char * /* O - PPD PageSize or NULL */
2266 _ppdCacheGetPageSize(
2267 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2268 ipp_t
*job
, /* I - Job attributes or NULL */
2269 const char *keyword
, /* I - Keyword string or NULL */
2270 int *exact
) /* O - 1 if exact match, 0 otherwise */
2272 int i
; /* Looping var */
2273 pwg_size_t
*size
, /* Current size */
2274 *closest
, /* Closest size */
2275 jobsize
; /* Size data from job */
2276 int margins_set
, /* Were the margins set? */
2277 dwidth
, /* Difference in width */
2278 dlength
, /* Difference in length */
2279 dleft
, /* Difference in left margins */
2280 dright
, /* Difference in right margins */
2281 dbottom
, /* Difference in bottom margins */
2282 dtop
, /* Difference in top margins */
2283 dmin
, /* Minimum difference */
2284 dclosest
; /* Closest difference */
2285 const char *ppd_name
; /* PPD media name */
2288 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2289 pc
, job
, keyword
, exact
));
2292 * Range check input...
2295 if (!pc
|| (!job
&& !keyword
))
2306 * Try getting the PPD media name from the job attributes...
2309 ipp_attribute_t
*attr
; /* Job attribute */
2311 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2312 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2313 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2317 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2318 attr
->name
, ippTagString(attr
->value_tag
)));
2320 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2323 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2324 attr
->value_tag
== IPP_TAG_KEYWORD
))
2325 ppd_name
= attr
->values
[0].string
.text
;
2328 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2333 * Try looking up the named PPD size first...
2336 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2338 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2339 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2341 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2342 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2347 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2349 return (size
->map
.ppd
);
2354 if (job
&& !keyword
)
2357 * Get the size using media-col or media, with the preference being
2361 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2367 * Get the size using a media keyword...
2370 pwg_media_t
*media
; /* Media definition */
2373 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2374 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2375 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2378 jobsize
.width
= media
->width
;
2379 jobsize
.length
= media
->length
;
2384 * Now that we have the dimensions and possibly the margins, look at the
2385 * available sizes and find the match...
2389 dclosest
= 999999999;
2391 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2392 _cups_strncasecmp(ppd_name
, "custom_", 7))
2394 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2397 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2398 * is just about 176/2540ths...
2401 dwidth
= size
->width
- jobsize
.width
;
2402 dlength
= size
->length
- jobsize
.length
;
2404 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2410 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2413 dleft
= size
->left
- jobsize
.left
;
2414 dright
= size
->right
- jobsize
.right
;
2415 dtop
= size
->top
- jobsize
.top
;
2416 dbottom
= size
->bottom
- jobsize
.bottom
;
2418 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2419 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2421 dleft
= dleft
< 0 ? -dleft
: dleft
;
2422 dright
= dright
< 0 ? -dright
: dright
;
2423 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2424 dtop
= dtop
< 0 ? -dtop
: dtop
;
2425 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2427 if (dmin
< dclosest
)
2440 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2442 return (size
->map
.ppd
);
2448 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2451 return (closest
->map
.ppd
);
2455 * If we get here we need to check for custom page size support...
2458 if (jobsize
.width
>= pc
->custom_min_width
&&
2459 jobsize
.width
<= pc
->custom_max_width
&&
2460 jobsize
.length
>= pc
->custom_min_length
&&
2461 jobsize
.length
<= pc
->custom_max_length
)
2464 * In range, format as Custom.WWWWxLLLL (points).
2467 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2468 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2470 if (margins_set
&& exact
)
2472 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2473 dright
= pc
->custom_size
.right
- jobsize
.right
;
2474 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2475 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2477 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2478 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2484 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2485 pc
->custom_ppd_size
));
2487 return (pc
->custom_ppd_size
);
2491 * No custom page size support or the size is out of range - return NULL.
2494 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2501 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2504 pwg_size_t
* /* O - PWG size or NULL */
2506 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2507 const char *page_size
) /* I - PPD PageSize */
2509 int i
; /* Looping var */
2510 pwg_media_t
*media
; /* Media */
2511 pwg_size_t
*size
; /* Current size */
2515 * Range check input...
2518 if (!pc
|| !page_size
)
2521 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2524 * Custom size; size name can be one of the following:
2526 * Custom.WIDTHxLENGTHin - Size in inches
2527 * Custom.WIDTHxLENGTHft - Size in feet
2528 * Custom.WIDTHxLENGTHcm - Size in centimeters
2529 * Custom.WIDTHxLENGTHmm - Size in millimeters
2530 * Custom.WIDTHxLENGTHm - Size in meters
2531 * Custom.WIDTHxLENGTH[pt] - Size in points
2534 double w
, l
; /* Width and length of page */
2535 char *ptr
; /* Pointer into PageSize */
2536 struct lconv
*loc
; /* Locale data */
2539 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2540 if (!ptr
|| *ptr
!= 'x')
2543 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2547 if (!_cups_strcasecmp(ptr
, "in"))
2552 else if (!_cups_strcasecmp(ptr
, "ft"))
2557 else if (!_cups_strcasecmp(ptr
, "mm"))
2562 else if (!_cups_strcasecmp(ptr
, "cm"))
2567 else if (!_cups_strcasecmp(ptr
, "m"))
2578 pc
->custom_size
.width
= (int)w
;
2579 pc
->custom_size
.length
= (int)l
;
2581 return (&(pc
->custom_size
));
2585 * Not a custom size - look it up...
2588 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2589 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2590 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2594 * Look up standard sizes...
2597 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2598 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2599 media
= pwgMediaForPWG(page_size
);
2603 pc
->custom_size
.width
= media
->width
;
2604 pc
->custom_size
.length
= media
->length
;
2606 return (&(pc
->custom_size
));
2614 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2618 const char * /* O - PWG media-source keyword */
2620 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2621 const char *input_slot
) /* I - PPD InputSlot */
2623 int i
; /* Looping var */
2624 pwg_map_t
*source
; /* Current source */
2628 * Range check input...
2631 if (!pc
|| !input_slot
)
2634 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2635 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2636 return (source
->pwg
);
2643 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2647 const char * /* O - PWG media-type keyword */
2649 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2650 const char *media_type
) /* I - PPD MediaType */
2652 int i
; /* Looping var */
2653 pwg_map_t
*type
; /* Current type */
2657 * Range check input...
2660 if (!pc
|| !media_type
)
2663 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2664 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2672 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2675 int /* O - 1 on success, 0 on failure */
2677 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2678 const char *filename
, /* I - File to write */
2679 ipp_t
*attrs
) /* I - Attributes to write, if any */
2681 int i
, j
, k
; /* Looping vars */
2682 cups_file_t
*fp
; /* Output file */
2683 pwg_size_t
*size
; /* Current size */
2684 pwg_map_t
*map
; /* Current map */
2685 _pwg_finishings_t
*f
; /* Current finishing option */
2686 cups_option_t
*option
; /* Current option */
2687 const char *value
; /* Filter/pre-filter value */
2688 char newfile
[1024]; /* New filename */
2689 _pwg_material_t
*m
; /* Material */
2693 * Range check input...
2696 if (!pc
|| !filename
)
2698 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2703 * Open the file and write with compression...
2706 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2707 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2709 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2714 * Standard header...
2717 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2723 if (pc
->num_bins
> 0)
2725 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2726 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2727 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2734 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2735 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2736 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2737 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2738 size
->bottom
, size
->right
, size
->top
);
2739 if (pc
->custom_max_width
> 0)
2740 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2741 pc
->custom_max_width
, pc
->custom_max_length
,
2742 pc
->custom_min_width
, pc
->custom_min_length
,
2743 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2744 pc
->custom_size
.right
, pc
->custom_size
.top
);
2750 if (pc
->source_option
)
2751 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2753 if (pc
->num_sources
> 0)
2755 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2756 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2757 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2764 if (pc
->num_types
> 0)
2766 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2767 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2768 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2775 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2776 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2777 if (pc
->num_presets
[i
][j
])
2779 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2780 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2783 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2784 cupsFilePutChar(fp
, '\n');
2791 if (pc
->sides_option
)
2792 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2794 if (pc
->sides_1sided
)
2795 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2797 if (pc
->sides_2sided_long
)
2798 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2800 if (pc
->sides_2sided_short
)
2801 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2804 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2808 cupsFilePutConf(fp
, "Product", pc
->product
);
2810 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2812 value
= (const char *)cupsArrayNext(pc
->filters
))
2813 cupsFilePutConf(fp
, "Filter", value
);
2815 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2817 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2818 cupsFilePutConf(fp
, "PreFilter", value
);
2820 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2823 * Finishing options...
2826 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2828 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2830 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2831 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2832 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2833 cupsFilePutChar(fp
, '\n');
2840 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2843 * Accounting/quota/PIN/managed printing values...
2846 if (pc
->charge_info_uri
)
2847 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2849 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2850 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2851 pc
->accounting_user_id
? "true" : "false");
2854 cupsFilePutConf(fp
, "Password", pc
->password
);
2856 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2858 value
= (char *)cupsArrayNext(pc
->mandatory
))
2859 cupsFilePutConf(fp
, "Mandatory", value
);
2865 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2867 value
= (char *)cupsArrayNext(pc
->support_files
))
2868 cupsFilePutConf(fp
, "SupportFile", value
);
2875 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2877 if (pc
->cups_layer_order
)
2878 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2880 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2881 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2883 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2884 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
2886 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
2888 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
2890 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
2891 for (i
= 0; i
< m
->num_props
; i
++)
2892 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
2893 cupsFilePuts(fp
, "\n");
2897 * IPP attributes, if any...
2902 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2904 attrs
->state
= IPP_STATE_IDLE
;
2905 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2909 * Close and return...
2912 if (cupsFileClose(fp
))
2919 return (!rename(newfile
, filename
));
2924 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2925 * of an IPP printer.
2928 char * /* O - PPD filename or @code NULL@ on error */
2929 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2930 size_t bufsize
, /* I - Size of filename buffer */
2931 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2933 cups_file_t
*fp
; /* PPD file */
2934 cups_array_t
*sizes
; /* Media sizes we've added */
2935 ipp_attribute_t
*attr
, /* xxx-supported */
2936 *defattr
, /* xxx-default */
2937 *x_dim
, *y_dim
; /* Media dimensions */
2938 ipp_t
*media_size
; /* Media size collection */
2939 char make
[256], /* Make and model */
2940 *model
, /* Model name */
2941 ppdname
[PPD_MAX_NAME
];
2943 int i
, j
, /* Looping vars */
2944 count
, /* Number of values */
2945 bottom
, /* Largest bottom margin */
2946 left
, /* Largest left margin */
2947 right
, /* Largest right margin */
2948 top
, /* Largest top margin */
2949 is_apple
= 0, /* Does the printer support Apple raster? */
2950 is_pdf
= 0, /* Does the printer support PDF? */
2951 is_pwg
= 0; /* Does the printer support PWG Raster? */
2952 pwg_media_t
*pwg
; /* PWG media size */
2953 int xres
, yres
; /* Resolution values */
2954 cups_lang_t
*lang
= cupsLangDefault();
2955 /* Localization info */
2956 struct lconv
*loc
= localeconv();
2958 static const char * const finishings
[][2] =
2959 { /* Finishings strings */
2960 { "bale", _("Bale") },
2961 { "bind", _("Bind") },
2962 { "bind-bottom", _("Bind (Reverse Landscape)") },
2963 { "bind-left", _("Bind (Portrait)") },
2964 { "bind-right", _("Bind (Reverse Portrait)") },
2965 { "bind-top", _("Bind (Landscape)") },
2966 { "booklet-maker", _("Booklet Maker") },
2967 { "coat", _("Coat") },
2968 { "cover", _("Cover") },
2969 { "edge-stitch", _("Staple Edge") },
2970 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
2971 { "edge-stitch-left", _("Staple Edge (Portrait)") },
2972 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
2973 { "edge-stitch-top", _("Staple Edge (Landscape)") },
2974 { "fold", _("Fold") },
2975 { "fold-accordian", _("Accordian Fold") },
2976 { "fold-double-gate", _("Double Gate Fold") },
2977 { "fold-engineering-z", _("Engineering Z Fold") },
2978 { "fold-gate", _("Gate Fold") },
2979 { "fold-half", _("Half Fold") },
2980 { "fold-half-z", _("Half Z Fold") },
2981 { "fold-left-gate", _("Left Gate Fold") },
2982 { "fold-letter", _("Letter Fold") },
2983 { "fold-parallel", _("Parallel Fold") },
2984 { "fold-poster", _("Poster Fold") },
2985 { "fold-right-gate", _("Right Gate Fold") },
2986 { "fold-z", _("Z Fold") },
2987 { "jog-offset", _("Jog") },
2988 { "laminate", _("Laminate") },
2989 { "punch", _("Punch") },
2990 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
2991 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
2992 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
2993 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
2994 { "punch-double-right", _("2-Hole Punch (Landscape)") },
2995 { "punch-double-top", _("2-Hole Punch (Portrait)") },
2996 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
2997 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
2998 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
2999 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3000 { "punch-top-left", _("Single Punch (Portrait)") },
3001 { "punch-top-right", _("Single Punch (Landscape)") },
3002 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3003 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3004 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3005 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3006 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3007 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3008 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3009 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3010 { "saddle-stitch", _("Saddle Stitch") },
3011 { "staple", _("Staple") },
3012 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3013 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3014 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3015 { "staple-dual-left", _("Double Staple (Portrait)") },
3016 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3017 { "staple-dual-top", _("Double Staple (Landscape)") },
3018 { "staple-top-left", _("Single Staple (Portrait)") },
3019 { "staple-top-right", _("Single Staple (Landscape)") },
3020 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3021 { "staple-triple-left", _("Triple Staple (Portrait)") },
3022 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3023 { "staple-triple-top", _("Triple Staple (Landscape)") },
3024 { "trim", _("Cut Media") }
3029 * Range check input...
3035 if (!buffer
|| bufsize
< 1 || !response
)
3039 * Open a temporary file for the PPD...
3042 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3046 * Standard stuff for PPD file...
3049 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3050 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3051 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3052 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3053 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3054 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3055 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3056 cupsFilePuts(fp
, "*FileSystem: False\n");
3057 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3059 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3060 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3062 strlcpy(make
, "Unknown Printer", sizeof(make
));
3064 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3065 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3068 strlcpy(make
, "HP", sizeof(make
));
3070 else if ((model
= strchr(make
, ' ')) != NULL
)
3075 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3076 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3077 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3078 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3079 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3081 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3082 cupsFilePuts(fp
, "*ColorDevice: True\n");
3084 cupsFilePuts(fp
, "*ColorDevice: False\n");
3086 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3087 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3088 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3094 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3096 is_apple
= ippContainsString(attr
, "image/urf");
3097 is_pdf
= ippContainsString(attr
, "application/pdf");
3098 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3100 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3102 const char *format
= ippGetString(attr
, i
, NULL
);
3106 * Write cupsFilter2 lines for supported formats...
3109 if (!_cups_strcasecmp(format
, "application/pdf"))
3110 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3111 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3112 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3113 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3114 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3118 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3122 * PageSize/PageRegion/ImageableArea/PaperDimension
3125 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3127 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3128 if (ippGetInteger(attr
, i
) > bottom
)
3129 bottom
= ippGetInteger(attr
, i
);
3134 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3136 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3137 if (ippGetInteger(attr
, i
) > left
)
3138 left
= ippGetInteger(attr
, i
);
3143 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3145 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3146 if (ippGetInteger(attr
, i
) > right
)
3147 right
= ippGetInteger(attr
, i
);
3152 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3154 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3155 if (ippGetInteger(attr
, i
) > top
)
3156 top
= ippGetInteger(attr
, i
);
3161 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3163 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3165 media_size
= ippGetCollection(attr
, 0);
3166 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3167 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3169 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3170 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3172 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3175 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3177 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3178 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3180 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3182 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3183 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3186 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3187 "*OrderDependency: 10 AnySetup *PageSize\n"
3188 "*DefaultPageSize: %s\n", ppdname
);
3190 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3192 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3194 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3196 media_size
= ippGetCollection(attr
, i
);
3197 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3198 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3200 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3203 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3207 char twidth
[256], /* Width string */
3208 tlength
[256]; /* Length string */
3210 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3212 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3216 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3218 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3219 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3221 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3224 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3226 cupsArrayDelete(sizes
);
3227 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3229 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3230 "*OrderDependency: 10 AnySetup *PageRegion\n"
3231 "*DefaultPageRegion: %s\n", ppdname
);
3232 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3234 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3236 media_size
= ippGetCollection(attr
, i
);
3237 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3238 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3240 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3243 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3247 char twidth
[256], /* Width string */
3248 tlength
[256]; /* Length string */
3250 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3253 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3255 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3256 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3258 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3261 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3263 cupsArrayDelete(sizes
);
3264 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3266 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3267 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3268 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3270 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3272 media_size
= ippGetCollection(attr
, i
);
3273 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3274 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3276 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3279 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3283 char tleft
[256], /* Left string */
3284 tbottom
[256], /* Bottom string */
3285 tright
[256], /* Right string */
3286 ttop
[256], /* Top string */
3287 twidth
[256], /* Width string */
3288 tlength
[256]; /* Length string */
3290 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3293 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3295 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3296 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3297 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3298 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3299 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3300 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3302 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3303 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3307 cupsArrayDelete(sizes
);
3316 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3317 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3319 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3321 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3323 static const char * const sources
[][2] =
3324 { /* "media-source" strings */
3325 { "Auto", _("Automatic") },
3326 { "Main", _("Main") },
3327 { "Alternate", _("Alternate") },
3328 { "LargeCapacity", _("Large Capacity") },
3329 { "Manual", _("Manual") },
3330 { "Envelope", _("Envelope") },
3331 { "Disc", _("Disc") },
3332 { "Photo", _("Photo") },
3333 { "Hagaki", _("Hagaki") },
3334 { "MainRoll", _("Main Roll") },
3335 { "AlternateRoll", _("Alternate Roll") },
3336 { "Top", _("Top") },
3337 { "Middle", _("Middle") },
3338 { "Bottom", _("Bottom") },
3339 { "Side", _("Side") },
3340 { "Left", _("Left") },
3341 { "Right", _("Right") },
3342 { "Center", _("Center") },
3343 { "Rear", _("Rear") },
3344 { "ByPassTray", _("Multipurpose") },
3345 { "Tray1", _("Tray 1") },
3346 { "Tray2", _("Tray 2") },
3347 { "Tray3", _("Tray 3") },
3348 { "Tray4", _("Tray 4") },
3349 { "Tray5", _("Tray 5") },
3350 { "Tray6", _("Tray 6") },
3351 { "Tray7", _("Tray 7") },
3352 { "Tray8", _("Tray 8") },
3353 { "Tray9", _("Tray 9") },
3354 { "Tray10", _("Tray 10") },
3355 { "Tray11", _("Tray 11") },
3356 { "Tray12", _("Tray 12") },
3357 { "Tray13", _("Tray 13") },
3358 { "Tray14", _("Tray 14") },
3359 { "Tray15", _("Tray 15") },
3360 { "Tray16", _("Tray 16") },
3361 { "Tray17", _("Tray 17") },
3362 { "Tray18", _("Tray 18") },
3363 { "Tray19", _("Tray 19") },
3364 { "Tray20", _("Tray 20") },
3365 { "Roll1", _("Roll 1") },
3366 { "Roll2", _("Roll 2") },
3367 { "Roll3", _("Roll 3") },
3368 { "Roll4", _("Roll 4") },
3369 { "Roll5", _("Roll 5") },
3370 { "Roll6", _("Roll 6") },
3371 { "Roll7", _("Roll 7") },
3372 { "Roll8", _("Roll 8") },
3373 { "Roll9", _("Roll 9") },
3374 { "Roll10", _("Roll 10") }
3377 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3378 "*OrderDependency: 10 AnySetup *InputSlot\n"
3379 "*DefaultInputSlot: %s\n", ppdname
);
3380 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3382 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3384 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3385 if (!strcmp(sources
[j
][0], ppdname
))
3387 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3391 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3398 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3399 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3401 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3403 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3405 static const char * const media_types
[][2] =
3406 { /* "media-type" strings */
3407 { "aluminum", _("Aluminum") },
3408 { "auto", _("Automatic") },
3409 { "back-print-film", _("Back Print Film") },
3410 { "cardboard", _("Cardboard") },
3411 { "cardstock", _("Cardstock") },
3413 { "continuous", _("Continuous") },
3414 { "continuous-long", _("Continuous Long") },
3415 { "continuous-short", _("Continuous Short") },
3416 { "disc", _("Optical Disc") },
3417 { "disc-glossy", _("Glossy Optical Disc") },
3418 { "disc-high-gloss", _("High Gloss Optical Disc") },
3419 { "disc-matte", _("Matte Optical Disc") },
3420 { "disc-satin", _("Satin Optical Disc") },
3421 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3422 { "double-wall", _("Double Wall Cardboard") },
3423 { "dry-film", _("Dry Film") },
3424 { "dvd", _("DVD") },
3425 { "embossing-foil", _("Embossing Foil") },
3426 { "end-board", _("End Board") },
3427 { "envelope", _("Envelope") },
3428 { "envelope-archival", _("Archival Envelope") },
3429 { "envelope-bond", _("Bond Envelope") },
3430 { "envelope-coated", _("Coated Envelope") },
3431 { "envelope-cotton", _("Cotton Envelope") },
3432 { "envelope-fine", _("Fine Envelope") },
3433 { "envelope-heavyweight", _("Heavyweight Envelope") },
3434 { "envelope-inkjet", _("Inkjet Envelope") },
3435 { "envelope-lightweight", _("Lightweight Envelope") },
3436 { "envelope-plain", _("Plain Envelope") },
3437 { "envelope-preprinted", _("Preprinted Envelope") },
3438 { "envelope-window", _("Windowed Envelope") },
3439 { "fabric", _("Fabric") },
3440 { "fabric-archival", _("Archival Fabric") },
3441 { "fabric-glossy", _("Glossy Fabric") },
3442 { "fabric-high-gloss", _("High Gloss Fabric") },
3443 { "fabric-matte", _("Matte Fabric") },
3444 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3445 { "fabric-waterproof", _("Waterproof Fabric") },
3446 { "film", _("Film") },
3447 { "flexo-base", _("Flexo Base") },
3448 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3449 { "flute", _("Flute") },
3450 { "foil", _("Foil") },
3451 { "full-cut-tabs", _("Full Cut Tabs") },
3452 { "glass", _("Glass") },
3453 { "glass-colored", _("Glass Colored") },
3454 { "glass-opaque", _("Glass Opaque") },
3455 { "glass-surfaced", _("Glass Surfaced") },
3456 { "glass-textured", _("Glass Textured") },
3457 { "gravure-cylinder", _("Gravure Cylinder") },
3458 { "image-setter-paper", _("Image Setter Paper") },
3459 { "imaging-cylinder", _("Imaging Cylinder") },
3460 { "labels", _("Labels") },
3461 { "labels-colored", _("Colored Labels") },
3462 { "labels-glossy", _("Glossy Labels") },
3463 { "labels-high-gloss", _("High Gloss Labels") },
3464 { "labels-inkjet", _("Inkjet Labels") },
3465 { "labels-matte", _("Matte Labels") },
3466 { "labels-permanent", _("Permanent Labels") },
3467 { "labels-satin", _("Satin Labels") },
3468 { "labels-security", _("Security Labels") },
3469 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3470 { "laminating-foil", _("Laminating Foil") },
3471 { "letterhead", _("Letterhead") },
3472 { "metal", _("Metal") },
3473 { "metal-glossy", _("Metal Glossy") },
3474 { "metal-high-gloss", _("Metal High Gloss") },
3475 { "metal-matte", _("Metal Matte") },
3476 { "metal-satin", _("Metal Satin") },
3477 { "metal-semi-gloss", _("Metal Semi Gloss") },
3478 { "mounting-tape", _("Mounting Tape") },
3479 { "multi-layer", _("Multi Layer") },
3480 { "multi-part-form", _("Multi Part Form") },
3481 { "other", _("Other") },
3482 { "paper", _("Paper") },
3483 { "photographic", _("Photo Paper") },
3484 { "photographic-archival", _("Photographic Archival") },
3485 { "photographic-film", _("Photo Film") },
3486 { "photographic-glossy", _("Glossy Photo Paper") },
3487 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3488 { "photographic-matte", _("Matte Photo Paper") },
3489 { "photographic-satin", _("Satin Photo Paper") },
3490 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3491 { "plastic", _("Plastic") },
3492 { "plastic-archival", _("Plastic Archival") },
3493 { "plastic-colored", _("Plastic Colored") },
3494 { "plastic-glossy", _("Plastic Glossy") },
3495 { "plastic-high-gloss", _("Plastic High Gloss") },
3496 { "plastic-matte", _("Plastic Matte") },
3497 { "plastic-satin", _("Plastic Satin") },
3498 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3499 { "plate", _("Plate") },
3500 { "polyester", _("Polyester") },
3501 { "pre-cut-tabs", _("Pre Cut Tabs") },
3502 { "roll", _("Roll") },
3503 { "screen", _("Screen") },
3504 { "screen-paged", _("Screen Paged") },
3505 { "self-adhesive", _("Self Adhesive") },
3506 { "self-adhesive-film", _("Self Adhesive Film") },
3507 { "shrink-foil", _("Shrink Foil") },
3508 { "single-face", _("Single Face") },
3509 { "single-wall", _("Single Wall Cardboard") },
3510 { "sleeve", _("Sleeve") },
3511 { "stationery", _("Stationery") },
3512 { "stationery-archival", _("Stationery Archival") },
3513 { "stationery-coated", _("Coated Paper") },
3514 { "stationery-cotton", _("Stationery Cotton") },
3515 { "stationery-fine", _("Vellum Paper") },
3516 { "stationery-heavyweight", _("Heavyweight Paper") },
3517 { "stationery-heavyweight-coated", _("Stationery Heavyweight Coated") },
3518 { "stationery-inkjet", _("Stationery Inkjet Paper") },
3519 { "stationery-letterhead", _("Letterhead") },
3520 { "stationery-lightweight", _("Lightweight Paper") },
3521 { "stationery-preprinted", _("Preprinted Paper") },
3522 { "stationery-prepunched", _("Punched Paper") },
3523 { "tab-stock", _("Tab Stock") },
3524 { "tractor", _("Tractor") },
3525 { "transfer", _("Transfer") },
3526 { "transparency", _("Transparency") },
3527 { "triple-wall", _("Triple Wall Cardboard") },
3528 { "wet-film", _("Wet Film") }
3531 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3532 "*OrderDependency: 10 AnySetup *MediaType\n"
3533 "*DefaultMediaType: %s\n", ppdname
);
3534 for (i
= 0; i
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); i
++)
3536 if (!ippContainsString(attr
, media_types
[i
][0]))
3539 pwg_ppdize_name(media_types
[i
][0], ppdname
, sizeof(ppdname
));
3541 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[i
][1]), ppdname
);
3543 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3550 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3551 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3552 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3553 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3557 const char *default_color
= NULL
; /* Default */
3559 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3561 const char *keyword
= ippGetString(attr
, i
, NULL
);
3562 /* Keyword for color/bit depth */
3564 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3567 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3568 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3570 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3573 default_color
= "FastGray";
3575 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3578 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3579 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3581 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3583 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3584 default_color
= "Gray";
3586 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3589 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3590 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3592 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3594 default_color
= "RGB";
3596 else if (!strcmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3599 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3600 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3602 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3605 default_color
= "AdobeRGB";
3611 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3612 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3620 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3622 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3623 "*OrderDependency: 10 AnySetup *Duplex\n"
3624 "*DefaultDuplex: None\n"
3625 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3626 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3627 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3628 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3630 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3632 const char *keyword
= ippGetString(attr
, 0, NULL
);
3635 if (!strcmp(keyword
, "flipped"))
3636 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3637 else if (!strcmp(keyword
, "manual-tumble"))
3638 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3639 else if (!strcmp(keyword
, "normal"))
3640 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3642 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3644 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3646 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3648 const char *dm
= ippGetString(attr
, i
, NULL
);
3651 if (!_cups_strcasecmp(dm
, "DM1"))
3653 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3656 else if (!_cups_strcasecmp(dm
, "DM2"))
3658 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3661 else if (!_cups_strcasecmp(dm
, "DM3"))
3663 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3666 else if (!_cups_strcasecmp(dm
, "DM4"))
3668 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3679 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3680 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3682 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3684 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3686 static const char * const output_bins
[][2] =
3687 { /* "output-bin" strings */
3688 { "auto", _("Automatic") },
3689 { "bottom", _("Bottom Tray") },
3690 { "center", _("Center Tray") },
3691 { "face-down", _("Face Down") },
3692 { "face-up", _("Face Up") },
3693 { "large-capacity", _("Large Capacity Tray") },
3694 { "left", _("Left Tray") },
3695 { "mailbox-1", _("Mailbox 1") },
3696 { "mailbox-2", _("Mailbox 2") },
3697 { "mailbox-3", _("Mailbox 3") },
3698 { "mailbox-4", _("Mailbox 4") },
3699 { "mailbox-5", _("Mailbox 5") },
3700 { "mailbox-6", _("Mailbox 6") },
3701 { "mailbox-7", _("Mailbox 7") },
3702 { "mailbox-8", _("Mailbox 8") },
3703 { "mailbox-9", _("Mailbox 9") },
3704 { "mailbox-10", _("Mailbox 10") },
3705 { "middle", _("Middle") },
3706 { "my-mailbox", _("My Mailbox") },
3707 { "rear", _("Rear Tray") },
3708 { "right", _("Right Tray") },
3709 { "side", _("Side Tray") },
3710 { "stacker-1", _("Stacker 1") },
3711 { "stacker-2", _("Stacker 2") },
3712 { "stacker-3", _("Stacker 3") },
3713 { "stacker-4", _("Stacker 4") },
3714 { "stacker-5", _("Stacker 5") },
3715 { "stacker-6", _("Stacker 6") },
3716 { "stacker-7", _("Stacker 7") },
3717 { "stacker-8", _("Stacker 8") },
3718 { "stacker-9", _("Stacker 9") },
3719 { "stacker-10", _("Stacker 10") },
3720 { "top", _("Top Tray") },
3721 { "tray-1", _("Tray 1") },
3722 { "tray-2", _("Tray 2") },
3723 { "tray-3", _("Tray 3") },
3724 { "tray-4", _("Tray 4") },
3725 { "tray-5", _("Tray 5") },
3726 { "tray-6", _("Tray 6") },
3727 { "tray-7", _("Tray 7") },
3728 { "tray-8", _("Tray 8") },
3729 { "tray-9", _("Tray 9") },
3730 { "tray-10", _("Tray 10") }
3733 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3734 "*OrderDependency: 10 AnySetup *OutputBin\n"
3735 "*DefaultOutputBin: %s\n", ppdname
);
3736 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3738 if (!ippContainsString(attr
, output_bins
[i
][0]))
3741 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3743 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3745 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3749 * Finishing options...
3752 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3754 ipp_t
*col
; /* Collection value */
3755 ipp_attribute_t
*template; /* "finishing-template" member */
3756 const char *name
; /* String name */
3757 int value
; /* Enum value, if any */
3758 cups_array_t
*names
; /* Names we've added */
3760 count
= ippGetCount(attr
);
3761 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3763 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3764 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3765 "*DefaultcupsFinishingTemplate: none\n"
3766 "*cupsFinishingTemplate none/%s: \"\"\n"
3767 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3769 for (i
= 0; i
< count
; i
++)
3771 col
= ippGetCollection(attr
, i
);
3772 template = ippFindAttribute(col
, "finishing-template", IPP_TAG_ZERO
);
3774 if ((name
= ippGetString(template, 0, NULL
)) == NULL
|| !strcmp(name
, "none"))
3777 if (cupsArrayFind(names
, (char *)name
))
3778 continue; /* Already did this finishing template */
3780 cupsArrayAdd(names
, (char *)name
);
3782 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3784 if (!strcmp(finishings
[j
][0], name
))
3786 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3788 value
= ippEnumValue("finishings", name
);
3791 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3797 cupsArrayDelete(names
);
3799 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3801 else if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
&& (count
= ippGetCount(attr
)) > 1 )
3803 const char *name
; /* String name */
3804 int value
; /* Enum value, if any */
3806 count
= ippGetCount(attr
);
3808 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3809 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3810 "*DefaultcupsFinishingTemplate: none\n"
3811 "*cupsFinishingTemplate none/%s: \"\"\n"
3812 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3814 for (i
= 0; i
< count
; i
++)
3816 if ((value
= ippGetInteger(attr
, i
)) == 3)
3819 name
= ippEnumString("finishings", value
);
3820 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3822 if (!strcmp(finishings
[j
][0], name
))
3824 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3825 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3831 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3835 * cupsPrintQuality and DefaultResolution...
3838 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3840 count
= ippGetCount(attr
);
3842 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3843 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3845 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3846 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3847 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
3850 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3851 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
3853 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3854 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
3857 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3858 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
3861 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3863 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3865 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3867 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3869 const char *rs
= ippGetString(attr
, i
, NULL
);
3872 if (_cups_strncasecmp(rs
, "RS", 2))
3875 lowdpi
= atoi(rs
+ 2);
3876 if ((rs
= strrchr(rs
, '-')) != NULL
)
3877 hidpi
= atoi(rs
+ 1);
3886 * Invalid "urf-supported" value...
3894 * Generate print qualities based on low and high DPIs...
3897 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
3899 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3900 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3901 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
3902 if ((lowdpi
& 1) == 0)
3903 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
3904 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
3906 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
3907 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3910 else if (is_apple
|| is_pwg
)
3912 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
3914 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3915 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3918 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3921 * Close up and return...
3929 * If we get here then there was a problem creating the PPD...
3943 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
3947 const char * /* O - InputSlot name */
3948 _pwgInputSlotForSource(
3949 const char *media_source
, /* I - PWG media-source */
3950 char *name
, /* I - Name buffer */
3951 size_t namesize
) /* I - Size of name buffer */
3954 * Range check input...
3957 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
3960 if (_cups_strcasecmp(media_source
, "main"))
3961 strlcpy(name
, "Cassette", namesize
);
3962 else if (_cups_strcasecmp(media_source
, "alternate"))
3963 strlcpy(name
, "Multipurpose", namesize
);
3964 else if (_cups_strcasecmp(media_source
, "large-capacity"))
3965 strlcpy(name
, "LargeCapacity", namesize
);
3966 else if (_cups_strcasecmp(media_source
, "bottom"))
3967 strlcpy(name
, "Lower", namesize
);
3968 else if (_cups_strcasecmp(media_source
, "middle"))
3969 strlcpy(name
, "Middle", namesize
);
3970 else if (_cups_strcasecmp(media_source
, "top"))
3971 strlcpy(name
, "Upper", namesize
);
3972 else if (_cups_strcasecmp(media_source
, "rear"))
3973 strlcpy(name
, "Rear", namesize
);
3974 else if (_cups_strcasecmp(media_source
, "side"))
3975 strlcpy(name
, "Side", namesize
);
3976 else if (_cups_strcasecmp(media_source
, "envelope"))
3977 strlcpy(name
, "Envelope", namesize
);
3978 else if (_cups_strcasecmp(media_source
, "main-roll"))
3979 strlcpy(name
, "Roll", namesize
);
3980 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
3981 strlcpy(name
, "Roll2", namesize
);
3983 pwg_ppdize_name(media_source
, name
, namesize
);
3990 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
3994 const char * /* O - MediaType name */
3995 _pwgMediaTypeForType(
3996 const char *media_type
, /* I - PWG media-type */
3997 char *name
, /* I - Name buffer */
3998 size_t namesize
) /* I - Size of name buffer */
4001 * Range check input...
4004 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4007 if (_cups_strcasecmp(media_type
, "auto"))
4008 strlcpy(name
, "Auto", namesize
);
4009 else if (_cups_strcasecmp(media_type
, "cardstock"))
4010 strlcpy(name
, "Cardstock", namesize
);
4011 else if (_cups_strcasecmp(media_type
, "envelope"))
4012 strlcpy(name
, "Envelope", namesize
);
4013 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4014 strlcpy(name
, "Glossy", namesize
);
4015 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4016 strlcpy(name
, "HighGloss", namesize
);
4017 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4018 strlcpy(name
, "Matte", namesize
);
4019 else if (_cups_strcasecmp(media_type
, "stationery"))
4020 strlcpy(name
, "Plain", namesize
);
4021 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4022 strlcpy(name
, "Coated", namesize
);
4023 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4024 strlcpy(name
, "Inkjet", namesize
);
4025 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4026 strlcpy(name
, "Letterhead", namesize
);
4027 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4028 strlcpy(name
, "Preprinted", namesize
);
4029 else if (_cups_strcasecmp(media_type
, "transparency"))
4030 strlcpy(name
, "Transparency", namesize
);
4032 pwg_ppdize_name(media_type
, name
, namesize
);
4039 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4042 const char * /* O - PageSize name */
4043 _pwgPageSizeForMedia(
4044 pwg_media_t
*media
, /* I - Media */
4045 char *name
, /* I - PageSize name buffer */
4046 size_t namesize
) /* I - Size of name buffer */
4048 const char *sizeptr
, /* Pointer to size in PWG name */
4049 *dimptr
; /* Pointer to dimensions in PWG name */
4053 * Range check input...
4056 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4060 * Copy or generate a PageSize name...
4066 * Use a standard Adobe name...
4069 strlcpy(name
, media
->ppd
, namesize
);
4071 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4072 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4073 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4074 (size_t)(dimptr
- sizeptr
) > namesize
)
4077 * Use a name of the form "wNNNhNNN"...
4080 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4081 (int)PWG_TO_POINTS(media
->length
));
4086 * Copy the size name from class_sizename_dimensions...
4089 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4090 name
[dimptr
- sizeptr
- 1] = '\0';
4098 * 'pwg_compare_finishings()' - Compare two finishings values.
4101 static int /* O- Result of comparison */
4102 pwg_compare_finishings(
4103 _pwg_finishings_t
*a
, /* I - First finishings value */
4104 _pwg_finishings_t
*b
) /* I - Second finishings value */
4106 return ((int)b
->value
- (int)a
->value
);
4111 * 'pwg_free_finishings()' - Free a finishings value.
4115 pwg_free_finishings(
4116 _pwg_finishings_t
*f
) /* I - Finishings value */
4118 cupsFreeOptions(f
->num_options
, f
->options
);
4124 * 'pwg_free_material()' - Free a material value.
4128 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
4130 _cupsStrFree(m
->key
);
4131 _cupsStrFree(m
->name
);
4133 cupsFreeOptions(m
->num_props
, m
->props
);
4140 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4144 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4145 char *name
, /* I - Name buffer */
4146 size_t namesize
) /* I - Size of name buffer */
4148 char *ptr
, /* Pointer into name buffer */
4149 *end
; /* End of name buffer */
4158 *name
= (char)toupper(*ipp
++);
4160 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4162 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4165 *ptr
++ = (char)toupper(*ipp
++ & 255);
4176 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4180 pwg_ppdize_resolution(
4181 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4182 int element
, /* I - Element to convert */
4183 int *xres
, /* O - X resolution in DPI */
4184 int *yres
, /* O - Y resolution in DPI */
4185 char *name
, /* I - Name buffer */
4186 size_t namesize
) /* I - Size of name buffer */
4188 ipp_res_t units
; /* Units for resolution */
4191 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4193 if (units
== IPP_RES_PER_CM
)
4195 *xres
= (int)(*xres
* 2.54);
4196 *yres
= (int)(*yres
* 2.54);
4199 if (name
&& namesize
> 4)
4202 snprintf(name
, namesize
, "%ddpi", *xres
);
4204 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4210 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4214 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4215 char *name
, /* I - Name buffer */
4216 size_t namesize
, /* I - Size of name buffer */
4217 const char *dashchars
)/* I - Characters to be replaced by dashes */
4219 char *ptr
, /* Pointer into name buffer */
4220 *end
; /* End of name buffer */
4223 if (_cups_islower(*ppd
))
4226 * Already lowercase name, use as-is?
4229 const char *ppdptr
; /* Pointer into PPD keyword */
4231 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4232 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4237 strlcpy(name
, ppd
, namesize
);
4242 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4244 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4245 *ptr
++ = (char)tolower(*ppd
& 255);
4246 else if (strchr(dashchars
, *ppd
))
4251 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4252 _cups_isupper(ppd
[1]) && ptr
< end
)
4254 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))