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 */
54 _cupsConvertOptions(ipp_t
*request
, /* I - IPP request */
55 ppd_file_t
*ppd
, /* I - PPD file */
56 _ppd_cache_t
*pc
, /* I - PPD cache info */
57 ipp_attribute_t
*media_col_sup
,
58 /* I - media-col-supported values */
59 ipp_attribute_t
*doc_handling_sup
,
60 /* I - multiple-document-handling-supported values */
61 ipp_attribute_t
*print_color_mode_sup
,
62 /* I - Printer supports print-color-mode */
63 const char *user
, /* I - User info */
64 const char *format
, /* I - document-format value */
65 int copies
, /* I - Number of copies */
66 int num_options
, /* I - Number of options */
67 cups_option_t
*options
) /* I - Options */
69 int i
; /* Looping var */
70 const char *keyword
, /* PWG keyword */
71 *password
; /* Password string */
72 pwg_size_t
*size
; /* PWG media size */
73 ipp_t
*media_col
, /* media-col value */
74 *media_size
; /* media-size value */
75 const char *media_source
, /* media-source value */
76 *media_type
, /* media-type value */
77 *collate_str
, /* multiple-document-handling value */
78 *color_attr_name
, /* Supported color attribute */
79 *mandatory
; /* Mandatory attributes */
80 int num_finishings
= 0, /* Number of finishing values */
81 finishings
[10]; /* Finishing enum values */
82 ppd_choice_t
*choice
; /* Marked choice */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "job-account-id") &&
145 strcmp(mandatory
, "job-accounting-user-id") &&
146 strcmp(mandatory
, "job-password") &&
147 strcmp(mandatory
, "job-password-encryption") &&
148 strcmp(mandatory
, "media") &&
149 strncmp(mandatory
, "media-col", 9) &&
150 strcmp(mandatory
, "multiple-document-handling") &&
151 strcmp(mandatory
, "output-bin") &&
152 strcmp(mandatory
, "print-color-mode") &&
153 strcmp(mandatory
, "print-quality") &&
154 strcmp(mandatory
, "sides") &&
155 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
157 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
159 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
164 case IPP_TAG_INTEGER
:
166 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
168 case IPP_TAG_BOOLEAN
:
169 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
173 int lower
, upper
; /* Range */
175 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
176 lower
= upper
= atoi(keyword
);
178 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
181 case IPP_TAG_STRING
:
182 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
185 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
187 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
188 keyword
= "auto-monochrome";
189 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
190 keyword
= "process-monochrome";
193 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
199 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
200 keyword
= cupsGetOption("media", num_options
, options
);
202 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
205 * Add a media-col value...
208 media_size
= ippNew();
209 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
210 "x-dimension", size
->width
);
211 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
212 "y-dimension", size
->length
);
214 media_col
= ippNew();
215 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
217 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
220 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
224 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
226 if (!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 (!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 (!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 (!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 (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
235 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
236 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && 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 *x_dim
, *y_dim
; /* Media dimensions */
3051 ipp_t
*media_size
; /* Media size collection */
3052 char make
[256], /* Make and model */
3053 *model
, /* Model name */
3054 ppdname
[PPD_MAX_NAME
];
3056 int i
, j
, /* Looping vars */
3057 count
, /* Number of values */
3058 bottom
, /* Largest bottom margin */
3059 left
, /* Largest left margin */
3060 right
, /* Largest right margin */
3061 top
, /* Largest top margin */
3062 is_apple
= 0, /* Does the printer support Apple raster? */
3063 is_pdf
= 0, /* Does the printer support PDF? */
3064 is_pwg
= 0; /* Does the printer support PWG Raster? */
3065 pwg_media_t
*pwg
; /* PWG media size */
3066 int xres
, yres
; /* Resolution values */
3067 cups_lang_t
*lang
= cupsLangDefault();
3068 /* Localization info */
3069 struct lconv
*loc
= localeconv();
3071 static const char * const finishings
[][2] =
3072 { /* Finishings strings */
3073 { "bale", _("Bale") },
3074 { "bind", _("Bind") },
3075 { "bind-bottom", _("Bind (Reverse Landscape)") },
3076 { "bind-left", _("Bind (Portrait)") },
3077 { "bind-right", _("Bind (Reverse Portrait)") },
3078 { "bind-top", _("Bind (Landscape)") },
3079 { "booklet-maker", _("Booklet Maker") },
3080 { "coat", _("Coat") },
3081 { "cover", _("Cover") },
3082 { "edge-stitch", _("Staple Edge") },
3083 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
3084 { "edge-stitch-left", _("Staple Edge (Portrait)") },
3085 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
3086 { "edge-stitch-top", _("Staple Edge (Landscape)") },
3087 { "fold", _("Fold") },
3088 { "fold-accordian", _("Accordian Fold") },
3089 { "fold-double-gate", _("Double Gate Fold") },
3090 { "fold-engineering-z", _("Engineering Z Fold") },
3091 { "fold-gate", _("Gate Fold") },
3092 { "fold-half", _("Half Fold") },
3093 { "fold-half-z", _("Half Z Fold") },
3094 { "fold-left-gate", _("Left Gate Fold") },
3095 { "fold-letter", _("Letter Fold") },
3096 { "fold-parallel", _("Parallel Fold") },
3097 { "fold-poster", _("Poster Fold") },
3098 { "fold-right-gate", _("Right Gate Fold") },
3099 { "fold-z", _("Z Fold") },
3100 { "jog-offset", _("Jog") },
3101 { "laminate", _("Laminate") },
3102 { "punch", _("Punch") },
3103 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3104 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3105 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3106 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3107 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3108 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3109 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3110 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3111 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3112 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3113 { "punch-top-left", _("Single Punch (Portrait)") },
3114 { "punch-top-right", _("Single Punch (Landscape)") },
3115 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3116 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3117 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3118 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3119 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3120 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3121 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3122 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3123 { "saddle-stitch", _("Saddle Stitch") },
3124 { "staple", _("Staple") },
3125 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3126 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3127 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3128 { "staple-dual-left", _("Double Staple (Portrait)") },
3129 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3130 { "staple-dual-top", _("Double Staple (Landscape)") },
3131 { "staple-top-left", _("Single Staple (Portrait)") },
3132 { "staple-top-right", _("Single Staple (Landscape)") },
3133 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3134 { "staple-triple-left", _("Triple Staple (Portrait)") },
3135 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3136 { "staple-triple-top", _("Triple Staple (Landscape)") },
3137 { "trim", _("Cut Media") }
3142 * Range check input...
3148 if (!buffer
|| bufsize
< 1 || !response
)
3152 * Open a temporary file for the PPD...
3155 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3159 * Standard stuff for PPD file...
3162 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3163 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3164 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3165 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3166 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3167 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3168 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3169 cupsFilePuts(fp
, "*FileSystem: False\n");
3170 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3172 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3173 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3175 strlcpy(make
, "Unknown Printer", sizeof(make
));
3177 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3178 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3181 strlcpy(make
, "HP", sizeof(make
));
3183 else if ((model
= strchr(make
, ' ')) != NULL
)
3188 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3189 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3190 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3191 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3192 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3194 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3195 cupsFilePuts(fp
, "*ColorDevice: True\n");
3197 cupsFilePuts(fp
, "*ColorDevice: False\n");
3199 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3200 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3201 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3207 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3209 is_apple
= ippContainsString(attr
, "image/urf");
3210 is_pdf
= ippContainsString(attr
, "application/pdf");
3211 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3213 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3215 const char *format
= ippGetString(attr
, i
, NULL
);
3219 * Write cupsFilter2 lines for supported formats...
3222 if (!_cups_strcasecmp(format
, "application/pdf"))
3223 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3224 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3225 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3226 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3227 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3231 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3235 * PageSize/PageRegion/ImageableArea/PaperDimension
3238 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3240 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3241 if (ippGetInteger(attr
, i
) > bottom
)
3242 bottom
= ippGetInteger(attr
, i
);
3247 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3249 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3250 if (ippGetInteger(attr
, i
) > left
)
3251 left
= ippGetInteger(attr
, i
);
3256 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3258 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3259 if (ippGetInteger(attr
, i
) > right
)
3260 right
= ippGetInteger(attr
, i
);
3265 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3267 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3268 if (ippGetInteger(attr
, i
) > top
)
3269 top
= ippGetInteger(attr
, i
);
3274 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3276 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3278 media_size
= ippGetCollection(attr
, 0);
3279 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3280 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3282 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3283 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3285 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3288 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3290 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3291 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3293 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3295 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3296 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3299 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3300 "*OrderDependency: 10 AnySetup *PageSize\n"
3301 "*DefaultPageSize: %s\n", ppdname
);
3303 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3305 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3307 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3309 media_size
= ippGetCollection(attr
, i
);
3310 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3311 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3313 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3316 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3320 char twidth
[256], /* Width string */
3321 tlength
[256]; /* Length string */
3323 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3325 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3329 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3331 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3332 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3334 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3337 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3339 cupsArrayDelete(sizes
);
3340 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3342 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3343 "*OrderDependency: 10 AnySetup *PageRegion\n"
3344 "*DefaultPageRegion: %s\n", ppdname
);
3345 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3347 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3349 media_size
= ippGetCollection(attr
, i
);
3350 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3351 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3353 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3356 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3360 char twidth
[256], /* Width string */
3361 tlength
[256]; /* Length string */
3363 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3366 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3368 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3369 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3371 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3374 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3376 cupsArrayDelete(sizes
);
3377 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3379 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3380 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3381 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3383 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3385 media_size
= ippGetCollection(attr
, i
);
3386 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3387 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3389 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3392 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3396 char tleft
[256], /* Left string */
3397 tbottom
[256], /* Bottom string */
3398 tright
[256], /* Right string */
3399 ttop
[256], /* Top string */
3400 twidth
[256], /* Width string */
3401 tlength
[256]; /* Length string */
3403 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3406 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3408 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3409 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3410 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3411 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3412 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3413 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3415 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3416 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3420 cupsArrayDelete(sizes
);
3429 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3430 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3432 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3434 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3436 static const char * const sources
[][2] =
3437 { /* "media-source" strings */
3438 { "Auto", _("Automatic") },
3439 { "Main", _("Main") },
3440 { "Alternate", _("Alternate") },
3441 { "LargeCapacity", _("Large Capacity") },
3442 { "Manual", _("Manual") },
3443 { "Envelope", _("Envelope") },
3444 { "Disc", _("Disc") },
3445 { "Photo", _("Photo") },
3446 { "Hagaki", _("Hagaki") },
3447 { "MainRoll", _("Main Roll") },
3448 { "AlternateRoll", _("Alternate Roll") },
3449 { "Top", _("Top") },
3450 { "Middle", _("Middle") },
3451 { "Bottom", _("Bottom") },
3452 { "Side", _("Side") },
3453 { "Left", _("Left") },
3454 { "Right", _("Right") },
3455 { "Center", _("Center") },
3456 { "Rear", _("Rear") },
3457 { "ByPassTray", _("Multipurpose") },
3458 { "Tray1", _("Tray 1") },
3459 { "Tray2", _("Tray 2") },
3460 { "Tray3", _("Tray 3") },
3461 { "Tray4", _("Tray 4") },
3462 { "Tray5", _("Tray 5") },
3463 { "Tray6", _("Tray 6") },
3464 { "Tray7", _("Tray 7") },
3465 { "Tray8", _("Tray 8") },
3466 { "Tray9", _("Tray 9") },
3467 { "Tray10", _("Tray 10") },
3468 { "Tray11", _("Tray 11") },
3469 { "Tray12", _("Tray 12") },
3470 { "Tray13", _("Tray 13") },
3471 { "Tray14", _("Tray 14") },
3472 { "Tray15", _("Tray 15") },
3473 { "Tray16", _("Tray 16") },
3474 { "Tray17", _("Tray 17") },
3475 { "Tray18", _("Tray 18") },
3476 { "Tray19", _("Tray 19") },
3477 { "Tray20", _("Tray 20") },
3478 { "Roll1", _("Roll 1") },
3479 { "Roll2", _("Roll 2") },
3480 { "Roll3", _("Roll 3") },
3481 { "Roll4", _("Roll 4") },
3482 { "Roll5", _("Roll 5") },
3483 { "Roll6", _("Roll 6") },
3484 { "Roll7", _("Roll 7") },
3485 { "Roll8", _("Roll 8") },
3486 { "Roll9", _("Roll 9") },
3487 { "Roll10", _("Roll 10") }
3490 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3491 "*OrderDependency: 10 AnySetup *InputSlot\n"
3492 "*DefaultInputSlot: %s\n", ppdname
);
3493 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3495 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3497 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3498 if (!strcmp(sources
[j
][0], ppdname
))
3500 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3504 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3511 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3512 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3514 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3516 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3518 static const char * const media_types
[][2] =
3519 { /* "media-type" strings */
3520 { "aluminum", _("Aluminum") },
3521 { "auto", _("Automatic") },
3522 { "back-print-film", _("Back Print Film") },
3523 { "cardboard", _("Cardboard") },
3524 { "cardstock", _("Cardstock") },
3526 { "continuous", _("Continuous") },
3527 { "continuous-long", _("Continuous Long") },
3528 { "continuous-short", _("Continuous Short") },
3529 { "disc", _("Optical Disc") },
3530 { "disc-glossy", _("Glossy Optical Disc") },
3531 { "disc-high-gloss", _("High Gloss Optical Disc") },
3532 { "disc-matte", _("Matte Optical Disc") },
3533 { "disc-satin", _("Satin Optical Disc") },
3534 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3535 { "double-wall", _("Double Wall Cardboard") },
3536 { "dry-film", _("Dry Film") },
3537 { "dvd", _("DVD") },
3538 { "embossing-foil", _("Embossing Foil") },
3539 { "end-board", _("End Board") },
3540 { "envelope", _("Envelope") },
3541 { "envelope-archival", _("Archival Envelope") },
3542 { "envelope-bond", _("Bond Envelope") },
3543 { "envelope-coated", _("Coated Envelope") },
3544 { "envelope-cotton", _("Cotton Envelope") },
3545 { "envelope-fine", _("Fine Envelope") },
3546 { "envelope-heavyweight", _("Heavyweight Envelope") },
3547 { "envelope-inkjet", _("Inkjet Envelope") },
3548 { "envelope-lightweight", _("Lightweight Envelope") },
3549 { "envelope-plain", _("Plain Envelope") },
3550 { "envelope-preprinted", _("Preprinted Envelope") },
3551 { "envelope-window", _("Windowed Envelope") },
3552 { "fabric", _("Fabric") },
3553 { "fabric-archival", _("Archival Fabric") },
3554 { "fabric-glossy", _("Glossy Fabric") },
3555 { "fabric-high-gloss", _("High Gloss Fabric") },
3556 { "fabric-matte", _("Matte Fabric") },
3557 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3558 { "fabric-waterproof", _("Waterproof Fabric") },
3559 { "film", _("Film") },
3560 { "flexo-base", _("Flexo Base") },
3561 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3562 { "flute", _("Flute") },
3563 { "foil", _("Foil") },
3564 { "full-cut-tabs", _("Full Cut Tabs") },
3565 { "glass", _("Glass") },
3566 { "glass-colored", _("Glass Colored") },
3567 { "glass-opaque", _("Glass Opaque") },
3568 { "glass-surfaced", _("Glass Surfaced") },
3569 { "glass-textured", _("Glass Textured") },
3570 { "gravure-cylinder", _("Gravure Cylinder") },
3571 { "image-setter-paper", _("Image Setter Paper") },
3572 { "imaging-cylinder", _("Imaging Cylinder") },
3573 { "labels", _("Labels") },
3574 { "labels-colored", _("Colored Labels") },
3575 { "labels-glossy", _("Glossy Labels") },
3576 { "labels-high-gloss", _("High Gloss Labels") },
3577 { "labels-inkjet", _("Inkjet Labels") },
3578 { "labels-matte", _("Matte Labels") },
3579 { "labels-permanent", _("Permanent Labels") },
3580 { "labels-satin", _("Satin Labels") },
3581 { "labels-security", _("Security Labels") },
3582 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3583 { "laminating-foil", _("Laminating Foil") },
3584 { "letterhead", _("Letterhead") },
3585 { "metal", _("Metal") },
3586 { "metal-glossy", _("Metal Glossy") },
3587 { "metal-high-gloss", _("Metal High Gloss") },
3588 { "metal-matte", _("Metal Matte") },
3589 { "metal-satin", _("Metal Satin") },
3590 { "metal-semi-gloss", _("Metal Semi Gloss") },
3591 { "mounting-tape", _("Mounting Tape") },
3592 { "multi-layer", _("Multi Layer") },
3593 { "multi-part-form", _("Multi Part Form") },
3594 { "other", _("Other") },
3595 { "paper", _("Paper") },
3596 { "photographic", _("Photo Paper") },
3597 { "photographic-archival", _("Photographic Archival") },
3598 { "photographic-film", _("Photo Film") },
3599 { "photographic-glossy", _("Glossy Photo Paper") },
3600 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3601 { "photographic-matte", _("Matte Photo Paper") },
3602 { "photographic-satin", _("Satin Photo Paper") },
3603 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3604 { "plastic", _("Plastic") },
3605 { "plastic-archival", _("Plastic Archival") },
3606 { "plastic-colored", _("Plastic Colored") },
3607 { "plastic-glossy", _("Plastic Glossy") },
3608 { "plastic-high-gloss", _("Plastic High Gloss") },
3609 { "plastic-matte", _("Plastic Matte") },
3610 { "plastic-satin", _("Plastic Satin") },
3611 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3612 { "plate", _("Plate") },
3613 { "polyester", _("Polyester") },
3614 { "pre-cut-tabs", _("Pre Cut Tabs") },
3615 { "roll", _("Roll") },
3616 { "screen", _("Screen") },
3617 { "screen-paged", _("Screen Paged") },
3618 { "self-adhesive", _("Self Adhesive") },
3619 { "self-adhesive-film", _("Self Adhesive Film") },
3620 { "shrink-foil", _("Shrink Foil") },
3621 { "single-face", _("Single Face") },
3622 { "single-wall", _("Single Wall Cardboard") },
3623 { "sleeve", _("Sleeve") },
3624 { "stationery", _("Stationery") },
3625 { "stationery-archival", _("Stationery Archival") },
3626 { "stationery-coated", _("Coated Paper") },
3627 { "stationery-cotton", _("Stationery Cotton") },
3628 { "stationery-fine", _("Vellum Paper") },
3629 { "stationery-heavyweight", _("Heavyweight Paper") },
3630 { "stationery-heavyweight-coated", _("Stationery Heavyweight Coated") },
3631 { "stationery-inkjet", _("Stationery Inkjet Paper") },
3632 { "stationery-letterhead", _("Letterhead") },
3633 { "stationery-lightweight", _("Lightweight Paper") },
3634 { "stationery-preprinted", _("Preprinted Paper") },
3635 { "stationery-prepunched", _("Punched Paper") },
3636 { "tab-stock", _("Tab Stock") },
3637 { "tractor", _("Tractor") },
3638 { "transfer", _("Transfer") },
3639 { "transparency", _("Transparency") },
3640 { "triple-wall", _("Triple Wall Cardboard") },
3641 { "wet-film", _("Wet Film") }
3644 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3645 "*OrderDependency: 10 AnySetup *MediaType\n"
3646 "*DefaultMediaType: %s\n", ppdname
);
3647 for (i
= 0; i
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); i
++)
3649 if (!ippContainsString(attr
, media_types
[i
][0]))
3652 pwg_ppdize_name(media_types
[i
][0], ppdname
, sizeof(ppdname
));
3654 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[i
][1]), ppdname
);
3656 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3663 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3664 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3665 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3666 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3670 const char *default_color
= NULL
; /* Default */
3672 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3674 const char *keyword
= ippGetString(attr
, i
, NULL
);
3675 /* Keyword for color/bit depth */
3677 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3680 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3681 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3683 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3686 default_color
= "FastGray";
3688 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3691 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3692 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3694 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3696 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3697 default_color
= "Gray";
3699 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3702 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3703 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3705 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3707 default_color
= "RGB";
3709 else if (!strcmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3712 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3713 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3715 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3718 default_color
= "AdobeRGB";
3724 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3725 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3733 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3735 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3736 "*OrderDependency: 10 AnySetup *Duplex\n"
3737 "*DefaultDuplex: None\n"
3738 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3739 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3740 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3741 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3743 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3745 const char *keyword
= ippGetString(attr
, 0, NULL
);
3748 if (!strcmp(keyword
, "flipped"))
3749 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3750 else if (!strcmp(keyword
, "manual-tumble"))
3751 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3752 else if (!strcmp(keyword
, "normal"))
3753 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3755 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3757 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3759 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3761 const char *dm
= ippGetString(attr
, i
, NULL
);
3764 if (!_cups_strcasecmp(dm
, "DM1"))
3766 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3769 else if (!_cups_strcasecmp(dm
, "DM2"))
3771 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3774 else if (!_cups_strcasecmp(dm
, "DM3"))
3776 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3779 else if (!_cups_strcasecmp(dm
, "DM4"))
3781 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3792 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3793 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3795 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3797 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3799 static const char * const output_bins
[][2] =
3800 { /* "output-bin" strings */
3801 { "auto", _("Automatic") },
3802 { "bottom", _("Bottom Tray") },
3803 { "center", _("Center Tray") },
3804 { "face-down", _("Face Down") },
3805 { "face-up", _("Face Up") },
3806 { "large-capacity", _("Large Capacity Tray") },
3807 { "left", _("Left Tray") },
3808 { "mailbox-1", _("Mailbox 1") },
3809 { "mailbox-2", _("Mailbox 2") },
3810 { "mailbox-3", _("Mailbox 3") },
3811 { "mailbox-4", _("Mailbox 4") },
3812 { "mailbox-5", _("Mailbox 5") },
3813 { "mailbox-6", _("Mailbox 6") },
3814 { "mailbox-7", _("Mailbox 7") },
3815 { "mailbox-8", _("Mailbox 8") },
3816 { "mailbox-9", _("Mailbox 9") },
3817 { "mailbox-10", _("Mailbox 10") },
3818 { "middle", _("Middle") },
3819 { "my-mailbox", _("My Mailbox") },
3820 { "rear", _("Rear Tray") },
3821 { "right", _("Right Tray") },
3822 { "side", _("Side Tray") },
3823 { "stacker-1", _("Stacker 1") },
3824 { "stacker-2", _("Stacker 2") },
3825 { "stacker-3", _("Stacker 3") },
3826 { "stacker-4", _("Stacker 4") },
3827 { "stacker-5", _("Stacker 5") },
3828 { "stacker-6", _("Stacker 6") },
3829 { "stacker-7", _("Stacker 7") },
3830 { "stacker-8", _("Stacker 8") },
3831 { "stacker-9", _("Stacker 9") },
3832 { "stacker-10", _("Stacker 10") },
3833 { "top", _("Top Tray") },
3834 { "tray-1", _("Tray 1") },
3835 { "tray-2", _("Tray 2") },
3836 { "tray-3", _("Tray 3") },
3837 { "tray-4", _("Tray 4") },
3838 { "tray-5", _("Tray 5") },
3839 { "tray-6", _("Tray 6") },
3840 { "tray-7", _("Tray 7") },
3841 { "tray-8", _("Tray 8") },
3842 { "tray-9", _("Tray 9") },
3843 { "tray-10", _("Tray 10") }
3846 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3847 "*OrderDependency: 10 AnySetup *OutputBin\n"
3848 "*DefaultOutputBin: %s\n", ppdname
);
3849 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3851 if (!ippContainsString(attr
, output_bins
[i
][0]))
3854 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3856 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3858 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3862 * Finishing options...
3865 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3867 ipp_t
*col
; /* Collection value */
3868 ipp_attribute_t
*template; /* "finishing-template" member */
3869 const char *name
; /* String name */
3870 int value
; /* Enum value, if any */
3871 cups_array_t
*names
; /* Names we've added */
3873 count
= ippGetCount(attr
);
3874 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3876 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3877 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3878 "*DefaultcupsFinishingTemplate: none\n"
3879 "*cupsFinishingTemplate none/%s: \"\"\n"
3880 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3882 for (i
= 0; i
< count
; i
++)
3884 col
= ippGetCollection(attr
, i
);
3885 template = ippFindAttribute(col
, "finishing-template", IPP_TAG_ZERO
);
3887 if ((name
= ippGetString(template, 0, NULL
)) == NULL
|| !strcmp(name
, "none"))
3890 if (cupsArrayFind(names
, (char *)name
))
3891 continue; /* Already did this finishing template */
3893 cupsArrayAdd(names
, (char *)name
);
3895 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3897 if (!strcmp(finishings
[j
][0], name
))
3899 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3901 value
= ippEnumValue("finishings", name
);
3904 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3910 cupsArrayDelete(names
);
3912 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3914 else if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
&& (count
= ippGetCount(attr
)) > 1 )
3916 const char *name
; /* String name */
3917 int value
; /* Enum value, if any */
3919 count
= ippGetCount(attr
);
3921 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3922 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3923 "*DefaultcupsFinishingTemplate: none\n"
3924 "*cupsFinishingTemplate none/%s: \"\"\n"
3925 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3927 for (i
= 0; i
< count
; i
++)
3929 if ((value
= ippGetInteger(attr
, i
)) == 3)
3932 name
= ippEnumString("finishings", value
);
3933 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3935 if (!strcmp(finishings
[j
][0], name
))
3937 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3938 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3944 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3948 * cupsPrintQuality and DefaultResolution...
3951 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3953 count
= ippGetCount(attr
);
3955 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3956 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3958 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3959 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3960 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
3963 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3964 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
3966 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3967 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
3970 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3971 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
3974 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3976 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3978 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3980 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3982 const char *rs
= ippGetString(attr
, i
, NULL
);
3985 if (_cups_strncasecmp(rs
, "RS", 2))
3988 lowdpi
= atoi(rs
+ 2);
3989 if ((rs
= strrchr(rs
, '-')) != NULL
)
3990 hidpi
= atoi(rs
+ 1);
3999 * Invalid "urf-supported" value...
4007 * Generate print qualities based on low and high DPIs...
4010 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4012 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4013 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4014 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4015 if ((lowdpi
& 1) == 0)
4016 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4017 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4019 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4020 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4023 else if (is_apple
|| is_pwg
)
4025 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4027 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4028 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4031 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
4034 * Close up and return...
4042 * If we get here then there was a problem creating the PPD...
4056 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4060 const char * /* O - InputSlot name */
4061 _pwgInputSlotForSource(
4062 const char *media_source
, /* I - PWG media-source */
4063 char *name
, /* I - Name buffer */
4064 size_t namesize
) /* I - Size of name buffer */
4067 * Range check input...
4070 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4073 if (_cups_strcasecmp(media_source
, "main"))
4074 strlcpy(name
, "Cassette", namesize
);
4075 else if (_cups_strcasecmp(media_source
, "alternate"))
4076 strlcpy(name
, "Multipurpose", namesize
);
4077 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4078 strlcpy(name
, "LargeCapacity", namesize
);
4079 else if (_cups_strcasecmp(media_source
, "bottom"))
4080 strlcpy(name
, "Lower", namesize
);
4081 else if (_cups_strcasecmp(media_source
, "middle"))
4082 strlcpy(name
, "Middle", namesize
);
4083 else if (_cups_strcasecmp(media_source
, "top"))
4084 strlcpy(name
, "Upper", namesize
);
4085 else if (_cups_strcasecmp(media_source
, "rear"))
4086 strlcpy(name
, "Rear", namesize
);
4087 else if (_cups_strcasecmp(media_source
, "side"))
4088 strlcpy(name
, "Side", namesize
);
4089 else if (_cups_strcasecmp(media_source
, "envelope"))
4090 strlcpy(name
, "Envelope", namesize
);
4091 else if (_cups_strcasecmp(media_source
, "main-roll"))
4092 strlcpy(name
, "Roll", namesize
);
4093 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4094 strlcpy(name
, "Roll2", namesize
);
4096 pwg_ppdize_name(media_source
, name
, namesize
);
4103 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4107 const char * /* O - MediaType name */
4108 _pwgMediaTypeForType(
4109 const char *media_type
, /* I - PWG media-type */
4110 char *name
, /* I - Name buffer */
4111 size_t namesize
) /* I - Size of name buffer */
4114 * Range check input...
4117 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4120 if (_cups_strcasecmp(media_type
, "auto"))
4121 strlcpy(name
, "Auto", namesize
);
4122 else if (_cups_strcasecmp(media_type
, "cardstock"))
4123 strlcpy(name
, "Cardstock", namesize
);
4124 else if (_cups_strcasecmp(media_type
, "envelope"))
4125 strlcpy(name
, "Envelope", namesize
);
4126 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4127 strlcpy(name
, "Glossy", namesize
);
4128 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4129 strlcpy(name
, "HighGloss", namesize
);
4130 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4131 strlcpy(name
, "Matte", namesize
);
4132 else if (_cups_strcasecmp(media_type
, "stationery"))
4133 strlcpy(name
, "Plain", namesize
);
4134 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4135 strlcpy(name
, "Coated", namesize
);
4136 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4137 strlcpy(name
, "Inkjet", namesize
);
4138 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4139 strlcpy(name
, "Letterhead", namesize
);
4140 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4141 strlcpy(name
, "Preprinted", namesize
);
4142 else if (_cups_strcasecmp(media_type
, "transparency"))
4143 strlcpy(name
, "Transparency", namesize
);
4145 pwg_ppdize_name(media_type
, name
, namesize
);
4152 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4155 const char * /* O - PageSize name */
4156 _pwgPageSizeForMedia(
4157 pwg_media_t
*media
, /* I - Media */
4158 char *name
, /* I - PageSize name buffer */
4159 size_t namesize
) /* I - Size of name buffer */
4161 const char *sizeptr
, /* Pointer to size in PWG name */
4162 *dimptr
; /* Pointer to dimensions in PWG name */
4166 * Range check input...
4169 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4173 * Copy or generate a PageSize name...
4179 * Use a standard Adobe name...
4182 strlcpy(name
, media
->ppd
, namesize
);
4184 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4185 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4186 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4187 (size_t)(dimptr
- sizeptr
) > namesize
)
4190 * Use a name of the form "wNNNhNNN"...
4193 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4194 (int)PWG_TO_POINTS(media
->length
));
4199 * Copy the size name from class_sizename_dimensions...
4202 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4203 name
[dimptr
- sizeptr
- 1] = '\0';
4211 * 'pwg_add_finishing()' - Add a finishings value.
4216 cups_array_t
*finishings
, /* I - Finishings array */
4217 ipp_finishings_t
template, /* I - Finishing template */
4218 const char *name
, /* I - PPD option */
4219 const char *value
) /* I - PPD choice */
4221 _pwg_finishings_t
*f
; /* New finishings value */
4224 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4226 f
->value
= template;
4227 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4229 cupsArrayAdd(finishings
, f
);
4235 * 'pwg_compare_finishings()' - Compare two finishings values.
4238 static int /* O - Result of comparison */
4239 pwg_compare_finishings(
4240 _pwg_finishings_t
*a
, /* I - First finishings value */
4241 _pwg_finishings_t
*b
) /* I - Second finishings value */
4243 return ((int)b
->value
- (int)a
->value
);
4248 * 'pwg_free_finishings()' - Free a finishings value.
4252 pwg_free_finishings(
4253 _pwg_finishings_t
*f
) /* I - Finishings value */
4255 cupsFreeOptions(f
->num_options
, f
->options
);
4261 * 'pwg_free_material()' - Free a material value.
4265 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
4267 _cupsStrFree(m
->key
);
4268 _cupsStrFree(m
->name
);
4270 cupsFreeOptions(m
->num_props
, m
->props
);
4277 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4281 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4282 char *name
, /* I - Name buffer */
4283 size_t namesize
) /* I - Size of name buffer */
4285 char *ptr
, /* Pointer into name buffer */
4286 *end
; /* End of name buffer */
4295 *name
= (char)toupper(*ipp
++);
4297 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4299 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4302 *ptr
++ = (char)toupper(*ipp
++ & 255);
4313 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4317 pwg_ppdize_resolution(
4318 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4319 int element
, /* I - Element to convert */
4320 int *xres
, /* O - X resolution in DPI */
4321 int *yres
, /* O - Y resolution in DPI */
4322 char *name
, /* I - Name buffer */
4323 size_t namesize
) /* I - Size of name buffer */
4325 ipp_res_t units
; /* Units for resolution */
4328 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4330 if (units
== IPP_RES_PER_CM
)
4332 *xres
= (int)(*xres
* 2.54);
4333 *yres
= (int)(*yres
* 2.54);
4336 if (name
&& namesize
> 4)
4339 snprintf(name
, namesize
, "%ddpi", *xres
);
4341 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4347 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4351 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4352 char *name
, /* I - Name buffer */
4353 size_t namesize
, /* I - Size of name buffer */
4354 const char *dashchars
)/* I - Characters to be replaced by dashes */
4356 char *ptr
, /* Pointer into name buffer */
4357 *end
; /* End of name buffer */
4360 if (_cups_islower(*ppd
))
4363 * Already lowercase name, use as-is?
4366 const char *ppdptr
; /* Pointer into PPD keyword */
4368 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4369 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4374 strlcpy(name
, ppd
, namesize
);
4379 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4381 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4382 *ptr
++ = (char)tolower(*ppd
& 255);
4383 else if (strchr(dashchars
, *ppd
))
4388 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4389 _cups_isupper(ppd
[1]) && ptr
< end
)
4391 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))