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 */
81 int finishings_copies
= copies
;
82 /* Number of copies for finishings */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "job-account-id") &&
145 strcmp(mandatory
, "job-accounting-user-id") &&
146 strcmp(mandatory
, "job-password") &&
147 strcmp(mandatory
, "job-password-encryption") &&
148 strcmp(mandatory
, "media") &&
149 strncmp(mandatory
, "media-col", 9) &&
150 strcmp(mandatory
, "multiple-document-handling") &&
151 strcmp(mandatory
, "output-bin") &&
152 strcmp(mandatory
, "print-color-mode") &&
153 strcmp(mandatory
, "print-quality") &&
154 strcmp(mandatory
, "sides") &&
155 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
157 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
159 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
164 case IPP_TAG_INTEGER
:
166 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
168 case IPP_TAG_BOOLEAN
:
169 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
173 int lower
, upper
; /* Range */
175 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
176 lower
= upper
= atoi(keyword
);
178 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
181 case IPP_TAG_STRING
:
182 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
185 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
187 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
188 keyword
= "auto-monochrome";
189 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
190 keyword
= "process-monochrome";
193 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
199 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
200 keyword
= cupsGetOption("media", num_options
, options
);
202 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
203 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
204 size
= _ppdCacheGetSize(pc
, keyword
);
206 if (size
|| media_source
|| media_type
)
209 * Add a media-col value...
212 media_col
= ippNew();
216 media_size
= ippNew();
217 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
218 "x-dimension", size
->width
);
219 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
220 "y-dimension", size
->length
);
222 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
225 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
227 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
229 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
233 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
234 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
235 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
237 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
238 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
241 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
244 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
246 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
247 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
251 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
253 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
255 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
257 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
259 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
260 keyword
= "monochrome";
266 if (keyword
&& !strcmp(keyword
, "monochrome"))
268 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
269 keyword
= "auto-monochrome";
270 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
271 keyword
= "process-monochrome";
275 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
277 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
278 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
279 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
281 if (!_cups_strcasecmp(choice
->choice
, "draft"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
283 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
285 else if (!_cups_strcasecmp(choice
->choice
, "high"))
286 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
289 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
290 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
291 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
293 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
295 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
297 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
298 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
305 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
307 if (strstr(keyword
, "uncollated"))
312 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
317 if (!_cups_strcasecmp(format
, "image/gif") ||
318 !_cups_strcasecmp(format
, "image/jp2") ||
319 !_cups_strcasecmp(format
, "image/jpeg") ||
320 !_cups_strcasecmp(format
, "image/png") ||
321 !_cups_strcasecmp(format
, "image/tiff") ||
322 !_cups_strncasecmp(format
, "image/x-", 8))
325 * Collation makes no sense for single page image formats...
330 else if (!_cups_strncasecmp(format
, "image/", 6) ||
331 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
334 * Multi-page image formats will have copies applied by the upstream
342 if (doc_handling_sup
)
344 if (!_cups_strcasecmp(keyword
, "true"))
345 collate_str
= "separate-documents-collated-copies";
347 collate_str
= "separate-documents-uncollated-copies";
349 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
351 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
353 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
358 if (i
>= doc_handling_sup
->num_values
)
363 * Map finishing options...
366 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
367 if (num_finishings
> 0)
369 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
371 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
374 * Send job-pages-per-set attribute to apply finishings correctly...
377 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
386 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
389 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
393 _ppd_cache_t
* /* O - PPD cache and mapping data */
394 _ppdCacheCreateWithFile(
395 const char *filename
, /* I - File to read */
396 ipp_t
**attrs
) /* IO - IPP attributes, if any */
398 cups_file_t
*fp
; /* File */
399 _ppd_cache_t
*pc
; /* PWG mapping data */
400 pwg_size_t
*size
; /* Current size */
401 pwg_map_t
*map
; /* Current map */
402 _pwg_finishings_t
*finishings
; /* Current finishings option */
403 int linenum
, /* Current line number */
404 num_bins
, /* Number of bins in file */
405 num_sizes
, /* Number of sizes in file */
406 num_sources
, /* Number of sources in file */
407 num_types
; /* Number of types in file */
408 char line
[2048], /* Current line */
409 *value
, /* Pointer to value in line */
410 *valueptr
, /* Pointer into value */
411 pwg_keyword
[128], /* PWG keyword */
412 ppd_keyword
[PPD_MAX_NAME
];
414 _pwg_print_color_mode_t print_color_mode
;
415 /* Print color mode for preset */
416 _pwg_print_quality_t print_quality
; /* Print quality for preset */
419 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
422 * Range check input...
430 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
438 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
440 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
445 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
448 if (!cupsFileGets(fp
, line
, sizeof(line
)))
450 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
451 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
456 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
458 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
459 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
464 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
466 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
467 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
468 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
474 * Allocate the mapping data structure...
477 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
479 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
480 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
484 pc
->max_copies
= 9999;
496 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
498 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
499 "linenum=%d", line
, value
, linenum
));
503 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
505 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
508 else if (!_cups_strcasecmp(line
, "Filter"))
511 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
512 (cups_acopy_func_t
)_cupsStrAlloc
,
513 (cups_afree_func_t
)_cupsStrFree
);
515 cupsArrayAdd(pc
->filters
, value
);
517 else if (!_cups_strcasecmp(line
, "PreFilter"))
520 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
521 (cups_acopy_func_t
)_cupsStrAlloc
,
522 (cups_afree_func_t
)_cupsStrFree
);
524 cupsArrayAdd(pc
->prefilters
, value
);
526 else if (!_cups_strcasecmp(line
, "Product"))
528 pc
->product
= _cupsStrAlloc(value
);
530 else if (!_cups_strcasecmp(line
, "SingleFile"))
532 pc
->single_file
= !_cups_strcasecmp(value
, "true");
534 else if (!_cups_strcasecmp(line
, "IPP"))
536 off_t pos
= cupsFileTell(fp
), /* Position in file */
537 length
= strtol(value
, NULL
, 10);
538 /* Length of IPP attributes */
542 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
543 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
546 else if (length
<= 0)
548 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
549 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
556 * Read IPP attributes into the provided variable...
561 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
562 *attrs
) != IPP_STATE_DATA
)
564 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
565 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
572 * Skip the IPP data entirely...
575 cupsFileSeek(fp
, pos
+ length
);
578 if (cupsFileTell(fp
) != (pos
+ length
))
580 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
581 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
585 else if (!_cups_strcasecmp(line
, "NumBins"))
589 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
590 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
594 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
596 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
597 "%d.", num_sizes
, linenum
));
598 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
602 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
604 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
606 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
610 else if (!_cups_strcasecmp(line
, "Bin"))
612 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
614 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
615 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
619 if (pc
->num_bins
>= num_bins
)
621 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
623 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
627 map
= pc
->bins
+ pc
->num_bins
;
628 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
629 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
633 else if (!_cups_strcasecmp(line
, "NumSizes"))
637 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
638 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
642 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
644 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
645 "%d.", num_sizes
, linenum
));
646 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
652 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
654 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
656 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
661 else if (!_cups_strcasecmp(line
, "Size"))
663 if (pc
->num_sizes
>= num_sizes
)
665 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
667 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
671 size
= pc
->sizes
+ pc
->num_sizes
;
673 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
674 &(size
->width
), &(size
->length
), &(size
->left
),
675 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
677 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
679 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
683 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
684 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
688 else if (!_cups_strcasecmp(line
, "CustomSize"))
690 if (pc
->custom_max_width
> 0)
692 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
694 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
698 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
699 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
700 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
701 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
702 &(pc
->custom_size
.top
)) != 8)
704 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
706 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
710 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
711 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
712 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
714 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
715 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
716 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
718 else if (!_cups_strcasecmp(line
, "SourceOption"))
720 pc
->source_option
= _cupsStrAlloc(value
);
722 else if (!_cups_strcasecmp(line
, "NumSources"))
726 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
728 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
732 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
734 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
735 "line %d.", num_sources
, linenum
));
736 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
740 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
742 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
744 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
748 else if (!_cups_strcasecmp(line
, "Source"))
750 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
752 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
754 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
758 if (pc
->num_sources
>= num_sources
)
760 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
762 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
766 map
= pc
->sources
+ pc
->num_sources
;
767 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
768 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
772 else if (!_cups_strcasecmp(line
, "NumTypes"))
776 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
777 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
781 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
783 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
784 "line %d.", num_types
, linenum
));
785 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
789 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
791 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
793 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
797 else if (!_cups_strcasecmp(line
, "Type"))
799 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
801 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
803 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
807 if (pc
->num_types
>= num_types
)
809 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
811 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
815 map
= pc
->types
+ pc
->num_types
;
816 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
817 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
821 else if (!_cups_strcasecmp(line
, "Preset"))
824 * Preset output-mode print-quality name=value ...
827 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
828 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
830 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
831 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
832 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
833 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
834 valueptr
== value
|| !*valueptr
)
836 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
838 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
842 pc
->num_presets
[print_color_mode
][print_quality
] =
843 cupsParseOptions(valueptr
, 0,
844 pc
->presets
[print_color_mode
] + print_quality
);
846 else if (!_cups_strcasecmp(line
, "SidesOption"))
847 pc
->sides_option
= _cupsStrAlloc(value
);
848 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
849 pc
->sides_1sided
= _cupsStrAlloc(value
);
850 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
851 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
852 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
853 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
854 else if (!_cups_strcasecmp(line
, "Finishings"))
858 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
860 (cups_afree_func_t
)pwg_free_finishings
);
862 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
865 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
866 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
867 &(finishings
->options
));
869 cupsArrayAdd(pc
->finishings
, finishings
);
871 else if (!_cups_strcasecmp(line
, "MaxCopies"))
872 pc
->max_copies
= atoi(value
);
873 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
874 pc
->charge_info_uri
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "JobAccountId"))
876 pc
->account_id
= !_cups_strcasecmp(value
, "true");
877 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
878 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
879 else if (!_cups_strcasecmp(line
, "JobPassword"))
880 pc
->password
= _cupsStrAlloc(value
);
881 else if (!_cups_strcasecmp(line
, "Mandatory"))
884 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
886 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
888 else if (!_cups_strcasecmp(line
, "SupportFile"))
890 if (!pc
->support_files
)
891 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
892 (cups_acopy_func_t
)_cupsStrAlloc
,
893 (cups_afree_func_t
)_cupsStrFree
);
895 cupsArrayAdd(pc
->support_files
, value
);
899 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
904 if (pc
->num_sizes
< num_sizes
)
906 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
907 pc
->num_sizes
, num_sizes
));
908 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
912 if (pc
->num_sources
< num_sources
)
914 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
915 pc
->num_sources
, num_sources
));
916 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
920 if (pc
->num_types
< num_types
)
922 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
923 pc
->num_types
, num_types
));
924 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
933 * If we get here the file was bad - free any data and return...
939 _ppdCacheDestroy(pc
);
952 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
955 _ppd_cache_t
* /* O - PPD cache and mapping data */
956 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
958 int i
, j
, k
; /* Looping vars */
959 _ppd_cache_t
*pc
; /* PWG mapping data */
960 ppd_option_t
*input_slot
, /* InputSlot option */
961 *media_type
, /* MediaType option */
962 *output_bin
, /* OutputBin option */
963 *color_model
, /* ColorModel option */
964 *duplex
; /* Duplex option */
965 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
966 pwg_map_t
*map
; /* Current source/type map */
967 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
968 int num_options
; /* Number of preset options and props */
969 cups_option_t
*options
; /* Preset options and properties */
970 ppd_size_t
*ppd_size
; /* Current PPD size */
971 pwg_size_t
*pwg_size
; /* Current PWG size */
972 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
973 /* PWG keyword string */
974 ppd_name
[PPD_MAX_NAME
];
975 /* Normalized PPD name */
976 const char *pwg_name
; /* Standard PWG media name */
977 pwg_media_t
*pwg_media
; /* PWG media data */
978 _pwg_print_color_mode_t pwg_print_color_mode
;
979 /* print-color-mode index */
980 _pwg_print_quality_t pwg_print_quality
;
981 /* print-quality index */
982 int similar
; /* Are the old and new size similar? */
983 pwg_size_t
*old_size
; /* Current old size */
984 int old_imageable
, /* Old imageable length in 2540ths */
985 old_borderless
, /* Old borderless state */
986 old_known_pwg
; /* Old PWG name is well-known */
987 int new_width
, /* New width in 2540ths */
988 new_length
, /* New length in 2540ths */
989 new_left
, /* New left margin in 2540ths */
990 new_bottom
, /* New bottom margin in 2540ths */
991 new_right
, /* New right margin in 2540ths */
992 new_top
, /* New top margin in 2540ths */
993 new_imageable
, /* New imageable length in 2540ths */
994 new_borderless
, /* New borderless state */
995 new_known_pwg
; /* New PWG name is well-known */
996 pwg_size_t
*new_size
; /* New size to add, if any */
997 const char *filter
; /* Current filter */
998 _pwg_finishings_t
*finishings
; /* Current finishings value */
1001 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1004 * Range check input...
1011 * Allocate memory...
1014 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1016 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1021 * Copy and convert size data...
1024 if (ppd
->num_sizes
> 0)
1026 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1028 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1029 "pwg_size_t's.", ppd
->num_sizes
));
1033 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1038 * Don't copy over custom size...
1041 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1045 * Convert the PPD size name to the corresponding PWG keyword name.
1048 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1051 * Standard name, do we have conflicts?
1054 for (j
= 0; j
< pc
->num_sizes
; j
++)
1055 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1065 * Standard name and no conflicts, use it!
1068 pwg_name
= pwg_media
->pwg
;
1074 * Not a standard name; convert it to a PWG vendor name of the form:
1076 * pp_lowerppd_WIDTHxHEIGHTuu
1079 pwg_name
= pwg_keyword
;
1082 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1083 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1084 PWG_FROM_POINTS(ppd_size
->width
),
1085 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1089 * If we have a similar paper with non-zero margins then we only want to
1090 * keep it if it has a larger imageable area length. The NULL check is for
1091 * dimensions that are <= 0...
1094 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1095 PWG_FROM_POINTS(ppd_size
->length
),
1099 new_width
= pwg_media
->width
;
1100 new_length
= pwg_media
->length
;
1101 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1102 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1103 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1104 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1105 new_imageable
= new_length
- new_top
- new_bottom
;
1106 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1107 new_left
== 0 && new_right
== 0;
1109 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1113 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1114 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1115 old_size
->right
== 0 && old_size
->top
== 0;
1116 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1117 strncmp(old_size
->map
.pwg
, "om_", 3);
1119 similar
= old_borderless
== new_borderless
&&
1120 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1121 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1124 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1127 * The new paper has a larger imageable area so it could replace
1128 * the older paper. Regardless of the imageable area, we always
1129 * prefer the size with a well-known PWG name.
1132 new_size
= old_size
;
1133 _cupsStrFree(old_size
->map
.ppd
);
1134 _cupsStrFree(old_size
->map
.pwg
);
1141 * The paper was unique enough to deserve its own entry so add it to the
1145 new_size
= pwg_size
++;
1155 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1156 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1157 new_size
->width
= new_width
;
1158 new_size
->length
= new_length
;
1159 new_size
->left
= new_left
;
1160 new_size
->bottom
= new_bottom
;
1161 new_size
->right
= new_right
;
1162 new_size
->top
= new_top
;
1167 if (ppd
->variable_sizes
)
1170 * Generate custom size data...
1173 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1174 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1175 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1176 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1177 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1178 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1180 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1181 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1182 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1183 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1184 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1185 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1187 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1188 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1189 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1190 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1194 * Copy and convert InputSlot data...
1197 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1198 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1202 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1204 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1206 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1207 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1211 pc
->num_sources
= input_slot
->num_choices
;
1213 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1216 i
--, choice
++, map
++)
1218 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1219 !_cups_strcasecmp(choice
->choice
, "Default"))
1221 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1223 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1225 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1227 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1228 !_cups_strcasecmp(choice
->choice
, "MP") ||
1229 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1230 pwg_name
= "by-pass-tray";
1231 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1232 pwg_name
= "large-capacity";
1233 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1234 pwg_name
= "bottom";
1235 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1236 pwg_name
= "middle";
1237 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1239 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1241 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1242 pwg_name
= "main-roll";
1246 * Convert PPD name to lowercase...
1249 pwg_name
= pwg_keyword
;
1250 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1254 map
->pwg
= _cupsStrAlloc(pwg_name
);
1255 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1260 * Copy and convert MediaType data...
1263 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1265 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1267 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1268 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1272 pc
->num_types
= media_type
->num_choices
;
1274 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1277 i
--, choice
++, map
++)
1279 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1280 !_cups_strcasecmp(choice
->choice
, "Any") ||
1281 !_cups_strcasecmp(choice
->choice
, "Default"))
1283 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1284 pwg_name
= "cardstock";
1285 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1286 pwg_name
= "envelope";
1287 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1288 pwg_name
= "photographic-glossy";
1289 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1290 pwg_name
= "photographic-high-gloss";
1291 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1292 pwg_name
= "photographic-matte";
1293 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1294 pwg_name
= "stationery";
1295 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1296 pwg_name
= "stationery-coated";
1297 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1298 pwg_name
= "stationery-inkjet";
1299 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1300 pwg_name
= "stationery-letterhead";
1301 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1302 pwg_name
= "stationery-preprinted";
1303 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1304 pwg_name
= "stationery-recycled";
1305 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1306 pwg_name
= "transparency";
1310 * Convert PPD name to lowercase...
1313 pwg_name
= pwg_keyword
;
1314 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1318 map
->pwg
= _cupsStrAlloc(pwg_name
);
1319 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1324 * Copy and convert OutputBin data...
1327 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1329 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1331 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1332 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1336 pc
->num_bins
= output_bin
->num_choices
;
1338 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1341 i
--, choice
++, map
++)
1343 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1345 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1346 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1350 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1353 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1356 const char *quality
, /* com.apple.print.preset.quality value */
1357 *output_mode
, /* com.apple.print.preset.output-mode value */
1358 *color_model_val
, /* ColorModel choice */
1359 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1360 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1364 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1367 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1368 num_options
, options
)) != NULL
)
1371 * Get the print-quality for this preset...
1374 if (!strcmp(quality
, "low"))
1375 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1376 else if (!strcmp(quality
, "high"))
1377 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1379 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1382 * Ignore graphicsType "Photo" presets that are not high quality.
1385 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1386 num_options
, options
);
1388 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1389 !strcmp(graphicsType
, "Photo"))
1393 * Ignore presets for normal and draft quality where the coating
1394 * isn't "none" or "autodetect".
1397 media_front_coating
= cupsGetOption(
1398 "com.apple.print.preset.media-front-coating",
1399 num_options
, options
);
1401 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1402 media_front_coating
&&
1403 strcmp(media_front_coating
, "none") &&
1404 strcmp(media_front_coating
, "autodetect"))
1408 * Get the output mode for this preset...
1411 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1412 num_options
, options
);
1413 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1417 if (!strcmp(output_mode
, "monochrome"))
1418 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1420 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1422 else if (color_model_val
)
1424 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1425 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1427 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1430 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1433 * Save the options for this combination as needed...
1436 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1437 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1438 _ppdParseOptions(ppd_attr
->value
, 0,
1439 pc
->presets
[pwg_print_color_mode
] +
1440 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1443 cupsFreeOptions(num_options
, options
);
1445 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1448 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1449 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1450 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1453 * Try adding some common color options to create grayscale presets. These
1454 * are listed in order of popularity...
1457 const char *color_option
= NULL
, /* Color control option */
1458 *gray_choice
= NULL
; /* Choice to select grayscale */
1460 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1461 ppdFindChoice(color_model
, "Gray"))
1463 color_option
= "ColorModel";
1464 gray_choice
= "Gray";
1466 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1467 ppdFindChoice(color_model
, "grayscale"))
1469 color_option
= "HPColorMode";
1470 gray_choice
= "grayscale";
1472 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1473 ppdFindChoice(color_model
, "Mono"))
1475 color_option
= "BRMonoColor";
1476 gray_choice
= "Mono";
1478 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1479 ppdFindChoice(color_model
, "1"))
1481 color_option
= "CNIJSGrayScale";
1484 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1485 ppdFindChoice(color_model
, "True"))
1487 color_option
= "HPColorAsGray";
1488 gray_choice
= "True";
1491 if (color_option
&& gray_choice
)
1494 * Copy and convert ColorModel (output-mode) data...
1497 cups_option_t
*coption
, /* Color option */
1498 *moption
; /* Monochrome option */
1500 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1501 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1502 pwg_print_quality
++)
1504 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1507 * Copy the color options...
1510 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1511 [pwg_print_quality
];
1512 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1516 for (i
= num_options
, moption
= options
,
1517 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1518 [pwg_print_quality
];
1520 i
--, moption
++, coption
++)
1522 moption
->name
= _cupsStrRetain(coption
->name
);
1523 moption
->value
= _cupsStrRetain(coption
->value
);
1526 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1528 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1532 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1536 * Add the grayscale option to the preset...
1539 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1540 cupsAddOption(color_option
, gray_choice
,
1541 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1542 [pwg_print_quality
],
1543 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1550 * Copy and convert Duplex (sides) data...
1553 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1554 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1555 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1556 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1557 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1561 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1563 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1567 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1568 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1569 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1570 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1571 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1572 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1573 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1574 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1575 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1576 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1577 !pc
->sides_2sided_short
)
1578 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1583 * Copy filters and pre-filters...
1586 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1587 (cups_acopy_func_t
)_cupsStrAlloc
,
1588 (cups_afree_func_t
)_cupsStrFree
);
1590 cupsArrayAdd(pc
->filters
,
1591 "application/vnd.cups-raw application/octet-stream 0 -");
1593 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1597 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1599 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1601 else if (ppd
->num_filters
> 0)
1603 for (i
= 0; i
< ppd
->num_filters
; i
++)
1604 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1607 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1610 * See if we have a command filter...
1613 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1615 filter
= (const char *)cupsArrayNext(pc
->filters
))
1616 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1617 _cups_isspace(filter
[28]))
1621 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1622 _cups_strcasecmp(ppd_attr
->value
, "none")))
1625 * No command filter and no cupsCommands keyword telling us not to use one.
1626 * See if this is a PostScript printer, and if so add a PostScript command
1630 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1632 filter
= (const char *)cupsArrayNext(pc
->filters
))
1633 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1634 _cups_isspace(filter
[31]))
1638 cupsArrayAdd(pc
->filters
,
1639 "application/vnd.cups-command application/postscript 100 "
1643 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1645 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1646 (cups_acopy_func_t
)_cupsStrAlloc
,
1647 (cups_afree_func_t
)_cupsStrFree
);
1651 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1653 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1656 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1657 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1660 * Copy the product string, if any...
1664 pc
->product
= _cupsStrAlloc(ppd
->product
);
1667 * Copy finishings mapping data...
1670 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1673 * Have proper vendor mapping of IPP finishings values to PPD options...
1676 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1677 NULL
, NULL
, 0, NULL
,
1678 (cups_afree_func_t
)pwg_free_finishings
);
1682 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1685 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1686 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1687 &(finishings
->options
),
1688 _PPD_PARSE_OPTIONS
);
1690 cupsArrayAdd(pc
->finishings
, finishings
);
1692 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1698 * No IPP mapping data, try to map common/standard PPD keywords...
1701 ppd_option_t
*ppd_option
; /* PPD option */
1703 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1705 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1708 * Add staple finishings...
1711 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1712 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1713 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1714 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1715 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1716 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1717 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1718 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1719 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1720 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1723 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1726 * Add (Ricoh) punch finishings...
1729 if (ppdFindChoice(ppd_option
, "Left2"))
1730 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1731 if (ppdFindChoice(ppd_option
, "Left3"))
1732 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1733 if (ppdFindChoice(ppd_option
, "Left4"))
1734 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1735 if (ppdFindChoice(ppd_option
, "Right2"))
1736 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1737 if (ppdFindChoice(ppd_option
, "Right3"))
1738 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1739 if (ppdFindChoice(ppd_option
, "Right4"))
1740 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1741 if (ppdFindChoice(ppd_option
, "Upper2"))
1742 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1743 if (ppdFindChoice(ppd_option
, "Upper3"))
1744 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1745 if (ppdFindChoice(ppd_option
, "Upper4"))
1746 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1749 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1752 * Add bind finishings...
1755 if (ppdFindChoice(ppd_option
, "Left"))
1756 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1757 if (ppdFindChoice(ppd_option
, "Right"))
1758 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1759 if (ppdFindChoice(ppd_option
, "Top"))
1760 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1761 if (ppdFindChoice(ppd_option
, "Bottom"))
1762 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1765 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1768 * Add (Adobe) fold finishings...
1771 if (ppdFindChoice(ppd_option
, "ZFold"))
1772 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1773 if (ppdFindChoice(ppd_option
, "Saddle"))
1774 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1775 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1777 if (ppdFindChoice(ppd_option
, "LeftGate"))
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1779 if (ppdFindChoice(ppd_option
, "RightGate"))
1780 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1781 if (ppdFindChoice(ppd_option
, "Letter"))
1782 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1783 if (ppdFindChoice(ppd_option
, "XFold"))
1784 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1787 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1790 * Add (Ricoh) fold finishings...
1793 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1794 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1797 if (cupsArrayCount(pc
->finishings
) == 0)
1799 cupsArrayDelete(pc
->finishings
);
1800 pc
->finishings
= NULL
;
1808 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1809 pc
->max_copies
= atoi(ppd_attr
->value
);
1810 else if (ppd
->manual_copies
)
1813 pc
->max_copies
= 9999;
1816 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1817 * cupsJobPassword, and cupsMandatory.
1820 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1821 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1823 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1824 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1826 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1827 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1829 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1830 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1832 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1833 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1839 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1840 (cups_acopy_func_t
)_cupsStrAlloc
,
1841 (cups_afree_func_t
)_cupsStrFree
);
1843 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1845 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1846 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1848 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1849 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1852 * Return the cache data...
1858 * If we get here we need to destroy the PWG mapping data and return NULL...
1863 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1864 _ppdCacheDestroy(pc
);
1871 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1875 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1877 int i
; /* Looping var */
1878 pwg_map_t
*map
; /* Current map */
1879 pwg_size_t
*size
; /* Current size */
1883 * Range check input...
1890 * Free memory as needed...
1895 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1897 _cupsStrFree(map
->pwg
);
1898 _cupsStrFree(map
->ppd
);
1906 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1908 _cupsStrFree(size
->map
.pwg
);
1909 _cupsStrFree(size
->map
.ppd
);
1915 if (pc
->source_option
)
1916 _cupsStrFree(pc
->source_option
);
1920 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1922 _cupsStrFree(map
->pwg
);
1923 _cupsStrFree(map
->ppd
);
1931 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1933 _cupsStrFree(map
->pwg
);
1934 _cupsStrFree(map
->ppd
);
1940 if (pc
->custom_max_keyword
)
1941 _cupsStrFree(pc
->custom_max_keyword
);
1943 if (pc
->custom_min_keyword
)
1944 _cupsStrFree(pc
->custom_min_keyword
);
1946 _cupsStrFree(pc
->product
);
1947 cupsArrayDelete(pc
->filters
);
1948 cupsArrayDelete(pc
->prefilters
);
1949 cupsArrayDelete(pc
->finishings
);
1951 _cupsStrFree(pc
->charge_info_uri
);
1952 _cupsStrFree(pc
->password
);
1954 cupsArrayDelete(pc
->mandatory
);
1956 cupsArrayDelete(pc
->support_files
);
1963 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1967 const char * /* O - output-bin or NULL */
1969 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1970 const char *output_bin
) /* I - PPD OutputBin string */
1972 int i
; /* Looping var */
1976 * Range check input...
1979 if (!pc
|| !output_bin
)
1983 * Look up the OutputBin string...
1987 for (i
= 0; i
< pc
->num_bins
; i
++)
1988 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1989 return (pc
->bins
[i
].pwg
);
1996 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1997 * IPP finishings value(s).
2000 int /* O - New number of options */
2001 _ppdCacheGetFinishingOptions(
2002 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2003 ipp_t
*job
, /* I - Job attributes or NULL */
2004 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2005 int num_options
, /* I - Number of options */
2006 cups_option_t
**options
) /* IO - Options */
2008 int i
; /* Looping var */
2009 _pwg_finishings_t
*f
, /* PWG finishings options */
2010 key
; /* Search key */
2011 ipp_attribute_t
*attr
; /* Finishings attribute */
2012 cups_option_t
*option
; /* Current finishings option */
2016 * Range check input...
2019 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2020 (!job
&& value
== IPP_FINISHINGS_NONE
))
2021 return (num_options
);
2024 * Apply finishing options...
2027 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2029 int num_values
= ippGetCount(attr
); /* Number of values */
2031 for (i
= 0; i
< num_values
; i
++)
2033 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2035 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2037 int j
; /* Another looping var */
2039 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2040 num_options
= cupsAddOption(option
->name
, option
->value
,
2041 num_options
, options
);
2045 else if (value
!= IPP_FINISHINGS_NONE
)
2049 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2051 int j
; /* Another looping var */
2053 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2054 num_options
= cupsAddOption(option
->name
, option
->value
,
2055 num_options
, options
);
2059 return (num_options
);
2064 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2068 int /* O - Number of finishings values */
2069 _ppdCacheGetFinishingValues(
2070 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2071 int num_options
, /* I - Number of options */
2072 cups_option_t
*options
, /* I - Options */
2073 int max_values
, /* I - Maximum number of finishings values */
2074 int *values
) /* O - Finishings values */
2076 int i
, /* Looping var */
2077 num_values
= 0; /* Number of values */
2078 _pwg_finishings_t
*f
; /* Current finishings option */
2079 cups_option_t
*option
; /* Current option */
2080 const char *val
; /* Value for option */
2084 * Range check input...
2087 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2089 if (!pc
|| max_values
< 1 || !values
)
2091 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2094 else if (!pc
->finishings
)
2096 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2101 * Go through the finishings options and see what is set...
2104 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2106 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2108 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2110 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2112 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2114 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2115 _cups_strcasecmp(option
->value
, val
))
2117 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2124 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2126 values
[num_values
++] = f
->value
;
2128 if (num_values
>= max_values
)
2133 if (num_values
== 0)
2136 * Always have at least "finishings" = 'none'...
2139 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2140 values
[0] = IPP_FINISHINGS_NONE
;
2144 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2146 return (num_values
);
2151 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2152 * attributes or a keyword string.
2155 const char * /* O - PPD InputSlot or NULL */
2156 _ppdCacheGetInputSlot(
2157 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2158 ipp_t
*job
, /* I - Job attributes or NULL */
2159 const char *keyword
) /* I - Keyword string or NULL */
2162 * Range check input...
2165 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2168 if (job
&& !keyword
)
2171 * Lookup the media-col attribute and any media-source found there...
2174 ipp_attribute_t
*media_col
, /* media-col attribute */
2175 *media_source
; /* media-source attribute */
2176 pwg_size_t size
; /* Dimensional size */
2177 int margins_set
; /* Were the margins set? */
2179 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2181 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2183 IPP_TAG_KEYWORD
)) != NULL
)
2186 * Use the media-source value from media-col...
2189 keyword
= ippGetString(media_source
, 0, NULL
);
2191 else if (pwgInitSize(&size
, job
, &margins_set
))
2194 * For media <= 5x7, look for a photo tray...
2197 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2204 int i
; /* Looping var */
2206 for (i
= 0; i
< pc
->num_sources
; i
++)
2207 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2208 return (pc
->sources
[i
].ppd
);
2216 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2217 * attributes or a keyword string.
2220 const char * /* O - PPD MediaType or NULL */
2221 _ppdCacheGetMediaType(
2222 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2223 ipp_t
*job
, /* I - Job attributes or NULL */
2224 const char *keyword
) /* I - Keyword string or NULL */
2227 * Range check input...
2230 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2233 if (job
&& !keyword
)
2236 * Lookup the media-col attribute and any media-source found there...
2239 ipp_attribute_t
*media_col
, /* media-col attribute */
2240 *media_type
; /* media-type attribute */
2242 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2245 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2247 IPP_TAG_KEYWORD
)) == NULL
)
2248 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2249 "media-type", IPP_TAG_NAME
);
2252 keyword
= media_type
->values
[0].string
.text
;
2258 int i
; /* Looping var */
2260 for (i
= 0; i
< pc
->num_types
; i
++)
2261 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2262 return (pc
->types
[i
].ppd
);
2270 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2274 const char * /* O - PPD OutputBin or NULL */
2275 _ppdCacheGetOutputBin(
2276 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2277 const char *output_bin
) /* I - Keyword string */
2279 int i
; /* Looping var */
2283 * Range check input...
2286 if (!pc
|| !output_bin
)
2290 * Look up the OutputBin string...
2294 for (i
= 0; i
< pc
->num_bins
; i
++)
2295 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2296 return (pc
->bins
[i
].ppd
);
2303 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2304 * attributes or a keyword string.
2307 const char * /* O - PPD PageSize or NULL */
2308 _ppdCacheGetPageSize(
2309 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2310 ipp_t
*job
, /* I - Job attributes or NULL */
2311 const char *keyword
, /* I - Keyword string or NULL */
2312 int *exact
) /* O - 1 if exact match, 0 otherwise */
2314 int i
; /* Looping var */
2315 pwg_size_t
*size
, /* Current size */
2316 *closest
, /* Closest size */
2317 jobsize
; /* Size data from job */
2318 int margins_set
, /* Were the margins set? */
2319 dwidth
, /* Difference in width */
2320 dlength
, /* Difference in length */
2321 dleft
, /* Difference in left margins */
2322 dright
, /* Difference in right margins */
2323 dbottom
, /* Difference in bottom margins */
2324 dtop
, /* Difference in top margins */
2325 dmin
, /* Minimum difference */
2326 dclosest
; /* Closest difference */
2327 const char *ppd_name
; /* PPD media name */
2330 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2331 pc
, job
, keyword
, exact
));
2334 * Range check input...
2337 if (!pc
|| (!job
&& !keyword
))
2348 * Try getting the PPD media name from the job attributes...
2351 ipp_attribute_t
*attr
; /* Job attribute */
2353 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2354 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2355 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2359 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2360 attr
->name
, ippTagString(attr
->value_tag
)));
2362 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2365 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2366 attr
->value_tag
== IPP_TAG_KEYWORD
))
2367 ppd_name
= attr
->values
[0].string
.text
;
2370 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2375 * Try looking up the named PPD size first...
2378 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2380 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2381 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2383 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2384 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2389 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2391 return (size
->map
.ppd
);
2396 if (job
&& !keyword
)
2399 * Get the size using media-col or media, with the preference being
2403 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2409 * Get the size using a media keyword...
2412 pwg_media_t
*media
; /* Media definition */
2415 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2416 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2417 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2420 jobsize
.width
= media
->width
;
2421 jobsize
.length
= media
->length
;
2426 * Now that we have the dimensions and possibly the margins, look at the
2427 * available sizes and find the match...
2431 dclosest
= 999999999;
2433 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2434 _cups_strncasecmp(ppd_name
, "custom_", 7))
2436 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2439 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2440 * is just about 176/2540ths...
2443 dwidth
= size
->width
- jobsize
.width
;
2444 dlength
= size
->length
- jobsize
.length
;
2446 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2452 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2455 dleft
= size
->left
- jobsize
.left
;
2456 dright
= size
->right
- jobsize
.right
;
2457 dtop
= size
->top
- jobsize
.top
;
2458 dbottom
= size
->bottom
- jobsize
.bottom
;
2460 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2461 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2463 dleft
= dleft
< 0 ? -dleft
: dleft
;
2464 dright
= dright
< 0 ? -dright
: dright
;
2465 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2466 dtop
= dtop
< 0 ? -dtop
: dtop
;
2467 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2469 if (dmin
< dclosest
)
2482 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2484 return (size
->map
.ppd
);
2490 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2493 return (closest
->map
.ppd
);
2497 * If we get here we need to check for custom page size support...
2500 if (jobsize
.width
>= pc
->custom_min_width
&&
2501 jobsize
.width
<= pc
->custom_max_width
&&
2502 jobsize
.length
>= pc
->custom_min_length
&&
2503 jobsize
.length
<= pc
->custom_max_length
)
2506 * In range, format as Custom.WWWWxLLLL (points).
2509 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2510 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2512 if (margins_set
&& exact
)
2514 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2515 dright
= pc
->custom_size
.right
- jobsize
.right
;
2516 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2517 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2519 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2520 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2526 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2527 pc
->custom_ppd_size
));
2529 return (pc
->custom_ppd_size
);
2533 * No custom page size support or the size is out of range - return NULL.
2536 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2543 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2546 pwg_size_t
* /* O - PWG size or NULL */
2548 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2549 const char *page_size
) /* I - PPD PageSize */
2551 int i
; /* Looping var */
2552 pwg_media_t
*media
; /* Media */
2553 pwg_size_t
*size
; /* Current size */
2557 * Range check input...
2560 if (!pc
|| !page_size
)
2563 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2566 * Custom size; size name can be one of the following:
2568 * Custom.WIDTHxLENGTHin - Size in inches
2569 * Custom.WIDTHxLENGTHft - Size in feet
2570 * Custom.WIDTHxLENGTHcm - Size in centimeters
2571 * Custom.WIDTHxLENGTHmm - Size in millimeters
2572 * Custom.WIDTHxLENGTHm - Size in meters
2573 * Custom.WIDTHxLENGTH[pt] - Size in points
2576 double w
, l
; /* Width and length of page */
2577 char *ptr
; /* Pointer into PageSize */
2578 struct lconv
*loc
; /* Locale data */
2581 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2582 if (!ptr
|| *ptr
!= 'x')
2585 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2589 if (!_cups_strcasecmp(ptr
, "in"))
2594 else if (!_cups_strcasecmp(ptr
, "ft"))
2599 else if (!_cups_strcasecmp(ptr
, "mm"))
2604 else if (!_cups_strcasecmp(ptr
, "cm"))
2609 else if (!_cups_strcasecmp(ptr
, "m"))
2620 pc
->custom_size
.width
= (int)w
;
2621 pc
->custom_size
.length
= (int)l
;
2623 return (&(pc
->custom_size
));
2627 * Not a custom size - look it up...
2630 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2631 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2632 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2636 * Look up standard sizes...
2639 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2640 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2641 media
= pwgMediaForPWG(page_size
);
2645 pc
->custom_size
.width
= media
->width
;
2646 pc
->custom_size
.length
= media
->length
;
2648 return (&(pc
->custom_size
));
2656 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2660 const char * /* O - PWG media-source keyword */
2662 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2663 const char *input_slot
) /* I - PPD InputSlot */
2665 int i
; /* Looping var */
2666 pwg_map_t
*source
; /* Current source */
2670 * Range check input...
2673 if (!pc
|| !input_slot
)
2676 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2677 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2678 return (source
->pwg
);
2685 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2689 const char * /* O - PWG media-type keyword */
2691 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2692 const char *media_type
) /* I - PPD MediaType */
2694 int i
; /* Looping var */
2695 pwg_map_t
*type
; /* Current type */
2699 * Range check input...
2702 if (!pc
|| !media_type
)
2705 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2706 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2714 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2717 int /* O - 1 on success, 0 on failure */
2719 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2720 const char *filename
, /* I - File to write */
2721 ipp_t
*attrs
) /* I - Attributes to write, if any */
2723 int i
, j
, k
; /* Looping vars */
2724 cups_file_t
*fp
; /* Output file */
2725 pwg_size_t
*size
; /* Current size */
2726 pwg_map_t
*map
; /* Current map */
2727 _pwg_finishings_t
*f
; /* Current finishing option */
2728 cups_option_t
*option
; /* Current option */
2729 const char *value
; /* Filter/pre-filter value */
2730 char newfile
[1024]; /* New filename */
2734 * Range check input...
2737 if (!pc
|| !filename
)
2739 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2744 * Open the file and write with compression...
2747 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2748 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2750 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2755 * Standard header...
2758 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2764 if (pc
->num_bins
> 0)
2766 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2767 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2768 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2775 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2776 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2777 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2778 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2779 size
->bottom
, size
->right
, size
->top
);
2780 if (pc
->custom_max_width
> 0)
2781 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2782 pc
->custom_max_width
, pc
->custom_max_length
,
2783 pc
->custom_min_width
, pc
->custom_min_length
,
2784 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2785 pc
->custom_size
.right
, pc
->custom_size
.top
);
2791 if (pc
->source_option
)
2792 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2794 if (pc
->num_sources
> 0)
2796 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2797 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2798 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2805 if (pc
->num_types
> 0)
2807 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2808 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2809 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2816 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2817 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2818 if (pc
->num_presets
[i
][j
])
2820 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2821 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2824 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2825 cupsFilePutChar(fp
, '\n');
2832 if (pc
->sides_option
)
2833 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2835 if (pc
->sides_1sided
)
2836 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2838 if (pc
->sides_2sided_long
)
2839 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2841 if (pc
->sides_2sided_short
)
2842 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2845 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2849 cupsFilePutConf(fp
, "Product", pc
->product
);
2851 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2853 value
= (const char *)cupsArrayNext(pc
->filters
))
2854 cupsFilePutConf(fp
, "Filter", value
);
2856 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2858 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2859 cupsFilePutConf(fp
, "PreFilter", value
);
2861 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2864 * Finishing options...
2867 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2869 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2871 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2872 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2873 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2874 cupsFilePutChar(fp
, '\n');
2881 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2884 * Accounting/quota/PIN/managed printing values...
2887 if (pc
->charge_info_uri
)
2888 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2890 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2891 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2892 pc
->accounting_user_id
? "true" : "false");
2895 cupsFilePutConf(fp
, "Password", pc
->password
);
2897 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2899 value
= (char *)cupsArrayNext(pc
->mandatory
))
2900 cupsFilePutConf(fp
, "Mandatory", value
);
2906 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2908 value
= (char *)cupsArrayNext(pc
->support_files
))
2909 cupsFilePutConf(fp
, "SupportFile", value
);
2912 * IPP attributes, if any...
2917 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2919 attrs
->state
= IPP_STATE_IDLE
;
2920 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2924 * Close and return...
2927 if (cupsFileClose(fp
))
2934 return (!rename(newfile
, filename
));
2939 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2940 * of an IPP printer.
2943 char * /* O - PPD filename or @code NULL@ on error */
2944 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2945 size_t bufsize
, /* I - Size of filename buffer */
2946 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2948 cups_file_t
*fp
; /* PPD file */
2949 cups_array_t
*sizes
; /* Media sizes we've added */
2950 ipp_attribute_t
*attr
, /* xxx-supported */
2951 *defattr
, /* xxx-default */
2952 *quality
, /* print-quality-supported */
2953 *x_dim
, *y_dim
; /* Media dimensions */
2954 ipp_t
*media_size
; /* Media size collection */
2955 char make
[256], /* Make and model */
2956 *model
, /* Model name */
2957 ppdname
[PPD_MAX_NAME
];
2959 int i
, j
, /* Looping vars */
2960 count
, /* Number of values */
2961 bottom
, /* Largest bottom margin */
2962 left
, /* Largest left margin */
2963 right
, /* Largest right margin */
2964 top
, /* Largest top margin */
2965 is_apple
= 0, /* Does the printer support Apple raster? */
2966 is_pdf
= 0, /* Does the printer support PDF? */
2967 is_pwg
= 0; /* Does the printer support PWG Raster? */
2968 pwg_media_t
*pwg
; /* PWG media size */
2969 int xres
, yres
; /* Resolution values */
2970 cups_lang_t
*lang
= cupsLangDefault();
2971 /* Localization info */
2972 struct lconv
*loc
= localeconv();
2974 static const char * const finishings
[][2] =
2975 { /* Finishings strings */
2976 { "bale", _("Bale") },
2977 { "bind", _("Bind") },
2978 { "bind-bottom", _("Bind (Reverse Landscape)") },
2979 { "bind-left", _("Bind (Portrait)") },
2980 { "bind-right", _("Bind (Reverse Portrait)") },
2981 { "bind-top", _("Bind (Landscape)") },
2982 { "booklet-maker", _("Booklet Maker") },
2983 { "coat", _("Coat") },
2984 { "cover", _("Cover") },
2985 { "edge-stitch", _("Staple Edge") },
2986 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
2987 { "edge-stitch-left", _("Staple Edge (Portrait)") },
2988 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
2989 { "edge-stitch-top", _("Staple Edge (Landscape)") },
2990 { "fold", _("Fold") },
2991 { "fold-accordian", _("Accordian Fold") },
2992 { "fold-double-gate", _("Double Gate Fold") },
2993 { "fold-engineering-z", _("Engineering Z Fold") },
2994 { "fold-gate", _("Gate Fold") },
2995 { "fold-half", _("Half Fold") },
2996 { "fold-half-z", _("Half Z Fold") },
2997 { "fold-left-gate", _("Left Gate Fold") },
2998 { "fold-letter", _("Letter Fold") },
2999 { "fold-parallel", _("Parallel Fold") },
3000 { "fold-poster", _("Poster Fold") },
3001 { "fold-right-gate", _("Right Gate Fold") },
3002 { "fold-z", _("Z Fold") },
3003 { "jog-offset", _("Jog") },
3004 { "laminate", _("Laminate") },
3005 { "punch", _("Punch") },
3006 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3007 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3008 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3009 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3010 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3011 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3012 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3013 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3014 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3015 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3016 { "punch-top-left", _("Single Punch (Portrait)") },
3017 { "punch-top-right", _("Single Punch (Landscape)") },
3018 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3019 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3020 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3021 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3022 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3023 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3024 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3025 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3026 { "saddle-stitch", _("Saddle Stitch") },
3027 { "staple", _("Staple") },
3028 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3029 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3030 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3031 { "staple-dual-left", _("Double Staple (Portrait)") },
3032 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3033 { "staple-dual-top", _("Double Staple (Landscape)") },
3034 { "staple-top-left", _("Single Staple (Portrait)") },
3035 { "staple-top-right", _("Single Staple (Landscape)") },
3036 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3037 { "staple-triple-left", _("Triple Staple (Portrait)") },
3038 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3039 { "staple-triple-top", _("Triple Staple (Landscape)") },
3040 { "trim", _("Cut Media") }
3045 * Range check input...
3051 if (!buffer
|| bufsize
< 1)
3053 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3059 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3064 * Open a temporary file for the PPD...
3067 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3069 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3074 * Standard stuff for PPD file...
3077 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3078 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3079 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3080 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3081 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3082 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3083 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3084 cupsFilePuts(fp
, "*FileSystem: False\n");
3085 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3087 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3088 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3090 strlcpy(make
, "Unknown Printer", sizeof(make
));
3092 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3093 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3096 strlcpy(make
, "HP", sizeof(make
));
3098 else if ((model
= strchr(make
, ' ')) != NULL
)
3103 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3104 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3105 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3106 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3107 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3109 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3110 cupsFilePuts(fp
, "*ColorDevice: True\n");
3112 cupsFilePuts(fp
, "*ColorDevice: False\n");
3114 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3115 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3116 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3122 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3124 is_apple
= ippContainsString(attr
, "image/urf");
3125 is_pdf
= ippContainsString(attr
, "application/pdf");
3126 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3128 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3130 const char *format
= ippGetString(attr
, i
, NULL
);
3134 * Write cupsFilter2 lines for supported formats...
3137 if (!_cups_strcasecmp(format
, "application/pdf"))
3138 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3139 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3140 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3141 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3142 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3146 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3150 * PageSize/PageRegion/ImageableArea/PaperDimension
3153 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3155 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3156 if (ippGetInteger(attr
, i
) > bottom
)
3157 bottom
= ippGetInteger(attr
, i
);
3162 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3164 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3165 if (ippGetInteger(attr
, i
) > left
)
3166 left
= ippGetInteger(attr
, i
);
3171 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3173 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3174 if (ippGetInteger(attr
, i
) > right
)
3175 right
= ippGetInteger(attr
, i
);
3180 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3182 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3183 if (ippGetInteger(attr
, i
) > top
)
3184 top
= ippGetInteger(attr
, i
);
3189 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3191 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3193 media_size
= ippGetCollection(attr
, 0);
3194 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3195 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3197 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3198 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3200 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3203 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3205 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3206 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3208 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3210 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3211 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3214 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3215 "*OrderDependency: 10 AnySetup *PageSize\n"
3216 "*DefaultPageSize: %s\n", ppdname
);
3218 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3220 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3222 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3224 media_size
= ippGetCollection(attr
, i
);
3225 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3226 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3228 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3231 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3235 char twidth
[256], /* Width string */
3236 tlength
[256]; /* Length string */
3238 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3240 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3244 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3246 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3247 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3249 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3252 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3254 cupsArrayDelete(sizes
);
3255 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3257 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3258 "*OrderDependency: 10 AnySetup *PageRegion\n"
3259 "*DefaultPageRegion: %s\n", ppdname
);
3260 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3262 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3264 media_size
= ippGetCollection(attr
, i
);
3265 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3266 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3268 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3271 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3275 char twidth
[256], /* Width string */
3276 tlength
[256]; /* Length string */
3278 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3281 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3283 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3284 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3286 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3289 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3291 cupsArrayDelete(sizes
);
3292 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3294 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3295 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3296 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3298 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3300 media_size
= ippGetCollection(attr
, i
);
3301 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3302 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3304 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3307 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3311 char tleft
[256], /* Left string */
3312 tbottom
[256], /* Bottom string */
3313 tright
[256], /* Right string */
3314 ttop
[256], /* Top string */
3315 twidth
[256], /* Width string */
3316 tlength
[256]; /* Length string */
3318 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3321 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3323 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3324 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3325 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3326 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3327 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3328 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3330 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3331 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3335 cupsArrayDelete(sizes
);
3344 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3345 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3347 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3349 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3351 static const char * const sources
[][2] =
3352 { /* "media-source" strings */
3353 { "Auto", _("Automatic") },
3354 { "Main", _("Main") },
3355 { "Alternate", _("Alternate") },
3356 { "LargeCapacity", _("Large Capacity") },
3357 { "Manual", _("Manual") },
3358 { "Envelope", _("Envelope") },
3359 { "Disc", _("Disc") },
3360 { "Photo", _("Photo") },
3361 { "Hagaki", _("Hagaki") },
3362 { "MainRoll", _("Main Roll") },
3363 { "AlternateRoll", _("Alternate Roll") },
3364 { "Top", _("Top") },
3365 { "Middle", _("Middle") },
3366 { "Bottom", _("Bottom") },
3367 { "Side", _("Side") },
3368 { "Left", _("Left") },
3369 { "Right", _("Right") },
3370 { "Center", _("Center") },
3371 { "Rear", _("Rear") },
3372 { "ByPassTray", _("Multipurpose") },
3373 { "Tray1", _("Tray 1") },
3374 { "Tray2", _("Tray 2") },
3375 { "Tray3", _("Tray 3") },
3376 { "Tray4", _("Tray 4") },
3377 { "Tray5", _("Tray 5") },
3378 { "Tray6", _("Tray 6") },
3379 { "Tray7", _("Tray 7") },
3380 { "Tray8", _("Tray 8") },
3381 { "Tray9", _("Tray 9") },
3382 { "Tray10", _("Tray 10") },
3383 { "Tray11", _("Tray 11") },
3384 { "Tray12", _("Tray 12") },
3385 { "Tray13", _("Tray 13") },
3386 { "Tray14", _("Tray 14") },
3387 { "Tray15", _("Tray 15") },
3388 { "Tray16", _("Tray 16") },
3389 { "Tray17", _("Tray 17") },
3390 { "Tray18", _("Tray 18") },
3391 { "Tray19", _("Tray 19") },
3392 { "Tray20", _("Tray 20") },
3393 { "Roll1", _("Roll 1") },
3394 { "Roll2", _("Roll 2") },
3395 { "Roll3", _("Roll 3") },
3396 { "Roll4", _("Roll 4") },
3397 { "Roll5", _("Roll 5") },
3398 { "Roll6", _("Roll 6") },
3399 { "Roll7", _("Roll 7") },
3400 { "Roll8", _("Roll 8") },
3401 { "Roll9", _("Roll 9") },
3402 { "Roll10", _("Roll 10") }
3405 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3406 "*OrderDependency: 10 AnySetup *InputSlot\n"
3407 "*DefaultInputSlot: %s\n", ppdname
);
3408 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3410 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3412 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3413 if (!strcmp(sources
[j
][0], ppdname
))
3415 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3419 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3426 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3427 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3429 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3431 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3433 static const char * const media_types
[][2] =
3434 { /* "media-type" strings */
3435 { "aluminum", _("Aluminum") },
3436 { "auto", _("Automatic") },
3437 { "back-print-film", _("Back Print Film") },
3438 { "cardboard", _("Cardboard") },
3439 { "cardstock", _("Cardstock") },
3441 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3442 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3443 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3444 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3445 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3446 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3447 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3448 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3449 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3450 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3451 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3452 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3453 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3454 { "continuous", _("Continuous") },
3455 { "continuous-long", _("Continuous Long") },
3456 { "continuous-short", _("Continuous Short") },
3457 { "disc", _("Optical Disc") },
3458 { "disc-glossy", _("Glossy Optical Disc") },
3459 { "disc-high-gloss", _("High Gloss Optical Disc") },
3460 { "disc-matte", _("Matte Optical Disc") },
3461 { "disc-satin", _("Satin Optical Disc") },
3462 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3463 { "double-wall", _("Double Wall Cardboard") },
3464 { "dry-film", _("Dry Film") },
3465 { "dvd", _("DVD") },
3466 { "embossing-foil", _("Embossing Foil") },
3467 { "end-board", _("End Board") },
3468 { "envelope", _("Envelope") },
3469 { "envelope-archival", _("Archival Envelope") },
3470 { "envelope-bond", _("Bond Envelope") },
3471 { "envelope-coated", _("Coated Envelope") },
3472 { "envelope-cotton", _("Cotton Envelope") },
3473 { "envelope-fine", _("Fine Envelope") },
3474 { "envelope-heavyweight", _("Heavyweight Envelope") },
3475 { "envelope-inkjet", _("Inkjet Envelope") },
3476 { "envelope-lightweight", _("Lightweight Envelope") },
3477 { "envelope-plain", _("Plain Envelope") },
3478 { "envelope-preprinted", _("Preprinted Envelope") },
3479 { "envelope-window", _("Windowed Envelope") },
3480 { "fabric", _("Fabric") },
3481 { "fabric-archival", _("Archival Fabric") },
3482 { "fabric-glossy", _("Glossy Fabric") },
3483 { "fabric-high-gloss", _("High Gloss Fabric") },
3484 { "fabric-matte", _("Matte Fabric") },
3485 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3486 { "fabric-waterproof", _("Waterproof Fabric") },
3487 { "film", _("Film") },
3488 { "flexo-base", _("Flexo Base") },
3489 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3490 { "flute", _("Flute") },
3491 { "foil", _("Foil") },
3492 { "full-cut-tabs", _("Full Cut Tabs") },
3493 { "glass", _("Glass") },
3494 { "glass-colored", _("Glass Colored") },
3495 { "glass-opaque", _("Glass Opaque") },
3496 { "glass-surfaced", _("Glass Surfaced") },
3497 { "glass-textured", _("Glass Textured") },
3498 { "gravure-cylinder", _("Gravure Cylinder") },
3499 { "image-setter-paper", _("Image Setter Paper") },
3500 { "imaging-cylinder", _("Imaging Cylinder") },
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 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3504 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3505 { "labels", _("Labels") },
3506 { "labels-colored", _("Colored Labels") },
3507 { "labels-glossy", _("Glossy Labels") },
3508 { "labels-high-gloss", _("High Gloss Labels") },
3509 { "labels-inkjet", _("Inkjet Labels") },
3510 { "labels-matte", _("Matte Labels") },
3511 { "labels-permanent", _("Permanent Labels") },
3512 { "labels-satin", _("Satin Labels") },
3513 { "labels-security", _("Security Labels") },
3514 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3515 { "laminating-foil", _("Laminating Foil") },
3516 { "letterhead", _("Letterhead") },
3517 { "metal", _("Metal") },
3518 { "metal-glossy", _("Metal Glossy") },
3519 { "metal-high-gloss", _("Metal High Gloss") },
3520 { "metal-matte", _("Metal Matte") },
3521 { "metal-satin", _("Metal Satin") },
3522 { "metal-semi-gloss", _("Metal Semi Gloss") },
3523 { "mounting-tape", _("Mounting Tape") },
3524 { "multi-layer", _("Multi Layer") },
3525 { "multi-part-form", _("Multi Part Form") },
3526 { "other", _("Other") },
3527 { "paper", _("Paper") },
3528 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3529 { "photographic", _("Photo Paper") },
3530 { "photographic-archival", _("Archival Photo Paper") },
3531 { "photographic-film", _("Photo Film") },
3532 { "photographic-glossy", _("Glossy Photo Paper") },
3533 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3534 { "photographic-matte", _("Matte Photo Paper") },
3535 { "photographic-satin", _("Satin Photo Paper") },
3536 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3537 { "plastic", _("Plastic") },
3538 { "plastic-archival", _("Plastic Archival") },
3539 { "plastic-colored", _("Plastic Colored") },
3540 { "plastic-glossy", _("Plastic Glossy") },
3541 { "plastic-high-gloss", _("Plastic High Gloss") },
3542 { "plastic-matte", _("Plastic Matte") },
3543 { "plastic-satin", _("Plastic Satin") },
3544 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3545 { "plate", _("Plate") },
3546 { "polyester", _("Polyester") },
3547 { "pre-cut-tabs", _("Pre Cut Tabs") },
3548 { "roll", _("Roll") },
3549 { "screen", _("Screen") },
3550 { "screen-paged", _("Screen Paged") },
3551 { "self-adhesive", _("Self Adhesive") },
3552 { "self-adhesive-film", _("Self Adhesive Film") },
3553 { "shrink-foil", _("Shrink Foil") },
3554 { "single-face", _("Single Face") },
3555 { "single-wall", _("Single Wall Cardboard") },
3556 { "sleeve", _("Sleeve") },
3557 { "stationery", _("Plain Paper") },
3558 { "stationery-archival", _("Archival Paper") },
3559 { "stationery-coated", _("Coated Paper") },
3560 { "stationery-cotton", _("Cotton Paper") },
3561 { "stationery-fine", _("Vellum Paper") },
3562 { "stationery-heavyweight", _("Heavyweight Paper") },
3563 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3564 { "stationery-inkjet", _("Inkjet Paper") },
3565 { "stationery-letterhead", _("Letterhead") },
3566 { "stationery-lightweight", _("Lightweight Paper") },
3567 { "stationery-preprinted", _("Preprinted Paper") },
3568 { "stationery-prepunched", _("Punched Paper") },
3569 { "tab-stock", _("Tab Stock") },
3570 { "tractor", _("Tractor") },
3571 { "transfer", _("Transfer") },
3572 { "transparency", _("Transparency") },
3573 { "triple-wall", _("Triple Wall Cardboard") },
3574 { "wet-film", _("Wet Film") }
3577 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3578 "*OrderDependency: 10 AnySetup *MediaType\n"
3579 "*DefaultMediaType: %s\n", ppdname
);
3580 for (i
= 0; i
< count
; i
++)
3582 const char *keyword
= ippGetString(attr
, i
, NULL
);
3584 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3586 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3587 if (!strcmp(keyword
, media_types
[j
][0]))
3590 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3591 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3593 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, keyword
, ppdname
);
3595 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3602 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3603 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3604 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3605 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3609 const char *default_color
= NULL
; /* Default */
3611 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3613 const char *keyword
= ippGetString(attr
, i
, NULL
);
3614 /* Keyword for color/bit depth */
3616 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3619 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3620 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3622 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3625 default_color
= "FastGray";
3627 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3630 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3631 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3633 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3635 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3636 default_color
= "Gray";
3638 else if (!strcasecmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3641 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3642 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3644 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3646 default_color
= "RGB";
3648 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3651 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3652 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3654 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3657 default_color
= "AdobeRGB";
3663 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3664 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3672 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3674 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3675 "*OrderDependency: 10 AnySetup *Duplex\n"
3676 "*DefaultDuplex: None\n"
3677 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3678 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3679 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3680 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3682 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3684 const char *keyword
= ippGetString(attr
, 0, NULL
);
3687 if (!strcmp(keyword
, "flipped"))
3688 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3689 else if (!strcmp(keyword
, "manual-tumble"))
3690 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3691 else if (!strcmp(keyword
, "normal"))
3692 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3694 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3696 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3698 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3700 const char *dm
= ippGetString(attr
, i
, NULL
);
3703 if (!_cups_strcasecmp(dm
, "DM1"))
3705 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3708 else if (!_cups_strcasecmp(dm
, "DM2"))
3710 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3713 else if (!_cups_strcasecmp(dm
, "DM3"))
3715 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3718 else if (!_cups_strcasecmp(dm
, "DM4"))
3720 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3731 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3732 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3734 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3736 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3738 static const char * const output_bins
[][2] =
3739 { /* "output-bin" strings */
3740 { "auto", _("Automatic") },
3741 { "bottom", _("Bottom Tray") },
3742 { "center", _("Center Tray") },
3743 { "face-down", _("Face Down") },
3744 { "face-up", _("Face Up") },
3745 { "large-capacity", _("Large Capacity Tray") },
3746 { "left", _("Left Tray") },
3747 { "mailbox-1", _("Mailbox 1") },
3748 { "mailbox-2", _("Mailbox 2") },
3749 { "mailbox-3", _("Mailbox 3") },
3750 { "mailbox-4", _("Mailbox 4") },
3751 { "mailbox-5", _("Mailbox 5") },
3752 { "mailbox-6", _("Mailbox 6") },
3753 { "mailbox-7", _("Mailbox 7") },
3754 { "mailbox-8", _("Mailbox 8") },
3755 { "mailbox-9", _("Mailbox 9") },
3756 { "mailbox-10", _("Mailbox 10") },
3757 { "middle", _("Middle") },
3758 { "my-mailbox", _("My Mailbox") },
3759 { "rear", _("Rear Tray") },
3760 { "right", _("Right Tray") },
3761 { "side", _("Side Tray") },
3762 { "stacker-1", _("Stacker 1") },
3763 { "stacker-2", _("Stacker 2") },
3764 { "stacker-3", _("Stacker 3") },
3765 { "stacker-4", _("Stacker 4") },
3766 { "stacker-5", _("Stacker 5") },
3767 { "stacker-6", _("Stacker 6") },
3768 { "stacker-7", _("Stacker 7") },
3769 { "stacker-8", _("Stacker 8") },
3770 { "stacker-9", _("Stacker 9") },
3771 { "stacker-10", _("Stacker 10") },
3772 { "top", _("Top Tray") },
3773 { "tray-1", _("Tray 1") },
3774 { "tray-2", _("Tray 2") },
3775 { "tray-3", _("Tray 3") },
3776 { "tray-4", _("Tray 4") },
3777 { "tray-5", _("Tray 5") },
3778 { "tray-6", _("Tray 6") },
3779 { "tray-7", _("Tray 7") },
3780 { "tray-8", _("Tray 8") },
3781 { "tray-9", _("Tray 9") },
3782 { "tray-10", _("Tray 10") }
3785 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3786 "*OrderDependency: 10 AnySetup *OutputBin\n"
3787 "*DefaultOutputBin: %s\n", ppdname
);
3788 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3790 if (!ippContainsString(attr
, output_bins
[i
][0]))
3793 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3795 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3797 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3801 * Finishing options...
3803 * Eventually need to re-add support for finishings-col-database, however
3804 * it is difficult to map arbitrary finishing-template values to PPD options
3805 * and have the right constraints apply (e.g. stapling vs. folding vs.
3809 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3811 const char *name
; /* String name */
3812 int value
; /* Enum value */
3813 cups_array_t
*names
; /* Names we've added */
3815 count
= ippGetCount(attr
);
3816 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3819 * Staple/Bind/Stitch
3822 for (i
= 0; i
< count
; i
++)
3824 value
= ippGetInteger(attr
, i
);
3825 name
= ippEnumString("finishings", value
);
3827 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3833 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3834 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3835 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3836 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3838 for (; i
< count
; i
++)
3840 value
= ippGetInteger(attr
, i
);
3841 name
= ippEnumString("finishings", value
);
3843 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3846 if (cupsArrayFind(names
, (char *)name
))
3847 continue; /* Already did this finishing template */
3849 cupsArrayAdd(names
, (char *)name
);
3851 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3853 if (!strcmp(finishings
[j
][0], name
))
3855 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3856 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3862 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3869 for (i
= 0; i
< count
; i
++)
3871 value
= ippGetInteger(attr
, i
);
3872 name
= ippEnumString("finishings", value
);
3874 if (!strncmp(name
, "fold-", 5))
3880 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3881 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3882 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3883 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3885 for (; i
< count
; i
++)
3887 value
= ippGetInteger(attr
, i
);
3888 name
= ippEnumString("finishings", value
);
3890 if (strncmp(name
, "fold-", 5))
3893 if (cupsArrayFind(names
, (char *)name
))
3894 continue; /* Already did this finishing template */
3896 cupsArrayAdd(names
, (char *)name
);
3898 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3900 if (!strcmp(finishings
[j
][0], name
))
3902 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3903 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
3909 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
3916 for (i
= 0; i
< count
; i
++)
3918 value
= ippGetInteger(attr
, i
);
3919 name
= ippEnumString("finishings", value
);
3921 if (!strncmp(name
, "punch-", 6))
3927 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
3928 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
3929 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
3930 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3932 for (i
= 0; i
< count
; i
++)
3934 value
= ippGetInteger(attr
, i
);
3935 name
= ippEnumString("finishings", value
);
3937 if (strncmp(name
, "punch-", 6))
3940 if (cupsArrayFind(names
, (char *)name
))
3941 continue; /* Already did this finishing template */
3943 cupsArrayAdd(names
, (char *)name
);
3945 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3947 if (!strcmp(finishings
[j
][0], name
))
3949 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3950 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
3956 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
3963 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
3965 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
3966 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
3967 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
3968 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
3969 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
3970 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
3971 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
3974 cupsArrayDelete(names
);
3978 * cupsPrintQuality and DefaultResolution...
3981 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
3983 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3985 count
= ippGetCount(attr
);
3987 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3988 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3990 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3991 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3992 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
3993 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
3995 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3996 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
3998 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3999 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4000 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4003 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
4005 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4006 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4009 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4011 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4013 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4015 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4017 const char *rs
= ippGetString(attr
, i
, NULL
);
4020 if (_cups_strncasecmp(rs
, "RS", 2))
4023 lowdpi
= atoi(rs
+ 2);
4024 if ((rs
= strrchr(rs
, '-')) != NULL
)
4025 hidpi
= atoi(rs
+ 1);
4034 * Invalid "urf-supported" value...
4042 * Generate print qualities based on low and high DPIs...
4045 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4047 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4048 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4049 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4050 if ((lowdpi
& 1) == 0)
4051 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4052 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4053 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4054 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4055 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4056 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4057 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4060 else if (is_apple
|| is_pwg
)
4064 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4066 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4071 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4074 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4076 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4077 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4078 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4079 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4080 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4081 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4082 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4083 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4084 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4088 * Close up and return...
4096 * If we get here then there was a problem creating the PPD...
4105 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4112 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4116 const char * /* O - InputSlot name */
4117 _pwgInputSlotForSource(
4118 const char *media_source
, /* I - PWG media-source */
4119 char *name
, /* I - Name buffer */
4120 size_t namesize
) /* I - Size of name buffer */
4123 * Range check input...
4126 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4129 if (_cups_strcasecmp(media_source
, "main"))
4130 strlcpy(name
, "Cassette", namesize
);
4131 else if (_cups_strcasecmp(media_source
, "alternate"))
4132 strlcpy(name
, "Multipurpose", namesize
);
4133 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4134 strlcpy(name
, "LargeCapacity", namesize
);
4135 else if (_cups_strcasecmp(media_source
, "bottom"))
4136 strlcpy(name
, "Lower", namesize
);
4137 else if (_cups_strcasecmp(media_source
, "middle"))
4138 strlcpy(name
, "Middle", namesize
);
4139 else if (_cups_strcasecmp(media_source
, "top"))
4140 strlcpy(name
, "Upper", namesize
);
4141 else if (_cups_strcasecmp(media_source
, "rear"))
4142 strlcpy(name
, "Rear", namesize
);
4143 else if (_cups_strcasecmp(media_source
, "side"))
4144 strlcpy(name
, "Side", namesize
);
4145 else if (_cups_strcasecmp(media_source
, "envelope"))
4146 strlcpy(name
, "Envelope", namesize
);
4147 else if (_cups_strcasecmp(media_source
, "main-roll"))
4148 strlcpy(name
, "Roll", namesize
);
4149 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4150 strlcpy(name
, "Roll2", namesize
);
4152 pwg_ppdize_name(media_source
, name
, namesize
);
4159 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4163 const char * /* O - MediaType name */
4164 _pwgMediaTypeForType(
4165 const char *media_type
, /* I - PWG media-type */
4166 char *name
, /* I - Name buffer */
4167 size_t namesize
) /* I - Size of name buffer */
4170 * Range check input...
4173 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4176 if (_cups_strcasecmp(media_type
, "auto"))
4177 strlcpy(name
, "Auto", namesize
);
4178 else if (_cups_strcasecmp(media_type
, "cardstock"))
4179 strlcpy(name
, "Cardstock", namesize
);
4180 else if (_cups_strcasecmp(media_type
, "envelope"))
4181 strlcpy(name
, "Envelope", namesize
);
4182 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4183 strlcpy(name
, "Glossy", namesize
);
4184 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4185 strlcpy(name
, "HighGloss", namesize
);
4186 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4187 strlcpy(name
, "Matte", namesize
);
4188 else if (_cups_strcasecmp(media_type
, "stationery"))
4189 strlcpy(name
, "Plain", namesize
);
4190 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4191 strlcpy(name
, "Coated", namesize
);
4192 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4193 strlcpy(name
, "Inkjet", namesize
);
4194 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4195 strlcpy(name
, "Letterhead", namesize
);
4196 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4197 strlcpy(name
, "Preprinted", namesize
);
4198 else if (_cups_strcasecmp(media_type
, "transparency"))
4199 strlcpy(name
, "Transparency", namesize
);
4201 pwg_ppdize_name(media_type
, name
, namesize
);
4208 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4211 const char * /* O - PageSize name */
4212 _pwgPageSizeForMedia(
4213 pwg_media_t
*media
, /* I - Media */
4214 char *name
, /* I - PageSize name buffer */
4215 size_t namesize
) /* I - Size of name buffer */
4217 const char *sizeptr
, /* Pointer to size in PWG name */
4218 *dimptr
; /* Pointer to dimensions in PWG name */
4222 * Range check input...
4225 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4229 * Copy or generate a PageSize name...
4235 * Use a standard Adobe name...
4238 strlcpy(name
, media
->ppd
, namesize
);
4240 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4241 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4242 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4243 (size_t)(dimptr
- sizeptr
) > namesize
)
4246 * Use a name of the form "wNNNhNNN"...
4249 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4250 (int)PWG_TO_POINTS(media
->length
));
4255 * Copy the size name from class_sizename_dimensions...
4258 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4259 name
[dimptr
- sizeptr
- 1] = '\0';
4267 * 'pwg_add_finishing()' - Add a finishings value.
4272 cups_array_t
*finishings
, /* I - Finishings array */
4273 ipp_finishings_t
template, /* I - Finishing template */
4274 const char *name
, /* I - PPD option */
4275 const char *value
) /* I - PPD choice */
4277 _pwg_finishings_t
*f
; /* New finishings value */
4280 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4282 f
->value
= template;
4283 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4285 cupsArrayAdd(finishings
, f
);
4291 * 'pwg_compare_finishings()' - Compare two finishings values.
4294 static int /* O - Result of comparison */
4295 pwg_compare_finishings(
4296 _pwg_finishings_t
*a
, /* I - First finishings value */
4297 _pwg_finishings_t
*b
) /* I - Second finishings value */
4299 return ((int)b
->value
- (int)a
->value
);
4304 * 'pwg_free_finishings()' - Free a finishings value.
4308 pwg_free_finishings(
4309 _pwg_finishings_t
*f
) /* I - Finishings value */
4311 cupsFreeOptions(f
->num_options
, f
->options
);
4317 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4321 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4322 char *name
, /* I - Name buffer */
4323 size_t namesize
) /* I - Size of name buffer */
4325 char *ptr
, /* Pointer into name buffer */
4326 *end
; /* End of name buffer */
4335 *name
= (char)toupper(*ipp
++);
4337 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4339 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4342 *ptr
++ = (char)toupper(*ipp
++ & 255);
4353 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4357 pwg_ppdize_resolution(
4358 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4359 int element
, /* I - Element to convert */
4360 int *xres
, /* O - X resolution in DPI */
4361 int *yres
, /* O - Y resolution in DPI */
4362 char *name
, /* I - Name buffer */
4363 size_t namesize
) /* I - Size of name buffer */
4365 ipp_res_t units
; /* Units for resolution */
4368 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4370 if (units
== IPP_RES_PER_CM
)
4372 *xres
= (int)(*xres
* 2.54);
4373 *yres
= (int)(*yres
* 2.54);
4376 if (name
&& namesize
> 4)
4379 snprintf(name
, namesize
, "%ddpi", *xres
);
4381 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4387 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4391 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4392 char *name
, /* I - Name buffer */
4393 size_t namesize
, /* I - Size of name buffer */
4394 const char *dashchars
)/* I - Characters to be replaced by dashes */
4396 char *ptr
, /* Pointer into name buffer */
4397 *end
; /* End of name buffer */
4400 if (_cups_islower(*ppd
))
4403 * Already lowercase name, use as-is?
4406 const char *ppdptr
; /* Pointer into PPD keyword */
4408 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4409 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4414 strlcpy(name
, ppd
, namesize
);
4419 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4421 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4422 *ptr
++ = (char)tolower(*ppd
& 255);
4423 else if (strchr(dashchars
, *ppd
))
4428 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4429 _cups_isupper(ppd
[1]) && ptr
< end
)
4431 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))