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 * 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 void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
36 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
37 _pwg_finishings_t
*b
);
38 static void pwg_free_finishings(_pwg_finishings_t
*f
);
39 static void pwg_free_material(_pwg_material_t
*m
);
40 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
41 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
42 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
43 const char *dashchars
);
47 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
49 * This functions converts PPD and CUPS-specific options to their standard IPP
50 * attributes and values and adds them to the specified IPP request.
53 int /* O - New number of copies */
55 ipp_t
*request
, /* I - IPP request */
56 ppd_file_t
*ppd
, /* I - PPD file */
57 _ppd_cache_t
*pc
, /* I - PPD cache info */
58 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
59 ipp_attribute_t
*doc_handling_sup
, /* 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 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
202 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
203 size
= _ppdCacheGetSize(pc
, keyword
);
205 if (size
|| media_source
|| media_type
)
208 * Add a media-col value...
211 media_col
= ippNew();
215 media_size
= ippNew();
216 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
217 "x-dimension", size
->width
);
218 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
219 "y-dimension", size
->length
);
221 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
224 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
226 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
227 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
228 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
229 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
230 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
231 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
232 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
233 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
234 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
235 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
236 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
237 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
240 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
243 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
245 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
246 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
250 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
252 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
254 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
256 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
258 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
259 keyword
= "monochrome";
265 if (keyword
&& !strcmp(keyword
, "monochrome"))
267 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
268 keyword
= "auto-monochrome";
269 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
270 keyword
= "process-monochrome";
274 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
276 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
277 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
278 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
280 if (!_cups_strcasecmp(choice
->choice
, "draft"))
281 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
282 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
283 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
284 else if (!_cups_strcasecmp(choice
->choice
, "high"))
285 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
288 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
289 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
290 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
292 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
293 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
294 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
295 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
296 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
297 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
304 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
306 if (strstr(keyword
, "uncollated"))
311 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
316 if (!_cups_strcasecmp(format
, "image/gif") ||
317 !_cups_strcasecmp(format
, "image/jp2") ||
318 !_cups_strcasecmp(format
, "image/jpeg") ||
319 !_cups_strcasecmp(format
, "image/png") ||
320 !_cups_strcasecmp(format
, "image/tiff") ||
321 !_cups_strncasecmp(format
, "image/x-", 8))
324 * Collation makes no sense for single page image formats...
329 else if (!_cups_strncasecmp(format
, "image/", 6) ||
330 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
333 * Multi-page image formats will have copies applied by the upstream
341 if (doc_handling_sup
)
343 if (!_cups_strcasecmp(keyword
, "true"))
344 collate_str
= "separate-documents-collated-copies";
346 collate_str
= "separate-documents-uncollated-copies";
348 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
350 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
352 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
357 if (i
>= doc_handling_sup
->num_values
)
362 * Map finishing options...
365 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
366 if (num_finishings
> 0)
368 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
370 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
373 * Send job-pages-per-set attribute to apply finishings correctly...
376 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
385 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
388 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
392 _ppd_cache_t
* /* O - PPD cache and mapping data */
393 _ppdCacheCreateWithFile(
394 const char *filename
, /* I - File to read */
395 ipp_t
**attrs
) /* IO - IPP attributes, if any */
397 cups_file_t
*fp
; /* File */
398 _ppd_cache_t
*pc
; /* PWG mapping data */
399 pwg_size_t
*size
; /* Current size */
400 pwg_map_t
*map
; /* Current map */
401 _pwg_finishings_t
*finishings
; /* Current finishings option */
402 int linenum
, /* Current line number */
403 num_bins
, /* Number of bins in file */
404 num_sizes
, /* Number of sizes in file */
405 num_sources
, /* Number of sources in file */
406 num_types
; /* Number of types in file */
407 char line
[2048], /* Current line */
408 *value
, /* Pointer to value in line */
409 *valueptr
, /* Pointer into value */
410 pwg_keyword
[128], /* PWG keyword */
411 ppd_keyword
[PPD_MAX_NAME
];
413 _pwg_print_color_mode_t print_color_mode
;
414 /* Print color mode for preset */
415 _pwg_print_quality_t print_quality
; /* Print quality for preset */
418 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
421 * Range check input...
429 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
437 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
439 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
444 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
447 if (!cupsFileGets(fp
, line
, sizeof(line
)))
449 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
450 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
455 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
457 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
458 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
463 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
465 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
466 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
467 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
473 * Allocate the mapping data structure...
476 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
478 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
479 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
483 pc
->max_copies
= 9999;
495 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
497 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
498 "linenum=%d", line
, value
, linenum
));
502 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
507 else if (!_cups_strcasecmp(line
, "3D"))
509 pc
->cups_3d
= _cupsStrAlloc(value
);
511 else if (!_cups_strcasecmp(line
, "LayerOrder"))
513 pc
->cups_layer_order
= _cupsStrAlloc(value
);
515 else if (!_cups_strcasecmp(line
, "Accuracy"))
517 sscanf(value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
519 else if (!_cups_strcasecmp(line
, "Volume"))
521 sscanf(value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
523 else if (!_cups_strcasecmp(line
, "Material"))
526 * Material key "name" name=value ... name=value
529 if ((valueptr
= strchr(value
, ' ')) != NULL
)
531 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
535 material
->key
= _cupsStrAlloc(value
);
537 if (*valueptr
== '\"')
539 value
= valueptr
+ 1;
540 if ((valueptr
= strchr(value
, '\"')) != NULL
)
543 material
->name
= _cupsStrAlloc(value
);
544 material
->num_props
= cupsParseOptions(valueptr
, 0, &material
->props
);
549 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
551 cupsArrayAdd(pc
->materials
, material
);
554 else if (!_cups_strcasecmp(line
, "Filter"))
557 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
558 (cups_acopy_func_t
)_cupsStrAlloc
,
559 (cups_afree_func_t
)_cupsStrFree
);
561 cupsArrayAdd(pc
->filters
, value
);
563 else if (!_cups_strcasecmp(line
, "PreFilter"))
566 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
567 (cups_acopy_func_t
)_cupsStrAlloc
,
568 (cups_afree_func_t
)_cupsStrFree
);
570 cupsArrayAdd(pc
->prefilters
, value
);
572 else if (!_cups_strcasecmp(line
, "Product"))
574 pc
->product
= _cupsStrAlloc(value
);
576 else if (!_cups_strcasecmp(line
, "SingleFile"))
578 pc
->single_file
= !_cups_strcasecmp(value
, "true");
580 else if (!_cups_strcasecmp(line
, "IPP"))
582 off_t pos
= cupsFileTell(fp
), /* Position in file */
583 length
= strtol(value
, NULL
, 10);
584 /* Length of IPP attributes */
588 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
592 else if (length
<= 0)
594 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
595 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
602 * Read IPP attributes into the provided variable...
607 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
608 *attrs
) != IPP_STATE_DATA
)
610 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
611 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
618 * Skip the IPP data entirely...
621 cupsFileSeek(fp
, pos
+ length
);
624 if (cupsFileTell(fp
) != (pos
+ length
))
626 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
627 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
631 else if (!_cups_strcasecmp(line
, "NumBins"))
635 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
643 "%d.", num_sizes
, linenum
));
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
648 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
650 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
652 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
656 else if (!_cups_strcasecmp(line
, "Bin"))
658 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
660 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 if (pc
->num_bins
>= num_bins
)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 map
= pc
->bins
+ pc
->num_bins
;
674 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
675 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
679 else if (!_cups_strcasecmp(line
, "NumSizes"))
683 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
684 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
688 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
690 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
691 "%d.", num_sizes
, linenum
));
692 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
698 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
700 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
702 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
707 else if (!_cups_strcasecmp(line
, "Size"))
709 if (pc
->num_sizes
>= num_sizes
)
711 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
713 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
717 size
= pc
->sizes
+ pc
->num_sizes
;
719 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
720 &(size
->width
), &(size
->length
), &(size
->left
),
721 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
723 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
725 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
729 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
730 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
734 else if (!_cups_strcasecmp(line
, "CustomSize"))
736 if (pc
->custom_max_width
> 0)
738 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
740 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
744 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
745 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
746 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
747 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
748 &(pc
->custom_size
.top
)) != 8)
750 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
757 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
758 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
760 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
761 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
762 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
764 else if (!_cups_strcasecmp(line
, "SourceOption"))
766 pc
->source_option
= _cupsStrAlloc(value
);
768 else if (!_cups_strcasecmp(line
, "NumSources"))
772 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
774 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
778 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
780 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
781 "line %d.", num_sources
, linenum
));
782 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
786 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
788 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
790 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
794 else if (!_cups_strcasecmp(line
, "Source"))
796 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
798 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
800 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
804 if (pc
->num_sources
>= num_sources
)
806 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
808 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
812 map
= pc
->sources
+ pc
->num_sources
;
813 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
814 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
818 else if (!_cups_strcasecmp(line
, "NumTypes"))
822 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
823 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
827 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
829 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
830 "line %d.", num_types
, linenum
));
831 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
835 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
837 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
839 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
843 else if (!_cups_strcasecmp(line
, "Type"))
845 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
847 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
849 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
853 if (pc
->num_types
>= num_types
)
855 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
857 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
861 map
= pc
->types
+ pc
->num_types
;
862 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
863 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
867 else if (!_cups_strcasecmp(line
, "Preset"))
870 * Preset output-mode print-quality name=value ...
873 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
874 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
876 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
877 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
878 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
879 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
880 valueptr
== value
|| !*valueptr
)
882 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
884 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
888 pc
->num_presets
[print_color_mode
][print_quality
] =
889 cupsParseOptions(valueptr
, 0,
890 pc
->presets
[print_color_mode
] + print_quality
);
892 else if (!_cups_strcasecmp(line
, "SidesOption"))
893 pc
->sides_option
= _cupsStrAlloc(value
);
894 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
895 pc
->sides_1sided
= _cupsStrAlloc(value
);
896 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
897 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
898 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
899 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
900 else if (!_cups_strcasecmp(line
, "Finishings"))
904 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
906 (cups_afree_func_t
)pwg_free_finishings
);
908 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
911 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
912 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
913 &(finishings
->options
));
915 cupsArrayAdd(pc
->finishings
, finishings
);
917 else if (!_cups_strcasecmp(line
, "MaxCopies"))
918 pc
->max_copies
= atoi(value
);
919 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
920 pc
->charge_info_uri
= _cupsStrAlloc(value
);
921 else if (!_cups_strcasecmp(line
, "JobAccountId"))
922 pc
->account_id
= !_cups_strcasecmp(value
, "true");
923 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
924 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
925 else if (!_cups_strcasecmp(line
, "JobPassword"))
926 pc
->password
= _cupsStrAlloc(value
);
927 else if (!_cups_strcasecmp(line
, "Mandatory"))
930 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
932 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
934 else if (!_cups_strcasecmp(line
, "SupportFile"))
936 if (!pc
->support_files
)
937 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
938 (cups_acopy_func_t
)_cupsStrAlloc
,
939 (cups_afree_func_t
)_cupsStrFree
);
941 cupsArrayAdd(pc
->support_files
, value
);
945 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
950 if (pc
->num_sizes
< num_sizes
)
952 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
953 pc
->num_sizes
, num_sizes
));
954 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
958 if (pc
->num_sources
< num_sources
)
960 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
961 pc
->num_sources
, num_sources
));
962 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
966 if (pc
->num_types
< num_types
)
968 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
969 pc
->num_types
, num_types
));
970 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
979 * If we get here the file was bad - free any data and return...
985 _ppdCacheDestroy(pc
);
998 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1001 _ppd_cache_t
* /* O - PPD cache and mapping data */
1002 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
1004 int i
, j
, k
; /* Looping vars */
1005 _ppd_cache_t
*pc
; /* PWG mapping data */
1006 ppd_option_t
*input_slot
, /* InputSlot option */
1007 *media_type
, /* MediaType option */
1008 *output_bin
, /* OutputBin option */
1009 *color_model
, /* ColorModel option */
1010 *duplex
; /* Duplex option */
1011 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1012 pwg_map_t
*map
; /* Current source/type map */
1013 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1014 int num_options
; /* Number of preset options and props */
1015 cups_option_t
*options
; /* Preset options and properties */
1016 ppd_size_t
*ppd_size
; /* Current PPD size */
1017 pwg_size_t
*pwg_size
; /* Current PWG size */
1018 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1019 /* PWG keyword string */
1020 ppd_name
[PPD_MAX_NAME
];
1021 /* Normalized PPD name */
1022 const char *pwg_name
; /* Standard PWG media name */
1023 pwg_media_t
*pwg_media
; /* PWG media data */
1024 _pwg_print_color_mode_t pwg_print_color_mode
;
1025 /* print-color-mode index */
1026 _pwg_print_quality_t pwg_print_quality
;
1027 /* print-quality index */
1028 int similar
; /* Are the old and new size similar? */
1029 pwg_size_t
*old_size
; /* Current old size */
1030 int old_imageable
, /* Old imageable length in 2540ths */
1031 old_borderless
, /* Old borderless state */
1032 old_known_pwg
; /* Old PWG name is well-known */
1033 int new_width
, /* New width in 2540ths */
1034 new_length
, /* New length in 2540ths */
1035 new_left
, /* New left margin in 2540ths */
1036 new_bottom
, /* New bottom margin in 2540ths */
1037 new_right
, /* New right margin in 2540ths */
1038 new_top
, /* New top margin in 2540ths */
1039 new_imageable
, /* New imageable length in 2540ths */
1040 new_borderless
, /* New borderless state */
1041 new_known_pwg
; /* New PWG name is well-known */
1042 pwg_size_t
*new_size
; /* New size to add, if any */
1043 const char *filter
; /* Current filter */
1044 _pwg_finishings_t
*finishings
; /* Current finishings value */
1047 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1050 * Range check input...
1057 * Allocate memory...
1060 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1062 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1067 * Copy and convert size data...
1070 if (ppd
->num_sizes
> 0)
1072 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1074 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1075 "pwg_size_t's.", ppd
->num_sizes
));
1079 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1084 * Don't copy over custom size...
1087 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1091 * Convert the PPD size name to the corresponding PWG keyword name.
1094 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1097 * Standard name, do we have conflicts?
1100 for (j
= 0; j
< pc
->num_sizes
; j
++)
1101 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1111 * Standard name and no conflicts, use it!
1114 pwg_name
= pwg_media
->pwg
;
1120 * Not a standard name; convert it to a PWG vendor name of the form:
1122 * pp_lowerppd_WIDTHxHEIGHTuu
1125 pwg_name
= pwg_keyword
;
1128 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1129 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1130 PWG_FROM_POINTS(ppd_size
->width
),
1131 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1135 * If we have a similar paper with non-zero margins then we only want to
1136 * keep it if it has a larger imageable area length. The NULL check is for
1137 * dimensions that are <= 0...
1140 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1141 PWG_FROM_POINTS(ppd_size
->length
),
1145 new_width
= pwg_media
->width
;
1146 new_length
= pwg_media
->length
;
1147 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1148 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1149 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1150 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1151 new_imageable
= new_length
- new_top
- new_bottom
;
1152 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1153 new_left
== 0 && new_right
== 0;
1155 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1159 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1160 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1161 old_size
->right
== 0 && old_size
->top
== 0;
1162 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1163 strncmp(old_size
->map
.pwg
, "om_", 3);
1165 similar
= old_borderless
== new_borderless
&&
1166 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1167 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1170 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1173 * The new paper has a larger imageable area so it could replace
1174 * the older paper. Regardless of the imageable area, we always
1175 * prefer the size with a well-known PWG name.
1178 new_size
= old_size
;
1179 _cupsStrFree(old_size
->map
.ppd
);
1180 _cupsStrFree(old_size
->map
.pwg
);
1187 * The paper was unique enough to deserve its own entry so add it to the
1191 new_size
= pwg_size
++;
1201 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1202 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1203 new_size
->width
= new_width
;
1204 new_size
->length
= new_length
;
1205 new_size
->left
= new_left
;
1206 new_size
->bottom
= new_bottom
;
1207 new_size
->right
= new_right
;
1208 new_size
->top
= new_top
;
1213 if (ppd
->variable_sizes
)
1216 * Generate custom size data...
1219 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1220 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1221 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1222 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1223 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1224 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1226 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1227 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1228 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1229 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1230 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1231 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1233 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1234 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1235 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1236 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1240 * Copy and convert InputSlot data...
1243 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1244 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1248 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1250 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1252 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1253 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1257 pc
->num_sources
= input_slot
->num_choices
;
1259 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1262 i
--, choice
++, map
++)
1264 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1265 !_cups_strcasecmp(choice
->choice
, "Default"))
1267 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1269 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1271 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1273 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1274 !_cups_strcasecmp(choice
->choice
, "MP") ||
1275 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1276 pwg_name
= "by-pass-tray";
1277 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1278 pwg_name
= "large-capacity";
1279 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1280 pwg_name
= "bottom";
1281 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1282 pwg_name
= "middle";
1283 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1285 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1287 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1288 pwg_name
= "main-roll";
1292 * Convert PPD name to lowercase...
1295 pwg_name
= pwg_keyword
;
1296 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1300 map
->pwg
= _cupsStrAlloc(pwg_name
);
1301 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1306 * Copy and convert MediaType data...
1309 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1311 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1313 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1314 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1318 pc
->num_types
= media_type
->num_choices
;
1320 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1323 i
--, choice
++, map
++)
1325 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1326 !_cups_strcasecmp(choice
->choice
, "Any") ||
1327 !_cups_strcasecmp(choice
->choice
, "Default"))
1329 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1330 pwg_name
= "cardstock";
1331 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1332 pwg_name
= "envelope";
1333 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1334 pwg_name
= "photographic-glossy";
1335 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1336 pwg_name
= "photographic-high-gloss";
1337 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1338 pwg_name
= "photographic-matte";
1339 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1340 pwg_name
= "stationery";
1341 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1342 pwg_name
= "stationery-coated";
1343 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1344 pwg_name
= "stationery-inkjet";
1345 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1346 pwg_name
= "stationery-letterhead";
1347 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1348 pwg_name
= "stationery-preprinted";
1349 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1350 pwg_name
= "stationery-recycled";
1351 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1352 pwg_name
= "transparency";
1356 * Convert PPD name to lowercase...
1359 pwg_name
= pwg_keyword
;
1360 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1364 map
->pwg
= _cupsStrAlloc(pwg_name
);
1365 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1370 * Copy and convert OutputBin data...
1373 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1375 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1377 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1378 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1382 pc
->num_bins
= output_bin
->num_choices
;
1384 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1387 i
--, choice
++, map
++)
1389 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1391 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1392 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1396 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1399 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1402 const char *quality
, /* com.apple.print.preset.quality value */
1403 *output_mode
, /* com.apple.print.preset.output-mode value */
1404 *color_model_val
, /* ColorModel choice */
1405 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1406 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1410 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1413 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1414 num_options
, options
)) != NULL
)
1417 * Get the print-quality for this preset...
1420 if (!strcmp(quality
, "low"))
1421 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1422 else if (!strcmp(quality
, "high"))
1423 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1425 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1428 * Ignore graphicsType "Photo" presets that are not high quality.
1431 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1432 num_options
, options
);
1434 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1435 !strcmp(graphicsType
, "Photo"))
1439 * Ignore presets for normal and draft quality where the coating
1440 * isn't "none" or "autodetect".
1443 media_front_coating
= cupsGetOption(
1444 "com.apple.print.preset.media-front-coating",
1445 num_options
, options
);
1447 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1448 media_front_coating
&&
1449 strcmp(media_front_coating
, "none") &&
1450 strcmp(media_front_coating
, "autodetect"))
1454 * Get the output mode for this preset...
1457 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1458 num_options
, options
);
1459 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1463 if (!strcmp(output_mode
, "monochrome"))
1464 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1466 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1468 else if (color_model_val
)
1470 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1471 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1473 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1476 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1479 * Save the options for this combination as needed...
1482 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1483 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1484 _ppdParseOptions(ppd_attr
->value
, 0,
1485 pc
->presets
[pwg_print_color_mode
] +
1486 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1489 cupsFreeOptions(num_options
, options
);
1491 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1494 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1495 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1496 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1499 * Try adding some common color options to create grayscale presets. These
1500 * are listed in order of popularity...
1503 const char *color_option
= NULL
, /* Color control option */
1504 *gray_choice
= NULL
; /* Choice to select grayscale */
1506 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1507 ppdFindChoice(color_model
, "Gray"))
1509 color_option
= "ColorModel";
1510 gray_choice
= "Gray";
1512 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1513 ppdFindChoice(color_model
, "grayscale"))
1515 color_option
= "HPColorMode";
1516 gray_choice
= "grayscale";
1518 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1519 ppdFindChoice(color_model
, "Mono"))
1521 color_option
= "BRMonoColor";
1522 gray_choice
= "Mono";
1524 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1525 ppdFindChoice(color_model
, "1"))
1527 color_option
= "CNIJSGrayScale";
1530 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1531 ppdFindChoice(color_model
, "True"))
1533 color_option
= "HPColorAsGray";
1534 gray_choice
= "True";
1537 if (color_option
&& gray_choice
)
1540 * Copy and convert ColorModel (output-mode) data...
1543 cups_option_t
*coption
, /* Color option */
1544 *moption
; /* Monochrome option */
1546 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1547 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1548 pwg_print_quality
++)
1550 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1553 * Copy the color options...
1556 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1557 [pwg_print_quality
];
1558 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1562 for (i
= num_options
, moption
= options
,
1563 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1564 [pwg_print_quality
];
1566 i
--, moption
++, coption
++)
1568 moption
->name
= _cupsStrRetain(coption
->name
);
1569 moption
->value
= _cupsStrRetain(coption
->value
);
1572 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1574 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1578 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1582 * Add the grayscale option to the preset...
1585 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1586 cupsAddOption(color_option
, gray_choice
,
1587 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1588 [pwg_print_quality
],
1589 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1596 * Copy and convert Duplex (sides) data...
1599 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1600 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1601 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1602 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1603 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1607 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1609 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1613 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1614 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1615 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1616 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1617 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1618 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1619 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1620 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1621 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1622 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1623 !pc
->sides_2sided_short
)
1624 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1629 * Copy filters and pre-filters...
1632 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1633 (cups_acopy_func_t
)_cupsStrAlloc
,
1634 (cups_afree_func_t
)_cupsStrFree
);
1636 cupsArrayAdd(pc
->filters
,
1637 "application/vnd.cups-raw application/octet-stream 0 -");
1639 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1643 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1645 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1647 else if (ppd
->num_filters
> 0)
1649 for (i
= 0; i
< ppd
->num_filters
; i
++)
1650 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1653 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1656 * See if we have a command filter...
1659 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1661 filter
= (const char *)cupsArrayNext(pc
->filters
))
1662 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1663 _cups_isspace(filter
[28]))
1667 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1668 _cups_strcasecmp(ppd_attr
->value
, "none")))
1671 * No command filter and no cupsCommands keyword telling us not to use one.
1672 * See if this is a PostScript printer, and if so add a PostScript command
1676 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1678 filter
= (const char *)cupsArrayNext(pc
->filters
))
1679 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1680 _cups_isspace(filter
[31]))
1684 cupsArrayAdd(pc
->filters
,
1685 "application/vnd.cups-command application/postscript 100 "
1689 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1691 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1692 (cups_acopy_func_t
)_cupsStrAlloc
,
1693 (cups_afree_func_t
)_cupsStrFree
);
1697 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1699 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1702 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1703 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1706 * Copy the product string, if any...
1710 pc
->product
= _cupsStrAlloc(ppd
->product
);
1713 * Copy finishings mapping data...
1716 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1719 * Have proper vendor mapping of IPP finishings values to PPD options...
1722 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1723 NULL
, NULL
, 0, NULL
,
1724 (cups_afree_func_t
)pwg_free_finishings
);
1728 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1731 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1732 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1733 &(finishings
->options
),
1734 _PPD_PARSE_OPTIONS
);
1736 cupsArrayAdd(pc
->finishings
, finishings
);
1738 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1744 * No IPP mapping data, try to map common/standard PPD keywords...
1747 ppd_option_t
*ppd_option
; /* PPD option */
1749 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1751 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1754 * Add staple finishings...
1757 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1758 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1759 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1760 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1761 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1762 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1763 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1764 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1765 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1766 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1769 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1772 * Add (Ricoh) punch finishings...
1775 if (ppdFindChoice(ppd_option
, "Left2"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1777 if (ppdFindChoice(ppd_option
, "Left3"))
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1779 if (ppdFindChoice(ppd_option
, "Left4"))
1780 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1781 if (ppdFindChoice(ppd_option
, "Right2"))
1782 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1783 if (ppdFindChoice(ppd_option
, "Right3"))
1784 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1785 if (ppdFindChoice(ppd_option
, "Right4"))
1786 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1787 if (ppdFindChoice(ppd_option
, "Upper2"))
1788 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1789 if (ppdFindChoice(ppd_option
, "Upper3"))
1790 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1791 if (ppdFindChoice(ppd_option
, "Upper4"))
1792 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1795 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1798 * Add bind finishings...
1801 if (ppdFindChoice(ppd_option
, "Left"))
1802 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1803 if (ppdFindChoice(ppd_option
, "Right"))
1804 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1805 if (ppdFindChoice(ppd_option
, "Top"))
1806 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1807 if (ppdFindChoice(ppd_option
, "Bottom"))
1808 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1811 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1814 * Add (Adobe) fold finishings...
1817 if (ppdFindChoice(ppd_option
, "ZFold"))
1818 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1819 if (ppdFindChoice(ppd_option
, "Saddle"))
1820 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1821 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1822 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1823 if (ppdFindChoice(ppd_option
, "LeftGate"))
1824 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1825 if (ppdFindChoice(ppd_option
, "RightGate"))
1826 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1827 if (ppdFindChoice(ppd_option
, "Letter"))
1828 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1829 if (ppdFindChoice(ppd_option
, "XFold"))
1830 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1833 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1836 * Add (Ricoh) fold finishings...
1839 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1840 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1843 if (cupsArrayCount(pc
->finishings
) == 0)
1845 cupsArrayDelete(pc
->finishings
);
1846 pc
->finishings
= NULL
;
1854 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1855 pc
->max_copies
= atoi(ppd_attr
->value
);
1856 else if (ppd
->manual_copies
)
1859 pc
->max_copies
= 9999;
1862 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1863 * cupsJobPassword, and cupsMandatory.
1866 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1867 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1869 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1870 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1872 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1873 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1875 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1876 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1878 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1879 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1885 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1886 (cups_acopy_func_t
)_cupsStrAlloc
,
1887 (cups_afree_func_t
)_cupsStrFree
);
1889 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1891 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1892 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1894 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1895 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1901 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1902 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1904 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1905 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1907 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1908 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1910 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1911 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1913 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1915 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1918 * *cupsMaterial key/name: "name=value ... name=value"
1921 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1923 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1924 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1925 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1928 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1930 cupsArrayAdd(pc
->materials
, material
);
1934 * Return the cache data...
1940 * If we get here we need to destroy the PWG mapping data and return NULL...
1945 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1946 _ppdCacheDestroy(pc
);
1953 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1957 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1959 int i
; /* Looping var */
1960 pwg_map_t
*map
; /* Current map */
1961 pwg_size_t
*size
; /* Current size */
1965 * Range check input...
1972 * Free memory as needed...
1977 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1979 _cupsStrFree(map
->pwg
);
1980 _cupsStrFree(map
->ppd
);
1988 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1990 _cupsStrFree(size
->map
.pwg
);
1991 _cupsStrFree(size
->map
.ppd
);
1997 if (pc
->source_option
)
1998 _cupsStrFree(pc
->source_option
);
2002 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2004 _cupsStrFree(map
->pwg
);
2005 _cupsStrFree(map
->ppd
);
2013 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2015 _cupsStrFree(map
->pwg
);
2016 _cupsStrFree(map
->ppd
);
2022 if (pc
->custom_max_keyword
)
2023 _cupsStrFree(pc
->custom_max_keyword
);
2025 if (pc
->custom_min_keyword
)
2026 _cupsStrFree(pc
->custom_min_keyword
);
2028 _cupsStrFree(pc
->product
);
2029 cupsArrayDelete(pc
->filters
);
2030 cupsArrayDelete(pc
->prefilters
);
2031 cupsArrayDelete(pc
->finishings
);
2033 _cupsStrFree(pc
->charge_info_uri
);
2034 _cupsStrFree(pc
->password
);
2036 cupsArrayDelete(pc
->mandatory
);
2038 cupsArrayDelete(pc
->support_files
);
2040 _cupsStrFree(pc
->cups_3d
);
2041 _cupsStrFree(pc
->cups_layer_order
);
2043 cupsArrayDelete(pc
->materials
);
2050 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2054 const char * /* O - output-bin or NULL */
2056 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2057 const char *output_bin
) /* I - PPD OutputBin string */
2059 int i
; /* Looping var */
2063 * Range check input...
2066 if (!pc
|| !output_bin
)
2070 * Look up the OutputBin string...
2074 for (i
= 0; i
< pc
->num_bins
; i
++)
2075 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2076 return (pc
->bins
[i
].pwg
);
2083 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2084 * IPP finishings value(s).
2087 int /* O - New number of options */
2088 _ppdCacheGetFinishingOptions(
2089 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2090 ipp_t
*job
, /* I - Job attributes or NULL */
2091 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2092 int num_options
, /* I - Number of options */
2093 cups_option_t
**options
) /* IO - Options */
2095 int i
; /* Looping var */
2096 _pwg_finishings_t
*f
, /* PWG finishings options */
2097 key
; /* Search key */
2098 ipp_attribute_t
*attr
; /* Finishings attribute */
2099 cups_option_t
*option
; /* Current finishings option */
2103 * Range check input...
2106 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2107 (!job
&& value
== IPP_FINISHINGS_NONE
))
2108 return (num_options
);
2111 * Apply finishing options...
2114 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2116 int num_values
= ippGetCount(attr
); /* Number of values */
2118 for (i
= 0; i
< num_values
; i
++)
2120 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2122 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2124 int j
; /* Another looping var */
2126 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2127 num_options
= cupsAddOption(option
->name
, option
->value
,
2128 num_options
, options
);
2132 else if (value
!= IPP_FINISHINGS_NONE
)
2136 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2138 int j
; /* Another looping var */
2140 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2141 num_options
= cupsAddOption(option
->name
, option
->value
,
2142 num_options
, options
);
2146 return (num_options
);
2151 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2155 int /* O - Number of finishings values */
2156 _ppdCacheGetFinishingValues(
2157 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2158 int num_options
, /* I - Number of options */
2159 cups_option_t
*options
, /* I - Options */
2160 int max_values
, /* I - Maximum number of finishings values */
2161 int *values
) /* O - Finishings values */
2163 int i
, /* Looping var */
2164 num_values
= 0; /* Number of values */
2165 _pwg_finishings_t
*f
; /* Current finishings option */
2166 cups_option_t
*option
; /* Current option */
2167 const char *val
; /* Value for option */
2171 * Range check input...
2174 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2176 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2178 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2183 * Go through the finishings options and see what is set...
2186 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2188 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2190 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2192 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2194 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2196 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2197 _cups_strcasecmp(option
->value
, val
))
2199 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2206 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2208 values
[num_values
++] = f
->value
;
2210 if (num_values
>= max_values
)
2215 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2217 return (num_values
);
2222 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2223 * attributes or a keyword string.
2226 const char * /* O - PPD InputSlot or NULL */
2227 _ppdCacheGetInputSlot(
2228 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2229 ipp_t
*job
, /* I - Job attributes or NULL */
2230 const char *keyword
) /* I - Keyword string or NULL */
2233 * Range check input...
2236 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2239 if (job
&& !keyword
)
2242 * Lookup the media-col attribute and any media-source found there...
2245 ipp_attribute_t
*media_col
, /* media-col attribute */
2246 *media_source
; /* media-source attribute */
2247 pwg_size_t size
; /* Dimensional size */
2248 int margins_set
; /* Were the margins set? */
2250 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2252 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2254 IPP_TAG_KEYWORD
)) != NULL
)
2257 * Use the media-source value from media-col...
2260 keyword
= ippGetString(media_source
, 0, NULL
);
2262 else if (pwgInitSize(&size
, job
, &margins_set
))
2265 * For media <= 5x7, look for a photo tray...
2268 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2275 int i
; /* Looping var */
2277 for (i
= 0; i
< pc
->num_sources
; i
++)
2278 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2279 return (pc
->sources
[i
].ppd
);
2287 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2288 * attributes or a keyword string.
2291 const char * /* O - PPD MediaType or NULL */
2292 _ppdCacheGetMediaType(
2293 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2294 ipp_t
*job
, /* I - Job attributes or NULL */
2295 const char *keyword
) /* I - Keyword string or NULL */
2298 * Range check input...
2301 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2304 if (job
&& !keyword
)
2307 * Lookup the media-col attribute and any media-source found there...
2310 ipp_attribute_t
*media_col
, /* media-col attribute */
2311 *media_type
; /* media-type attribute */
2313 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2316 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2318 IPP_TAG_KEYWORD
)) == NULL
)
2319 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2320 "media-type", IPP_TAG_NAME
);
2323 keyword
= media_type
->values
[0].string
.text
;
2329 int i
; /* Looping var */
2331 for (i
= 0; i
< pc
->num_types
; i
++)
2332 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2333 return (pc
->types
[i
].ppd
);
2341 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2345 const char * /* O - PPD OutputBin or NULL */
2346 _ppdCacheGetOutputBin(
2347 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2348 const char *output_bin
) /* I - Keyword string */
2350 int i
; /* Looping var */
2354 * Range check input...
2357 if (!pc
|| !output_bin
)
2361 * Look up the OutputBin string...
2365 for (i
= 0; i
< pc
->num_bins
; i
++)
2366 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2367 return (pc
->bins
[i
].ppd
);
2374 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2375 * attributes or a keyword string.
2378 const char * /* O - PPD PageSize or NULL */
2379 _ppdCacheGetPageSize(
2380 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2381 ipp_t
*job
, /* I - Job attributes or NULL */
2382 const char *keyword
, /* I - Keyword string or NULL */
2383 int *exact
) /* O - 1 if exact match, 0 otherwise */
2385 int i
; /* Looping var */
2386 pwg_size_t
*size
, /* Current size */
2387 *closest
, /* Closest size */
2388 jobsize
; /* Size data from job */
2389 int margins_set
, /* Were the margins set? */
2390 dwidth
, /* Difference in width */
2391 dlength
, /* Difference in length */
2392 dleft
, /* Difference in left margins */
2393 dright
, /* Difference in right margins */
2394 dbottom
, /* Difference in bottom margins */
2395 dtop
, /* Difference in top margins */
2396 dmin
, /* Minimum difference */
2397 dclosest
; /* Closest difference */
2398 const char *ppd_name
; /* PPD media name */
2401 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2402 pc
, job
, keyword
, exact
));
2405 * Range check input...
2408 if (!pc
|| (!job
&& !keyword
))
2419 * Try getting the PPD media name from the job attributes...
2422 ipp_attribute_t
*attr
; /* Job attribute */
2424 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2425 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2426 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2430 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2431 attr
->name
, ippTagString(attr
->value_tag
)));
2433 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2436 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2437 attr
->value_tag
== IPP_TAG_KEYWORD
))
2438 ppd_name
= attr
->values
[0].string
.text
;
2441 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2446 * Try looking up the named PPD size first...
2449 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2451 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2452 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2454 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2455 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2460 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2462 return (size
->map
.ppd
);
2467 if (job
&& !keyword
)
2470 * Get the size using media-col or media, with the preference being
2474 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2480 * Get the size using a media keyword...
2483 pwg_media_t
*media
; /* Media definition */
2486 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2487 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2488 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2491 jobsize
.width
= media
->width
;
2492 jobsize
.length
= media
->length
;
2497 * Now that we have the dimensions and possibly the margins, look at the
2498 * available sizes and find the match...
2502 dclosest
= 999999999;
2504 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2505 _cups_strncasecmp(ppd_name
, "custom_", 7))
2507 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2510 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2511 * is just about 176/2540ths...
2514 dwidth
= size
->width
- jobsize
.width
;
2515 dlength
= size
->length
- jobsize
.length
;
2517 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2523 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2526 dleft
= size
->left
- jobsize
.left
;
2527 dright
= size
->right
- jobsize
.right
;
2528 dtop
= size
->top
- jobsize
.top
;
2529 dbottom
= size
->bottom
- jobsize
.bottom
;
2531 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2532 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2534 dleft
= dleft
< 0 ? -dleft
: dleft
;
2535 dright
= dright
< 0 ? -dright
: dright
;
2536 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2537 dtop
= dtop
< 0 ? -dtop
: dtop
;
2538 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2540 if (dmin
< dclosest
)
2553 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2555 return (size
->map
.ppd
);
2561 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2564 return (closest
->map
.ppd
);
2568 * If we get here we need to check for custom page size support...
2571 if (jobsize
.width
>= pc
->custom_min_width
&&
2572 jobsize
.width
<= pc
->custom_max_width
&&
2573 jobsize
.length
>= pc
->custom_min_length
&&
2574 jobsize
.length
<= pc
->custom_max_length
)
2577 * In range, format as Custom.WWWWxLLLL (points).
2580 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2581 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2583 if (margins_set
&& exact
)
2585 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2586 dright
= pc
->custom_size
.right
- jobsize
.right
;
2587 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2588 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2590 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2591 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2597 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2598 pc
->custom_ppd_size
));
2600 return (pc
->custom_ppd_size
);
2604 * No custom page size support or the size is out of range - return NULL.
2607 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2614 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2617 pwg_size_t
* /* O - PWG size or NULL */
2619 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2620 const char *page_size
) /* I - PPD PageSize */
2622 int i
; /* Looping var */
2623 pwg_media_t
*media
; /* Media */
2624 pwg_size_t
*size
; /* Current size */
2628 * Range check input...
2631 if (!pc
|| !page_size
)
2634 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2637 * Custom size; size name can be one of the following:
2639 * Custom.WIDTHxLENGTHin - Size in inches
2640 * Custom.WIDTHxLENGTHft - Size in feet
2641 * Custom.WIDTHxLENGTHcm - Size in centimeters
2642 * Custom.WIDTHxLENGTHmm - Size in millimeters
2643 * Custom.WIDTHxLENGTHm - Size in meters
2644 * Custom.WIDTHxLENGTH[pt] - Size in points
2647 double w
, l
; /* Width and length of page */
2648 char *ptr
; /* Pointer into PageSize */
2649 struct lconv
*loc
; /* Locale data */
2652 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2653 if (!ptr
|| *ptr
!= 'x')
2656 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2660 if (!_cups_strcasecmp(ptr
, "in"))
2665 else if (!_cups_strcasecmp(ptr
, "ft"))
2670 else if (!_cups_strcasecmp(ptr
, "mm"))
2675 else if (!_cups_strcasecmp(ptr
, "cm"))
2680 else if (!_cups_strcasecmp(ptr
, "m"))
2691 pc
->custom_size
.width
= (int)w
;
2692 pc
->custom_size
.length
= (int)l
;
2694 return (&(pc
->custom_size
));
2698 * Not a custom size - look it up...
2701 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2702 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2703 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2707 * Look up standard sizes...
2710 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2711 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2712 media
= pwgMediaForPWG(page_size
);
2716 pc
->custom_size
.width
= media
->width
;
2717 pc
->custom_size
.length
= media
->length
;
2719 return (&(pc
->custom_size
));
2727 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2731 const char * /* O - PWG media-source keyword */
2733 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2734 const char *input_slot
) /* I - PPD InputSlot */
2736 int i
; /* Looping var */
2737 pwg_map_t
*source
; /* Current source */
2741 * Range check input...
2744 if (!pc
|| !input_slot
)
2747 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2748 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2749 return (source
->pwg
);
2756 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2760 const char * /* O - PWG media-type keyword */
2762 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2763 const char *media_type
) /* I - PPD MediaType */
2765 int i
; /* Looping var */
2766 pwg_map_t
*type
; /* Current type */
2770 * Range check input...
2773 if (!pc
|| !media_type
)
2776 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2777 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2785 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2788 int /* O - 1 on success, 0 on failure */
2790 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2791 const char *filename
, /* I - File to write */
2792 ipp_t
*attrs
) /* I - Attributes to write, if any */
2794 int i
, j
, k
; /* Looping vars */
2795 cups_file_t
*fp
; /* Output file */
2796 pwg_size_t
*size
; /* Current size */
2797 pwg_map_t
*map
; /* Current map */
2798 _pwg_finishings_t
*f
; /* Current finishing option */
2799 cups_option_t
*option
; /* Current option */
2800 const char *value
; /* Filter/pre-filter value */
2801 char newfile
[1024]; /* New filename */
2802 _pwg_material_t
*m
; /* Material */
2806 * Range check input...
2809 if (!pc
|| !filename
)
2811 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2816 * Open the file and write with compression...
2819 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2820 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2822 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2827 * Standard header...
2830 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2836 if (pc
->num_bins
> 0)
2838 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2839 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2840 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2847 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2848 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2849 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2850 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2851 size
->bottom
, size
->right
, size
->top
);
2852 if (pc
->custom_max_width
> 0)
2853 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2854 pc
->custom_max_width
, pc
->custom_max_length
,
2855 pc
->custom_min_width
, pc
->custom_min_length
,
2856 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2857 pc
->custom_size
.right
, pc
->custom_size
.top
);
2863 if (pc
->source_option
)
2864 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2866 if (pc
->num_sources
> 0)
2868 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2869 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2870 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2877 if (pc
->num_types
> 0)
2879 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2880 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2881 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2888 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2889 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2890 if (pc
->num_presets
[i
][j
])
2892 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2893 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2896 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2897 cupsFilePutChar(fp
, '\n');
2904 if (pc
->sides_option
)
2905 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2907 if (pc
->sides_1sided
)
2908 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2910 if (pc
->sides_2sided_long
)
2911 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2913 if (pc
->sides_2sided_short
)
2914 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2917 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2921 cupsFilePutConf(fp
, "Product", pc
->product
);
2923 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2925 value
= (const char *)cupsArrayNext(pc
->filters
))
2926 cupsFilePutConf(fp
, "Filter", value
);
2928 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2930 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2931 cupsFilePutConf(fp
, "PreFilter", value
);
2933 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2936 * Finishing options...
2939 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2941 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2943 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2944 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2945 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2946 cupsFilePutChar(fp
, '\n');
2953 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2956 * Accounting/quota/PIN/managed printing values...
2959 if (pc
->charge_info_uri
)
2960 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2962 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2963 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2964 pc
->accounting_user_id
? "true" : "false");
2967 cupsFilePutConf(fp
, "Password", pc
->password
);
2969 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2971 value
= (char *)cupsArrayNext(pc
->mandatory
))
2972 cupsFilePutConf(fp
, "Mandatory", value
);
2978 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2980 value
= (char *)cupsArrayNext(pc
->support_files
))
2981 cupsFilePutConf(fp
, "SupportFile", value
);
2988 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2990 if (pc
->cups_layer_order
)
2991 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2993 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2994 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2996 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2997 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
2999 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
3001 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
3003 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
3004 for (i
= 0; i
< m
->num_props
; i
++)
3005 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
3006 cupsFilePuts(fp
, "\n");
3010 * IPP attributes, if any...
3015 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3017 attrs
->state
= IPP_STATE_IDLE
;
3018 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3022 * Close and return...
3025 if (cupsFileClose(fp
))
3032 return (!rename(newfile
, filename
));
3037 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3038 * of an IPP printer.
3041 char * /* O - PPD filename or @code NULL@ on error */
3042 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3043 size_t bufsize
, /* I - Size of filename buffer */
3044 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3046 cups_file_t
*fp
; /* PPD file */
3047 cups_array_t
*sizes
; /* Media sizes we've added */
3048 ipp_attribute_t
*attr
, /* xxx-supported */
3049 *defattr
, /* xxx-default */
3050 *quality
, /* print-quality-supported */
3051 *x_dim
, *y_dim
; /* Media dimensions */
3052 ipp_t
*media_size
; /* Media size collection */
3053 char make
[256], /* Make and model */
3054 *model
, /* Model name */
3055 ppdname
[PPD_MAX_NAME
];
3057 int i
, j
, /* Looping vars */
3058 count
, /* Number of values */
3059 bottom
, /* Largest bottom margin */
3060 left
, /* Largest left margin */
3061 right
, /* Largest right margin */
3062 top
, /* Largest top margin */
3063 is_apple
= 0, /* Does the printer support Apple raster? */
3064 is_pdf
= 0, /* Does the printer support PDF? */
3065 is_pwg
= 0; /* Does the printer support PWG Raster? */
3066 pwg_media_t
*pwg
; /* PWG media size */
3067 int xres
, yres
; /* Resolution values */
3068 cups_lang_t
*lang
= cupsLangDefault();
3069 /* Localization info */
3070 struct lconv
*loc
= localeconv();
3072 static const char * const finishings
[][2] =
3073 { /* Finishings strings */
3074 { "bale", _("Bale") },
3075 { "bind", _("Bind") },
3076 { "bind-bottom", _("Bind (Reverse Landscape)") },
3077 { "bind-left", _("Bind (Portrait)") },
3078 { "bind-right", _("Bind (Reverse Portrait)") },
3079 { "bind-top", _("Bind (Landscape)") },
3080 { "booklet-maker", _("Booklet Maker") },
3081 { "coat", _("Coat") },
3082 { "cover", _("Cover") },
3083 { "edge-stitch", _("Staple Edge") },
3084 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
3085 { "edge-stitch-left", _("Staple Edge (Portrait)") },
3086 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
3087 { "edge-stitch-top", _("Staple Edge (Landscape)") },
3088 { "fold", _("Fold") },
3089 { "fold-accordian", _("Accordian Fold") },
3090 { "fold-double-gate", _("Double Gate Fold") },
3091 { "fold-engineering-z", _("Engineering Z Fold") },
3092 { "fold-gate", _("Gate Fold") },
3093 { "fold-half", _("Half Fold") },
3094 { "fold-half-z", _("Half Z Fold") },
3095 { "fold-left-gate", _("Left Gate Fold") },
3096 { "fold-letter", _("Letter Fold") },
3097 { "fold-parallel", _("Parallel Fold") },
3098 { "fold-poster", _("Poster Fold") },
3099 { "fold-right-gate", _("Right Gate Fold") },
3100 { "fold-z", _("Z Fold") },
3101 { "jog-offset", _("Jog") },
3102 { "laminate", _("Laminate") },
3103 { "punch", _("Punch") },
3104 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3105 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3106 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3107 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3108 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3109 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3110 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3111 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3112 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3113 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3114 { "punch-top-left", _("Single Punch (Portrait)") },
3115 { "punch-top-right", _("Single Punch (Landscape)") },
3116 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3117 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3118 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3119 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3120 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3121 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3122 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3123 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3124 { "saddle-stitch", _("Saddle Stitch") },
3125 { "staple", _("Staple") },
3126 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3127 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3128 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3129 { "staple-dual-left", _("Double Staple (Portrait)") },
3130 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3131 { "staple-dual-top", _("Double Staple (Landscape)") },
3132 { "staple-top-left", _("Single Staple (Portrait)") },
3133 { "staple-top-right", _("Single Staple (Landscape)") },
3134 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3135 { "staple-triple-left", _("Triple Staple (Portrait)") },
3136 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3137 { "staple-triple-top", _("Triple Staple (Landscape)") },
3138 { "trim", _("Cut Media") }
3143 * Range check input...
3149 if (!buffer
|| bufsize
< 1)
3151 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3157 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3162 * Open a temporary file for the PPD...
3165 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3167 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3172 * Standard stuff for PPD file...
3175 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3176 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3177 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3178 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3179 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3180 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3181 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3182 cupsFilePuts(fp
, "*FileSystem: False\n");
3183 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3185 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3186 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3188 strlcpy(make
, "Unknown Printer", sizeof(make
));
3190 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3191 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3194 strlcpy(make
, "HP", sizeof(make
));
3196 else if ((model
= strchr(make
, ' ')) != NULL
)
3201 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3202 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3203 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3204 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3205 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3207 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3208 cupsFilePuts(fp
, "*ColorDevice: True\n");
3210 cupsFilePuts(fp
, "*ColorDevice: False\n");
3212 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3213 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3214 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3220 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3222 is_apple
= ippContainsString(attr
, "image/urf");
3223 is_pdf
= ippContainsString(attr
, "application/pdf");
3224 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3226 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3228 const char *format
= ippGetString(attr
, i
, NULL
);
3232 * Write cupsFilter2 lines for supported formats...
3235 if (!_cups_strcasecmp(format
, "application/pdf"))
3236 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3237 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3238 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3239 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3240 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3244 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3248 * PageSize/PageRegion/ImageableArea/PaperDimension
3251 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3253 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3254 if (ippGetInteger(attr
, i
) > bottom
)
3255 bottom
= ippGetInteger(attr
, i
);
3260 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3262 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3263 if (ippGetInteger(attr
, i
) > left
)
3264 left
= ippGetInteger(attr
, i
);
3269 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3271 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3272 if (ippGetInteger(attr
, i
) > right
)
3273 right
= ippGetInteger(attr
, i
);
3278 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3280 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3281 if (ippGetInteger(attr
, i
) > top
)
3282 top
= ippGetInteger(attr
, i
);
3287 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3289 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3291 media_size
= ippGetCollection(attr
, 0);
3292 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3293 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3295 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3296 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3298 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3301 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3303 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3304 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3306 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3308 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3309 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3312 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3313 "*OrderDependency: 10 AnySetup *PageSize\n"
3314 "*DefaultPageSize: %s\n", ppdname
);
3316 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3318 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3320 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3322 media_size
= ippGetCollection(attr
, i
);
3323 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3324 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3326 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3329 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3333 char twidth
[256], /* Width string */
3334 tlength
[256]; /* Length string */
3336 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3338 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3342 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3344 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3345 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3347 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3350 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3352 cupsArrayDelete(sizes
);
3353 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3355 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3356 "*OrderDependency: 10 AnySetup *PageRegion\n"
3357 "*DefaultPageRegion: %s\n", ppdname
);
3358 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3360 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3362 media_size
= ippGetCollection(attr
, i
);
3363 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3364 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3366 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3369 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3373 char twidth
[256], /* Width string */
3374 tlength
[256]; /* Length string */
3376 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3379 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3381 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3382 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3384 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3387 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3389 cupsArrayDelete(sizes
);
3390 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3392 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3393 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3394 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3396 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3398 media_size
= ippGetCollection(attr
, i
);
3399 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3400 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3402 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3405 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3409 char tleft
[256], /* Left string */
3410 tbottom
[256], /* Bottom string */
3411 tright
[256], /* Right string */
3412 ttop
[256], /* Top string */
3413 twidth
[256], /* Width string */
3414 tlength
[256]; /* Length string */
3416 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3419 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3421 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3422 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3423 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3424 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3425 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3426 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3428 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3429 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3433 cupsArrayDelete(sizes
);
3442 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3443 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3445 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3447 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3449 static const char * const sources
[][2] =
3450 { /* "media-source" strings */
3451 { "Auto", _("Automatic") },
3452 { "Main", _("Main") },
3453 { "Alternate", _("Alternate") },
3454 { "LargeCapacity", _("Large Capacity") },
3455 { "Manual", _("Manual") },
3456 { "Envelope", _("Envelope") },
3457 { "Disc", _("Disc") },
3458 { "Photo", _("Photo") },
3459 { "Hagaki", _("Hagaki") },
3460 { "MainRoll", _("Main Roll") },
3461 { "AlternateRoll", _("Alternate Roll") },
3462 { "Top", _("Top") },
3463 { "Middle", _("Middle") },
3464 { "Bottom", _("Bottom") },
3465 { "Side", _("Side") },
3466 { "Left", _("Left") },
3467 { "Right", _("Right") },
3468 { "Center", _("Center") },
3469 { "Rear", _("Rear") },
3470 { "ByPassTray", _("Multipurpose") },
3471 { "Tray1", _("Tray 1") },
3472 { "Tray2", _("Tray 2") },
3473 { "Tray3", _("Tray 3") },
3474 { "Tray4", _("Tray 4") },
3475 { "Tray5", _("Tray 5") },
3476 { "Tray6", _("Tray 6") },
3477 { "Tray7", _("Tray 7") },
3478 { "Tray8", _("Tray 8") },
3479 { "Tray9", _("Tray 9") },
3480 { "Tray10", _("Tray 10") },
3481 { "Tray11", _("Tray 11") },
3482 { "Tray12", _("Tray 12") },
3483 { "Tray13", _("Tray 13") },
3484 { "Tray14", _("Tray 14") },
3485 { "Tray15", _("Tray 15") },
3486 { "Tray16", _("Tray 16") },
3487 { "Tray17", _("Tray 17") },
3488 { "Tray18", _("Tray 18") },
3489 { "Tray19", _("Tray 19") },
3490 { "Tray20", _("Tray 20") },
3491 { "Roll1", _("Roll 1") },
3492 { "Roll2", _("Roll 2") },
3493 { "Roll3", _("Roll 3") },
3494 { "Roll4", _("Roll 4") },
3495 { "Roll5", _("Roll 5") },
3496 { "Roll6", _("Roll 6") },
3497 { "Roll7", _("Roll 7") },
3498 { "Roll8", _("Roll 8") },
3499 { "Roll9", _("Roll 9") },
3500 { "Roll10", _("Roll 10") }
3503 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3504 "*OrderDependency: 10 AnySetup *InputSlot\n"
3505 "*DefaultInputSlot: %s\n", ppdname
);
3506 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3508 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3510 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3511 if (!strcmp(sources
[j
][0], ppdname
))
3513 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3517 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3524 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3525 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3527 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3529 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3531 static const char * const media_types
[][2] =
3532 { /* "media-type" strings */
3533 { "aluminum", _("Aluminum") },
3534 { "auto", _("Automatic") },
3535 { "back-print-film", _("Back Print Film") },
3536 { "cardboard", _("Cardboard") },
3537 { "cardstock", _("Cardstock") },
3539 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3540 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3541 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3542 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3543 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3544 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3545 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3546 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3547 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3548 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3549 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3550 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3551 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3552 { "continuous", _("Continuous") },
3553 { "continuous-long", _("Continuous Long") },
3554 { "continuous-short", _("Continuous Short") },
3555 { "disc", _("Optical Disc") },
3556 { "disc-glossy", _("Glossy Optical Disc") },
3557 { "disc-high-gloss", _("High Gloss Optical Disc") },
3558 { "disc-matte", _("Matte Optical Disc") },
3559 { "disc-satin", _("Satin Optical Disc") },
3560 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3561 { "double-wall", _("Double Wall Cardboard") },
3562 { "dry-film", _("Dry Film") },
3563 { "dvd", _("DVD") },
3564 { "embossing-foil", _("Embossing Foil") },
3565 { "end-board", _("End Board") },
3566 { "envelope", _("Envelope") },
3567 { "envelope-archival", _("Archival Envelope") },
3568 { "envelope-bond", _("Bond Envelope") },
3569 { "envelope-coated", _("Coated Envelope") },
3570 { "envelope-cotton", _("Cotton Envelope") },
3571 { "envelope-fine", _("Fine Envelope") },
3572 { "envelope-heavyweight", _("Heavyweight Envelope") },
3573 { "envelope-inkjet", _("Inkjet Envelope") },
3574 { "envelope-lightweight", _("Lightweight Envelope") },
3575 { "envelope-plain", _("Plain Envelope") },
3576 { "envelope-preprinted", _("Preprinted Envelope") },
3577 { "envelope-window", _("Windowed Envelope") },
3578 { "fabric", _("Fabric") },
3579 { "fabric-archival", _("Archival Fabric") },
3580 { "fabric-glossy", _("Glossy Fabric") },
3581 { "fabric-high-gloss", _("High Gloss Fabric") },
3582 { "fabric-matte", _("Matte Fabric") },
3583 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3584 { "fabric-waterproof", _("Waterproof Fabric") },
3585 { "film", _("Film") },
3586 { "flexo-base", _("Flexo Base") },
3587 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3588 { "flute", _("Flute") },
3589 { "foil", _("Foil") },
3590 { "full-cut-tabs", _("Full Cut Tabs") },
3591 { "glass", _("Glass") },
3592 { "glass-colored", _("Glass Colored") },
3593 { "glass-opaque", _("Glass Opaque") },
3594 { "glass-surfaced", _("Glass Surfaced") },
3595 { "glass-textured", _("Glass Textured") },
3596 { "gravure-cylinder", _("Gravure Cylinder") },
3597 { "image-setter-paper", _("Image Setter Paper") },
3598 { "imaging-cylinder", _("Imaging Cylinder") },
3599 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3600 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3601 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3602 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3603 { "labels", _("Labels") },
3604 { "labels-colored", _("Colored Labels") },
3605 { "labels-glossy", _("Glossy Labels") },
3606 { "labels-high-gloss", _("High Gloss Labels") },
3607 { "labels-inkjet", _("Inkjet Labels") },
3608 { "labels-matte", _("Matte Labels") },
3609 { "labels-permanent", _("Permanent Labels") },
3610 { "labels-satin", _("Satin Labels") },
3611 { "labels-security", _("Security Labels") },
3612 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3613 { "laminating-foil", _("Laminating Foil") },
3614 { "letterhead", _("Letterhead") },
3615 { "metal", _("Metal") },
3616 { "metal-glossy", _("Metal Glossy") },
3617 { "metal-high-gloss", _("Metal High Gloss") },
3618 { "metal-matte", _("Metal Matte") },
3619 { "metal-satin", _("Metal Satin") },
3620 { "metal-semi-gloss", _("Metal Semi Gloss") },
3621 { "mounting-tape", _("Mounting Tape") },
3622 { "multi-layer", _("Multi Layer") },
3623 { "multi-part-form", _("Multi Part Form") },
3624 { "other", _("Other") },
3625 { "paper", _("Paper") },
3626 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3627 { "photographic", _("Photo Paper") },
3628 { "photographic-archival", _("Archival Photo Paper") },
3629 { "photographic-film", _("Photo Film") },
3630 { "photographic-glossy", _("Glossy Photo Paper") },
3631 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3632 { "photographic-matte", _("Matte Photo Paper") },
3633 { "photographic-satin", _("Satin Photo Paper") },
3634 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3635 { "plastic", _("Plastic") },
3636 { "plastic-archival", _("Plastic Archival") },
3637 { "plastic-colored", _("Plastic Colored") },
3638 { "plastic-glossy", _("Plastic Glossy") },
3639 { "plastic-high-gloss", _("Plastic High Gloss") },
3640 { "plastic-matte", _("Plastic Matte") },
3641 { "plastic-satin", _("Plastic Satin") },
3642 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3643 { "plate", _("Plate") },
3644 { "polyester", _("Polyester") },
3645 { "pre-cut-tabs", _("Pre Cut Tabs") },
3646 { "roll", _("Roll") },
3647 { "screen", _("Screen") },
3648 { "screen-paged", _("Screen Paged") },
3649 { "self-adhesive", _("Self Adhesive") },
3650 { "self-adhesive-film", _("Self Adhesive Film") },
3651 { "shrink-foil", _("Shrink Foil") },
3652 { "single-face", _("Single Face") },
3653 { "single-wall", _("Single Wall Cardboard") },
3654 { "sleeve", _("Sleeve") },
3655 { "stationery", _("Plain Paper") },
3656 { "stationery-archival", _("Archival Paper") },
3657 { "stationery-coated", _("Coated Paper") },
3658 { "stationery-cotton", _("Cotton Paper") },
3659 { "stationery-fine", _("Vellum Paper") },
3660 { "stationery-heavyweight", _("Heavyweight Paper") },
3661 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3662 { "stationery-inkjet", _("Inkjet Paper") },
3663 { "stationery-letterhead", _("Letterhead") },
3664 { "stationery-lightweight", _("Lightweight Paper") },
3665 { "stationery-preprinted", _("Preprinted Paper") },
3666 { "stationery-prepunched", _("Punched Paper") },
3667 { "tab-stock", _("Tab Stock") },
3668 { "tractor", _("Tractor") },
3669 { "transfer", _("Transfer") },
3670 { "transparency", _("Transparency") },
3671 { "triple-wall", _("Triple Wall Cardboard") },
3672 { "wet-film", _("Wet Film") }
3675 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3676 "*OrderDependency: 10 AnySetup *MediaType\n"
3677 "*DefaultMediaType: %s\n", ppdname
);
3678 for (i
= 0; i
< count
; i
++)
3680 const char *keyword
= ippGetString(attr
, i
, NULL
);
3682 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3684 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3685 if (!strcmp(keyword
, media_types
[j
][0]))
3688 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3689 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3691 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, keyword
, ppdname
);
3693 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3700 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3701 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3702 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3703 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3707 const char *default_color
= NULL
; /* Default */
3709 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3711 const char *keyword
= ippGetString(attr
, i
, NULL
);
3712 /* Keyword for color/bit depth */
3714 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3717 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3718 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3720 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3723 default_color
= "FastGray";
3725 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3728 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3729 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3731 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3733 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3734 default_color
= "Gray";
3736 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3739 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3740 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3742 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3744 default_color
= "RGB";
3746 else if (!strcmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3749 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3750 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3752 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3755 default_color
= "AdobeRGB";
3761 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3762 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3770 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3772 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3773 "*OrderDependency: 10 AnySetup *Duplex\n"
3774 "*DefaultDuplex: None\n"
3775 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3776 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3777 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3778 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3780 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3782 const char *keyword
= ippGetString(attr
, 0, NULL
);
3785 if (!strcmp(keyword
, "flipped"))
3786 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3787 else if (!strcmp(keyword
, "manual-tumble"))
3788 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3789 else if (!strcmp(keyword
, "normal"))
3790 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3792 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3794 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3796 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3798 const char *dm
= ippGetString(attr
, i
, NULL
);
3801 if (!_cups_strcasecmp(dm
, "DM1"))
3803 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3806 else if (!_cups_strcasecmp(dm
, "DM2"))
3808 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3811 else if (!_cups_strcasecmp(dm
, "DM3"))
3813 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3816 else if (!_cups_strcasecmp(dm
, "DM4"))
3818 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3829 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3830 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3832 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3834 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3836 static const char * const output_bins
[][2] =
3837 { /* "output-bin" strings */
3838 { "auto", _("Automatic") },
3839 { "bottom", _("Bottom Tray") },
3840 { "center", _("Center Tray") },
3841 { "face-down", _("Face Down") },
3842 { "face-up", _("Face Up") },
3843 { "large-capacity", _("Large Capacity Tray") },
3844 { "left", _("Left Tray") },
3845 { "mailbox-1", _("Mailbox 1") },
3846 { "mailbox-2", _("Mailbox 2") },
3847 { "mailbox-3", _("Mailbox 3") },
3848 { "mailbox-4", _("Mailbox 4") },
3849 { "mailbox-5", _("Mailbox 5") },
3850 { "mailbox-6", _("Mailbox 6") },
3851 { "mailbox-7", _("Mailbox 7") },
3852 { "mailbox-8", _("Mailbox 8") },
3853 { "mailbox-9", _("Mailbox 9") },
3854 { "mailbox-10", _("Mailbox 10") },
3855 { "middle", _("Middle") },
3856 { "my-mailbox", _("My Mailbox") },
3857 { "rear", _("Rear Tray") },
3858 { "right", _("Right Tray") },
3859 { "side", _("Side Tray") },
3860 { "stacker-1", _("Stacker 1") },
3861 { "stacker-2", _("Stacker 2") },
3862 { "stacker-3", _("Stacker 3") },
3863 { "stacker-4", _("Stacker 4") },
3864 { "stacker-5", _("Stacker 5") },
3865 { "stacker-6", _("Stacker 6") },
3866 { "stacker-7", _("Stacker 7") },
3867 { "stacker-8", _("Stacker 8") },
3868 { "stacker-9", _("Stacker 9") },
3869 { "stacker-10", _("Stacker 10") },
3870 { "top", _("Top Tray") },
3871 { "tray-1", _("Tray 1") },
3872 { "tray-2", _("Tray 2") },
3873 { "tray-3", _("Tray 3") },
3874 { "tray-4", _("Tray 4") },
3875 { "tray-5", _("Tray 5") },
3876 { "tray-6", _("Tray 6") },
3877 { "tray-7", _("Tray 7") },
3878 { "tray-8", _("Tray 8") },
3879 { "tray-9", _("Tray 9") },
3880 { "tray-10", _("Tray 10") }
3883 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3884 "*OrderDependency: 10 AnySetup *OutputBin\n"
3885 "*DefaultOutputBin: %s\n", ppdname
);
3886 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3888 if (!ippContainsString(attr
, output_bins
[i
][0]))
3891 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3893 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3895 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3899 * Finishing options...
3901 * Eventually need to re-add support for finishings-col-database, however
3902 * it is difficult to map arbitrary finishing-template values to PPD options
3903 * and have the right constraints apply (e.g. stapling vs. folding vs.
3907 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3909 const char *name
; /* String name */
3910 int value
; /* Enum value */
3911 cups_array_t
*names
; /* Names we've added */
3913 count
= ippGetCount(attr
);
3914 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3917 * Staple/Bind/Stitch
3920 for (i
= 0; i
< count
; i
++)
3922 value
= ippGetInteger(attr
, i
);
3923 name
= ippEnumString("finishings", value
);
3925 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3931 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3932 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3933 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3934 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3936 for (; i
< count
; i
++)
3938 value
= ippGetInteger(attr
, i
);
3939 name
= ippEnumString("finishings", value
);
3941 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3944 if (cupsArrayFind(names
, (char *)name
))
3945 continue; /* Already did this finishing template */
3947 cupsArrayAdd(names
, (char *)name
);
3949 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3951 if (!strcmp(finishings
[j
][0], name
))
3953 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3954 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3960 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3967 for (i
= 0; i
< count
; i
++)
3969 value
= ippGetInteger(attr
, i
);
3970 name
= ippEnumString("finishings", value
);
3972 if (!strncmp(name
, "fold-", 5))
3978 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3979 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3980 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3981 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3983 for (; i
< count
; i
++)
3985 value
= ippGetInteger(attr
, i
);
3986 name
= ippEnumString("finishings", value
);
3988 if (strncmp(name
, "fold-", 5))
3991 if (cupsArrayFind(names
, (char *)name
))
3992 continue; /* Already did this finishing template */
3994 cupsArrayAdd(names
, (char *)name
);
3996 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3998 if (!strcmp(finishings
[j
][0], name
))
4000 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
4001 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
4007 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
4014 for (i
= 0; i
< count
; i
++)
4016 value
= ippGetInteger(attr
, i
);
4017 name
= ippEnumString("finishings", value
);
4019 if (!strncmp(name
, "punch-", 6))
4025 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
4026 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4027 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4028 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4030 for (i
= 0; i
< count
; i
++)
4032 value
= ippGetInteger(attr
, i
);
4033 name
= ippEnumString("finishings", value
);
4035 if (strncmp(name
, "punch-", 6))
4038 if (cupsArrayFind(names
, (char *)name
))
4039 continue; /* Already did this finishing template */
4041 cupsArrayAdd(names
, (char *)name
);
4043 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
4045 if (!strcmp(finishings
[j
][0], name
))
4047 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
4048 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
4054 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4061 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4063 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
4064 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4065 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4066 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4067 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4068 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4069 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4072 cupsArrayDelete(names
);
4076 * cupsPrintQuality and DefaultResolution...
4079 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4081 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4083 count
= ippGetCount(attr
);
4085 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4086 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4088 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4089 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4090 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4091 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4093 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4094 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4096 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
4097 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4098 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4101 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
4103 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4104 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4107 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4109 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4111 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4113 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4115 const char *rs
= ippGetString(attr
, i
, NULL
);
4118 if (_cups_strncasecmp(rs
, "RS", 2))
4121 lowdpi
= atoi(rs
+ 2);
4122 if ((rs
= strrchr(rs
, '-')) != NULL
)
4123 hidpi
= atoi(rs
+ 1);
4132 * Invalid "urf-supported" value...
4140 * Generate print qualities based on low and high DPIs...
4143 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4145 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4146 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4147 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4148 if ((lowdpi
& 1) == 0)
4149 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4150 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4151 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4152 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4153 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4154 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4155 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4158 else if (is_apple
|| is_pwg
)
4162 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4164 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4169 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4172 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4174 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4175 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4176 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4177 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4178 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4179 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4180 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4181 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4182 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4186 * Close up and return...
4194 * If we get here then there was a problem creating the PPD...
4203 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4210 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4214 const char * /* O - InputSlot name */
4215 _pwgInputSlotForSource(
4216 const char *media_source
, /* I - PWG media-source */
4217 char *name
, /* I - Name buffer */
4218 size_t namesize
) /* I - Size of name buffer */
4221 * Range check input...
4224 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4227 if (_cups_strcasecmp(media_source
, "main"))
4228 strlcpy(name
, "Cassette", namesize
);
4229 else if (_cups_strcasecmp(media_source
, "alternate"))
4230 strlcpy(name
, "Multipurpose", namesize
);
4231 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4232 strlcpy(name
, "LargeCapacity", namesize
);
4233 else if (_cups_strcasecmp(media_source
, "bottom"))
4234 strlcpy(name
, "Lower", namesize
);
4235 else if (_cups_strcasecmp(media_source
, "middle"))
4236 strlcpy(name
, "Middle", namesize
);
4237 else if (_cups_strcasecmp(media_source
, "top"))
4238 strlcpy(name
, "Upper", namesize
);
4239 else if (_cups_strcasecmp(media_source
, "rear"))
4240 strlcpy(name
, "Rear", namesize
);
4241 else if (_cups_strcasecmp(media_source
, "side"))
4242 strlcpy(name
, "Side", namesize
);
4243 else if (_cups_strcasecmp(media_source
, "envelope"))
4244 strlcpy(name
, "Envelope", namesize
);
4245 else if (_cups_strcasecmp(media_source
, "main-roll"))
4246 strlcpy(name
, "Roll", namesize
);
4247 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4248 strlcpy(name
, "Roll2", namesize
);
4250 pwg_ppdize_name(media_source
, name
, namesize
);
4257 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4261 const char * /* O - MediaType name */
4262 _pwgMediaTypeForType(
4263 const char *media_type
, /* I - PWG media-type */
4264 char *name
, /* I - Name buffer */
4265 size_t namesize
) /* I - Size of name buffer */
4268 * Range check input...
4271 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4274 if (_cups_strcasecmp(media_type
, "auto"))
4275 strlcpy(name
, "Auto", namesize
);
4276 else if (_cups_strcasecmp(media_type
, "cardstock"))
4277 strlcpy(name
, "Cardstock", namesize
);
4278 else if (_cups_strcasecmp(media_type
, "envelope"))
4279 strlcpy(name
, "Envelope", namesize
);
4280 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4281 strlcpy(name
, "Glossy", namesize
);
4282 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4283 strlcpy(name
, "HighGloss", namesize
);
4284 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4285 strlcpy(name
, "Matte", namesize
);
4286 else if (_cups_strcasecmp(media_type
, "stationery"))
4287 strlcpy(name
, "Plain", namesize
);
4288 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4289 strlcpy(name
, "Coated", namesize
);
4290 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4291 strlcpy(name
, "Inkjet", namesize
);
4292 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4293 strlcpy(name
, "Letterhead", namesize
);
4294 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4295 strlcpy(name
, "Preprinted", namesize
);
4296 else if (_cups_strcasecmp(media_type
, "transparency"))
4297 strlcpy(name
, "Transparency", namesize
);
4299 pwg_ppdize_name(media_type
, name
, namesize
);
4306 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4309 const char * /* O - PageSize name */
4310 _pwgPageSizeForMedia(
4311 pwg_media_t
*media
, /* I - Media */
4312 char *name
, /* I - PageSize name buffer */
4313 size_t namesize
) /* I - Size of name buffer */
4315 const char *sizeptr
, /* Pointer to size in PWG name */
4316 *dimptr
; /* Pointer to dimensions in PWG name */
4320 * Range check input...
4323 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4327 * Copy or generate a PageSize name...
4333 * Use a standard Adobe name...
4336 strlcpy(name
, media
->ppd
, namesize
);
4338 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4339 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4340 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4341 (size_t)(dimptr
- sizeptr
) > namesize
)
4344 * Use a name of the form "wNNNhNNN"...
4347 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4348 (int)PWG_TO_POINTS(media
->length
));
4353 * Copy the size name from class_sizename_dimensions...
4356 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4357 name
[dimptr
- sizeptr
- 1] = '\0';
4365 * 'pwg_add_finishing()' - Add a finishings value.
4370 cups_array_t
*finishings
, /* I - Finishings array */
4371 ipp_finishings_t
template, /* I - Finishing template */
4372 const char *name
, /* I - PPD option */
4373 const char *value
) /* I - PPD choice */
4375 _pwg_finishings_t
*f
; /* New finishings value */
4378 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4380 f
->value
= template;
4381 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4383 cupsArrayAdd(finishings
, f
);
4389 * 'pwg_compare_finishings()' - Compare two finishings values.
4392 static int /* O - Result of comparison */
4393 pwg_compare_finishings(
4394 _pwg_finishings_t
*a
, /* I - First finishings value */
4395 _pwg_finishings_t
*b
) /* I - Second finishings value */
4397 return ((int)b
->value
- (int)a
->value
);
4402 * 'pwg_free_finishings()' - Free a finishings value.
4406 pwg_free_finishings(
4407 _pwg_finishings_t
*f
) /* I - Finishings value */
4409 cupsFreeOptions(f
->num_options
, f
->options
);
4415 * 'pwg_free_material()' - Free a material value.
4419 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
4421 _cupsStrFree(m
->key
);
4422 _cupsStrFree(m
->name
);
4424 cupsFreeOptions(m
->num_props
, m
->props
);
4431 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4435 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4436 char *name
, /* I - Name buffer */
4437 size_t namesize
) /* I - Size of name buffer */
4439 char *ptr
, /* Pointer into name buffer */
4440 *end
; /* End of name buffer */
4449 *name
= (char)toupper(*ipp
++);
4451 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4453 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4456 *ptr
++ = (char)toupper(*ipp
++ & 255);
4467 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4471 pwg_ppdize_resolution(
4472 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4473 int element
, /* I - Element to convert */
4474 int *xres
, /* O - X resolution in DPI */
4475 int *yres
, /* O - Y resolution in DPI */
4476 char *name
, /* I - Name buffer */
4477 size_t namesize
) /* I - Size of name buffer */
4479 ipp_res_t units
; /* Units for resolution */
4482 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4484 if (units
== IPP_RES_PER_CM
)
4486 *xres
= (int)(*xres
* 2.54);
4487 *yres
= (int)(*yres
* 2.54);
4490 if (name
&& namesize
> 4)
4493 snprintf(name
, namesize
, "%ddpi", *xres
);
4495 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4501 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4505 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4506 char *name
, /* I - Name buffer */
4507 size_t namesize
, /* I - Size of name buffer */
4508 const char *dashchars
)/* I - Characters to be replaced by dashes */
4510 char *ptr
, /* Pointer into name buffer */
4511 *end
; /* End of name buffer */
4514 if (_cups_islower(*ppd
))
4517 * Already lowercase name, use as-is?
4520 const char *ppdptr
; /* Pointer into PPD keyword */
4522 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4523 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4528 strlcpy(name
, ppd
, namesize
);
4533 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4535 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4536 *ptr
++ = (char)tolower(*ppd
& 255);
4537 else if (strchr(dashchars
, *ppd
))
4542 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4543 _cups_isupper(ppd
[1]) && ptr
< end
)
4545 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))