2 * PPD cache implementation for CUPS.
4 * Copyright 2010-2017 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * Include necessary headers...
13 #include "cups-private.h"
14 #include "ppd-private.h"
19 * Macro to test for two almost-equal PWG measurements.
22 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
29 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
30 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
31 _pwg_finishings_t
*b
);
32 static void pwg_free_finishings(_pwg_finishings_t
*f
);
33 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
34 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
35 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
36 const char *dashchars
);
40 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
42 * This functions converts PPD and CUPS-specific options to their standard IPP
43 * attributes and values and adds them to the specified IPP request.
46 int /* O - New number of copies */
48 ipp_t
*request
, /* I - IPP request */
49 ppd_file_t
*ppd
, /* I - PPD file */
50 _ppd_cache_t
*pc
, /* I - PPD cache info */
51 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
52 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
53 ipp_attribute_t
*print_color_mode_sup
,
54 /* I - Printer supports print-color-mode */
55 const char *user
, /* I - User info */
56 const char *format
, /* I - document-format value */
57 int copies
, /* I - Number of copies */
58 int num_options
, /* I - Number of options */
59 cups_option_t
*options
) /* I - Options */
61 int i
; /* Looping var */
62 const char *keyword
, /* PWG keyword */
63 *password
; /* Password string */
64 pwg_size_t
*size
; /* PWG media size */
65 ipp_t
*media_col
, /* media-col value */
66 *media_size
; /* media-size value */
67 const char *media_source
, /* media-source value */
68 *media_type
, /* media-type value */
69 *collate_str
, /* multiple-document-handling value */
70 *color_attr_name
, /* Supported color attribute */
71 *mandatory
; /* Mandatory attributes */
72 int num_finishings
= 0, /* Number of finishing values */
73 finishings
[10]; /* Finishing enum values */
74 ppd_choice_t
*choice
; /* Marked choice */
75 int finishings_copies
= copies
;
76 /* Number of copies for finishings */
80 * Send standard IPP attributes...
83 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
85 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
87 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
90 if (!strcmp(keyword
, "none"))
93 * Add plain-text job-password...
96 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
101 * Add hashed job-password...
104 unsigned char hash
[64]; /* Hash of password */
105 ssize_t hashlen
; /* Length of hash */
107 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
108 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
112 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
117 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
118 keyword
= cupsGetOption("job-billing", num_options
, options
);
121 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
124 if (pc
->accounting_user_id
)
126 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
130 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
133 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
135 if (strcmp(mandatory
, "copies") &&
136 strcmp(mandatory
, "destination-uris") &&
137 strcmp(mandatory
, "finishings") &&
138 strcmp(mandatory
, "job-account-id") &&
139 strcmp(mandatory
, "job-accounting-user-id") &&
140 strcmp(mandatory
, "job-password") &&
141 strcmp(mandatory
, "job-password-encryption") &&
142 strcmp(mandatory
, "media") &&
143 strncmp(mandatory
, "media-col", 9) &&
144 strcmp(mandatory
, "multiple-document-handling") &&
145 strcmp(mandatory
, "output-bin") &&
146 strcmp(mandatory
, "print-color-mode") &&
147 strcmp(mandatory
, "print-quality") &&
148 strcmp(mandatory
, "sides") &&
149 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
151 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
153 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
158 case IPP_TAG_INTEGER
:
160 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
162 case IPP_TAG_BOOLEAN
:
163 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
167 int lower
, upper
; /* Range */
169 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
170 lower
= upper
= atoi(keyword
);
172 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
175 case IPP_TAG_STRING
:
176 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
179 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
181 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
182 keyword
= "auto-monochrome";
183 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
184 keyword
= "process-monochrome";
187 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
193 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
194 keyword
= cupsGetOption("media", num_options
, options
);
196 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
197 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
198 size
= _ppdCacheGetSize(pc
, keyword
);
200 if (size
|| media_source
|| media_type
)
203 * Add a media-col value...
206 media_col
= ippNew();
210 media_size
= ippNew();
211 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
212 "x-dimension", size
->width
);
213 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
214 "y-dimension", size
->length
);
216 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
219 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
221 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
222 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
223 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
224 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
225 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
226 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
227 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
229 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
230 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
231 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
232 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
235 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
238 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
240 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
241 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
245 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
247 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
249 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
251 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
253 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
254 keyword
= "monochrome";
260 if (keyword
&& !strcmp(keyword
, "monochrome"))
262 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
263 keyword
= "auto-monochrome";
264 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
265 keyword
= "process-monochrome";
269 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
271 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
272 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
273 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
275 if (!_cups_strcasecmp(choice
->choice
, "draft"))
276 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
277 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
278 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
279 else if (!_cups_strcasecmp(choice
->choice
, "high"))
280 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
283 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
284 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
285 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
287 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
288 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
289 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
290 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
291 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
292 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
299 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
301 if (strstr(keyword
, "uncollated"))
306 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
311 if (!_cups_strcasecmp(format
, "image/gif") ||
312 !_cups_strcasecmp(format
, "image/jp2") ||
313 !_cups_strcasecmp(format
, "image/jpeg") ||
314 !_cups_strcasecmp(format
, "image/png") ||
315 !_cups_strcasecmp(format
, "image/tiff") ||
316 !_cups_strncasecmp(format
, "image/x-", 8))
319 * Collation makes no sense for single page image formats...
324 else if (!_cups_strncasecmp(format
, "image/", 6) ||
325 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
328 * Multi-page image formats will have copies applied by the upstream
336 if (doc_handling_sup
)
338 if (!_cups_strcasecmp(keyword
, "true"))
339 collate_str
= "separate-documents-collated-copies";
341 collate_str
= "separate-documents-uncollated-copies";
343 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
345 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
347 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
352 if (i
>= doc_handling_sup
->num_values
)
357 * Map finishing options...
360 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
361 if (num_finishings
> 0)
363 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
365 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
368 * Send job-pages-per-set attribute to apply finishings correctly...
371 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
380 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
383 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
387 _ppd_cache_t
* /* O - PPD cache and mapping data */
388 _ppdCacheCreateWithFile(
389 const char *filename
, /* I - File to read */
390 ipp_t
**attrs
) /* IO - IPP attributes, if any */
392 cups_file_t
*fp
; /* File */
393 _ppd_cache_t
*pc
; /* PWG mapping data */
394 pwg_size_t
*size
; /* Current size */
395 pwg_map_t
*map
; /* Current map */
396 _pwg_finishings_t
*finishings
; /* Current finishings option */
397 int linenum
, /* Current line number */
398 num_bins
, /* Number of bins in file */
399 num_sizes
, /* Number of sizes in file */
400 num_sources
, /* Number of sources in file */
401 num_types
; /* Number of types in file */
402 char line
[2048], /* Current line */
403 *value
, /* Pointer to value in line */
404 *valueptr
, /* Pointer into value */
405 pwg_keyword
[128], /* PWG keyword */
406 ppd_keyword
[PPD_MAX_NAME
];
408 _pwg_print_color_mode_t print_color_mode
;
409 /* Print color mode for preset */
410 _pwg_print_quality_t print_quality
; /* Print quality for preset */
413 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
416 * Range check input...
424 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
432 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
434 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
439 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
442 if (!cupsFileGets(fp
, line
, sizeof(line
)))
444 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
445 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
450 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
452 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
453 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
458 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
460 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
461 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
462 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
468 * Allocate the mapping data structure...
471 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
473 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
474 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
478 pc
->max_copies
= 9999;
490 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
492 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
493 "linenum=%d", line
, value
, linenum
));
497 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
499 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
502 else if (!_cups_strcasecmp(line
, "Filter"))
505 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
506 (cups_acopy_func_t
)_cupsStrAlloc
,
507 (cups_afree_func_t
)_cupsStrFree
);
509 cupsArrayAdd(pc
->filters
, value
);
511 else if (!_cups_strcasecmp(line
, "PreFilter"))
514 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
515 (cups_acopy_func_t
)_cupsStrAlloc
,
516 (cups_afree_func_t
)_cupsStrFree
);
518 cupsArrayAdd(pc
->prefilters
, value
);
520 else if (!_cups_strcasecmp(line
, "Product"))
522 pc
->product
= _cupsStrAlloc(value
);
524 else if (!_cups_strcasecmp(line
, "SingleFile"))
526 pc
->single_file
= !_cups_strcasecmp(value
, "true");
528 else if (!_cups_strcasecmp(line
, "IPP"))
530 off_t pos
= cupsFileTell(fp
), /* Position in file */
531 length
= strtol(value
, NULL
, 10);
532 /* Length of IPP attributes */
536 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
537 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
540 else if (length
<= 0)
542 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
543 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
550 * Read IPP attributes into the provided variable...
555 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
556 *attrs
) != IPP_STATE_DATA
)
558 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
559 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
566 * Skip the IPP data entirely...
569 cupsFileSeek(fp
, pos
+ length
);
572 if (cupsFileTell(fp
) != (pos
+ length
))
574 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
575 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
579 else if (!_cups_strcasecmp(line
, "NumBins"))
583 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
584 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
588 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
590 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
591 "%d.", num_sizes
, linenum
));
592 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
596 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
598 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
600 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
604 else if (!_cups_strcasecmp(line
, "Bin"))
606 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
608 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
609 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
613 if (pc
->num_bins
>= num_bins
)
615 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
617 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
621 map
= pc
->bins
+ pc
->num_bins
;
622 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
623 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
627 else if (!_cups_strcasecmp(line
, "NumSizes"))
631 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
632 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
636 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
638 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
639 "%d.", num_sizes
, linenum
));
640 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
646 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
648 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
650 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
655 else if (!_cups_strcasecmp(line
, "Size"))
657 if (pc
->num_sizes
>= num_sizes
)
659 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 size
= pc
->sizes
+ pc
->num_sizes
;
667 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
668 &(size
->width
), &(size
->length
), &(size
->left
),
669 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
671 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
673 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
677 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
678 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
682 else if (!_cups_strcasecmp(line
, "CustomSize"))
684 if (pc
->custom_max_width
> 0)
686 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
688 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
692 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
693 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
694 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
695 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
696 &(pc
->custom_size
.top
)) != 8)
698 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
700 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
704 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
705 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
706 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
708 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
709 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
710 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
712 else if (!_cups_strcasecmp(line
, "SourceOption"))
714 pc
->source_option
= _cupsStrAlloc(value
);
716 else if (!_cups_strcasecmp(line
, "NumSources"))
720 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
722 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
726 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
728 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
729 "line %d.", num_sources
, linenum
));
730 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
734 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
736 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
738 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
742 else if (!_cups_strcasecmp(line
, "Source"))
744 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
746 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
748 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
752 if (pc
->num_sources
>= num_sources
)
754 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
756 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
760 map
= pc
->sources
+ pc
->num_sources
;
761 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
762 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
766 else if (!_cups_strcasecmp(line
, "NumTypes"))
770 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
771 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
775 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
777 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
778 "line %d.", num_types
, linenum
));
779 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
783 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
785 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
787 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
791 else if (!_cups_strcasecmp(line
, "Type"))
793 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
795 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
797 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
801 if (pc
->num_types
>= num_types
)
803 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
805 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
809 map
= pc
->types
+ pc
->num_types
;
810 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
811 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
815 else if (!_cups_strcasecmp(line
, "Preset"))
818 * Preset output-mode print-quality name=value ...
821 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
822 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
824 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
825 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
826 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
827 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
828 valueptr
== value
|| !*valueptr
)
830 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
836 pc
->num_presets
[print_color_mode
][print_quality
] =
837 cupsParseOptions(valueptr
, 0,
838 pc
->presets
[print_color_mode
] + print_quality
);
840 else if (!_cups_strcasecmp(line
, "SidesOption"))
841 pc
->sides_option
= _cupsStrAlloc(value
);
842 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
843 pc
->sides_1sided
= _cupsStrAlloc(value
);
844 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
845 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
846 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
847 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
848 else if (!_cups_strcasecmp(line
, "Finishings"))
852 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
854 (cups_afree_func_t
)pwg_free_finishings
);
856 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
859 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
860 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
861 &(finishings
->options
));
863 cupsArrayAdd(pc
->finishings
, finishings
);
865 else if (!_cups_strcasecmp(line
, "MaxCopies"))
866 pc
->max_copies
= atoi(value
);
867 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
868 pc
->charge_info_uri
= _cupsStrAlloc(value
);
869 else if (!_cups_strcasecmp(line
, "JobAccountId"))
870 pc
->account_id
= !_cups_strcasecmp(value
, "true");
871 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
872 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
873 else if (!_cups_strcasecmp(line
, "JobPassword"))
874 pc
->password
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "Mandatory"))
878 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
880 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
882 else if (!_cups_strcasecmp(line
, "SupportFile"))
884 if (!pc
->support_files
)
885 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
886 (cups_acopy_func_t
)_cupsStrAlloc
,
887 (cups_afree_func_t
)_cupsStrFree
);
889 cupsArrayAdd(pc
->support_files
, value
);
893 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
898 if (pc
->num_sizes
< num_sizes
)
900 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
901 pc
->num_sizes
, num_sizes
));
902 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
906 if (pc
->num_sources
< num_sources
)
908 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
909 pc
->num_sources
, num_sources
));
910 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
914 if (pc
->num_types
< num_types
)
916 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
917 pc
->num_types
, num_types
));
918 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
927 * If we get here the file was bad - free any data and return...
933 _ppdCacheDestroy(pc
);
946 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
949 _ppd_cache_t
* /* O - PPD cache and mapping data */
950 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
952 int i
, j
, k
; /* Looping vars */
953 _ppd_cache_t
*pc
; /* PWG mapping data */
954 ppd_option_t
*input_slot
, /* InputSlot option */
955 *media_type
, /* MediaType option */
956 *output_bin
, /* OutputBin option */
957 *color_model
, /* ColorModel option */
958 *duplex
; /* Duplex option */
959 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
960 pwg_map_t
*map
; /* Current source/type map */
961 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
962 int num_options
; /* Number of preset options and props */
963 cups_option_t
*options
; /* Preset options and properties */
964 ppd_size_t
*ppd_size
; /* Current PPD size */
965 pwg_size_t
*pwg_size
; /* Current PWG size */
966 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
967 /* PWG keyword string */
968 ppd_name
[PPD_MAX_NAME
];
969 /* Normalized PPD name */
970 const char *pwg_name
; /* Standard PWG media name */
971 pwg_media_t
*pwg_media
; /* PWG media data */
972 _pwg_print_color_mode_t pwg_print_color_mode
;
973 /* print-color-mode index */
974 _pwg_print_quality_t pwg_print_quality
;
975 /* print-quality index */
976 int similar
; /* Are the old and new size similar? */
977 pwg_size_t
*old_size
; /* Current old size */
978 int old_imageable
, /* Old imageable length in 2540ths */
979 old_borderless
, /* Old borderless state */
980 old_known_pwg
; /* Old PWG name is well-known */
981 int new_width
, /* New width in 2540ths */
982 new_length
, /* New length in 2540ths */
983 new_left
, /* New left margin in 2540ths */
984 new_bottom
, /* New bottom margin in 2540ths */
985 new_right
, /* New right margin in 2540ths */
986 new_top
, /* New top margin in 2540ths */
987 new_imageable
, /* New imageable length in 2540ths */
988 new_borderless
, /* New borderless state */
989 new_known_pwg
; /* New PWG name is well-known */
990 pwg_size_t
*new_size
; /* New size to add, if any */
991 const char *filter
; /* Current filter */
992 _pwg_finishings_t
*finishings
; /* Current finishings value */
995 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
998 * Range check input...
1005 * Allocate memory...
1008 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1010 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1015 * Copy and convert size data...
1018 if (ppd
->num_sizes
> 0)
1020 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1022 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1023 "pwg_size_t's.", ppd
->num_sizes
));
1027 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1032 * Don't copy over custom size...
1035 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1039 * Convert the PPD size name to the corresponding PWG keyword name.
1042 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1045 * Standard name, do we have conflicts?
1048 for (j
= 0; j
< pc
->num_sizes
; j
++)
1049 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1059 * Standard name and no conflicts, use it!
1062 pwg_name
= pwg_media
->pwg
;
1068 * Not a standard name; convert it to a PWG vendor name of the form:
1070 * pp_lowerppd_WIDTHxHEIGHTuu
1073 pwg_name
= pwg_keyword
;
1076 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1077 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1078 PWG_FROM_POINTS(ppd_size
->width
),
1079 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1083 * If we have a similar paper with non-zero margins then we only want to
1084 * keep it if it has a larger imageable area length. The NULL check is for
1085 * dimensions that are <= 0...
1088 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1089 PWG_FROM_POINTS(ppd_size
->length
),
1093 new_width
= pwg_media
->width
;
1094 new_length
= pwg_media
->length
;
1095 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1096 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1097 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1098 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1099 new_imageable
= new_length
- new_top
- new_bottom
;
1100 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1101 new_left
== 0 && new_right
== 0;
1103 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1107 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1108 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1109 old_size
->right
== 0 && old_size
->top
== 0;
1110 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1111 strncmp(old_size
->map
.pwg
, "om_", 3);
1113 similar
= old_borderless
== new_borderless
&&
1114 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1115 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1118 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1121 * The new paper has a larger imageable area so it could replace
1122 * the older paper. Regardless of the imageable area, we always
1123 * prefer the size with a well-known PWG name.
1126 new_size
= old_size
;
1127 _cupsStrFree(old_size
->map
.ppd
);
1128 _cupsStrFree(old_size
->map
.pwg
);
1135 * The paper was unique enough to deserve its own entry so add it to the
1139 new_size
= pwg_size
++;
1149 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1150 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1151 new_size
->width
= new_width
;
1152 new_size
->length
= new_length
;
1153 new_size
->left
= new_left
;
1154 new_size
->bottom
= new_bottom
;
1155 new_size
->right
= new_right
;
1156 new_size
->top
= new_top
;
1161 if (ppd
->variable_sizes
)
1164 * Generate custom size data...
1167 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1168 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1169 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1170 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1171 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1172 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1174 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1175 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1176 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1177 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1178 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1179 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1181 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1182 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1183 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1184 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1188 * Copy and convert InputSlot data...
1191 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1192 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1196 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1198 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1200 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1201 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1205 pc
->num_sources
= input_slot
->num_choices
;
1207 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1210 i
--, choice
++, map
++)
1212 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1213 !_cups_strcasecmp(choice
->choice
, "Default"))
1215 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1217 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1219 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1221 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1222 !_cups_strcasecmp(choice
->choice
, "MP") ||
1223 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1224 pwg_name
= "by-pass-tray";
1225 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1226 pwg_name
= "large-capacity";
1227 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1228 pwg_name
= "bottom";
1229 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1230 pwg_name
= "middle";
1231 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1233 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1235 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1236 pwg_name
= "main-roll";
1240 * Convert PPD name to lowercase...
1243 pwg_name
= pwg_keyword
;
1244 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1248 map
->pwg
= _cupsStrAlloc(pwg_name
);
1249 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1254 * Copy and convert MediaType data...
1257 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1259 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1261 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1262 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1266 pc
->num_types
= media_type
->num_choices
;
1268 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1271 i
--, choice
++, map
++)
1273 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1274 !_cups_strcasecmp(choice
->choice
, "Any") ||
1275 !_cups_strcasecmp(choice
->choice
, "Default"))
1277 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1278 pwg_name
= "cardstock";
1279 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1280 pwg_name
= "envelope";
1281 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1282 pwg_name
= "photographic-glossy";
1283 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1284 pwg_name
= "photographic-high-gloss";
1285 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1286 pwg_name
= "photographic-matte";
1287 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1288 pwg_name
= "stationery";
1289 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1290 pwg_name
= "stationery-coated";
1291 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1292 pwg_name
= "stationery-inkjet";
1293 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1294 pwg_name
= "stationery-letterhead";
1295 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1296 pwg_name
= "stationery-preprinted";
1297 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1298 pwg_name
= "stationery-recycled";
1299 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1300 pwg_name
= "transparency";
1304 * Convert PPD name to lowercase...
1307 pwg_name
= pwg_keyword
;
1308 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1312 map
->pwg
= _cupsStrAlloc(pwg_name
);
1313 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1318 * Copy and convert OutputBin data...
1321 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1323 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1325 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1326 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1330 pc
->num_bins
= output_bin
->num_choices
;
1332 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1335 i
--, choice
++, map
++)
1337 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1339 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1340 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1344 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1347 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1350 const char *quality
, /* com.apple.print.preset.quality value */
1351 *output_mode
, /* com.apple.print.preset.output-mode value */
1352 *color_model_val
, /* ColorModel choice */
1353 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1354 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1358 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1361 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1362 num_options
, options
)) != NULL
)
1365 * Get the print-quality for this preset...
1368 if (!strcmp(quality
, "low"))
1369 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1370 else if (!strcmp(quality
, "high"))
1371 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1373 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1376 * Ignore graphicsType "Photo" presets that are not high quality.
1379 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1380 num_options
, options
);
1382 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1383 !strcmp(graphicsType
, "Photo"))
1387 * Ignore presets for normal and draft quality where the coating
1388 * isn't "none" or "autodetect".
1391 media_front_coating
= cupsGetOption(
1392 "com.apple.print.preset.media-front-coating",
1393 num_options
, options
);
1395 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1396 media_front_coating
&&
1397 strcmp(media_front_coating
, "none") &&
1398 strcmp(media_front_coating
, "autodetect"))
1402 * Get the output mode for this preset...
1405 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1406 num_options
, options
);
1407 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1411 if (!strcmp(output_mode
, "monochrome"))
1412 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1414 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1416 else if (color_model_val
)
1418 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1419 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1421 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1424 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1427 * Save the options for this combination as needed...
1430 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1431 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1432 _ppdParseOptions(ppd_attr
->value
, 0,
1433 pc
->presets
[pwg_print_color_mode
] +
1434 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1437 cupsFreeOptions(num_options
, options
);
1439 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1442 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1443 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1444 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1447 * Try adding some common color options to create grayscale presets. These
1448 * are listed in order of popularity...
1451 const char *color_option
= NULL
, /* Color control option */
1452 *gray_choice
= NULL
; /* Choice to select grayscale */
1454 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1455 ppdFindChoice(color_model
, "Gray"))
1457 color_option
= "ColorModel";
1458 gray_choice
= "Gray";
1460 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1461 ppdFindChoice(color_model
, "grayscale"))
1463 color_option
= "HPColorMode";
1464 gray_choice
= "grayscale";
1466 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1467 ppdFindChoice(color_model
, "Mono"))
1469 color_option
= "BRMonoColor";
1470 gray_choice
= "Mono";
1472 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1473 ppdFindChoice(color_model
, "1"))
1475 color_option
= "CNIJSGrayScale";
1478 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1479 ppdFindChoice(color_model
, "True"))
1481 color_option
= "HPColorAsGray";
1482 gray_choice
= "True";
1485 if (color_option
&& gray_choice
)
1488 * Copy and convert ColorModel (output-mode) data...
1491 cups_option_t
*coption
, /* Color option */
1492 *moption
; /* Monochrome option */
1494 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1495 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1496 pwg_print_quality
++)
1498 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1501 * Copy the color options...
1504 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1505 [pwg_print_quality
];
1506 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1510 for (i
= num_options
, moption
= options
,
1511 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1512 [pwg_print_quality
];
1514 i
--, moption
++, coption
++)
1516 moption
->name
= _cupsStrRetain(coption
->name
);
1517 moption
->value
= _cupsStrRetain(coption
->value
);
1520 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1522 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1526 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1530 * Add the grayscale option to the preset...
1533 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1534 cupsAddOption(color_option
, gray_choice
,
1535 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1536 [pwg_print_quality
],
1537 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1544 * Copy and convert Duplex (sides) data...
1547 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1548 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1549 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1550 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1551 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1555 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1557 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1561 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1562 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1563 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1564 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1565 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1566 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1567 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1568 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1569 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1570 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1571 !pc
->sides_2sided_short
)
1572 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1577 * Copy filters and pre-filters...
1580 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1581 (cups_acopy_func_t
)_cupsStrAlloc
,
1582 (cups_afree_func_t
)_cupsStrFree
);
1584 cupsArrayAdd(pc
->filters
,
1585 "application/vnd.cups-raw application/octet-stream 0 -");
1587 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1591 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1593 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1595 else if (ppd
->num_filters
> 0)
1597 for (i
= 0; i
< ppd
->num_filters
; i
++)
1598 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1601 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1604 * See if we have a command filter...
1607 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1609 filter
= (const char *)cupsArrayNext(pc
->filters
))
1610 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1611 _cups_isspace(filter
[28]))
1615 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1616 _cups_strcasecmp(ppd_attr
->value
, "none")))
1619 * No command filter and no cupsCommands keyword telling us not to use one.
1620 * See if this is a PostScript printer, and if so add a PostScript command
1624 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1626 filter
= (const char *)cupsArrayNext(pc
->filters
))
1627 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1628 _cups_isspace(filter
[31]))
1632 cupsArrayAdd(pc
->filters
,
1633 "application/vnd.cups-command application/postscript 100 "
1637 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1639 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1640 (cups_acopy_func_t
)_cupsStrAlloc
,
1641 (cups_afree_func_t
)_cupsStrFree
);
1645 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1647 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1650 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1651 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1654 * Copy the product string, if any...
1658 pc
->product
= _cupsStrAlloc(ppd
->product
);
1661 * Copy finishings mapping data...
1664 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1667 * Have proper vendor mapping of IPP finishings values to PPD options...
1670 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1671 NULL
, NULL
, 0, NULL
,
1672 (cups_afree_func_t
)pwg_free_finishings
);
1676 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1679 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1680 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1681 &(finishings
->options
),
1682 _PPD_PARSE_OPTIONS
);
1684 cupsArrayAdd(pc
->finishings
, finishings
);
1686 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1692 * No IPP mapping data, try to map common/standard PPD keywords...
1695 ppd_option_t
*ppd_option
; /* PPD option */
1697 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1699 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1702 * Add staple finishings...
1705 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1706 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1707 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1708 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1709 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1710 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1711 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1712 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1713 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1714 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1717 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1720 * Add (Ricoh) punch finishings...
1723 if (ppdFindChoice(ppd_option
, "Left2"))
1724 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1725 if (ppdFindChoice(ppd_option
, "Left3"))
1726 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1727 if (ppdFindChoice(ppd_option
, "Left4"))
1728 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1729 if (ppdFindChoice(ppd_option
, "Right2"))
1730 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1731 if (ppdFindChoice(ppd_option
, "Right3"))
1732 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1733 if (ppdFindChoice(ppd_option
, "Right4"))
1734 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1735 if (ppdFindChoice(ppd_option
, "Upper2"))
1736 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1737 if (ppdFindChoice(ppd_option
, "Upper3"))
1738 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1739 if (ppdFindChoice(ppd_option
, "Upper4"))
1740 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1743 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1746 * Add bind finishings...
1749 if (ppdFindChoice(ppd_option
, "Left"))
1750 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1751 if (ppdFindChoice(ppd_option
, "Right"))
1752 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1753 if (ppdFindChoice(ppd_option
, "Top"))
1754 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1755 if (ppdFindChoice(ppd_option
, "Bottom"))
1756 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1759 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1762 * Add (Adobe) fold finishings...
1765 if (ppdFindChoice(ppd_option
, "ZFold"))
1766 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1767 if (ppdFindChoice(ppd_option
, "Saddle"))
1768 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1769 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1770 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1771 if (ppdFindChoice(ppd_option
, "LeftGate"))
1772 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1773 if (ppdFindChoice(ppd_option
, "RightGate"))
1774 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1775 if (ppdFindChoice(ppd_option
, "Letter"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1777 if (ppdFindChoice(ppd_option
, "XFold"))
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1781 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1784 * Add (Ricoh) fold finishings...
1787 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1788 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1791 if (cupsArrayCount(pc
->finishings
) == 0)
1793 cupsArrayDelete(pc
->finishings
);
1794 pc
->finishings
= NULL
;
1802 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1803 pc
->max_copies
= atoi(ppd_attr
->value
);
1804 else if (ppd
->manual_copies
)
1807 pc
->max_copies
= 9999;
1810 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1811 * cupsJobPassword, and cupsMandatory.
1814 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1815 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1817 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1818 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1820 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1821 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1823 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1824 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1826 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1827 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1833 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1834 (cups_acopy_func_t
)_cupsStrAlloc
,
1835 (cups_afree_func_t
)_cupsStrFree
);
1837 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1839 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1840 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1842 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1843 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1846 * Return the cache data...
1852 * If we get here we need to destroy the PWG mapping data and return NULL...
1857 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1858 _ppdCacheDestroy(pc
);
1865 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1869 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1871 int i
; /* Looping var */
1872 pwg_map_t
*map
; /* Current map */
1873 pwg_size_t
*size
; /* Current size */
1877 * Range check input...
1884 * Free memory as needed...
1889 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1891 _cupsStrFree(map
->pwg
);
1892 _cupsStrFree(map
->ppd
);
1900 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1902 _cupsStrFree(size
->map
.pwg
);
1903 _cupsStrFree(size
->map
.ppd
);
1909 if (pc
->source_option
)
1910 _cupsStrFree(pc
->source_option
);
1914 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1916 _cupsStrFree(map
->pwg
);
1917 _cupsStrFree(map
->ppd
);
1925 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1927 _cupsStrFree(map
->pwg
);
1928 _cupsStrFree(map
->ppd
);
1934 if (pc
->custom_max_keyword
)
1935 _cupsStrFree(pc
->custom_max_keyword
);
1937 if (pc
->custom_min_keyword
)
1938 _cupsStrFree(pc
->custom_min_keyword
);
1940 _cupsStrFree(pc
->product
);
1941 cupsArrayDelete(pc
->filters
);
1942 cupsArrayDelete(pc
->prefilters
);
1943 cupsArrayDelete(pc
->finishings
);
1945 _cupsStrFree(pc
->charge_info_uri
);
1946 _cupsStrFree(pc
->password
);
1948 cupsArrayDelete(pc
->mandatory
);
1950 cupsArrayDelete(pc
->support_files
);
1957 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1961 const char * /* O - output-bin or NULL */
1963 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1964 const char *output_bin
) /* I - PPD OutputBin string */
1966 int i
; /* Looping var */
1970 * Range check input...
1973 if (!pc
|| !output_bin
)
1977 * Look up the OutputBin string...
1981 for (i
= 0; i
< pc
->num_bins
; i
++)
1982 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1983 return (pc
->bins
[i
].pwg
);
1990 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1991 * IPP finishings value(s).
1994 int /* O - New number of options */
1995 _ppdCacheGetFinishingOptions(
1996 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1997 ipp_t
*job
, /* I - Job attributes or NULL */
1998 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1999 int num_options
, /* I - Number of options */
2000 cups_option_t
**options
) /* IO - Options */
2002 int i
; /* Looping var */
2003 _pwg_finishings_t
*f
, /* PWG finishings options */
2004 key
; /* Search key */
2005 ipp_attribute_t
*attr
; /* Finishings attribute */
2006 cups_option_t
*option
; /* Current finishings option */
2010 * Range check input...
2013 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2014 (!job
&& value
== IPP_FINISHINGS_NONE
))
2015 return (num_options
);
2018 * Apply finishing options...
2021 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2023 int num_values
= ippGetCount(attr
); /* Number of values */
2025 for (i
= 0; i
< num_values
; i
++)
2027 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2029 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2031 int j
; /* Another looping var */
2033 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2034 num_options
= cupsAddOption(option
->name
, option
->value
,
2035 num_options
, options
);
2039 else if (value
!= IPP_FINISHINGS_NONE
)
2043 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2045 int j
; /* Another looping var */
2047 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2048 num_options
= cupsAddOption(option
->name
, option
->value
,
2049 num_options
, options
);
2053 return (num_options
);
2058 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2062 int /* O - Number of finishings values */
2063 _ppdCacheGetFinishingValues(
2064 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2065 int num_options
, /* I - Number of options */
2066 cups_option_t
*options
, /* I - Options */
2067 int max_values
, /* I - Maximum number of finishings values */
2068 int *values
) /* O - Finishings values */
2070 int i
, /* Looping var */
2071 num_values
= 0; /* Number of values */
2072 _pwg_finishings_t
*f
; /* Current finishings option */
2073 cups_option_t
*option
; /* Current option */
2074 const char *val
; /* Value for option */
2078 * Range check input...
2081 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2083 if (!pc
|| max_values
< 1 || !values
)
2085 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2088 else if (!pc
->finishings
)
2090 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2095 * Go through the finishings options and see what is set...
2098 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2100 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2102 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2104 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2106 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2108 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2109 _cups_strcasecmp(option
->value
, val
))
2111 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2118 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2120 values
[num_values
++] = f
->value
;
2122 if (num_values
>= max_values
)
2127 if (num_values
== 0)
2130 * Always have at least "finishings" = 'none'...
2133 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2134 values
[0] = IPP_FINISHINGS_NONE
;
2138 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2140 return (num_values
);
2145 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2146 * attributes or a keyword string.
2149 const char * /* O - PPD InputSlot or NULL */
2150 _ppdCacheGetInputSlot(
2151 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2152 ipp_t
*job
, /* I - Job attributes or NULL */
2153 const char *keyword
) /* I - Keyword string or NULL */
2156 * Range check input...
2159 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2162 if (job
&& !keyword
)
2165 * Lookup the media-col attribute and any media-source found there...
2168 ipp_attribute_t
*media_col
, /* media-col attribute */
2169 *media_source
; /* media-source attribute */
2170 pwg_size_t size
; /* Dimensional size */
2171 int margins_set
; /* Were the margins set? */
2173 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2175 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2177 IPP_TAG_KEYWORD
)) != NULL
)
2180 * Use the media-source value from media-col...
2183 keyword
= ippGetString(media_source
, 0, NULL
);
2185 else if (pwgInitSize(&size
, job
, &margins_set
))
2188 * For media <= 5x7, look for a photo tray...
2191 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2198 int i
; /* Looping var */
2200 for (i
= 0; i
< pc
->num_sources
; i
++)
2201 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2202 return (pc
->sources
[i
].ppd
);
2210 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2211 * attributes or a keyword string.
2214 const char * /* O - PPD MediaType or NULL */
2215 _ppdCacheGetMediaType(
2216 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2217 ipp_t
*job
, /* I - Job attributes or NULL */
2218 const char *keyword
) /* I - Keyword string or NULL */
2221 * Range check input...
2224 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2227 if (job
&& !keyword
)
2230 * Lookup the media-col attribute and any media-source found there...
2233 ipp_attribute_t
*media_col
, /* media-col attribute */
2234 *media_type
; /* media-type attribute */
2236 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2239 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2241 IPP_TAG_KEYWORD
)) == NULL
)
2242 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2243 "media-type", IPP_TAG_NAME
);
2246 keyword
= media_type
->values
[0].string
.text
;
2252 int i
; /* Looping var */
2254 for (i
= 0; i
< pc
->num_types
; i
++)
2255 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2256 return (pc
->types
[i
].ppd
);
2264 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2268 const char * /* O - PPD OutputBin or NULL */
2269 _ppdCacheGetOutputBin(
2270 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2271 const char *output_bin
) /* I - Keyword string */
2273 int i
; /* Looping var */
2277 * Range check input...
2280 if (!pc
|| !output_bin
)
2284 * Look up the OutputBin string...
2288 for (i
= 0; i
< pc
->num_bins
; i
++)
2289 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2290 return (pc
->bins
[i
].ppd
);
2297 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2298 * attributes or a keyword string.
2301 const char * /* O - PPD PageSize or NULL */
2302 _ppdCacheGetPageSize(
2303 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2304 ipp_t
*job
, /* I - Job attributes or NULL */
2305 const char *keyword
, /* I - Keyword string or NULL */
2306 int *exact
) /* O - 1 if exact match, 0 otherwise */
2308 int i
; /* Looping var */
2309 pwg_size_t
*size
, /* Current size */
2310 *closest
, /* Closest size */
2311 jobsize
; /* Size data from job */
2312 int margins_set
, /* Were the margins set? */
2313 dwidth
, /* Difference in width */
2314 dlength
, /* Difference in length */
2315 dleft
, /* Difference in left margins */
2316 dright
, /* Difference in right margins */
2317 dbottom
, /* Difference in bottom margins */
2318 dtop
, /* Difference in top margins */
2319 dmin
, /* Minimum difference */
2320 dclosest
; /* Closest difference */
2321 const char *ppd_name
; /* PPD media name */
2324 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2325 pc
, job
, keyword
, exact
));
2328 * Range check input...
2331 if (!pc
|| (!job
&& !keyword
))
2342 * Try getting the PPD media name from the job attributes...
2345 ipp_attribute_t
*attr
; /* Job attribute */
2347 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2348 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2349 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2353 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2354 attr
->name
, ippTagString(attr
->value_tag
)));
2356 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2359 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2360 attr
->value_tag
== IPP_TAG_KEYWORD
))
2361 ppd_name
= attr
->values
[0].string
.text
;
2364 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2369 * Try looking up the named PPD size first...
2372 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2374 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2375 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2377 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2378 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2383 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2385 return (size
->map
.ppd
);
2390 if (job
&& !keyword
)
2393 * Get the size using media-col or media, with the preference being
2397 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2403 * Get the size using a media keyword...
2406 pwg_media_t
*media
; /* Media definition */
2409 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2410 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2411 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2414 jobsize
.width
= media
->width
;
2415 jobsize
.length
= media
->length
;
2420 * Now that we have the dimensions and possibly the margins, look at the
2421 * available sizes and find the match...
2425 dclosest
= 999999999;
2427 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2428 _cups_strncasecmp(ppd_name
, "custom_", 7))
2430 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2433 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2434 * is just about 176/2540ths...
2437 dwidth
= size
->width
- jobsize
.width
;
2438 dlength
= size
->length
- jobsize
.length
;
2440 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2446 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2449 dleft
= size
->left
- jobsize
.left
;
2450 dright
= size
->right
- jobsize
.right
;
2451 dtop
= size
->top
- jobsize
.top
;
2452 dbottom
= size
->bottom
- jobsize
.bottom
;
2454 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2455 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2457 dleft
= dleft
< 0 ? -dleft
: dleft
;
2458 dright
= dright
< 0 ? -dright
: dright
;
2459 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2460 dtop
= dtop
< 0 ? -dtop
: dtop
;
2461 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2463 if (dmin
< dclosest
)
2476 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2478 return (size
->map
.ppd
);
2484 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2487 return (closest
->map
.ppd
);
2491 * If we get here we need to check for custom page size support...
2494 if (jobsize
.width
>= pc
->custom_min_width
&&
2495 jobsize
.width
<= pc
->custom_max_width
&&
2496 jobsize
.length
>= pc
->custom_min_length
&&
2497 jobsize
.length
<= pc
->custom_max_length
)
2500 * In range, format as Custom.WWWWxLLLL (points).
2503 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2504 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2506 if (margins_set
&& exact
)
2508 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2509 dright
= pc
->custom_size
.right
- jobsize
.right
;
2510 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2511 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2513 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2514 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2520 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2521 pc
->custom_ppd_size
));
2523 return (pc
->custom_ppd_size
);
2527 * No custom page size support or the size is out of range - return NULL.
2530 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2537 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2540 pwg_size_t
* /* O - PWG size or NULL */
2542 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2543 const char *page_size
) /* I - PPD PageSize */
2545 int i
; /* Looping var */
2546 pwg_media_t
*media
; /* Media */
2547 pwg_size_t
*size
; /* Current size */
2551 * Range check input...
2554 if (!pc
|| !page_size
)
2557 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2560 * Custom size; size name can be one of the following:
2562 * Custom.WIDTHxLENGTHin - Size in inches
2563 * Custom.WIDTHxLENGTHft - Size in feet
2564 * Custom.WIDTHxLENGTHcm - Size in centimeters
2565 * Custom.WIDTHxLENGTHmm - Size in millimeters
2566 * Custom.WIDTHxLENGTHm - Size in meters
2567 * Custom.WIDTHxLENGTH[pt] - Size in points
2570 double w
, l
; /* Width and length of page */
2571 char *ptr
; /* Pointer into PageSize */
2572 struct lconv
*loc
; /* Locale data */
2575 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2576 if (!ptr
|| *ptr
!= 'x')
2579 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2583 if (!_cups_strcasecmp(ptr
, "in"))
2588 else if (!_cups_strcasecmp(ptr
, "ft"))
2593 else if (!_cups_strcasecmp(ptr
, "mm"))
2598 else if (!_cups_strcasecmp(ptr
, "cm"))
2603 else if (!_cups_strcasecmp(ptr
, "m"))
2614 pc
->custom_size
.width
= (int)w
;
2615 pc
->custom_size
.length
= (int)l
;
2617 return (&(pc
->custom_size
));
2621 * Not a custom size - look it up...
2624 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2625 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2626 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2630 * Look up standard sizes...
2633 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2634 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2635 media
= pwgMediaForPWG(page_size
);
2639 pc
->custom_size
.width
= media
->width
;
2640 pc
->custom_size
.length
= media
->length
;
2642 return (&(pc
->custom_size
));
2650 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2654 const char * /* O - PWG media-source keyword */
2656 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2657 const char *input_slot
) /* I - PPD InputSlot */
2659 int i
; /* Looping var */
2660 pwg_map_t
*source
; /* Current source */
2664 * Range check input...
2667 if (!pc
|| !input_slot
)
2670 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2671 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2672 return (source
->pwg
);
2679 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2683 const char * /* O - PWG media-type keyword */
2685 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2686 const char *media_type
) /* I - PPD MediaType */
2688 int i
; /* Looping var */
2689 pwg_map_t
*type
; /* Current type */
2693 * Range check input...
2696 if (!pc
|| !media_type
)
2699 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2700 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2708 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2711 int /* O - 1 on success, 0 on failure */
2713 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2714 const char *filename
, /* I - File to write */
2715 ipp_t
*attrs
) /* I - Attributes to write, if any */
2717 int i
, j
, k
; /* Looping vars */
2718 cups_file_t
*fp
; /* Output file */
2719 pwg_size_t
*size
; /* Current size */
2720 pwg_map_t
*map
; /* Current map */
2721 _pwg_finishings_t
*f
; /* Current finishing option */
2722 cups_option_t
*option
; /* Current option */
2723 const char *value
; /* Filter/pre-filter value */
2724 char newfile
[1024]; /* New filename */
2728 * Range check input...
2731 if (!pc
|| !filename
)
2733 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2738 * Open the file and write with compression...
2741 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2742 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2744 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2749 * Standard header...
2752 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2758 if (pc
->num_bins
> 0)
2760 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2761 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2762 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2769 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2770 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2771 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2772 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2773 size
->bottom
, size
->right
, size
->top
);
2774 if (pc
->custom_max_width
> 0)
2775 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2776 pc
->custom_max_width
, pc
->custom_max_length
,
2777 pc
->custom_min_width
, pc
->custom_min_length
,
2778 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2779 pc
->custom_size
.right
, pc
->custom_size
.top
);
2785 if (pc
->source_option
)
2786 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2788 if (pc
->num_sources
> 0)
2790 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2791 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2792 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2799 if (pc
->num_types
> 0)
2801 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2802 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2803 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2810 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2811 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2812 if (pc
->num_presets
[i
][j
])
2814 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2815 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2818 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2819 cupsFilePutChar(fp
, '\n');
2826 if (pc
->sides_option
)
2827 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2829 if (pc
->sides_1sided
)
2830 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2832 if (pc
->sides_2sided_long
)
2833 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2835 if (pc
->sides_2sided_short
)
2836 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2839 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2843 cupsFilePutConf(fp
, "Product", pc
->product
);
2845 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2847 value
= (const char *)cupsArrayNext(pc
->filters
))
2848 cupsFilePutConf(fp
, "Filter", value
);
2850 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2852 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2853 cupsFilePutConf(fp
, "PreFilter", value
);
2855 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2858 * Finishing options...
2861 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2863 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2865 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2866 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2867 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2868 cupsFilePutChar(fp
, '\n');
2875 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2878 * Accounting/quota/PIN/managed printing values...
2881 if (pc
->charge_info_uri
)
2882 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2884 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2885 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2886 pc
->accounting_user_id
? "true" : "false");
2889 cupsFilePutConf(fp
, "Password", pc
->password
);
2891 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2893 value
= (char *)cupsArrayNext(pc
->mandatory
))
2894 cupsFilePutConf(fp
, "Mandatory", value
);
2900 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2902 value
= (char *)cupsArrayNext(pc
->support_files
))
2903 cupsFilePutConf(fp
, "SupportFile", value
);
2906 * IPP attributes, if any...
2911 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2913 attrs
->state
= IPP_STATE_IDLE
;
2914 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2918 * Close and return...
2921 if (cupsFileClose(fp
))
2928 return (!rename(newfile
, filename
));
2933 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2934 * of an IPP printer.
2937 char * /* O - PPD filename or @code NULL@ on error */
2938 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2939 size_t bufsize
, /* I - Size of filename buffer */
2940 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2942 cups_file_t
*fp
; /* PPD file */
2943 cups_array_t
*sizes
; /* Media sizes we've added */
2944 ipp_attribute_t
*attr
, /* xxx-supported */
2945 *defattr
, /* xxx-default */
2946 *quality
, /* print-quality-supported */
2947 *x_dim
, *y_dim
; /* Media dimensions */
2948 ipp_t
*media_size
; /* Media size collection */
2949 char make
[256], /* Make and model */
2950 *model
, /* Model name */
2951 ppdname
[PPD_MAX_NAME
];
2953 int i
, j
, /* Looping vars */
2954 count
, /* Number of values */
2955 bottom
, /* Largest bottom margin */
2956 left
, /* Largest left margin */
2957 right
, /* Largest right margin */
2958 top
, /* Largest top margin */
2959 is_apple
= 0, /* Does the printer support Apple raster? */
2960 is_pdf
= 0, /* Does the printer support PDF? */
2961 is_pwg
= 0; /* Does the printer support PWG Raster? */
2962 pwg_media_t
*pwg
; /* PWG media size */
2963 int xres
, yres
; /* Resolution values */
2964 int resolutions
[1000];
2965 /* Array of resolution indices */
2966 cups_lang_t
*lang
= cupsLangDefault();
2967 /* Localization info */
2968 struct lconv
*loc
= localeconv();
2970 static const char * const finishings
[][2] =
2971 { /* Finishings strings */
2972 { "bale", _("Bale") },
2973 { "bind", _("Bind") },
2974 { "bind-bottom", _("Bind (Reverse Landscape)") },
2975 { "bind-left", _("Bind (Portrait)") },
2976 { "bind-right", _("Bind (Reverse Portrait)") },
2977 { "bind-top", _("Bind (Landscape)") },
2978 { "booklet-maker", _("Booklet Maker") },
2979 { "coat", _("Coat") },
2980 { "cover", _("Cover") },
2981 { "edge-stitch", _("Staple Edge") },
2982 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
2983 { "edge-stitch-left", _("Staple Edge (Portrait)") },
2984 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
2985 { "edge-stitch-top", _("Staple Edge (Landscape)") },
2986 { "fold", _("Fold") },
2987 { "fold-accordian", _("Accordian Fold") },
2988 { "fold-double-gate", _("Double Gate Fold") },
2989 { "fold-engineering-z", _("Engineering Z Fold") },
2990 { "fold-gate", _("Gate Fold") },
2991 { "fold-half", _("Half Fold") },
2992 { "fold-half-z", _("Half Z Fold") },
2993 { "fold-left-gate", _("Left Gate Fold") },
2994 { "fold-letter", _("Letter Fold") },
2995 { "fold-parallel", _("Parallel Fold") },
2996 { "fold-poster", _("Poster Fold") },
2997 { "fold-right-gate", _("Right Gate Fold") },
2998 { "fold-z", _("Z Fold") },
2999 { "jog-offset", _("Jog") },
3000 { "laminate", _("Laminate") },
3001 { "punch", _("Punch") },
3002 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3003 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3004 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3005 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3006 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3007 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3008 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3009 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3010 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3011 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3012 { "punch-top-left", _("Single Punch (Portrait)") },
3013 { "punch-top-right", _("Single Punch (Landscape)") },
3014 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3015 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3016 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3017 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3018 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3019 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3020 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3021 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3022 { "saddle-stitch", _("Saddle Stitch") },
3023 { "staple", _("Staple") },
3024 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3025 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3026 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3027 { "staple-dual-left", _("Double Staple (Portrait)") },
3028 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3029 { "staple-dual-top", _("Double Staple (Landscape)") },
3030 { "staple-top-left", _("Single Staple (Portrait)") },
3031 { "staple-top-right", _("Single Staple (Landscape)") },
3032 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3033 { "staple-triple-left", _("Triple Staple (Portrait)") },
3034 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3035 { "staple-triple-top", _("Triple Staple (Landscape)") },
3036 { "trim", _("Cut Media") }
3041 * Range check input...
3047 if (!buffer
|| bufsize
< 1)
3049 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3055 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3060 * Open a temporary file for the PPD...
3063 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3065 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3070 * Standard stuff for PPD file...
3073 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3074 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3075 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3076 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3077 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3078 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3079 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3080 cupsFilePuts(fp
, "*FileSystem: False\n");
3081 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3083 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3084 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3086 strlcpy(make
, "Unknown Printer", sizeof(make
));
3088 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3089 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3092 strlcpy(make
, "HP", sizeof(make
));
3094 else if ((model
= strchr(make
, ' ')) != NULL
)
3099 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3100 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3101 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3102 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3103 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3105 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3106 cupsFilePuts(fp
, "*ColorDevice: True\n");
3108 cupsFilePuts(fp
, "*ColorDevice: False\n");
3110 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3111 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3112 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3118 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3120 is_apple
= ippContainsString(attr
, "image/urf");
3121 is_pdf
= ippContainsString(attr
, "application/pdf");
3122 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3124 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3126 const char *format
= ippGetString(attr
, i
, NULL
);
3130 * Write cupsFilter2 lines for supported formats...
3133 if (!_cups_strcasecmp(format
, "application/pdf"))
3134 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3135 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3136 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3137 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3138 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3142 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3146 * PageSize/PageRegion/ImageableArea/PaperDimension
3149 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3151 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3152 if (ippGetInteger(attr
, i
) > bottom
)
3153 bottom
= ippGetInteger(attr
, i
);
3158 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3160 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3161 if (ippGetInteger(attr
, i
) > left
)
3162 left
= ippGetInteger(attr
, i
);
3167 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3169 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3170 if (ippGetInteger(attr
, i
) > right
)
3171 right
= ippGetInteger(attr
, i
);
3176 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3178 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3179 if (ippGetInteger(attr
, i
) > top
)
3180 top
= ippGetInteger(attr
, i
);
3185 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3187 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3189 media_size
= ippGetCollection(attr
, 0);
3190 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3191 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3193 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3194 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3196 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3199 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3201 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3202 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3204 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3206 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3207 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3210 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3211 "*OrderDependency: 10 AnySetup *PageSize\n"
3212 "*DefaultPageSize: %s\n", ppdname
);
3214 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3216 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3218 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3220 media_size
= ippGetCollection(attr
, i
);
3221 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3222 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3224 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3227 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3231 char twidth
[256], /* Width string */
3232 tlength
[256]; /* Length string */
3234 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3236 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3240 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3242 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3243 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3245 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3248 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3250 cupsArrayDelete(sizes
);
3251 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3253 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3254 "*OrderDependency: 10 AnySetup *PageRegion\n"
3255 "*DefaultPageRegion: %s\n", ppdname
);
3256 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3258 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3260 media_size
= ippGetCollection(attr
, i
);
3261 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3262 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3264 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3267 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3271 char twidth
[256], /* Width string */
3272 tlength
[256]; /* Length string */
3274 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3277 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3279 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3280 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3282 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3285 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3287 cupsArrayDelete(sizes
);
3288 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3290 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3291 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3292 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3294 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3296 media_size
= ippGetCollection(attr
, i
);
3297 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3298 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3300 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3303 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3307 char tleft
[256], /* Left string */
3308 tbottom
[256], /* Bottom string */
3309 tright
[256], /* Right string */
3310 ttop
[256], /* Top string */
3311 twidth
[256], /* Width string */
3312 tlength
[256]; /* Length string */
3314 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3317 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3319 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3320 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3321 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3322 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3323 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3324 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3326 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3327 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3331 cupsArrayDelete(sizes
);
3340 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3341 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3343 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3345 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3347 static const char * const sources
[][2] =
3348 { /* "media-source" strings */
3349 { "Auto", _("Automatic") },
3350 { "Main", _("Main") },
3351 { "Alternate", _("Alternate") },
3352 { "LargeCapacity", _("Large Capacity") },
3353 { "Manual", _("Manual") },
3354 { "Envelope", _("Envelope") },
3355 { "Disc", _("Disc") },
3356 { "Photo", _("Photo") },
3357 { "Hagaki", _("Hagaki") },
3358 { "MainRoll", _("Main Roll") },
3359 { "AlternateRoll", _("Alternate Roll") },
3360 { "Top", _("Top") },
3361 { "Middle", _("Middle") },
3362 { "Bottom", _("Bottom") },
3363 { "Side", _("Side") },
3364 { "Left", _("Left") },
3365 { "Right", _("Right") },
3366 { "Center", _("Center") },
3367 { "Rear", _("Rear") },
3368 { "ByPassTray", _("Multipurpose") },
3369 { "Tray1", _("Tray 1") },
3370 { "Tray2", _("Tray 2") },
3371 { "Tray3", _("Tray 3") },
3372 { "Tray4", _("Tray 4") },
3373 { "Tray5", _("Tray 5") },
3374 { "Tray6", _("Tray 6") },
3375 { "Tray7", _("Tray 7") },
3376 { "Tray8", _("Tray 8") },
3377 { "Tray9", _("Tray 9") },
3378 { "Tray10", _("Tray 10") },
3379 { "Tray11", _("Tray 11") },
3380 { "Tray12", _("Tray 12") },
3381 { "Tray13", _("Tray 13") },
3382 { "Tray14", _("Tray 14") },
3383 { "Tray15", _("Tray 15") },
3384 { "Tray16", _("Tray 16") },
3385 { "Tray17", _("Tray 17") },
3386 { "Tray18", _("Tray 18") },
3387 { "Tray19", _("Tray 19") },
3388 { "Tray20", _("Tray 20") },
3389 { "Roll1", _("Roll 1") },
3390 { "Roll2", _("Roll 2") },
3391 { "Roll3", _("Roll 3") },
3392 { "Roll4", _("Roll 4") },
3393 { "Roll5", _("Roll 5") },
3394 { "Roll6", _("Roll 6") },
3395 { "Roll7", _("Roll 7") },
3396 { "Roll8", _("Roll 8") },
3397 { "Roll9", _("Roll 9") },
3398 { "Roll10", _("Roll 10") }
3401 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3402 "*OrderDependency: 10 AnySetup *InputSlot\n"
3403 "*DefaultInputSlot: %s\n", ppdname
);
3404 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3406 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3408 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3409 if (!strcmp(sources
[j
][0], ppdname
))
3411 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3415 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3422 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3423 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3425 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3427 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3429 static const char * const media_types
[][2] =
3430 { /* "media-type" strings */
3431 { "aluminum", _("Aluminum") },
3432 { "auto", _("Automatic") },
3433 { "back-print-film", _("Back Print Film") },
3434 { "cardboard", _("Cardboard") },
3435 { "cardstock", _("Cardstock") },
3437 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3438 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3439 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3440 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3441 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3442 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3443 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3444 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3445 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3446 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3447 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3448 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3449 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3450 { "continuous", _("Continuous") },
3451 { "continuous-long", _("Continuous Long") },
3452 { "continuous-short", _("Continuous Short") },
3453 { "disc", _("Optical Disc") },
3454 { "disc-glossy", _("Glossy Optical Disc") },
3455 { "disc-high-gloss", _("High Gloss Optical Disc") },
3456 { "disc-matte", _("Matte Optical Disc") },
3457 { "disc-satin", _("Satin Optical Disc") },
3458 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3459 { "double-wall", _("Double Wall Cardboard") },
3460 { "dry-film", _("Dry Film") },
3461 { "dvd", _("DVD") },
3462 { "embossing-foil", _("Embossing Foil") },
3463 { "end-board", _("End Board") },
3464 { "envelope", _("Envelope") },
3465 { "envelope-archival", _("Archival Envelope") },
3466 { "envelope-bond", _("Bond Envelope") },
3467 { "envelope-coated", _("Coated Envelope") },
3468 { "envelope-cotton", _("Cotton Envelope") },
3469 { "envelope-fine", _("Fine Envelope") },
3470 { "envelope-heavyweight", _("Heavyweight Envelope") },
3471 { "envelope-inkjet", _("Inkjet Envelope") },
3472 { "envelope-lightweight", _("Lightweight Envelope") },
3473 { "envelope-plain", _("Plain Envelope") },
3474 { "envelope-preprinted", _("Preprinted Envelope") },
3475 { "envelope-window", _("Windowed Envelope") },
3476 { "fabric", _("Fabric") },
3477 { "fabric-archival", _("Archival Fabric") },
3478 { "fabric-glossy", _("Glossy Fabric") },
3479 { "fabric-high-gloss", _("High Gloss Fabric") },
3480 { "fabric-matte", _("Matte Fabric") },
3481 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3482 { "fabric-waterproof", _("Waterproof Fabric") },
3483 { "film", _("Film") },
3484 { "flexo-base", _("Flexo Base") },
3485 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3486 { "flute", _("Flute") },
3487 { "foil", _("Foil") },
3488 { "full-cut-tabs", _("Full Cut Tabs") },
3489 { "glass", _("Glass") },
3490 { "glass-colored", _("Glass Colored") },
3491 { "glass-opaque", _("Glass Opaque") },
3492 { "glass-surfaced", _("Glass Surfaced") },
3493 { "glass-textured", _("Glass Textured") },
3494 { "gravure-cylinder", _("Gravure Cylinder") },
3495 { "image-setter-paper", _("Image Setter Paper") },
3496 { "imaging-cylinder", _("Imaging Cylinder") },
3497 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3498 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3499 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3500 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3501 { "labels", _("Labels") },
3502 { "labels-colored", _("Colored Labels") },
3503 { "labels-glossy", _("Glossy Labels") },
3504 { "labels-high-gloss", _("High Gloss Labels") },
3505 { "labels-inkjet", _("Inkjet Labels") },
3506 { "labels-matte", _("Matte Labels") },
3507 { "labels-permanent", _("Permanent Labels") },
3508 { "labels-satin", _("Satin Labels") },
3509 { "labels-security", _("Security Labels") },
3510 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3511 { "laminating-foil", _("Laminating Foil") },
3512 { "letterhead", _("Letterhead") },
3513 { "metal", _("Metal") },
3514 { "metal-glossy", _("Metal Glossy") },
3515 { "metal-high-gloss", _("Metal High Gloss") },
3516 { "metal-matte", _("Metal Matte") },
3517 { "metal-satin", _("Metal Satin") },
3518 { "metal-semi-gloss", _("Metal Semi Gloss") },
3519 { "mounting-tape", _("Mounting Tape") },
3520 { "multi-layer", _("Multi Layer") },
3521 { "multi-part-form", _("Multi Part Form") },
3522 { "other", _("Other") },
3523 { "paper", _("Paper") },
3524 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3525 { "photographic", _("Photo Paper") },
3526 { "photographic-archival", _("Archival Photo Paper") },
3527 { "photographic-film", _("Photo Film") },
3528 { "photographic-glossy", _("Glossy Photo Paper") },
3529 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3530 { "photographic-matte", _("Matte Photo Paper") },
3531 { "photographic-satin", _("Satin Photo Paper") },
3532 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3533 { "plastic", _("Plastic") },
3534 { "plastic-archival", _("Plastic Archival") },
3535 { "plastic-colored", _("Plastic Colored") },
3536 { "plastic-glossy", _("Plastic Glossy") },
3537 { "plastic-high-gloss", _("Plastic High Gloss") },
3538 { "plastic-matte", _("Plastic Matte") },
3539 { "plastic-satin", _("Plastic Satin") },
3540 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3541 { "plate", _("Plate") },
3542 { "polyester", _("Polyester") },
3543 { "pre-cut-tabs", _("Pre Cut Tabs") },
3544 { "roll", _("Roll") },
3545 { "screen", _("Screen") },
3546 { "screen-paged", _("Screen Paged") },
3547 { "self-adhesive", _("Self Adhesive") },
3548 { "self-adhesive-film", _("Self Adhesive Film") },
3549 { "shrink-foil", _("Shrink Foil") },
3550 { "single-face", _("Single Face") },
3551 { "single-wall", _("Single Wall Cardboard") },
3552 { "sleeve", _("Sleeve") },
3553 { "stationery", _("Plain Paper") },
3554 { "stationery-archival", _("Archival Paper") },
3555 { "stationery-coated", _("Coated Paper") },
3556 { "stationery-cotton", _("Cotton Paper") },
3557 { "stationery-fine", _("Vellum Paper") },
3558 { "stationery-heavyweight", _("Heavyweight Paper") },
3559 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3560 { "stationery-inkjet", _("Inkjet Paper") },
3561 { "stationery-letterhead", _("Letterhead") },
3562 { "stationery-lightweight", _("Lightweight Paper") },
3563 { "stationery-preprinted", _("Preprinted Paper") },
3564 { "stationery-prepunched", _("Punched Paper") },
3565 { "tab-stock", _("Tab Stock") },
3566 { "tractor", _("Tractor") },
3567 { "transfer", _("Transfer") },
3568 { "transparency", _("Transparency") },
3569 { "triple-wall", _("Triple Wall Cardboard") },
3570 { "wet-film", _("Wet Film") }
3573 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3574 "*OrderDependency: 10 AnySetup *MediaType\n"
3575 "*DefaultMediaType: %s\n", ppdname
);
3576 for (i
= 0; i
< count
; i
++)
3578 const char *keyword
= ippGetString(attr
, i
, NULL
);
3580 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3582 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3583 if (!strcmp(keyword
, media_types
[j
][0]))
3586 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3587 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3589 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, keyword
, ppdname
);
3591 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3598 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3599 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3600 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3601 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3605 const char *default_color
= NULL
; /* Default */
3607 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3609 const char *keyword
= ippGetString(attr
, i
, NULL
);
3610 /* Keyword for color/bit depth */
3612 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3615 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3616 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3618 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3621 default_color
= "FastGray";
3623 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3626 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3627 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3629 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3631 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3632 default_color
= "Gray";
3634 else if (!strcasecmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3637 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3638 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3640 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3642 default_color
= "RGB";
3644 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3647 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3648 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3650 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3653 default_color
= "AdobeRGB";
3659 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3660 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3668 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3670 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3671 "*OrderDependency: 10 AnySetup *Duplex\n"
3672 "*DefaultDuplex: None\n"
3673 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3674 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3675 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3676 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3678 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3680 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3682 const char *dm
= ippGetString(attr
, i
, NULL
);
3685 if (!_cups_strcasecmp(dm
, "DM1"))
3687 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3690 else if (!_cups_strcasecmp(dm
, "DM2"))
3692 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3695 else if (!_cups_strcasecmp(dm
, "DM3"))
3697 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3700 else if (!_cups_strcasecmp(dm
, "DM4"))
3702 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3707 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3709 const char *keyword
= ippGetString(attr
, 0, NULL
);
3712 if (!strcmp(keyword
, "flipped"))
3713 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3714 else if (!strcmp(keyword
, "manual-tumble"))
3715 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3716 else if (!strcmp(keyword
, "normal"))
3717 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3719 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3727 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3728 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3730 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3732 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3734 static const char * const output_bins
[][2] =
3735 { /* "output-bin" strings */
3736 { "auto", _("Automatic") },
3737 { "bottom", _("Bottom Tray") },
3738 { "center", _("Center Tray") },
3739 { "face-down", _("Face Down") },
3740 { "face-up", _("Face Up") },
3741 { "large-capacity", _("Large Capacity Tray") },
3742 { "left", _("Left Tray") },
3743 { "mailbox-1", _("Mailbox 1") },
3744 { "mailbox-2", _("Mailbox 2") },
3745 { "mailbox-3", _("Mailbox 3") },
3746 { "mailbox-4", _("Mailbox 4") },
3747 { "mailbox-5", _("Mailbox 5") },
3748 { "mailbox-6", _("Mailbox 6") },
3749 { "mailbox-7", _("Mailbox 7") },
3750 { "mailbox-8", _("Mailbox 8") },
3751 { "mailbox-9", _("Mailbox 9") },
3752 { "mailbox-10", _("Mailbox 10") },
3753 { "middle", _("Middle") },
3754 { "my-mailbox", _("My Mailbox") },
3755 { "rear", _("Rear Tray") },
3756 { "right", _("Right Tray") },
3757 { "side", _("Side Tray") },
3758 { "stacker-1", _("Stacker 1") },
3759 { "stacker-2", _("Stacker 2") },
3760 { "stacker-3", _("Stacker 3") },
3761 { "stacker-4", _("Stacker 4") },
3762 { "stacker-5", _("Stacker 5") },
3763 { "stacker-6", _("Stacker 6") },
3764 { "stacker-7", _("Stacker 7") },
3765 { "stacker-8", _("Stacker 8") },
3766 { "stacker-9", _("Stacker 9") },
3767 { "stacker-10", _("Stacker 10") },
3768 { "top", _("Top Tray") },
3769 { "tray-1", _("Tray 1") },
3770 { "tray-2", _("Tray 2") },
3771 { "tray-3", _("Tray 3") },
3772 { "tray-4", _("Tray 4") },
3773 { "tray-5", _("Tray 5") },
3774 { "tray-6", _("Tray 6") },
3775 { "tray-7", _("Tray 7") },
3776 { "tray-8", _("Tray 8") },
3777 { "tray-9", _("Tray 9") },
3778 { "tray-10", _("Tray 10") }
3781 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3782 "*OrderDependency: 10 AnySetup *OutputBin\n"
3783 "*DefaultOutputBin: %s\n", ppdname
);
3784 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3786 if (!ippContainsString(attr
, output_bins
[i
][0]))
3789 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3791 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3793 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3797 * Finishing options...
3799 * Eventually need to re-add support for finishings-col-database, however
3800 * it is difficult to map arbitrary finishing-template values to PPD options
3801 * and have the right constraints apply (e.g. stapling vs. folding vs.
3805 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3807 const char *name
; /* String name */
3808 int value
; /* Enum value */
3809 cups_array_t
*names
; /* Names we've added */
3811 count
= ippGetCount(attr
);
3812 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3815 * Staple/Bind/Stitch
3818 for (i
= 0; i
< count
; i
++)
3820 value
= ippGetInteger(attr
, i
);
3821 name
= ippEnumString("finishings", value
);
3823 if (!strncmp(name
, "staple-", 7) || !strncmp(name
, "bind-", 5) || !strncmp(name
, "edge-stitch-", 12) || !strcmp(name
, "saddle-stitch"))
3829 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3830 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3831 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3832 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3834 for (; i
< count
; i
++)
3836 value
= ippGetInteger(attr
, i
);
3837 name
= ippEnumString("finishings", value
);
3839 if (strncmp(name
, "staple-", 7) && strncmp(name
, "bind-", 5) && strncmp(name
, "edge-stitch-", 12) && strcmp(name
, "saddle-stitch"))
3842 if (cupsArrayFind(names
, (char *)name
))
3843 continue; /* Already did this finishing template */
3845 cupsArrayAdd(names
, (char *)name
);
3847 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3849 if (!strcmp(finishings
[j
][0], name
))
3851 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3852 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, name
, name
);
3858 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3865 for (i
= 0; i
< count
; i
++)
3867 value
= ippGetInteger(attr
, i
);
3868 name
= ippEnumString("finishings", value
);
3870 if (!strncmp(name
, "fold-", 5))
3876 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3877 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3878 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3879 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3881 for (; i
< count
; i
++)
3883 value
= ippGetInteger(attr
, i
);
3884 name
= ippEnumString("finishings", value
);
3886 if (strncmp(name
, "fold-", 5))
3889 if (cupsArrayFind(names
, (char *)name
))
3890 continue; /* Already did this finishing template */
3892 cupsArrayAdd(names
, (char *)name
);
3894 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3896 if (!strcmp(finishings
[j
][0], name
))
3898 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3899 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, name
, name
);
3905 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
3912 for (i
= 0; i
< count
; i
++)
3914 value
= ippGetInteger(attr
, i
);
3915 name
= ippEnumString("finishings", value
);
3917 if (!strncmp(name
, "punch-", 6))
3923 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
3924 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
3925 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
3926 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3928 for (i
= 0; i
< count
; i
++)
3930 value
= ippGetInteger(attr
, i
);
3931 name
= ippEnumString("finishings", value
);
3933 if (strncmp(name
, "punch-", 6))
3936 if (cupsArrayFind(names
, (char *)name
))
3937 continue; /* Already did this finishing template */
3939 cupsArrayAdd(names
, (char *)name
);
3941 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3943 if (!strcmp(finishings
[j
][0], name
))
3945 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3946 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, name
, name
);
3952 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
3959 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
3961 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
3962 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
3963 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
3964 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
3965 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
3966 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
3967 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
3970 cupsArrayDelete(names
);
3974 * cupsPrintQuality and DefaultResolution...
3977 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
3979 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3981 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3983 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3985 const char *rs
= ippGetString(attr
, i
, NULL
);
3988 if (_cups_strncasecmp(rs
, "RS", 2))
3991 lowdpi
= atoi(rs
+ 2);
3992 if ((rs
= strrchr(rs
, '-')) != NULL
)
3993 hidpi
= atoi(rs
+ 1);
4002 * Invalid "urf-supported" value...
4010 * Generate print qualities based on low and high DPIs...
4013 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4015 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4016 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4017 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4018 if ((lowdpi
& 1) == 0)
4019 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4020 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4021 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4022 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4023 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4024 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4025 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4028 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4031 * Make a sorted list of resolutions.
4034 count
= ippGetCount(attr
);
4035 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4036 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4038 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4039 for (i
= 1; i
< count
; i
++)
4042 for (i
= 0; i
< (count
- 1); i
++)
4044 for (j
= i
+ 1; j
< count
; j
++)
4046 int ix
, iy
, /* First X and Y resolution */
4047 jx
, jy
, /* Second X and Y resolution */
4048 temp
; /* Swap variable */
4049 ipp_res_t units
; /* Resolution units */
4051 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4052 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4054 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4057 * Swap these two resolutions...
4060 temp
= resolutions
[i
];
4061 resolutions
[i
] = resolutions
[j
];
4062 resolutions
[j
] = temp
;
4068 * Generate print quality options...
4071 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4072 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4074 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4075 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4076 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4077 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4079 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4080 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4082 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4083 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4084 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4086 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4087 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4090 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4092 else if (is_apple
|| is_pwg
)
4096 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4098 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4103 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4106 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4108 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4109 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4110 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4111 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4112 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4113 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4114 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4115 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4116 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4120 * Close up and return...
4128 * If we get here then there was a problem creating the PPD...
4137 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4144 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4148 const char * /* O - InputSlot name */
4149 _pwgInputSlotForSource(
4150 const char *media_source
, /* I - PWG media-source */
4151 char *name
, /* I - Name buffer */
4152 size_t namesize
) /* I - Size of name buffer */
4155 * Range check input...
4158 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4161 if (_cups_strcasecmp(media_source
, "main"))
4162 strlcpy(name
, "Cassette", namesize
);
4163 else if (_cups_strcasecmp(media_source
, "alternate"))
4164 strlcpy(name
, "Multipurpose", namesize
);
4165 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4166 strlcpy(name
, "LargeCapacity", namesize
);
4167 else if (_cups_strcasecmp(media_source
, "bottom"))
4168 strlcpy(name
, "Lower", namesize
);
4169 else if (_cups_strcasecmp(media_source
, "middle"))
4170 strlcpy(name
, "Middle", namesize
);
4171 else if (_cups_strcasecmp(media_source
, "top"))
4172 strlcpy(name
, "Upper", namesize
);
4173 else if (_cups_strcasecmp(media_source
, "rear"))
4174 strlcpy(name
, "Rear", namesize
);
4175 else if (_cups_strcasecmp(media_source
, "side"))
4176 strlcpy(name
, "Side", namesize
);
4177 else if (_cups_strcasecmp(media_source
, "envelope"))
4178 strlcpy(name
, "Envelope", namesize
);
4179 else if (_cups_strcasecmp(media_source
, "main-roll"))
4180 strlcpy(name
, "Roll", namesize
);
4181 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4182 strlcpy(name
, "Roll2", namesize
);
4184 pwg_ppdize_name(media_source
, name
, namesize
);
4191 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4195 const char * /* O - MediaType name */
4196 _pwgMediaTypeForType(
4197 const char *media_type
, /* I - PWG media-type */
4198 char *name
, /* I - Name buffer */
4199 size_t namesize
) /* I - Size of name buffer */
4202 * Range check input...
4205 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4208 if (_cups_strcasecmp(media_type
, "auto"))
4209 strlcpy(name
, "Auto", namesize
);
4210 else if (_cups_strcasecmp(media_type
, "cardstock"))
4211 strlcpy(name
, "Cardstock", namesize
);
4212 else if (_cups_strcasecmp(media_type
, "envelope"))
4213 strlcpy(name
, "Envelope", namesize
);
4214 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4215 strlcpy(name
, "Glossy", namesize
);
4216 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4217 strlcpy(name
, "HighGloss", namesize
);
4218 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4219 strlcpy(name
, "Matte", namesize
);
4220 else if (_cups_strcasecmp(media_type
, "stationery"))
4221 strlcpy(name
, "Plain", namesize
);
4222 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4223 strlcpy(name
, "Coated", namesize
);
4224 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4225 strlcpy(name
, "Inkjet", namesize
);
4226 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4227 strlcpy(name
, "Letterhead", namesize
);
4228 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4229 strlcpy(name
, "Preprinted", namesize
);
4230 else if (_cups_strcasecmp(media_type
, "transparency"))
4231 strlcpy(name
, "Transparency", namesize
);
4233 pwg_ppdize_name(media_type
, name
, namesize
);
4240 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4243 const char * /* O - PageSize name */
4244 _pwgPageSizeForMedia(
4245 pwg_media_t
*media
, /* I - Media */
4246 char *name
, /* I - PageSize name buffer */
4247 size_t namesize
) /* I - Size of name buffer */
4249 const char *sizeptr
, /* Pointer to size in PWG name */
4250 *dimptr
; /* Pointer to dimensions in PWG name */
4254 * Range check input...
4257 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4261 * Copy or generate a PageSize name...
4267 * Use a standard Adobe name...
4270 strlcpy(name
, media
->ppd
, namesize
);
4272 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4273 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4274 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4275 (size_t)(dimptr
- sizeptr
) > namesize
)
4278 * Use a name of the form "wNNNhNNN"...
4281 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4282 (int)PWG_TO_POINTS(media
->length
));
4287 * Copy the size name from class_sizename_dimensions...
4290 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4291 name
[dimptr
- sizeptr
- 1] = '\0';
4299 * 'pwg_add_finishing()' - Add a finishings value.
4304 cups_array_t
*finishings
, /* I - Finishings array */
4305 ipp_finishings_t
template, /* I - Finishing template */
4306 const char *name
, /* I - PPD option */
4307 const char *value
) /* I - PPD choice */
4309 _pwg_finishings_t
*f
; /* New finishings value */
4312 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4314 f
->value
= template;
4315 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4317 cupsArrayAdd(finishings
, f
);
4323 * 'pwg_compare_finishings()' - Compare two finishings values.
4326 static int /* O - Result of comparison */
4327 pwg_compare_finishings(
4328 _pwg_finishings_t
*a
, /* I - First finishings value */
4329 _pwg_finishings_t
*b
) /* I - Second finishings value */
4331 return ((int)b
->value
- (int)a
->value
);
4336 * 'pwg_free_finishings()' - Free a finishings value.
4340 pwg_free_finishings(
4341 _pwg_finishings_t
*f
) /* I - Finishings value */
4343 cupsFreeOptions(f
->num_options
, f
->options
);
4349 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4353 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4354 char *name
, /* I - Name buffer */
4355 size_t namesize
) /* I - Size of name buffer */
4357 char *ptr
, /* Pointer into name buffer */
4358 *end
; /* End of name buffer */
4367 *name
= (char)toupper(*ipp
++);
4369 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4371 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4374 *ptr
++ = (char)toupper(*ipp
++ & 255);
4385 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4389 pwg_ppdize_resolution(
4390 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4391 int element
, /* I - Element to convert */
4392 int *xres
, /* O - X resolution in DPI */
4393 int *yres
, /* O - Y resolution in DPI */
4394 char *name
, /* I - Name buffer */
4395 size_t namesize
) /* I - Size of name buffer */
4397 ipp_res_t units
; /* Units for resolution */
4400 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4402 if (units
== IPP_RES_PER_CM
)
4404 *xres
= (int)(*xres
* 2.54);
4405 *yres
= (int)(*yres
* 2.54);
4408 if (name
&& namesize
> 4)
4411 snprintf(name
, namesize
, "%ddpi", *xres
);
4413 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4419 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4423 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4424 char *name
, /* I - Name buffer */
4425 size_t namesize
, /* I - Size of name buffer */
4426 const char *dashchars
)/* I - Characters to be replaced by dashes */
4428 char *ptr
, /* Pointer into name buffer */
4429 *end
; /* End of name buffer */
4432 if (_cups_islower(*ppd
))
4435 * Already lowercase name, use as-is?
4438 const char *ppdptr
; /* Pointer into PPD keyword */
4440 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4441 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4446 strlcpy(name
, ppd
, namesize
);
4451 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4453 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4454 *ptr
++ = (char)tolower(*ppd
& 255);
4455 else if (strchr(dashchars
, *ppd
))
4460 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4461 _cups_isupper(ppd
[1]) && ptr
< end
)
4463 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))