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_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
40 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
41 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
42 const char *dashchars
);
46 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
48 * This functions converts PPD and CUPS-specific options to their standard IPP
49 * attributes and values and adds them to the specified IPP request.
52 int /* O - New number of copies */
54 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
, /* I - media-col-supported values */
58 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
59 ipp_attribute_t
*print_color_mode_sup
,
60 /* I - Printer supports print-color-mode */
61 const char *user
, /* I - User info */
62 const char *format
, /* I - document-format value */
63 int copies
, /* I - Number of copies */
64 int num_options
, /* I - Number of options */
65 cups_option_t
*options
) /* I - Options */
67 int i
; /* Looping var */
68 const char *keyword
, /* PWG keyword */
69 *password
; /* Password string */
70 pwg_size_t
*size
; /* PWG media size */
71 ipp_t
*media_col
, /* media-col value */
72 *media_size
; /* media-size value */
73 const char *media_source
, /* media-source value */
74 *media_type
, /* media-type value */
75 *collate_str
, /* multiple-document-handling value */
76 *color_attr_name
, /* Supported color attribute */
77 *mandatory
; /* Mandatory attributes */
78 int num_finishings
= 0, /* Number of finishing values */
79 finishings
[10]; /* Finishing enum values */
80 ppd_choice_t
*choice
; /* Marked choice */
84 * Send standard IPP attributes...
87 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
89 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
91 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
94 if (!strcmp(keyword
, "none"))
97 * Add plain-text job-password...
100 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
105 * Add hashed job-password...
108 unsigned char hash
[64]; /* Hash of password */
109 ssize_t hashlen
; /* Length of hash */
111 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
112 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
116 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
121 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
122 keyword
= cupsGetOption("job-billing", num_options
, options
);
125 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
128 if (pc
->accounting_user_id
)
130 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
134 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
137 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
139 if (strcmp(mandatory
, "copies") &&
140 strcmp(mandatory
, "destination-uris") &&
141 strcmp(mandatory
, "finishings") &&
142 strcmp(mandatory
, "job-account-id") &&
143 strcmp(mandatory
, "job-accounting-user-id") &&
144 strcmp(mandatory
, "job-password") &&
145 strcmp(mandatory
, "job-password-encryption") &&
146 strcmp(mandatory
, "media") &&
147 strncmp(mandatory
, "media-col", 9) &&
148 strcmp(mandatory
, "multiple-document-handling") &&
149 strcmp(mandatory
, "output-bin") &&
150 strcmp(mandatory
, "print-color-mode") &&
151 strcmp(mandatory
, "print-quality") &&
152 strcmp(mandatory
, "sides") &&
153 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
155 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
157 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
162 case IPP_TAG_INTEGER
:
164 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
166 case IPP_TAG_BOOLEAN
:
167 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
171 int lower
, upper
; /* Range */
173 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
174 lower
= upper
= atoi(keyword
);
176 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
179 case IPP_TAG_STRING
:
180 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
183 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
185 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
186 keyword
= "auto-monochrome";
187 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
188 keyword
= "process-monochrome";
191 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
197 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
198 keyword
= cupsGetOption("media", num_options
, options
);
200 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
201 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
202 size
= _ppdCacheGetSize(pc
, keyword
);
204 if (size
|| media_source
|| media_type
)
207 * Add a media-col value...
210 media_col
= ippNew();
214 media_size
= ippNew();
215 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
216 "x-dimension", size
->width
);
217 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
218 "y-dimension", size
->length
);
220 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
223 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
225 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
226 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
227 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
229 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
233 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
234 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
235 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
239 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
242 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
244 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
245 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
249 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
251 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
253 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
255 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
257 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
258 keyword
= "monochrome";
264 if (keyword
&& !strcmp(keyword
, "monochrome"))
266 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
267 keyword
= "auto-monochrome";
268 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
269 keyword
= "process-monochrome";
273 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
275 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
276 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
277 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
279 if (!_cups_strcasecmp(choice
->choice
, "draft"))
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
281 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
283 else if (!_cups_strcasecmp(choice
->choice
, "high"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
287 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
288 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
289 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
291 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
293 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
295 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
303 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
305 if (strstr(keyword
, "uncollated"))
310 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
315 if (!_cups_strcasecmp(format
, "image/gif") ||
316 !_cups_strcasecmp(format
, "image/jp2") ||
317 !_cups_strcasecmp(format
, "image/jpeg") ||
318 !_cups_strcasecmp(format
, "image/png") ||
319 !_cups_strcasecmp(format
, "image/tiff") ||
320 !_cups_strncasecmp(format
, "image/x-", 8))
323 * Collation makes no sense for single page image formats...
328 else if (!_cups_strncasecmp(format
, "image/", 6) ||
329 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
332 * Multi-page image formats will have copies applied by the upstream
340 if (doc_handling_sup
)
342 if (!_cups_strcasecmp(keyword
, "true"))
343 collate_str
= "separate-documents-collated-copies";
345 collate_str
= "separate-documents-uncollated-copies";
347 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
349 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
351 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
356 if (i
>= doc_handling_sup
->num_values
)
361 * Map finishing options...
364 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
365 if (num_finishings
> 0)
367 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
369 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
372 * Send job-pages-per-set attribute to apply finishings correctly...
375 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
384 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
387 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
391 _ppd_cache_t
* /* O - PPD cache and mapping data */
392 _ppdCacheCreateWithFile(
393 const char *filename
, /* I - File to read */
394 ipp_t
**attrs
) /* IO - IPP attributes, if any */
396 cups_file_t
*fp
; /* File */
397 _ppd_cache_t
*pc
; /* PWG mapping data */
398 pwg_size_t
*size
; /* Current size */
399 pwg_map_t
*map
; /* Current map */
400 _pwg_finishings_t
*finishings
; /* Current finishings option */
401 int linenum
, /* Current line number */
402 num_bins
, /* Number of bins in file */
403 num_sizes
, /* Number of sizes in file */
404 num_sources
, /* Number of sources in file */
405 num_types
; /* Number of types in file */
406 char line
[2048], /* Current line */
407 *value
, /* Pointer to value in line */
408 *valueptr
, /* Pointer into value */
409 pwg_keyword
[128], /* PWG keyword */
410 ppd_keyword
[PPD_MAX_NAME
];
412 _pwg_print_color_mode_t print_color_mode
;
413 /* Print color mode for preset */
414 _pwg_print_quality_t print_quality
; /* Print quality for preset */
417 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
420 * Range check input...
428 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
436 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
438 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
443 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
446 if (!cupsFileGets(fp
, line
, sizeof(line
)))
448 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
449 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
454 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
456 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
457 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
462 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
464 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
465 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
466 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
472 * Allocate the mapping data structure...
475 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
477 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
478 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
482 pc
->max_copies
= 9999;
494 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
496 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
497 "linenum=%d", line
, value
, linenum
));
501 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
503 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
506 else if (!_cups_strcasecmp(line
, "Filter"))
509 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
510 (cups_acopy_func_t
)_cupsStrAlloc
,
511 (cups_afree_func_t
)_cupsStrFree
);
513 cupsArrayAdd(pc
->filters
, value
);
515 else if (!_cups_strcasecmp(line
, "PreFilter"))
518 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
519 (cups_acopy_func_t
)_cupsStrAlloc
,
520 (cups_afree_func_t
)_cupsStrFree
);
522 cupsArrayAdd(pc
->prefilters
, value
);
524 else if (!_cups_strcasecmp(line
, "Product"))
526 pc
->product
= _cupsStrAlloc(value
);
528 else if (!_cups_strcasecmp(line
, "SingleFile"))
530 pc
->single_file
= !_cups_strcasecmp(value
, "true");
532 else if (!_cups_strcasecmp(line
, "IPP"))
534 off_t pos
= cupsFileTell(fp
), /* Position in file */
535 length
= strtol(value
, NULL
, 10);
536 /* Length of IPP attributes */
540 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
541 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
544 else if (length
<= 0)
546 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
547 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
554 * Read IPP attributes into the provided variable...
559 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
560 *attrs
) != IPP_STATE_DATA
)
562 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
563 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
570 * Skip the IPP data entirely...
573 cupsFileSeek(fp
, pos
+ length
);
576 if (cupsFileTell(fp
) != (pos
+ length
))
578 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
579 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
583 else if (!_cups_strcasecmp(line
, "NumBins"))
587 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
588 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
592 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
594 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
595 "%d.", num_sizes
, linenum
));
596 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
600 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
602 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
604 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
608 else if (!_cups_strcasecmp(line
, "Bin"))
610 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
612 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
613 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
617 if (pc
->num_bins
>= num_bins
)
619 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
621 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
625 map
= pc
->bins
+ pc
->num_bins
;
626 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
627 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
631 else if (!_cups_strcasecmp(line
, "NumSizes"))
635 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
643 "%d.", num_sizes
, linenum
));
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
650 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
652 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
654 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
659 else if (!_cups_strcasecmp(line
, "Size"))
661 if (pc
->num_sizes
>= num_sizes
)
663 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
665 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
669 size
= pc
->sizes
+ pc
->num_sizes
;
671 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
672 &(size
->width
), &(size
->length
), &(size
->left
),
673 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
675 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
677 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
681 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
682 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
686 else if (!_cups_strcasecmp(line
, "CustomSize"))
688 if (pc
->custom_max_width
> 0)
690 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
692 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
696 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
697 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
698 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
699 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
700 &(pc
->custom_size
.top
)) != 8)
702 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
704 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
708 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
709 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
710 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
712 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
713 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
714 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
716 else if (!_cups_strcasecmp(line
, "SourceOption"))
718 pc
->source_option
= _cupsStrAlloc(value
);
720 else if (!_cups_strcasecmp(line
, "NumSources"))
724 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
726 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
730 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
732 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
733 "line %d.", num_sources
, linenum
));
734 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
738 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
740 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
742 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
746 else if (!_cups_strcasecmp(line
, "Source"))
748 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
750 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 if (pc
->num_sources
>= num_sources
)
758 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
760 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
764 map
= pc
->sources
+ pc
->num_sources
;
765 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
766 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
770 else if (!_cups_strcasecmp(line
, "NumTypes"))
774 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
775 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
779 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
781 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
782 "line %d.", num_types
, linenum
));
783 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
787 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
789 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
791 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
795 else if (!_cups_strcasecmp(line
, "Type"))
797 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
799 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
801 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
805 if (pc
->num_types
>= num_types
)
807 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
809 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
813 map
= pc
->types
+ pc
->num_types
;
814 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
815 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
819 else if (!_cups_strcasecmp(line
, "Preset"))
822 * Preset output-mode print-quality name=value ...
825 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
826 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
828 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
829 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
830 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
831 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
832 valueptr
== value
|| !*valueptr
)
834 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
836 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
840 pc
->num_presets
[print_color_mode
][print_quality
] =
841 cupsParseOptions(valueptr
, 0,
842 pc
->presets
[print_color_mode
] + print_quality
);
844 else if (!_cups_strcasecmp(line
, "SidesOption"))
845 pc
->sides_option
= _cupsStrAlloc(value
);
846 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
847 pc
->sides_1sided
= _cupsStrAlloc(value
);
848 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
849 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
850 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
851 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
852 else if (!_cups_strcasecmp(line
, "Finishings"))
856 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
858 (cups_afree_func_t
)pwg_free_finishings
);
860 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
863 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
864 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
865 &(finishings
->options
));
867 cupsArrayAdd(pc
->finishings
, finishings
);
869 else if (!_cups_strcasecmp(line
, "MaxCopies"))
870 pc
->max_copies
= atoi(value
);
871 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
872 pc
->charge_info_uri
= _cupsStrAlloc(value
);
873 else if (!_cups_strcasecmp(line
, "JobAccountId"))
874 pc
->account_id
= !_cups_strcasecmp(value
, "true");
875 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
876 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
877 else if (!_cups_strcasecmp(line
, "JobPassword"))
878 pc
->password
= _cupsStrAlloc(value
);
879 else if (!_cups_strcasecmp(line
, "Mandatory"))
882 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
884 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
886 else if (!_cups_strcasecmp(line
, "SupportFile"))
888 if (!pc
->support_files
)
889 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
890 (cups_acopy_func_t
)_cupsStrAlloc
,
891 (cups_afree_func_t
)_cupsStrFree
);
893 cupsArrayAdd(pc
->support_files
, value
);
897 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
902 if (pc
->num_sizes
< num_sizes
)
904 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
905 pc
->num_sizes
, num_sizes
));
906 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
910 if (pc
->num_sources
< num_sources
)
912 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
913 pc
->num_sources
, num_sources
));
914 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
918 if (pc
->num_types
< num_types
)
920 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
921 pc
->num_types
, num_types
));
922 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
931 * If we get here the file was bad - free any data and return...
937 _ppdCacheDestroy(pc
);
950 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
953 _ppd_cache_t
* /* O - PPD cache and mapping data */
954 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
956 int i
, j
, k
; /* Looping vars */
957 _ppd_cache_t
*pc
; /* PWG mapping data */
958 ppd_option_t
*input_slot
, /* InputSlot option */
959 *media_type
, /* MediaType option */
960 *output_bin
, /* OutputBin option */
961 *color_model
, /* ColorModel option */
962 *duplex
; /* Duplex option */
963 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
964 pwg_map_t
*map
; /* Current source/type map */
965 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
966 int num_options
; /* Number of preset options and props */
967 cups_option_t
*options
; /* Preset options and properties */
968 ppd_size_t
*ppd_size
; /* Current PPD size */
969 pwg_size_t
*pwg_size
; /* Current PWG size */
970 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
971 /* PWG keyword string */
972 ppd_name
[PPD_MAX_NAME
];
973 /* Normalized PPD name */
974 const char *pwg_name
; /* Standard PWG media name */
975 pwg_media_t
*pwg_media
; /* PWG media data */
976 _pwg_print_color_mode_t pwg_print_color_mode
;
977 /* print-color-mode index */
978 _pwg_print_quality_t pwg_print_quality
;
979 /* print-quality index */
980 int similar
; /* Are the old and new size similar? */
981 pwg_size_t
*old_size
; /* Current old size */
982 int old_imageable
, /* Old imageable length in 2540ths */
983 old_borderless
, /* Old borderless state */
984 old_known_pwg
; /* Old PWG name is well-known */
985 int new_width
, /* New width in 2540ths */
986 new_length
, /* New length in 2540ths */
987 new_left
, /* New left margin in 2540ths */
988 new_bottom
, /* New bottom margin in 2540ths */
989 new_right
, /* New right margin in 2540ths */
990 new_top
, /* New top margin in 2540ths */
991 new_imageable
, /* New imageable length in 2540ths */
992 new_borderless
, /* New borderless state */
993 new_known_pwg
; /* New PWG name is well-known */
994 pwg_size_t
*new_size
; /* New size to add, if any */
995 const char *filter
; /* Current filter */
996 _pwg_finishings_t
*finishings
; /* Current finishings value */
999 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1002 * Range check input...
1009 * Allocate memory...
1012 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1014 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1019 * Copy and convert size data...
1022 if (ppd
->num_sizes
> 0)
1024 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1026 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1027 "pwg_size_t's.", ppd
->num_sizes
));
1031 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1036 * Don't copy over custom size...
1039 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1043 * Convert the PPD size name to the corresponding PWG keyword name.
1046 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1049 * Standard name, do we have conflicts?
1052 for (j
= 0; j
< pc
->num_sizes
; j
++)
1053 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1063 * Standard name and no conflicts, use it!
1066 pwg_name
= pwg_media
->pwg
;
1072 * Not a standard name; convert it to a PWG vendor name of the form:
1074 * pp_lowerppd_WIDTHxHEIGHTuu
1077 pwg_name
= pwg_keyword
;
1080 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1081 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1082 PWG_FROM_POINTS(ppd_size
->width
),
1083 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1087 * If we have a similar paper with non-zero margins then we only want to
1088 * keep it if it has a larger imageable area length. The NULL check is for
1089 * dimensions that are <= 0...
1092 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1093 PWG_FROM_POINTS(ppd_size
->length
),
1097 new_width
= pwg_media
->width
;
1098 new_length
= pwg_media
->length
;
1099 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1100 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1101 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1102 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1103 new_imageable
= new_length
- new_top
- new_bottom
;
1104 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1105 new_left
== 0 && new_right
== 0;
1107 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1111 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1112 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1113 old_size
->right
== 0 && old_size
->top
== 0;
1114 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1115 strncmp(old_size
->map
.pwg
, "om_", 3);
1117 similar
= old_borderless
== new_borderless
&&
1118 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1119 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1122 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1125 * The new paper has a larger imageable area so it could replace
1126 * the older paper. Regardless of the imageable area, we always
1127 * prefer the size with a well-known PWG name.
1130 new_size
= old_size
;
1131 _cupsStrFree(old_size
->map
.ppd
);
1132 _cupsStrFree(old_size
->map
.pwg
);
1139 * The paper was unique enough to deserve its own entry so add it to the
1143 new_size
= pwg_size
++;
1153 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1154 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1155 new_size
->width
= new_width
;
1156 new_size
->length
= new_length
;
1157 new_size
->left
= new_left
;
1158 new_size
->bottom
= new_bottom
;
1159 new_size
->right
= new_right
;
1160 new_size
->top
= new_top
;
1165 if (ppd
->variable_sizes
)
1168 * Generate custom size data...
1171 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1172 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1173 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1174 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1175 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1176 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1178 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1179 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1180 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1181 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1182 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1183 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1185 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1186 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1187 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1188 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1192 * Copy and convert InputSlot data...
1195 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1196 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1200 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1202 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1204 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1205 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1209 pc
->num_sources
= input_slot
->num_choices
;
1211 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1214 i
--, choice
++, map
++)
1216 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1217 !_cups_strcasecmp(choice
->choice
, "Default"))
1219 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1221 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1223 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1225 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1226 !_cups_strcasecmp(choice
->choice
, "MP") ||
1227 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1228 pwg_name
= "by-pass-tray";
1229 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1230 pwg_name
= "large-capacity";
1231 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1232 pwg_name
= "bottom";
1233 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1234 pwg_name
= "middle";
1235 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1237 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1239 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1240 pwg_name
= "main-roll";
1244 * Convert PPD name to lowercase...
1247 pwg_name
= pwg_keyword
;
1248 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1252 map
->pwg
= _cupsStrAlloc(pwg_name
);
1253 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1258 * Copy and convert MediaType data...
1261 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1263 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1265 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1266 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1270 pc
->num_types
= media_type
->num_choices
;
1272 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1275 i
--, choice
++, map
++)
1277 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1278 !_cups_strcasecmp(choice
->choice
, "Any") ||
1279 !_cups_strcasecmp(choice
->choice
, "Default"))
1281 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1282 pwg_name
= "cardstock";
1283 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1284 pwg_name
= "envelope";
1285 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1286 pwg_name
= "photographic-glossy";
1287 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1288 pwg_name
= "photographic-high-gloss";
1289 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1290 pwg_name
= "photographic-matte";
1291 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1292 pwg_name
= "stationery";
1293 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1294 pwg_name
= "stationery-coated";
1295 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1296 pwg_name
= "stationery-inkjet";
1297 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1298 pwg_name
= "stationery-letterhead";
1299 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1300 pwg_name
= "stationery-preprinted";
1301 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1302 pwg_name
= "stationery-recycled";
1303 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1304 pwg_name
= "transparency";
1308 * Convert PPD name to lowercase...
1311 pwg_name
= pwg_keyword
;
1312 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1316 map
->pwg
= _cupsStrAlloc(pwg_name
);
1317 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1322 * Copy and convert OutputBin data...
1325 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1327 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1329 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1330 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1334 pc
->num_bins
= output_bin
->num_choices
;
1336 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1339 i
--, choice
++, map
++)
1341 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1343 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1344 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1348 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1351 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1354 const char *quality
, /* com.apple.print.preset.quality value */
1355 *output_mode
, /* com.apple.print.preset.output-mode value */
1356 *color_model_val
, /* ColorModel choice */
1357 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1358 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1362 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1365 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1366 num_options
, options
)) != NULL
)
1369 * Get the print-quality for this preset...
1372 if (!strcmp(quality
, "low"))
1373 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1374 else if (!strcmp(quality
, "high"))
1375 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1377 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1380 * Ignore graphicsType "Photo" presets that are not high quality.
1383 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1384 num_options
, options
);
1386 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1387 !strcmp(graphicsType
, "Photo"))
1391 * Ignore presets for normal and draft quality where the coating
1392 * isn't "none" or "autodetect".
1395 media_front_coating
= cupsGetOption(
1396 "com.apple.print.preset.media-front-coating",
1397 num_options
, options
);
1399 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1400 media_front_coating
&&
1401 strcmp(media_front_coating
, "none") &&
1402 strcmp(media_front_coating
, "autodetect"))
1406 * Get the output mode for this preset...
1409 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1410 num_options
, options
);
1411 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1415 if (!strcmp(output_mode
, "monochrome"))
1416 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1418 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1420 else if (color_model_val
)
1422 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1423 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1425 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1428 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1431 * Save the options for this combination as needed...
1434 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1435 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1436 _ppdParseOptions(ppd_attr
->value
, 0,
1437 pc
->presets
[pwg_print_color_mode
] +
1438 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1441 cupsFreeOptions(num_options
, options
);
1443 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1446 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1447 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1448 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1451 * Try adding some common color options to create grayscale presets. These
1452 * are listed in order of popularity...
1455 const char *color_option
= NULL
, /* Color control option */
1456 *gray_choice
= NULL
; /* Choice to select grayscale */
1458 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1459 ppdFindChoice(color_model
, "Gray"))
1461 color_option
= "ColorModel";
1462 gray_choice
= "Gray";
1464 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1465 ppdFindChoice(color_model
, "grayscale"))
1467 color_option
= "HPColorMode";
1468 gray_choice
= "grayscale";
1470 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1471 ppdFindChoice(color_model
, "Mono"))
1473 color_option
= "BRMonoColor";
1474 gray_choice
= "Mono";
1476 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1477 ppdFindChoice(color_model
, "1"))
1479 color_option
= "CNIJSGrayScale";
1482 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1483 ppdFindChoice(color_model
, "True"))
1485 color_option
= "HPColorAsGray";
1486 gray_choice
= "True";
1489 if (color_option
&& gray_choice
)
1492 * Copy and convert ColorModel (output-mode) data...
1495 cups_option_t
*coption
, /* Color option */
1496 *moption
; /* Monochrome option */
1498 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1499 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1500 pwg_print_quality
++)
1502 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1505 * Copy the color options...
1508 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1509 [pwg_print_quality
];
1510 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1514 for (i
= num_options
, moption
= options
,
1515 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1516 [pwg_print_quality
];
1518 i
--, moption
++, coption
++)
1520 moption
->name
= _cupsStrRetain(coption
->name
);
1521 moption
->value
= _cupsStrRetain(coption
->value
);
1524 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1526 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1530 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1534 * Add the grayscale option to the preset...
1537 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1538 cupsAddOption(color_option
, gray_choice
,
1539 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1540 [pwg_print_quality
],
1541 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1548 * Copy and convert Duplex (sides) data...
1551 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1552 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1553 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1554 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1555 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1559 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1561 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1565 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1566 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1567 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1568 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1569 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1570 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1571 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1572 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1573 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1574 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1575 !pc
->sides_2sided_short
)
1576 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1581 * Copy filters and pre-filters...
1584 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1585 (cups_acopy_func_t
)_cupsStrAlloc
,
1586 (cups_afree_func_t
)_cupsStrFree
);
1588 cupsArrayAdd(pc
->filters
,
1589 "application/vnd.cups-raw application/octet-stream 0 -");
1591 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1595 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1597 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1599 else if (ppd
->num_filters
> 0)
1601 for (i
= 0; i
< ppd
->num_filters
; i
++)
1602 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1605 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1608 * See if we have a command filter...
1611 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1613 filter
= (const char *)cupsArrayNext(pc
->filters
))
1614 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1615 _cups_isspace(filter
[28]))
1619 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1620 _cups_strcasecmp(ppd_attr
->value
, "none")))
1623 * No command filter and no cupsCommands keyword telling us not to use one.
1624 * See if this is a PostScript printer, and if so add a PostScript command
1628 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1630 filter
= (const char *)cupsArrayNext(pc
->filters
))
1631 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1632 _cups_isspace(filter
[31]))
1636 cupsArrayAdd(pc
->filters
,
1637 "application/vnd.cups-command application/postscript 100 "
1641 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1643 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1644 (cups_acopy_func_t
)_cupsStrAlloc
,
1645 (cups_afree_func_t
)_cupsStrFree
);
1649 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1651 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1654 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1655 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1658 * Copy the product string, if any...
1662 pc
->product
= _cupsStrAlloc(ppd
->product
);
1665 * Copy finishings mapping data...
1668 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1671 * Have proper vendor mapping of IPP finishings values to PPD options...
1674 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1675 NULL
, NULL
, 0, NULL
,
1676 (cups_afree_func_t
)pwg_free_finishings
);
1680 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1683 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1684 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1685 &(finishings
->options
),
1686 _PPD_PARSE_OPTIONS
);
1688 cupsArrayAdd(pc
->finishings
, finishings
);
1690 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1696 * No IPP mapping data, try to map common/standard PPD keywords...
1699 ppd_option_t
*ppd_option
; /* PPD option */
1701 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1703 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1706 * Add staple finishings...
1709 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1710 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1711 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1712 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1713 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1714 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1715 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1716 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1717 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1718 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1721 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1724 * Add (Ricoh) punch finishings...
1727 if (ppdFindChoice(ppd_option
, "Left2"))
1728 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1729 if (ppdFindChoice(ppd_option
, "Left3"))
1730 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1731 if (ppdFindChoice(ppd_option
, "Left4"))
1732 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1733 if (ppdFindChoice(ppd_option
, "Right2"))
1734 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1735 if (ppdFindChoice(ppd_option
, "Right3"))
1736 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1737 if (ppdFindChoice(ppd_option
, "Right4"))
1738 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1739 if (ppdFindChoice(ppd_option
, "Upper2"))
1740 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1741 if (ppdFindChoice(ppd_option
, "Upper3"))
1742 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1743 if (ppdFindChoice(ppd_option
, "Upper4"))
1744 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1747 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1750 * Add bind finishings...
1753 if (ppdFindChoice(ppd_option
, "Left"))
1754 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1755 if (ppdFindChoice(ppd_option
, "Right"))
1756 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1757 if (ppdFindChoice(ppd_option
, "Top"))
1758 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1759 if (ppdFindChoice(ppd_option
, "Bottom"))
1760 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1763 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1766 * Add (Adobe) fold finishings...
1769 if (ppdFindChoice(ppd_option
, "ZFold"))
1770 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1771 if (ppdFindChoice(ppd_option
, "Saddle"))
1772 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1773 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1774 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1775 if (ppdFindChoice(ppd_option
, "LeftGate"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1777 if (ppdFindChoice(ppd_option
, "RightGate"))
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1779 if (ppdFindChoice(ppd_option
, "Letter"))
1780 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1781 if (ppdFindChoice(ppd_option
, "XFold"))
1782 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1785 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1788 * Add (Ricoh) fold finishings...
1791 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1792 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1795 if (cupsArrayCount(pc
->finishings
) == 0)
1797 cupsArrayDelete(pc
->finishings
);
1798 pc
->finishings
= NULL
;
1806 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1807 pc
->max_copies
= atoi(ppd_attr
->value
);
1808 else if (ppd
->manual_copies
)
1811 pc
->max_copies
= 9999;
1814 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1815 * cupsJobPassword, and cupsMandatory.
1818 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1819 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1821 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1822 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1824 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1825 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1827 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1828 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1830 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1831 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1837 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1838 (cups_acopy_func_t
)_cupsStrAlloc
,
1839 (cups_afree_func_t
)_cupsStrFree
);
1841 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1843 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1844 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1846 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1847 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1850 * Return the cache data...
1856 * If we get here we need to destroy the PWG mapping data and return NULL...
1861 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1862 _ppdCacheDestroy(pc
);
1869 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1873 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1875 int i
; /* Looping var */
1876 pwg_map_t
*map
; /* Current map */
1877 pwg_size_t
*size
; /* Current size */
1881 * Range check input...
1888 * Free memory as needed...
1893 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1895 _cupsStrFree(map
->pwg
);
1896 _cupsStrFree(map
->ppd
);
1904 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1906 _cupsStrFree(size
->map
.pwg
);
1907 _cupsStrFree(size
->map
.ppd
);
1913 if (pc
->source_option
)
1914 _cupsStrFree(pc
->source_option
);
1918 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1920 _cupsStrFree(map
->pwg
);
1921 _cupsStrFree(map
->ppd
);
1929 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1931 _cupsStrFree(map
->pwg
);
1932 _cupsStrFree(map
->ppd
);
1938 if (pc
->custom_max_keyword
)
1939 _cupsStrFree(pc
->custom_max_keyword
);
1941 if (pc
->custom_min_keyword
)
1942 _cupsStrFree(pc
->custom_min_keyword
);
1944 _cupsStrFree(pc
->product
);
1945 cupsArrayDelete(pc
->filters
);
1946 cupsArrayDelete(pc
->prefilters
);
1947 cupsArrayDelete(pc
->finishings
);
1949 _cupsStrFree(pc
->charge_info_uri
);
1950 _cupsStrFree(pc
->password
);
1952 cupsArrayDelete(pc
->mandatory
);
1954 cupsArrayDelete(pc
->support_files
);
1961 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1965 const char * /* O - output-bin or NULL */
1967 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1968 const char *output_bin
) /* I - PPD OutputBin string */
1970 int i
; /* Looping var */
1974 * Range check input...
1977 if (!pc
|| !output_bin
)
1981 * Look up the OutputBin string...
1985 for (i
= 0; i
< pc
->num_bins
; i
++)
1986 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1987 return (pc
->bins
[i
].pwg
);
1994 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1995 * IPP finishings value(s).
1998 int /* O - New number of options */
1999 _ppdCacheGetFinishingOptions(
2000 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2001 ipp_t
*job
, /* I - Job attributes or NULL */
2002 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2003 int num_options
, /* I - Number of options */
2004 cups_option_t
**options
) /* IO - Options */
2006 int i
; /* Looping var */
2007 _pwg_finishings_t
*f
, /* PWG finishings options */
2008 key
; /* Search key */
2009 ipp_attribute_t
*attr
; /* Finishings attribute */
2010 cups_option_t
*option
; /* Current finishings option */
2014 * Range check input...
2017 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2018 (!job
&& value
== IPP_FINISHINGS_NONE
))
2019 return (num_options
);
2022 * Apply finishing options...
2025 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2027 int num_values
= ippGetCount(attr
); /* Number of values */
2029 for (i
= 0; i
< num_values
; i
++)
2031 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2033 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2035 int j
; /* Another looping var */
2037 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2038 num_options
= cupsAddOption(option
->name
, option
->value
,
2039 num_options
, options
);
2043 else if (value
!= IPP_FINISHINGS_NONE
)
2047 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2049 int j
; /* Another looping var */
2051 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2052 num_options
= cupsAddOption(option
->name
, option
->value
,
2053 num_options
, options
);
2057 return (num_options
);
2062 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2066 int /* O - Number of finishings values */
2067 _ppdCacheGetFinishingValues(
2068 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2069 int num_options
, /* I - Number of options */
2070 cups_option_t
*options
, /* I - Options */
2071 int max_values
, /* I - Maximum number of finishings values */
2072 int *values
) /* O - Finishings values */
2074 int i
, /* Looping var */
2075 num_values
= 0; /* Number of values */
2076 _pwg_finishings_t
*f
; /* Current finishings option */
2077 cups_option_t
*option
; /* Current option */
2078 const char *val
; /* Value for option */
2082 * Range check input...
2085 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2087 if (!pc
|| max_values
< 1 || !values
)
2089 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2092 else if (!pc
->finishings
)
2094 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2099 * Go through the finishings options and see what is set...
2102 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2104 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2106 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2108 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2110 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2112 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2113 _cups_strcasecmp(option
->value
, val
))
2115 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2122 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2124 values
[num_values
++] = f
->value
;
2126 if (num_values
>= max_values
)
2131 if (num_values
== 0)
2134 * Always have at least "finishings" = 'none'...
2137 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2138 values
[0] = IPP_FINISHINGS_NONE
;
2142 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2144 return (num_values
);
2149 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2150 * attributes or a keyword string.
2153 const char * /* O - PPD InputSlot or NULL */
2154 _ppdCacheGetInputSlot(
2155 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2156 ipp_t
*job
, /* I - Job attributes or NULL */
2157 const char *keyword
) /* I - Keyword string or NULL */
2160 * Range check input...
2163 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2166 if (job
&& !keyword
)
2169 * Lookup the media-col attribute and any media-source found there...
2172 ipp_attribute_t
*media_col
, /* media-col attribute */
2173 *media_source
; /* media-source attribute */
2174 pwg_size_t size
; /* Dimensional size */
2175 int margins_set
; /* Were the margins set? */
2177 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2179 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2181 IPP_TAG_KEYWORD
)) != NULL
)
2184 * Use the media-source value from media-col...
2187 keyword
= ippGetString(media_source
, 0, NULL
);
2189 else if (pwgInitSize(&size
, job
, &margins_set
))
2192 * For media <= 5x7, look for a photo tray...
2195 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2202 int i
; /* Looping var */
2204 for (i
= 0; i
< pc
->num_sources
; i
++)
2205 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2206 return (pc
->sources
[i
].ppd
);
2214 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2215 * attributes or a keyword string.
2218 const char * /* O - PPD MediaType or NULL */
2219 _ppdCacheGetMediaType(
2220 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2221 ipp_t
*job
, /* I - Job attributes or NULL */
2222 const char *keyword
) /* I - Keyword string or NULL */
2225 * Range check input...
2228 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2231 if (job
&& !keyword
)
2234 * Lookup the media-col attribute and any media-source found there...
2237 ipp_attribute_t
*media_col
, /* media-col attribute */
2238 *media_type
; /* media-type attribute */
2240 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2243 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2245 IPP_TAG_KEYWORD
)) == NULL
)
2246 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2247 "media-type", IPP_TAG_NAME
);
2250 keyword
= media_type
->values
[0].string
.text
;
2256 int i
; /* Looping var */
2258 for (i
= 0; i
< pc
->num_types
; i
++)
2259 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2260 return (pc
->types
[i
].ppd
);
2268 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2272 const char * /* O - PPD OutputBin or NULL */
2273 _ppdCacheGetOutputBin(
2274 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2275 const char *output_bin
) /* I - Keyword string */
2277 int i
; /* Looping var */
2281 * Range check input...
2284 if (!pc
|| !output_bin
)
2288 * Look up the OutputBin string...
2292 for (i
= 0; i
< pc
->num_bins
; i
++)
2293 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2294 return (pc
->bins
[i
].ppd
);
2301 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2302 * attributes or a keyword string.
2305 const char * /* O - PPD PageSize or NULL */
2306 _ppdCacheGetPageSize(
2307 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2308 ipp_t
*job
, /* I - Job attributes or NULL */
2309 const char *keyword
, /* I - Keyword string or NULL */
2310 int *exact
) /* O - 1 if exact match, 0 otherwise */
2312 int i
; /* Looping var */
2313 pwg_size_t
*size
, /* Current size */
2314 *closest
, /* Closest size */
2315 jobsize
; /* Size data from job */
2316 int margins_set
, /* Were the margins set? */
2317 dwidth
, /* Difference in width */
2318 dlength
, /* Difference in length */
2319 dleft
, /* Difference in left margins */
2320 dright
, /* Difference in right margins */
2321 dbottom
, /* Difference in bottom margins */
2322 dtop
, /* Difference in top margins */
2323 dmin
, /* Minimum difference */
2324 dclosest
; /* Closest difference */
2325 const char *ppd_name
; /* PPD media name */
2328 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2329 pc
, job
, keyword
, exact
));
2332 * Range check input...
2335 if (!pc
|| (!job
&& !keyword
))
2346 * Try getting the PPD media name from the job attributes...
2349 ipp_attribute_t
*attr
; /* Job attribute */
2351 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2352 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2353 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2357 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2358 attr
->name
, ippTagString(attr
->value_tag
)));
2360 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2363 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2364 attr
->value_tag
== IPP_TAG_KEYWORD
))
2365 ppd_name
= attr
->values
[0].string
.text
;
2368 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2373 * Try looking up the named PPD size first...
2376 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2378 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2379 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2381 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2382 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2387 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2389 return (size
->map
.ppd
);
2394 if (job
&& !keyword
)
2397 * Get the size using media-col or media, with the preference being
2401 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2407 * Get the size using a media keyword...
2410 pwg_media_t
*media
; /* Media definition */
2413 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2414 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2415 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2418 jobsize
.width
= media
->width
;
2419 jobsize
.length
= media
->length
;
2424 * Now that we have the dimensions and possibly the margins, look at the
2425 * available sizes and find the match...
2429 dclosest
= 999999999;
2431 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2432 _cups_strncasecmp(ppd_name
, "custom_", 7))
2434 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2437 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2438 * is just about 176/2540ths...
2441 dwidth
= size
->width
- jobsize
.width
;
2442 dlength
= size
->length
- jobsize
.length
;
2444 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2450 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2453 dleft
= size
->left
- jobsize
.left
;
2454 dright
= size
->right
- jobsize
.right
;
2455 dtop
= size
->top
- jobsize
.top
;
2456 dbottom
= size
->bottom
- jobsize
.bottom
;
2458 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2459 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2461 dleft
= dleft
< 0 ? -dleft
: dleft
;
2462 dright
= dright
< 0 ? -dright
: dright
;
2463 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2464 dtop
= dtop
< 0 ? -dtop
: dtop
;
2465 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2467 if (dmin
< dclosest
)
2480 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2482 return (size
->map
.ppd
);
2488 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2491 return (closest
->map
.ppd
);
2495 * If we get here we need to check for custom page size support...
2498 if (jobsize
.width
>= pc
->custom_min_width
&&
2499 jobsize
.width
<= pc
->custom_max_width
&&
2500 jobsize
.length
>= pc
->custom_min_length
&&
2501 jobsize
.length
<= pc
->custom_max_length
)
2504 * In range, format as Custom.WWWWxLLLL (points).
2507 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2508 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2510 if (margins_set
&& exact
)
2512 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2513 dright
= pc
->custom_size
.right
- jobsize
.right
;
2514 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2515 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2517 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2518 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2524 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2525 pc
->custom_ppd_size
));
2527 return (pc
->custom_ppd_size
);
2531 * No custom page size support or the size is out of range - return NULL.
2534 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2541 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2544 pwg_size_t
* /* O - PWG size or NULL */
2546 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2547 const char *page_size
) /* I - PPD PageSize */
2549 int i
; /* Looping var */
2550 pwg_media_t
*media
; /* Media */
2551 pwg_size_t
*size
; /* Current size */
2555 * Range check input...
2558 if (!pc
|| !page_size
)
2561 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2564 * Custom size; size name can be one of the following:
2566 * Custom.WIDTHxLENGTHin - Size in inches
2567 * Custom.WIDTHxLENGTHft - Size in feet
2568 * Custom.WIDTHxLENGTHcm - Size in centimeters
2569 * Custom.WIDTHxLENGTHmm - Size in millimeters
2570 * Custom.WIDTHxLENGTHm - Size in meters
2571 * Custom.WIDTHxLENGTH[pt] - Size in points
2574 double w
, l
; /* Width and length of page */
2575 char *ptr
; /* Pointer into PageSize */
2576 struct lconv
*loc
; /* Locale data */
2579 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2580 if (!ptr
|| *ptr
!= 'x')
2583 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2587 if (!_cups_strcasecmp(ptr
, "in"))
2592 else if (!_cups_strcasecmp(ptr
, "ft"))
2597 else if (!_cups_strcasecmp(ptr
, "mm"))
2602 else if (!_cups_strcasecmp(ptr
, "cm"))
2607 else if (!_cups_strcasecmp(ptr
, "m"))
2618 pc
->custom_size
.width
= (int)w
;
2619 pc
->custom_size
.length
= (int)l
;
2621 return (&(pc
->custom_size
));
2625 * Not a custom size - look it up...
2628 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2629 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2630 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2634 * Look up standard sizes...
2637 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2638 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2639 media
= pwgMediaForPWG(page_size
);
2643 pc
->custom_size
.width
= media
->width
;
2644 pc
->custom_size
.length
= media
->length
;
2646 return (&(pc
->custom_size
));
2654 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2658 const char * /* O - PWG media-source keyword */
2660 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2661 const char *input_slot
) /* I - PPD InputSlot */
2663 int i
; /* Looping var */
2664 pwg_map_t
*source
; /* Current source */
2668 * Range check input...
2671 if (!pc
|| !input_slot
)
2674 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2675 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2676 return (source
->pwg
);
2683 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2687 const char * /* O - PWG media-type keyword */
2689 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2690 const char *media_type
) /* I - PPD MediaType */
2692 int i
; /* Looping var */
2693 pwg_map_t
*type
; /* Current type */
2697 * Range check input...
2700 if (!pc
|| !media_type
)
2703 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2704 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2712 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2715 int /* O - 1 on success, 0 on failure */
2717 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2718 const char *filename
, /* I - File to write */
2719 ipp_t
*attrs
) /* I - Attributes to write, if any */
2721 int i
, j
, k
; /* Looping vars */
2722 cups_file_t
*fp
; /* Output file */
2723 pwg_size_t
*size
; /* Current size */
2724 pwg_map_t
*map
; /* Current map */
2725 _pwg_finishings_t
*f
; /* Current finishing option */
2726 cups_option_t
*option
; /* Current option */
2727 const char *value
; /* Filter/pre-filter value */
2728 char newfile
[1024]; /* New filename */
2732 * Range check input...
2735 if (!pc
|| !filename
)
2737 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2742 * Open the file and write with compression...
2745 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2746 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2748 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2753 * Standard header...
2756 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2762 if (pc
->num_bins
> 0)
2764 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2765 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2766 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2773 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2774 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2775 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2776 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2777 size
->bottom
, size
->right
, size
->top
);
2778 if (pc
->custom_max_width
> 0)
2779 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2780 pc
->custom_max_width
, pc
->custom_max_length
,
2781 pc
->custom_min_width
, pc
->custom_min_length
,
2782 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2783 pc
->custom_size
.right
, pc
->custom_size
.top
);
2789 if (pc
->source_option
)
2790 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2792 if (pc
->num_sources
> 0)
2794 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2795 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2796 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2803 if (pc
->num_types
> 0)
2805 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2806 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2807 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2814 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2815 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2816 if (pc
->num_presets
[i
][j
])
2818 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2819 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2822 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2823 cupsFilePutChar(fp
, '\n');
2830 if (pc
->sides_option
)
2831 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2833 if (pc
->sides_1sided
)
2834 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2836 if (pc
->sides_2sided_long
)
2837 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2839 if (pc
->sides_2sided_short
)
2840 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2843 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2847 cupsFilePutConf(fp
, "Product", pc
->product
);
2849 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2851 value
= (const char *)cupsArrayNext(pc
->filters
))
2852 cupsFilePutConf(fp
, "Filter", value
);
2854 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2856 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2857 cupsFilePutConf(fp
, "PreFilter", value
);
2859 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2862 * Finishing options...
2865 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2867 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2869 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2870 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2871 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2872 cupsFilePutChar(fp
, '\n');
2879 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2882 * Accounting/quota/PIN/managed printing values...
2885 if (pc
->charge_info_uri
)
2886 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2888 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2889 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2890 pc
->accounting_user_id
? "true" : "false");
2893 cupsFilePutConf(fp
, "Password", pc
->password
);
2895 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2897 value
= (char *)cupsArrayNext(pc
->mandatory
))
2898 cupsFilePutConf(fp
, "Mandatory", value
);
2904 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2906 value
= (char *)cupsArrayNext(pc
->support_files
))
2907 cupsFilePutConf(fp
, "SupportFile", value
);
2910 * IPP attributes, if any...
2915 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2917 attrs
->state
= IPP_STATE_IDLE
;
2918 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2922 * Close and return...
2925 if (cupsFileClose(fp
))
2932 return (!rename(newfile
, filename
));
2937 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2938 * of an IPP printer.
2941 char * /* O - PPD filename or @code NULL@ on error */
2942 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2943 size_t bufsize
, /* I - Size of filename buffer */
2944 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2946 cups_file_t
*fp
; /* PPD file */
2947 cups_array_t
*sizes
; /* Media sizes we've added */
2948 ipp_attribute_t
*attr
, /* xxx-supported */
2949 *defattr
, /* xxx-default */
2950 *quality
, /* print-quality-supported */
2951 *x_dim
, *y_dim
; /* Media dimensions */
2952 ipp_t
*media_size
; /* Media size collection */
2953 char make
[256], /* Make and model */
2954 *model
, /* Model name */
2955 ppdname
[PPD_MAX_NAME
];
2957 int i
, j
, /* Looping vars */
2958 count
, /* Number of values */
2959 bottom
, /* Largest bottom margin */
2960 left
, /* Largest left margin */
2961 right
, /* Largest right margin */
2962 top
, /* Largest top margin */
2963 is_apple
= 0, /* Does the printer support Apple raster? */
2964 is_pdf
= 0, /* Does the printer support PDF? */
2965 is_pwg
= 0; /* Does the printer support PWG Raster? */
2966 pwg_media_t
*pwg
; /* PWG media size */
2967 int xres
, yres
; /* Resolution values */
2968 cups_lang_t
*lang
= cupsLangDefault();
2969 /* Localization info */
2970 struct lconv
*loc
= localeconv();
2972 static const char * const finishings
[][2] =
2973 { /* Finishings strings */
2974 { "bale", _("Bale") },
2975 { "bind", _("Bind") },
2976 { "bind-bottom", _("Bind (Reverse Landscape)") },
2977 { "bind-left", _("Bind (Portrait)") },
2978 { "bind-right", _("Bind (Reverse Portrait)") },
2979 { "bind-top", _("Bind (Landscape)") },
2980 { "booklet-maker", _("Booklet Maker") },
2981 { "coat", _("Coat") },
2982 { "cover", _("Cover") },
2983 { "edge-stitch", _("Staple Edge") },
2984 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
2985 { "edge-stitch-left", _("Staple Edge (Portrait)") },
2986 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
2987 { "edge-stitch-top", _("Staple Edge (Landscape)") },
2988 { "fold", _("Fold") },
2989 { "fold-accordian", _("Accordian Fold") },
2990 { "fold-double-gate", _("Double Gate Fold") },
2991 { "fold-engineering-z", _("Engineering Z Fold") },
2992 { "fold-gate", _("Gate Fold") },
2993 { "fold-half", _("Half Fold") },
2994 { "fold-half-z", _("Half Z Fold") },
2995 { "fold-left-gate", _("Left Gate Fold") },
2996 { "fold-letter", _("Letter Fold") },
2997 { "fold-parallel", _("Parallel Fold") },
2998 { "fold-poster", _("Poster Fold") },
2999 { "fold-right-gate", _("Right Gate Fold") },
3000 { "fold-z", _("Z Fold") },
3001 { "jog-offset", _("Jog") },
3002 { "laminate", _("Laminate") },
3003 { "punch", _("Punch") },
3004 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3005 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3006 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3007 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3008 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3009 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3010 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3011 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3012 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3013 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3014 { "punch-top-left", _("Single Punch (Portrait)") },
3015 { "punch-top-right", _("Single Punch (Landscape)") },
3016 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3017 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3018 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3019 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3020 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3021 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3022 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3023 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3024 { "saddle-stitch", _("Saddle Stitch") },
3025 { "staple", _("Staple") },
3026 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3027 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3028 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3029 { "staple-dual-left", _("Double Staple (Portrait)") },
3030 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3031 { "staple-dual-top", _("Double Staple (Landscape)") },
3032 { "staple-top-left", _("Single Staple (Portrait)") },
3033 { "staple-top-right", _("Single Staple (Landscape)") },
3034 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3035 { "staple-triple-left", _("Triple Staple (Portrait)") },
3036 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3037 { "staple-triple-top", _("Triple Staple (Landscape)") },
3038 { "trim", _("Cut Media") }
3043 * Range check input...
3049 if (!buffer
|| bufsize
< 1)
3051 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3057 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3062 * Open a temporary file for the PPD...
3065 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3067 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3072 * Standard stuff for PPD file...
3075 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3076 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3077 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3078 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3079 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3080 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3081 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3082 cupsFilePuts(fp
, "*FileSystem: False\n");
3083 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3085 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3086 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3088 strlcpy(make
, "Unknown Printer", sizeof(make
));
3090 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3091 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3094 strlcpy(make
, "HP", sizeof(make
));
3096 else if ((model
= strchr(make
, ' ')) != NULL
)
3101 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3102 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3103 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3104 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3105 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3107 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3108 cupsFilePuts(fp
, "*ColorDevice: True\n");
3110 cupsFilePuts(fp
, "*ColorDevice: False\n");
3112 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3113 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3114 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3120 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3122 is_apple
= ippContainsString(attr
, "image/urf");
3123 is_pdf
= ippContainsString(attr
, "application/pdf");
3124 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3126 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3128 const char *format
= ippGetString(attr
, i
, NULL
);
3132 * Write cupsFilter2 lines for supported formats...
3135 if (!_cups_strcasecmp(format
, "application/pdf"))
3136 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3137 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3138 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3139 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3140 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3144 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3148 * PageSize/PageRegion/ImageableArea/PaperDimension
3151 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3153 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3154 if (ippGetInteger(attr
, i
) > bottom
)
3155 bottom
= ippGetInteger(attr
, i
);
3160 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3162 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3163 if (ippGetInteger(attr
, i
) > left
)
3164 left
= ippGetInteger(attr
, i
);
3169 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3171 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3172 if (ippGetInteger(attr
, i
) > right
)
3173 right
= ippGetInteger(attr
, i
);
3178 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3180 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3181 if (ippGetInteger(attr
, i
) > top
)
3182 top
= ippGetInteger(attr
, i
);
3187 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3189 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3191 media_size
= ippGetCollection(attr
, 0);
3192 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3193 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3195 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3196 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3198 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3201 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3203 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3204 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3206 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3208 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3209 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3212 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3213 "*OrderDependency: 10 AnySetup *PageSize\n"
3214 "*DefaultPageSize: %s\n", ppdname
);
3216 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3218 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3220 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3222 media_size
= ippGetCollection(attr
, i
);
3223 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3224 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3226 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3229 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3233 char twidth
[256], /* Width string */
3234 tlength
[256]; /* Length string */
3236 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3238 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3242 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3244 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3245 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3247 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3250 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3252 cupsArrayDelete(sizes
);
3253 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3255 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3256 "*OrderDependency: 10 AnySetup *PageRegion\n"
3257 "*DefaultPageRegion: %s\n", ppdname
);
3258 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3260 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3262 media_size
= ippGetCollection(attr
, i
);
3263 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3264 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3266 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3269 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3273 char twidth
[256], /* Width string */
3274 tlength
[256]; /* Length string */
3276 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3279 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3281 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3282 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3284 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3287 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3289 cupsArrayDelete(sizes
);
3290 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3292 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3293 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3294 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3296 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3298 media_size
= ippGetCollection(attr
, i
);
3299 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3300 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3302 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3305 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3309 char tleft
[256], /* Left string */
3310 tbottom
[256], /* Bottom string */
3311 tright
[256], /* Right string */
3312 ttop
[256], /* Top string */
3313 twidth
[256], /* Width string */
3314 tlength
[256]; /* Length string */
3316 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3319 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3321 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3322 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3323 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3324 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3325 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3326 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3328 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3329 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3333 cupsArrayDelete(sizes
);
3342 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3343 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3345 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3347 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3349 static const char * const sources
[][2] =
3350 { /* "media-source" strings */
3351 { "Auto", _("Automatic") },
3352 { "Main", _("Main") },
3353 { "Alternate", _("Alternate") },
3354 { "LargeCapacity", _("Large Capacity") },
3355 { "Manual", _("Manual") },
3356 { "Envelope", _("Envelope") },
3357 { "Disc", _("Disc") },
3358 { "Photo", _("Photo") },
3359 { "Hagaki", _("Hagaki") },
3360 { "MainRoll", _("Main Roll") },
3361 { "AlternateRoll", _("Alternate Roll") },
3362 { "Top", _("Top") },
3363 { "Middle", _("Middle") },
3364 { "Bottom", _("Bottom") },
3365 { "Side", _("Side") },
3366 { "Left", _("Left") },
3367 { "Right", _("Right") },
3368 { "Center", _("Center") },
3369 { "Rear", _("Rear") },
3370 { "ByPassTray", _("Multipurpose") },
3371 { "Tray1", _("Tray 1") },
3372 { "Tray2", _("Tray 2") },
3373 { "Tray3", _("Tray 3") },
3374 { "Tray4", _("Tray 4") },
3375 { "Tray5", _("Tray 5") },
3376 { "Tray6", _("Tray 6") },
3377 { "Tray7", _("Tray 7") },
3378 { "Tray8", _("Tray 8") },
3379 { "Tray9", _("Tray 9") },
3380 { "Tray10", _("Tray 10") },
3381 { "Tray11", _("Tray 11") },
3382 { "Tray12", _("Tray 12") },
3383 { "Tray13", _("Tray 13") },
3384 { "Tray14", _("Tray 14") },
3385 { "Tray15", _("Tray 15") },
3386 { "Tray16", _("Tray 16") },
3387 { "Tray17", _("Tray 17") },
3388 { "Tray18", _("Tray 18") },
3389 { "Tray19", _("Tray 19") },
3390 { "Tray20", _("Tray 20") },
3391 { "Roll1", _("Roll 1") },
3392 { "Roll2", _("Roll 2") },
3393 { "Roll3", _("Roll 3") },
3394 { "Roll4", _("Roll 4") },
3395 { "Roll5", _("Roll 5") },
3396 { "Roll6", _("Roll 6") },
3397 { "Roll7", _("Roll 7") },
3398 { "Roll8", _("Roll 8") },
3399 { "Roll9", _("Roll 9") },
3400 { "Roll10", _("Roll 10") }
3403 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3404 "*OrderDependency: 10 AnySetup *InputSlot\n"
3405 "*DefaultInputSlot: %s\n", ppdname
);
3406 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3408 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3410 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3411 if (!strcmp(sources
[j
][0], ppdname
))
3413 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3417 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3424 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3425 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3427 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3429 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3431 static const char * const media_types
[][2] =
3432 { /* "media-type" strings */
3433 { "aluminum", _("Aluminum") },
3434 { "auto", _("Automatic") },
3435 { "back-print-film", _("Back Print Film") },
3436 { "cardboard", _("Cardboard") },
3437 { "cardstock", _("Cardstock") },
3439 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3440 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3441 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3442 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3443 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3444 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3445 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3446 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3447 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3448 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3449 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3450 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3451 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3452 { "continuous", _("Continuous") },
3453 { "continuous-long", _("Continuous Long") },
3454 { "continuous-short", _("Continuous Short") },
3455 { "disc", _("Optical Disc") },
3456 { "disc-glossy", _("Glossy Optical Disc") },
3457 { "disc-high-gloss", _("High Gloss Optical Disc") },
3458 { "disc-matte", _("Matte Optical Disc") },
3459 { "disc-satin", _("Satin Optical Disc") },
3460 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3461 { "double-wall", _("Double Wall Cardboard") },
3462 { "dry-film", _("Dry Film") },
3463 { "dvd", _("DVD") },
3464 { "embossing-foil", _("Embossing Foil") },
3465 { "end-board", _("End Board") },
3466 { "envelope", _("Envelope") },
3467 { "envelope-archival", _("Archival Envelope") },
3468 { "envelope-bond", _("Bond Envelope") },
3469 { "envelope-coated", _("Coated Envelope") },
3470 { "envelope-cotton", _("Cotton Envelope") },
3471 { "envelope-fine", _("Fine Envelope") },
3472 { "envelope-heavyweight", _("Heavyweight Envelope") },
3473 { "envelope-inkjet", _("Inkjet Envelope") },
3474 { "envelope-lightweight", _("Lightweight Envelope") },
3475 { "envelope-plain", _("Plain Envelope") },
3476 { "envelope-preprinted", _("Preprinted Envelope") },
3477 { "envelope-window", _("Windowed Envelope") },
3478 { "fabric", _("Fabric") },
3479 { "fabric-archival", _("Archival Fabric") },
3480 { "fabric-glossy", _("Glossy Fabric") },
3481 { "fabric-high-gloss", _("High Gloss Fabric") },
3482 { "fabric-matte", _("Matte Fabric") },
3483 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3484 { "fabric-waterproof", _("Waterproof Fabric") },
3485 { "film", _("Film") },
3486 { "flexo-base", _("Flexo Base") },
3487 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3488 { "flute", _("Flute") },
3489 { "foil", _("Foil") },
3490 { "full-cut-tabs", _("Full Cut Tabs") },
3491 { "glass", _("Glass") },
3492 { "glass-colored", _("Glass Colored") },
3493 { "glass-opaque", _("Glass Opaque") },
3494 { "glass-surfaced", _("Glass Surfaced") },
3495 { "glass-textured", _("Glass Textured") },
3496 { "gravure-cylinder", _("Gravure Cylinder") },
3497 { "image-setter-paper", _("Image Setter Paper") },
3498 { "imaging-cylinder", _("Imaging Cylinder") },
3499 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3500 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3501 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3502 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3503 { "labels", _("Labels") },
3504 { "labels-colored", _("Colored Labels") },
3505 { "labels-glossy", _("Glossy Labels") },
3506 { "labels-high-gloss", _("High Gloss Labels") },
3507 { "labels-inkjet", _("Inkjet Labels") },
3508 { "labels-matte", _("Matte Labels") },
3509 { "labels-permanent", _("Permanent Labels") },
3510 { "labels-satin", _("Satin Labels") },
3511 { "labels-security", _("Security Labels") },
3512 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3513 { "laminating-foil", _("Laminating Foil") },
3514 { "letterhead", _("Letterhead") },
3515 { "metal", _("Metal") },
3516 { "metal-glossy", _("Metal Glossy") },
3517 { "metal-high-gloss", _("Metal High Gloss") },
3518 { "metal-matte", _("Metal Matte") },
3519 { "metal-satin", _("Metal Satin") },
3520 { "metal-semi-gloss", _("Metal Semi Gloss") },
3521 { "mounting-tape", _("Mounting Tape") },
3522 { "multi-layer", _("Multi Layer") },
3523 { "multi-part-form", _("Multi Part Form") },
3524 { "other", _("Other") },
3525 { "paper", _("Paper") },
3526 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3527 { "photographic", _("Photo Paper") },
3528 { "photographic-archival", _("Archival Photo Paper") },
3529 { "photographic-film", _("Photo Film") },
3530 { "photographic-glossy", _("Glossy Photo Paper") },
3531 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3532 { "photographic-matte", _("Matte Photo Paper") },
3533 { "photographic-satin", _("Satin Photo Paper") },
3534 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3535 { "plastic", _("Plastic") },
3536 { "plastic-archival", _("Plastic Archival") },
3537 { "plastic-colored", _("Plastic Colored") },
3538 { "plastic-glossy", _("Plastic Glossy") },
3539 { "plastic-high-gloss", _("Plastic High Gloss") },
3540 { "plastic-matte", _("Plastic Matte") },
3541 { "plastic-satin", _("Plastic Satin") },
3542 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3543 { "plate", _("Plate") },
3544 { "polyester", _("Polyester") },
3545 { "pre-cut-tabs", _("Pre Cut Tabs") },
3546 { "roll", _("Roll") },
3547 { "screen", _("Screen") },
3548 { "screen-paged", _("Screen Paged") },
3549 { "self-adhesive", _("Self Adhesive") },
3550 { "self-adhesive-film", _("Self Adhesive Film") },
3551 { "shrink-foil", _("Shrink Foil") },
3552 { "single-face", _("Single Face") },
3553 { "single-wall", _("Single Wall Cardboard") },
3554 { "sleeve", _("Sleeve") },
3555 { "stationery", _("Plain Paper") },
3556 { "stationery-archival", _("Archival Paper") },
3557 { "stationery-coated", _("Coated Paper") },
3558 { "stationery-cotton", _("Cotton Paper") },
3559 { "stationery-fine", _("Vellum Paper") },
3560 { "stationery-heavyweight", _("Heavyweight Paper") },
3561 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3562 { "stationery-inkjet", _("Inkjet Paper") },
3563 { "stationery-letterhead", _("Letterhead") },
3564 { "stationery-lightweight", _("Lightweight Paper") },
3565 { "stationery-preprinted", _("Preprinted Paper") },
3566 { "stationery-prepunched", _("Punched Paper") },
3567 { "tab-stock", _("Tab Stock") },
3568 { "tractor", _("Tractor") },
3569 { "transfer", _("Transfer") },
3570 { "transparency", _("Transparency") },
3571 { "triple-wall", _("Triple Wall Cardboard") },
3572 { "wet-film", _("Wet Film") }
3575 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3576 "*OrderDependency: 10 AnySetup *MediaType\n"
3577 "*DefaultMediaType: %s\n", ppdname
);
3578 for (i
= 0; i
< count
; i
++)
3580 const char *keyword
= ippGetString(attr
, i
, NULL
);
3582 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3584 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3585 if (!strcmp(keyword
, media_types
[j
][0]))
3588 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3589 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3591 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, keyword
, ppdname
);
3593 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3600 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3601 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3602 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3603 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3607 const char *default_color
= NULL
; /* Default */
3609 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3611 const char *keyword
= ippGetString(attr
, i
, NULL
);
3612 /* Keyword for color/bit depth */
3614 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3617 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3618 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3620 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3623 default_color
= "FastGray";
3625 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3628 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3629 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3631 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3633 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3634 default_color
= "Gray";
3636 else if (!strcasecmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3639 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3640 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3642 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3644 default_color
= "RGB";
3646 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3649 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3650 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3652 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3655 default_color
= "AdobeRGB";
3661 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3662 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3670 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3672 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3673 "*OrderDependency: 10 AnySetup *Duplex\n"
3674 "*DefaultDuplex: None\n"
3675 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3676 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3677 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3678 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3680 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3682 const char *keyword
= ippGetString(attr
, 0, NULL
);
3685 if (!strcmp(keyword
, "flipped"))
3686 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3687 else if (!strcmp(keyword
, "manual-tumble"))
3688 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3689 else if (!strcmp(keyword
, "normal"))
3690 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3692 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3694 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3696 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3698 const char *dm
= ippGetString(attr
, i
, NULL
);
3701 if (!_cups_strcasecmp(dm
, "DM1"))
3703 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3706 else if (!_cups_strcasecmp(dm
, "DM2"))
3708 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3711 else if (!_cups_strcasecmp(dm
, "DM3"))
3713 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3716 else if (!_cups_strcasecmp(dm
, "DM4"))
3718 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3729 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3730 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3732 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3734 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3736 static const char * const output_bins
[][2] =
3737 { /* "output-bin" strings */
3738 { "auto", _("Automatic") },
3739 { "bottom", _("Bottom Tray") },
3740 { "center", _("Center Tray") },
3741 { "face-down", _("Face Down") },
3742 { "face-up", _("Face Up") },
3743 { "large-capacity", _("Large Capacity Tray") },
3744 { "left", _("Left Tray") },
3745 { "mailbox-1", _("Mailbox 1") },
3746 { "mailbox-2", _("Mailbox 2") },
3747 { "mailbox-3", _("Mailbox 3") },
3748 { "mailbox-4", _("Mailbox 4") },
3749 { "mailbox-5", _("Mailbox 5") },
3750 { "mailbox-6", _("Mailbox 6") },
3751 { "mailbox-7", _("Mailbox 7") },
3752 { "mailbox-8", _("Mailbox 8") },
3753 { "mailbox-9", _("Mailbox 9") },
3754 { "mailbox-10", _("Mailbox 10") },
3755 { "middle", _("Middle") },
3756 { "my-mailbox", _("My Mailbox") },
3757 { "rear", _("Rear Tray") },
3758 { "right", _("Right Tray") },
3759 { "side", _("Side Tray") },
3760 { "stacker-1", _("Stacker 1") },
3761 { "stacker-2", _("Stacker 2") },
3762 { "stacker-3", _("Stacker 3") },
3763 { "stacker-4", _("Stacker 4") },
3764 { "stacker-5", _("Stacker 5") },
3765 { "stacker-6", _("Stacker 6") },
3766 { "stacker-7", _("Stacker 7") },
3767 { "stacker-8", _("Stacker 8") },
3768 { "stacker-9", _("Stacker 9") },
3769 { "stacker-10", _("Stacker 10") },
3770 { "top", _("Top Tray") },
3771 { "tray-1", _("Tray 1") },
3772 { "tray-2", _("Tray 2") },
3773 { "tray-3", _("Tray 3") },
3774 { "tray-4", _("Tray 4") },
3775 { "tray-5", _("Tray 5") },
3776 { "tray-6", _("Tray 6") },
3777 { "tray-7", _("Tray 7") },
3778 { "tray-8", _("Tray 8") },
3779 { "tray-9", _("Tray 9") },
3780 { "tray-10", _("Tray 10") }
3783 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3784 "*OrderDependency: 10 AnySetup *OutputBin\n"
3785 "*DefaultOutputBin: %s\n", ppdname
);
3786 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3788 if (!ippContainsString(attr
, output_bins
[i
][0]))
3791 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3793 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3795 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3799 * Finishing options...
3801 * Eventually need to re-add support for finishings-col-database, however
3802 * it is difficult to map arbitrary finishing-template values to PPD options
3803 * and have the right constraints apply (e.g. stapling vs. folding vs.
3807 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3809 const char *name
; /* String name */
3810 int value
; /* Enum value */
3811 cups_array_t
*names
; /* Names we've added */
3813 count
= ippGetCount(attr
);
3814 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3817 * Staple/Bind/Stitch
3820 for (i
= 0; i
< count
; i
++)
3822 value
= ippGetInteger(attr
, i
);
3823 name
= ippEnumString("finishings", value
);
3825 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3831 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3832 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3833 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3834 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3836 for (; i
< count
; i
++)
3838 value
= ippGetInteger(attr
, i
);
3839 name
= ippEnumString("finishings", value
);
3841 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3844 if (cupsArrayFind(names
, (char *)name
))
3845 continue; /* Already did this finishing template */
3847 cupsArrayAdd(names
, (char *)name
);
3849 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3851 if (!strcmp(finishings
[j
][0], name
))
3853 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3854 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3860 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3867 for (i
= 0; i
< count
; i
++)
3869 value
= ippGetInteger(attr
, i
);
3870 name
= ippEnumString("finishings", value
);
3872 if (!strncmp(name
, "fold-", 5))
3878 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3879 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3880 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3881 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3883 for (; i
< count
; i
++)
3885 value
= ippGetInteger(attr
, i
);
3886 name
= ippEnumString("finishings", value
);
3888 if (strncmp(name
, "fold-", 5))
3891 if (cupsArrayFind(names
, (char *)name
))
3892 continue; /* Already did this finishing template */
3894 cupsArrayAdd(names
, (char *)name
);
3896 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3898 if (!strcmp(finishings
[j
][0], name
))
3900 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3901 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
3907 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
3914 for (i
= 0; i
< count
; i
++)
3916 value
= ippGetInteger(attr
, i
);
3917 name
= ippEnumString("finishings", value
);
3919 if (!strncmp(name
, "punch-", 6))
3925 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
3926 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
3927 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
3928 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3930 for (i
= 0; i
< count
; i
++)
3932 value
= ippGetInteger(attr
, i
);
3933 name
= ippEnumString("finishings", value
);
3935 if (strncmp(name
, "punch-", 6))
3938 if (cupsArrayFind(names
, (char *)name
))
3939 continue; /* Already did this finishing template */
3941 cupsArrayAdd(names
, (char *)name
);
3943 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3945 if (!strcmp(finishings
[j
][0], name
))
3947 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3948 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
3954 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
3961 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
3963 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
3964 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
3965 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
3966 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
3967 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
3968 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
3969 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
3972 cupsArrayDelete(names
);
3976 * cupsPrintQuality and DefaultResolution...
3979 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
3981 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3983 count
= ippGetCount(attr
);
3985 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3986 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3988 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3989 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3990 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
3991 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
3993 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3994 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
3996 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3997 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
3998 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4001 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
4003 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4004 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4007 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4009 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4011 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4013 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4015 const char *rs
= ippGetString(attr
, i
, NULL
);
4018 if (_cups_strncasecmp(rs
, "RS", 2))
4021 lowdpi
= atoi(rs
+ 2);
4022 if ((rs
= strrchr(rs
, '-')) != NULL
)
4023 hidpi
= atoi(rs
+ 1);
4032 * Invalid "urf-supported" value...
4040 * Generate print qualities based on low and high DPIs...
4043 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4045 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4046 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4047 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4048 if ((lowdpi
& 1) == 0)
4049 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4050 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4051 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4052 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4053 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4054 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4055 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4058 else if (is_apple
|| is_pwg
)
4062 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4064 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4069 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4072 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4074 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4075 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4076 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4077 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4078 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4079 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4080 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4081 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4082 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4086 * Close up and return...
4094 * If we get here then there was a problem creating the PPD...
4103 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4110 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4114 const char * /* O - InputSlot name */
4115 _pwgInputSlotForSource(
4116 const char *media_source
, /* I - PWG media-source */
4117 char *name
, /* I - Name buffer */
4118 size_t namesize
) /* I - Size of name buffer */
4121 * Range check input...
4124 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4127 if (_cups_strcasecmp(media_source
, "main"))
4128 strlcpy(name
, "Cassette", namesize
);
4129 else if (_cups_strcasecmp(media_source
, "alternate"))
4130 strlcpy(name
, "Multipurpose", namesize
);
4131 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4132 strlcpy(name
, "LargeCapacity", namesize
);
4133 else if (_cups_strcasecmp(media_source
, "bottom"))
4134 strlcpy(name
, "Lower", namesize
);
4135 else if (_cups_strcasecmp(media_source
, "middle"))
4136 strlcpy(name
, "Middle", namesize
);
4137 else if (_cups_strcasecmp(media_source
, "top"))
4138 strlcpy(name
, "Upper", namesize
);
4139 else if (_cups_strcasecmp(media_source
, "rear"))
4140 strlcpy(name
, "Rear", namesize
);
4141 else if (_cups_strcasecmp(media_source
, "side"))
4142 strlcpy(name
, "Side", namesize
);
4143 else if (_cups_strcasecmp(media_source
, "envelope"))
4144 strlcpy(name
, "Envelope", namesize
);
4145 else if (_cups_strcasecmp(media_source
, "main-roll"))
4146 strlcpy(name
, "Roll", namesize
);
4147 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4148 strlcpy(name
, "Roll2", namesize
);
4150 pwg_ppdize_name(media_source
, name
, namesize
);
4157 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4161 const char * /* O - MediaType name */
4162 _pwgMediaTypeForType(
4163 const char *media_type
, /* I - PWG media-type */
4164 char *name
, /* I - Name buffer */
4165 size_t namesize
) /* I - Size of name buffer */
4168 * Range check input...
4171 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4174 if (_cups_strcasecmp(media_type
, "auto"))
4175 strlcpy(name
, "Auto", namesize
);
4176 else if (_cups_strcasecmp(media_type
, "cardstock"))
4177 strlcpy(name
, "Cardstock", namesize
);
4178 else if (_cups_strcasecmp(media_type
, "envelope"))
4179 strlcpy(name
, "Envelope", namesize
);
4180 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4181 strlcpy(name
, "Glossy", namesize
);
4182 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4183 strlcpy(name
, "HighGloss", namesize
);
4184 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4185 strlcpy(name
, "Matte", namesize
);
4186 else if (_cups_strcasecmp(media_type
, "stationery"))
4187 strlcpy(name
, "Plain", namesize
);
4188 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4189 strlcpy(name
, "Coated", namesize
);
4190 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4191 strlcpy(name
, "Inkjet", namesize
);
4192 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4193 strlcpy(name
, "Letterhead", namesize
);
4194 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4195 strlcpy(name
, "Preprinted", namesize
);
4196 else if (_cups_strcasecmp(media_type
, "transparency"))
4197 strlcpy(name
, "Transparency", namesize
);
4199 pwg_ppdize_name(media_type
, name
, namesize
);
4206 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4209 const char * /* O - PageSize name */
4210 _pwgPageSizeForMedia(
4211 pwg_media_t
*media
, /* I - Media */
4212 char *name
, /* I - PageSize name buffer */
4213 size_t namesize
) /* I - Size of name buffer */
4215 const char *sizeptr
, /* Pointer to size in PWG name */
4216 *dimptr
; /* Pointer to dimensions in PWG name */
4220 * Range check input...
4223 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4227 * Copy or generate a PageSize name...
4233 * Use a standard Adobe name...
4236 strlcpy(name
, media
->ppd
, namesize
);
4238 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4239 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4240 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4241 (size_t)(dimptr
- sizeptr
) > namesize
)
4244 * Use a name of the form "wNNNhNNN"...
4247 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4248 (int)PWG_TO_POINTS(media
->length
));
4253 * Copy the size name from class_sizename_dimensions...
4256 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4257 name
[dimptr
- sizeptr
- 1] = '\0';
4265 * 'pwg_add_finishing()' - Add a finishings value.
4270 cups_array_t
*finishings
, /* I - Finishings array */
4271 ipp_finishings_t
template, /* I - Finishing template */
4272 const char *name
, /* I - PPD option */
4273 const char *value
) /* I - PPD choice */
4275 _pwg_finishings_t
*f
; /* New finishings value */
4278 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4280 f
->value
= template;
4281 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4283 cupsArrayAdd(finishings
, f
);
4289 * 'pwg_compare_finishings()' - Compare two finishings values.
4292 static int /* O - Result of comparison */
4293 pwg_compare_finishings(
4294 _pwg_finishings_t
*a
, /* I - First finishings value */
4295 _pwg_finishings_t
*b
) /* I - Second finishings value */
4297 return ((int)b
->value
- (int)a
->value
);
4302 * 'pwg_free_finishings()' - Free a finishings value.
4306 pwg_free_finishings(
4307 _pwg_finishings_t
*f
) /* I - Finishings value */
4309 cupsFreeOptions(f
->num_options
, f
->options
);
4315 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4319 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4320 char *name
, /* I - Name buffer */
4321 size_t namesize
) /* I - Size of name buffer */
4323 char *ptr
, /* Pointer into name buffer */
4324 *end
; /* End of name buffer */
4333 *name
= (char)toupper(*ipp
++);
4335 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4337 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4340 *ptr
++ = (char)toupper(*ipp
++ & 255);
4351 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4355 pwg_ppdize_resolution(
4356 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4357 int element
, /* I - Element to convert */
4358 int *xres
, /* O - X resolution in DPI */
4359 int *yres
, /* O - Y resolution in DPI */
4360 char *name
, /* I - Name buffer */
4361 size_t namesize
) /* I - Size of name buffer */
4363 ipp_res_t units
; /* Units for resolution */
4366 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4368 if (units
== IPP_RES_PER_CM
)
4370 *xres
= (int)(*xres
* 2.54);
4371 *yres
= (int)(*yres
* 2.54);
4374 if (name
&& namesize
> 4)
4377 snprintf(name
, namesize
, "%ddpi", *xres
);
4379 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4385 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4389 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4390 char *name
, /* I - Name buffer */
4391 size_t namesize
, /* I - Size of name buffer */
4392 const char *dashchars
)/* I - Characters to be replaced by dashes */
4394 char *ptr
, /* Pointer into name buffer */
4395 *end
; /* End of name buffer */
4398 if (_cups_islower(*ppd
))
4401 * Already lowercase name, use as-is?
4404 const char *ppdptr
; /* Pointer into PPD keyword */
4406 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4407 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4412 strlcpy(name
, ppd
, namesize
);
4417 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4419 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4420 *ptr
++ = (char)tolower(*ppd
& 255);
4421 else if (strchr(dashchars
, *ppd
))
4426 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4427 _cups_isupper(ppd
[1]) && ptr
< end
)
4429 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))