2 * PPD cache implementation for CUPS.
4 * Copyright 2010-2017 by Apple Inc.
6 * These coded instructions, statements, and computer programs are the
7 * property of Apple Inc. and are protected by Federal copyright
8 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
9 * which should have been included with this file. If this file is
10 * missing or damaged, see the license at "http://www.cups.org/".
12 * This file is subject to the Apple OS-Developed Software exception.
16 * Include necessary headers...
19 #include "cups-private.h"
20 #include "ppd-private.h"
25 * Macro to test for two almost-equal PWG measurements.
28 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
35 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
36 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
37 _pwg_finishings_t
*b
);
38 static void pwg_free_finishings(_pwg_finishings_t
*f
);
39 static void pwg_free_material(_pwg_material_t
*m
);
40 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
41 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
42 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
43 const char *dashchars
);
47 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
49 * This functions converts PPD and CUPS-specific options to their standard IPP
50 * attributes and values and adds them to the specified IPP request.
53 int /* O - New number of copies */
54 _cupsConvertOptions(ipp_t
*request
, /* I - IPP request */
55 ppd_file_t
*ppd
, /* I - PPD file */
56 _ppd_cache_t
*pc
, /* I - PPD cache info */
57 ipp_attribute_t
*media_col_sup
,
58 /* I - media-col-supported values */
59 ipp_attribute_t
*doc_handling_sup
,
60 /* I - multiple-document-handling-supported values */
61 ipp_attribute_t
*print_color_mode_sup
,
62 /* I - Printer supports print-color-mode */
63 const char *user
, /* I - User info */
64 const char *format
, /* I - document-format value */
65 int copies
, /* I - Number of copies */
66 int num_options
, /* I - Number of options */
67 cups_option_t
*options
) /* I - Options */
69 int i
; /* Looping var */
70 const char *keyword
, /* PWG keyword */
71 *password
; /* Password string */
72 pwg_size_t
*size
; /* PWG media size */
73 ipp_t
*media_col
, /* media-col value */
74 *media_size
; /* media-size value */
75 const char *media_source
, /* media-source value */
76 *media_type
, /* media-type value */
77 *collate_str
, /* multiple-document-handling value */
78 *color_attr_name
, /* Supported color attribute */
79 *mandatory
; /* Mandatory attributes */
80 int num_finishings
= 0, /* Number of finishing values */
81 finishings
[10]; /* Finishing enum values */
82 ppd_choice_t
*choice
; /* Marked choice */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "job-account-id") &&
145 strcmp(mandatory
, "job-accounting-user-id") &&
146 strcmp(mandatory
, "job-password") &&
147 strcmp(mandatory
, "job-password-encryption") &&
148 strcmp(mandatory
, "media") &&
149 strncmp(mandatory
, "media-col", 9) &&
150 strcmp(mandatory
, "multiple-document-handling") &&
151 strcmp(mandatory
, "output-bin") &&
152 strcmp(mandatory
, "print-color-mode") &&
153 strcmp(mandatory
, "print-quality") &&
154 strcmp(mandatory
, "sides") &&
155 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
157 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
159 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
164 case IPP_TAG_INTEGER
:
166 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
168 case IPP_TAG_BOOLEAN
:
169 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
173 int lower
, upper
; /* Range */
175 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
176 lower
= upper
= atoi(keyword
);
178 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
181 case IPP_TAG_STRING
:
182 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
185 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
187 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
188 keyword
= "auto-monochrome";
189 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
190 keyword
= "process-monochrome";
193 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
199 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
200 keyword
= cupsGetOption("media", num_options
, options
);
202 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
203 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
204 size
= _ppdCacheGetSize(pc
, keyword
);
206 if (size
|| media_source
|| media_type
)
209 * Add a media-col value...
212 media_col
= ippNew();
216 media_size
= ippNew();
217 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
218 "x-dimension", size
->width
);
219 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
220 "y-dimension", size
->length
);
222 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
225 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
227 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
229 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
233 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
234 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
235 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
237 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
238 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
241 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
244 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
246 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
247 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
251 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
253 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
255 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
257 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
259 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
260 keyword
= "monochrome";
266 if (keyword
&& !strcmp(keyword
, "monochrome"))
268 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
269 keyword
= "auto-monochrome";
270 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
271 keyword
= "process-monochrome";
275 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
277 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
278 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
279 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
281 if (!_cups_strcasecmp(choice
->choice
, "draft"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
283 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
285 else if (!_cups_strcasecmp(choice
->choice
, "high"))
286 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
289 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
290 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
291 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
293 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
295 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
297 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
298 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
305 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
307 if (strstr(keyword
, "uncollated"))
312 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
317 if (!_cups_strcasecmp(format
, "image/gif") ||
318 !_cups_strcasecmp(format
, "image/jp2") ||
319 !_cups_strcasecmp(format
, "image/jpeg") ||
320 !_cups_strcasecmp(format
, "image/png") ||
321 !_cups_strcasecmp(format
, "image/tiff") ||
322 !_cups_strncasecmp(format
, "image/x-", 8))
325 * Collation makes no sense for single page image formats...
330 else if (!_cups_strncasecmp(format
, "image/", 6) ||
331 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
334 * Multi-page image formats will have copies applied by the upstream
342 if (doc_handling_sup
)
344 if (!_cups_strcasecmp(keyword
, "true"))
345 collate_str
= "separate-documents-collated-copies";
347 collate_str
= "separate-documents-uncollated-copies";
349 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
351 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
353 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
358 if (i
>= doc_handling_sup
->num_values
)
363 * Map finishing options...
366 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
367 if (num_finishings
> 0)
369 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
371 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
374 * Send job-pages-per-set attribute to apply finishings correctly...
377 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
386 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
389 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
393 _ppd_cache_t
* /* O - PPD cache and mapping data */
394 _ppdCacheCreateWithFile(
395 const char *filename
, /* I - File to read */
396 ipp_t
**attrs
) /* IO - IPP attributes, if any */
398 cups_file_t
*fp
; /* File */
399 _ppd_cache_t
*pc
; /* PWG mapping data */
400 pwg_size_t
*size
; /* Current size */
401 pwg_map_t
*map
; /* Current map */
402 _pwg_finishings_t
*finishings
; /* Current finishings option */
403 int linenum
, /* Current line number */
404 num_bins
, /* Number of bins in file */
405 num_sizes
, /* Number of sizes in file */
406 num_sources
, /* Number of sources in file */
407 num_types
; /* Number of types in file */
408 char line
[2048], /* Current line */
409 *value
, /* Pointer to value in line */
410 *valueptr
, /* Pointer into value */
411 pwg_keyword
[128], /* PWG keyword */
412 ppd_keyword
[PPD_MAX_NAME
];
414 _pwg_print_color_mode_t print_color_mode
;
415 /* Print color mode for preset */
416 _pwg_print_quality_t print_quality
; /* Print quality for preset */
419 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
422 * Range check input...
430 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
438 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
440 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
445 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
448 if (!cupsFileGets(fp
, line
, sizeof(line
)))
450 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
451 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
456 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
458 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
459 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
464 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
466 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
467 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
468 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
474 * Allocate the mapping data structure...
477 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
479 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
480 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
484 pc
->max_copies
= 9999;
496 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
498 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
499 "linenum=%d", line
, value
, linenum
));
503 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
505 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
508 else if (!_cups_strcasecmp(line
, "3D"))
510 pc
->cups_3d
= _cupsStrAlloc(value
);
512 else if (!_cups_strcasecmp(line
, "LayerOrder"))
514 pc
->cups_layer_order
= _cupsStrAlloc(value
);
516 else if (!_cups_strcasecmp(line
, "Accuracy"))
518 sscanf(value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
520 else if (!_cups_strcasecmp(line
, "Volume"))
522 sscanf(value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
524 else if (!_cups_strcasecmp(line
, "Material"))
527 * Material key "name" name=value ... name=value
530 if ((valueptr
= strchr(value
, ' ')) != NULL
)
532 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
536 material
->key
= _cupsStrAlloc(value
);
538 if (*valueptr
== '\"')
540 value
= valueptr
+ 1;
541 if ((valueptr
= strchr(value
, '\"')) != NULL
)
544 material
->name
= _cupsStrAlloc(value
);
545 material
->num_props
= cupsParseOptions(valueptr
, 0, &material
->props
);
550 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
552 cupsArrayAdd(pc
->materials
, material
);
555 else if (!_cups_strcasecmp(line
, "Filter"))
558 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
559 (cups_acopy_func_t
)_cupsStrAlloc
,
560 (cups_afree_func_t
)_cupsStrFree
);
562 cupsArrayAdd(pc
->filters
, value
);
564 else if (!_cups_strcasecmp(line
, "PreFilter"))
567 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
568 (cups_acopy_func_t
)_cupsStrAlloc
,
569 (cups_afree_func_t
)_cupsStrFree
);
571 cupsArrayAdd(pc
->prefilters
, value
);
573 else if (!_cups_strcasecmp(line
, "Product"))
575 pc
->product
= _cupsStrAlloc(value
);
577 else if (!_cups_strcasecmp(line
, "SingleFile"))
579 pc
->single_file
= !_cups_strcasecmp(value
, "true");
581 else if (!_cups_strcasecmp(line
, "IPP"))
583 off_t pos
= cupsFileTell(fp
), /* Position in file */
584 length
= strtol(value
, NULL
, 10);
585 /* Length of IPP attributes */
589 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
590 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
593 else if (length
<= 0)
595 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
596 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
603 * Read IPP attributes into the provided variable...
608 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
609 *attrs
) != IPP_STATE_DATA
)
611 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
612 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
619 * Skip the IPP data entirely...
622 cupsFileSeek(fp
, pos
+ length
);
625 if (cupsFileTell(fp
) != (pos
+ length
))
627 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
628 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
632 else if (!_cups_strcasecmp(line
, "NumBins"))
636 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
637 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
641 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
643 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
644 "%d.", num_sizes
, linenum
));
645 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
649 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
651 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
653 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
657 else if (!_cups_strcasecmp(line
, "Bin"))
659 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
661 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
662 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
666 if (pc
->num_bins
>= num_bins
)
668 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
670 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
674 map
= pc
->bins
+ pc
->num_bins
;
675 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
676 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
680 else if (!_cups_strcasecmp(line
, "NumSizes"))
684 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
685 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
689 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
691 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
692 "%d.", num_sizes
, linenum
));
693 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
699 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
701 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
703 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
708 else if (!_cups_strcasecmp(line
, "Size"))
710 if (pc
->num_sizes
>= num_sizes
)
712 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
714 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
718 size
= pc
->sizes
+ pc
->num_sizes
;
720 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
721 &(size
->width
), &(size
->length
), &(size
->left
),
722 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
724 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
726 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
730 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
731 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
735 else if (!_cups_strcasecmp(line
, "CustomSize"))
737 if (pc
->custom_max_width
> 0)
739 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
741 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
745 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
746 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
747 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
748 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
749 &(pc
->custom_size
.top
)) != 8)
751 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
753 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
757 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
758 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
759 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
761 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
762 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
763 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
765 else if (!_cups_strcasecmp(line
, "SourceOption"))
767 pc
->source_option
= _cupsStrAlloc(value
);
769 else if (!_cups_strcasecmp(line
, "NumSources"))
773 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
775 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
779 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
781 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
782 "line %d.", num_sources
, linenum
));
783 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
787 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
789 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
791 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
795 else if (!_cups_strcasecmp(line
, "Source"))
797 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
799 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
801 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
805 if (pc
->num_sources
>= num_sources
)
807 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
809 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
813 map
= pc
->sources
+ pc
->num_sources
;
814 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
815 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
819 else if (!_cups_strcasecmp(line
, "NumTypes"))
823 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
824 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
828 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
830 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
831 "line %d.", num_types
, linenum
));
832 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
836 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
838 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
840 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
844 else if (!_cups_strcasecmp(line
, "Type"))
846 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
848 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
850 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
854 if (pc
->num_types
>= num_types
)
856 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
858 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
862 map
= pc
->types
+ pc
->num_types
;
863 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
864 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
868 else if (!_cups_strcasecmp(line
, "Preset"))
871 * Preset output-mode print-quality name=value ...
874 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
875 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
877 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
878 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
879 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
880 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
881 valueptr
== value
|| !*valueptr
)
883 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
885 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
889 pc
->num_presets
[print_color_mode
][print_quality
] =
890 cupsParseOptions(valueptr
, 0,
891 pc
->presets
[print_color_mode
] + print_quality
);
893 else if (!_cups_strcasecmp(line
, "SidesOption"))
894 pc
->sides_option
= _cupsStrAlloc(value
);
895 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
896 pc
->sides_1sided
= _cupsStrAlloc(value
);
897 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
898 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
899 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
900 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
901 else if (!_cups_strcasecmp(line
, "Finishings"))
905 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
907 (cups_afree_func_t
)pwg_free_finishings
);
909 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
912 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
913 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
914 &(finishings
->options
));
916 cupsArrayAdd(pc
->finishings
, finishings
);
918 else if (!_cups_strcasecmp(line
, "MaxCopies"))
919 pc
->max_copies
= atoi(value
);
920 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
921 pc
->charge_info_uri
= _cupsStrAlloc(value
);
922 else if (!_cups_strcasecmp(line
, "JobAccountId"))
923 pc
->account_id
= !_cups_strcasecmp(value
, "true");
924 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
925 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
926 else if (!_cups_strcasecmp(line
, "JobPassword"))
927 pc
->password
= _cupsStrAlloc(value
);
928 else if (!_cups_strcasecmp(line
, "Mandatory"))
931 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
933 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
935 else if (!_cups_strcasecmp(line
, "SupportFile"))
937 if (!pc
->support_files
)
938 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
939 (cups_acopy_func_t
)_cupsStrAlloc
,
940 (cups_afree_func_t
)_cupsStrFree
);
942 cupsArrayAdd(pc
->support_files
, value
);
946 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
951 if (pc
->num_sizes
< num_sizes
)
953 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
954 pc
->num_sizes
, num_sizes
));
955 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
959 if (pc
->num_sources
< num_sources
)
961 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
962 pc
->num_sources
, num_sources
));
963 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
967 if (pc
->num_types
< num_types
)
969 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
970 pc
->num_types
, num_types
));
971 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
980 * If we get here the file was bad - free any data and return...
986 _ppdCacheDestroy(pc
);
999 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1002 _ppd_cache_t
* /* O - PPD cache and mapping data */
1003 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
1005 int i
, j
, k
; /* Looping vars */
1006 _ppd_cache_t
*pc
; /* PWG mapping data */
1007 ppd_option_t
*input_slot
, /* InputSlot option */
1008 *media_type
, /* MediaType option */
1009 *output_bin
, /* OutputBin option */
1010 *color_model
, /* ColorModel option */
1011 *duplex
; /* Duplex option */
1012 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1013 pwg_map_t
*map
; /* Current source/type map */
1014 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1015 int num_options
; /* Number of preset options and props */
1016 cups_option_t
*options
; /* Preset options and properties */
1017 ppd_size_t
*ppd_size
; /* Current PPD size */
1018 pwg_size_t
*pwg_size
; /* Current PWG size */
1019 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1020 /* PWG keyword string */
1021 ppd_name
[PPD_MAX_NAME
];
1022 /* Normalized PPD name */
1023 const char *pwg_name
; /* Standard PWG media name */
1024 pwg_media_t
*pwg_media
; /* PWG media data */
1025 _pwg_print_color_mode_t pwg_print_color_mode
;
1026 /* print-color-mode index */
1027 _pwg_print_quality_t pwg_print_quality
;
1028 /* print-quality index */
1029 int similar
; /* Are the old and new size similar? */
1030 pwg_size_t
*old_size
; /* Current old size */
1031 int old_imageable
, /* Old imageable length in 2540ths */
1032 old_borderless
, /* Old borderless state */
1033 old_known_pwg
; /* Old PWG name is well-known */
1034 int new_width
, /* New width in 2540ths */
1035 new_length
, /* New length in 2540ths */
1036 new_left
, /* New left margin in 2540ths */
1037 new_bottom
, /* New bottom margin in 2540ths */
1038 new_right
, /* New right margin in 2540ths */
1039 new_top
, /* New top margin in 2540ths */
1040 new_imageable
, /* New imageable length in 2540ths */
1041 new_borderless
, /* New borderless state */
1042 new_known_pwg
; /* New PWG name is well-known */
1043 pwg_size_t
*new_size
; /* New size to add, if any */
1044 const char *filter
; /* Current filter */
1045 _pwg_finishings_t
*finishings
; /* Current finishings value */
1048 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1051 * Range check input...
1058 * Allocate memory...
1061 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1063 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1068 * Copy and convert size data...
1071 if (ppd
->num_sizes
> 0)
1073 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1075 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1076 "pwg_size_t's.", ppd
->num_sizes
));
1080 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1085 * Don't copy over custom size...
1088 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1092 * Convert the PPD size name to the corresponding PWG keyword name.
1095 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1098 * Standard name, do we have conflicts?
1101 for (j
= 0; j
< pc
->num_sizes
; j
++)
1102 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1112 * Standard name and no conflicts, use it!
1115 pwg_name
= pwg_media
->pwg
;
1121 * Not a standard name; convert it to a PWG vendor name of the form:
1123 * pp_lowerppd_WIDTHxHEIGHTuu
1126 pwg_name
= pwg_keyword
;
1129 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1130 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1131 PWG_FROM_POINTS(ppd_size
->width
),
1132 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1136 * If we have a similar paper with non-zero margins then we only want to
1137 * keep it if it has a larger imageable area length. The NULL check is for
1138 * dimensions that are <= 0...
1141 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1142 PWG_FROM_POINTS(ppd_size
->length
),
1146 new_width
= pwg_media
->width
;
1147 new_length
= pwg_media
->length
;
1148 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1149 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1150 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1151 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1152 new_imageable
= new_length
- new_top
- new_bottom
;
1153 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1154 new_left
== 0 && new_right
== 0;
1156 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1160 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1161 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1162 old_size
->right
== 0 && old_size
->top
== 0;
1163 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1164 strncmp(old_size
->map
.pwg
, "om_", 3);
1166 similar
= old_borderless
== new_borderless
&&
1167 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1168 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1171 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1174 * The new paper has a larger imageable area so it could replace
1175 * the older paper. Regardless of the imageable area, we always
1176 * prefer the size with a well-known PWG name.
1179 new_size
= old_size
;
1180 _cupsStrFree(old_size
->map
.ppd
);
1181 _cupsStrFree(old_size
->map
.pwg
);
1188 * The paper was unique enough to deserve its own entry so add it to the
1192 new_size
= pwg_size
++;
1202 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1203 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1204 new_size
->width
= new_width
;
1205 new_size
->length
= new_length
;
1206 new_size
->left
= new_left
;
1207 new_size
->bottom
= new_bottom
;
1208 new_size
->right
= new_right
;
1209 new_size
->top
= new_top
;
1214 if (ppd
->variable_sizes
)
1217 * Generate custom size data...
1220 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1221 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1222 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1223 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1224 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1225 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1227 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1228 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1229 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1230 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1231 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1232 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1234 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1235 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1236 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1237 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1241 * Copy and convert InputSlot data...
1244 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1245 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1249 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1251 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1253 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1254 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1258 pc
->num_sources
= input_slot
->num_choices
;
1260 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1263 i
--, choice
++, map
++)
1265 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1266 !_cups_strcasecmp(choice
->choice
, "Default"))
1268 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1270 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1272 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1274 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1275 !_cups_strcasecmp(choice
->choice
, "MP") ||
1276 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1277 pwg_name
= "by-pass-tray";
1278 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1279 pwg_name
= "large-capacity";
1280 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1281 pwg_name
= "bottom";
1282 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1283 pwg_name
= "middle";
1284 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1286 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1288 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1289 pwg_name
= "main-roll";
1293 * Convert PPD name to lowercase...
1296 pwg_name
= pwg_keyword
;
1297 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1301 map
->pwg
= _cupsStrAlloc(pwg_name
);
1302 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1307 * Copy and convert MediaType data...
1310 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1312 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1314 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1315 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1319 pc
->num_types
= media_type
->num_choices
;
1321 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1324 i
--, choice
++, map
++)
1326 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1327 !_cups_strcasecmp(choice
->choice
, "Any") ||
1328 !_cups_strcasecmp(choice
->choice
, "Default"))
1330 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1331 pwg_name
= "cardstock";
1332 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1333 pwg_name
= "envelope";
1334 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1335 pwg_name
= "photographic-glossy";
1336 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1337 pwg_name
= "photographic-high-gloss";
1338 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1339 pwg_name
= "photographic-matte";
1340 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1341 pwg_name
= "stationery";
1342 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1343 pwg_name
= "stationery-coated";
1344 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1345 pwg_name
= "stationery-inkjet";
1346 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1347 pwg_name
= "stationery-letterhead";
1348 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1349 pwg_name
= "stationery-preprinted";
1350 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1351 pwg_name
= "stationery-recycled";
1352 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1353 pwg_name
= "transparency";
1357 * Convert PPD name to lowercase...
1360 pwg_name
= pwg_keyword
;
1361 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1365 map
->pwg
= _cupsStrAlloc(pwg_name
);
1366 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1371 * Copy and convert OutputBin data...
1374 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1376 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1378 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1379 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1383 pc
->num_bins
= output_bin
->num_choices
;
1385 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1388 i
--, choice
++, map
++)
1390 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1392 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1393 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1397 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1400 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1403 const char *quality
, /* com.apple.print.preset.quality value */
1404 *output_mode
, /* com.apple.print.preset.output-mode value */
1405 *color_model_val
, /* ColorModel choice */
1406 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1407 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1411 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1414 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1415 num_options
, options
)) != NULL
)
1418 * Get the print-quality for this preset...
1421 if (!strcmp(quality
, "low"))
1422 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1423 else if (!strcmp(quality
, "high"))
1424 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1426 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1429 * Ignore graphicsType "Photo" presets that are not high quality.
1432 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1433 num_options
, options
);
1435 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1436 !strcmp(graphicsType
, "Photo"))
1440 * Ignore presets for normal and draft quality where the coating
1441 * isn't "none" or "autodetect".
1444 media_front_coating
= cupsGetOption(
1445 "com.apple.print.preset.media-front-coating",
1446 num_options
, options
);
1448 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1449 media_front_coating
&&
1450 strcmp(media_front_coating
, "none") &&
1451 strcmp(media_front_coating
, "autodetect"))
1455 * Get the output mode for this preset...
1458 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1459 num_options
, options
);
1460 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1464 if (!strcmp(output_mode
, "monochrome"))
1465 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1467 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1469 else if (color_model_val
)
1471 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1472 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1474 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1477 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1480 * Save the options for this combination as needed...
1483 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1484 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1485 _ppdParseOptions(ppd_attr
->value
, 0,
1486 pc
->presets
[pwg_print_color_mode
] +
1487 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1490 cupsFreeOptions(num_options
, options
);
1492 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1495 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1496 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1497 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1500 * Try adding some common color options to create grayscale presets. These
1501 * are listed in order of popularity...
1504 const char *color_option
= NULL
, /* Color control option */
1505 *gray_choice
= NULL
; /* Choice to select grayscale */
1507 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1508 ppdFindChoice(color_model
, "Gray"))
1510 color_option
= "ColorModel";
1511 gray_choice
= "Gray";
1513 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1514 ppdFindChoice(color_model
, "grayscale"))
1516 color_option
= "HPColorMode";
1517 gray_choice
= "grayscale";
1519 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1520 ppdFindChoice(color_model
, "Mono"))
1522 color_option
= "BRMonoColor";
1523 gray_choice
= "Mono";
1525 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1526 ppdFindChoice(color_model
, "1"))
1528 color_option
= "CNIJSGrayScale";
1531 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1532 ppdFindChoice(color_model
, "True"))
1534 color_option
= "HPColorAsGray";
1535 gray_choice
= "True";
1538 if (color_option
&& gray_choice
)
1541 * Copy and convert ColorModel (output-mode) data...
1544 cups_option_t
*coption
, /* Color option */
1545 *moption
; /* Monochrome option */
1547 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1548 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1549 pwg_print_quality
++)
1551 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1554 * Copy the color options...
1557 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1558 [pwg_print_quality
];
1559 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1563 for (i
= num_options
, moption
= options
,
1564 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1565 [pwg_print_quality
];
1567 i
--, moption
++, coption
++)
1569 moption
->name
= _cupsStrRetain(coption
->name
);
1570 moption
->value
= _cupsStrRetain(coption
->value
);
1573 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1575 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1579 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1583 * Add the grayscale option to the preset...
1586 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1587 cupsAddOption(color_option
, gray_choice
,
1588 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1589 [pwg_print_quality
],
1590 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1597 * Copy and convert Duplex (sides) data...
1600 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1601 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1602 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1603 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1604 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1608 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1610 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1614 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1615 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1616 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1617 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1618 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1619 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1620 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1621 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1622 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1623 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1624 !pc
->sides_2sided_short
)
1625 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1630 * Copy filters and pre-filters...
1633 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1634 (cups_acopy_func_t
)_cupsStrAlloc
,
1635 (cups_afree_func_t
)_cupsStrFree
);
1637 cupsArrayAdd(pc
->filters
,
1638 "application/vnd.cups-raw application/octet-stream 0 -");
1640 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1644 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1646 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1648 else if (ppd
->num_filters
> 0)
1650 for (i
= 0; i
< ppd
->num_filters
; i
++)
1651 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1654 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1657 * See if we have a command filter...
1660 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1662 filter
= (const char *)cupsArrayNext(pc
->filters
))
1663 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1664 _cups_isspace(filter
[28]))
1668 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1669 _cups_strcasecmp(ppd_attr
->value
, "none")))
1672 * No command filter and no cupsCommands keyword telling us not to use one.
1673 * See if this is a PostScript printer, and if so add a PostScript command
1677 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1679 filter
= (const char *)cupsArrayNext(pc
->filters
))
1680 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1681 _cups_isspace(filter
[31]))
1685 cupsArrayAdd(pc
->filters
,
1686 "application/vnd.cups-command application/postscript 100 "
1690 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1692 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1693 (cups_acopy_func_t
)_cupsStrAlloc
,
1694 (cups_afree_func_t
)_cupsStrFree
);
1698 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1700 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1703 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1704 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1707 * Copy the product string, if any...
1711 pc
->product
= _cupsStrAlloc(ppd
->product
);
1714 * Copy finishings mapping data...
1717 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1720 * Have proper vendor mapping of IPP finishings values to PPD options...
1723 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1724 NULL
, NULL
, 0, NULL
,
1725 (cups_afree_func_t
)pwg_free_finishings
);
1729 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1732 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1733 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1734 &(finishings
->options
),
1735 _PPD_PARSE_OPTIONS
);
1737 cupsArrayAdd(pc
->finishings
, finishings
);
1739 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1745 * No IPP mapping data, try to map common/standard PPD keywords...
1748 ppd_option_t
*ppd_option
; /* PPD option */
1750 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1752 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1755 * Add staple finishings...
1758 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1759 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1760 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1761 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1762 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1763 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1764 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1765 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1766 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1767 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1770 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1773 * Add (Ricoh) punch finishings...
1776 if (ppdFindChoice(ppd_option
, "Left2"))
1777 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1778 if (ppdFindChoice(ppd_option
, "Left3"))
1779 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1780 if (ppdFindChoice(ppd_option
, "Left4"))
1781 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1782 if (ppdFindChoice(ppd_option
, "Right2"))
1783 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1784 if (ppdFindChoice(ppd_option
, "Right3"))
1785 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1786 if (ppdFindChoice(ppd_option
, "Right4"))
1787 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1788 if (ppdFindChoice(ppd_option
, "Upper2"))
1789 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1790 if (ppdFindChoice(ppd_option
, "Upper3"))
1791 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1792 if (ppdFindChoice(ppd_option
, "Upper4"))
1793 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1796 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1799 * Add bind finishings...
1802 if (ppdFindChoice(ppd_option
, "Left"))
1803 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1804 if (ppdFindChoice(ppd_option
, "Right"))
1805 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1806 if (ppdFindChoice(ppd_option
, "Top"))
1807 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1808 if (ppdFindChoice(ppd_option
, "Bottom"))
1809 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1812 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1815 * Add (Adobe) fold finishings...
1818 if (ppdFindChoice(ppd_option
, "ZFold"))
1819 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1820 if (ppdFindChoice(ppd_option
, "Saddle"))
1821 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1822 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1823 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1824 if (ppdFindChoice(ppd_option
, "LeftGate"))
1825 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1826 if (ppdFindChoice(ppd_option
, "RightGate"))
1827 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1828 if (ppdFindChoice(ppd_option
, "Letter"))
1829 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1830 if (ppdFindChoice(ppd_option
, "XFold"))
1831 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1834 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1837 * Add (Ricoh) fold finishings...
1840 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1841 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1844 if (cupsArrayCount(pc
->finishings
) == 0)
1846 cupsArrayDelete(pc
->finishings
);
1847 pc
->finishings
= NULL
;
1855 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1856 pc
->max_copies
= atoi(ppd_attr
->value
);
1857 else if (ppd
->manual_copies
)
1860 pc
->max_copies
= 9999;
1863 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1864 * cupsJobPassword, and cupsMandatory.
1867 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1868 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1870 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1871 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1873 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1874 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1876 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1877 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1879 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1880 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1886 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1887 (cups_acopy_func_t
)_cupsStrAlloc
,
1888 (cups_afree_func_t
)_cupsStrFree
);
1890 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1892 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1893 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1895 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1896 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1902 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1903 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1905 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1906 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1908 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1909 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1911 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1912 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1914 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1916 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1919 * *cupsMaterial key/name: "name=value ... name=value"
1922 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1924 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1925 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1926 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1929 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1931 cupsArrayAdd(pc
->materials
, material
);
1935 * Return the cache data...
1941 * If we get here we need to destroy the PWG mapping data and return NULL...
1946 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1947 _ppdCacheDestroy(pc
);
1954 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1958 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1960 int i
; /* Looping var */
1961 pwg_map_t
*map
; /* Current map */
1962 pwg_size_t
*size
; /* Current size */
1966 * Range check input...
1973 * Free memory as needed...
1978 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1980 _cupsStrFree(map
->pwg
);
1981 _cupsStrFree(map
->ppd
);
1989 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1991 _cupsStrFree(size
->map
.pwg
);
1992 _cupsStrFree(size
->map
.ppd
);
1998 if (pc
->source_option
)
1999 _cupsStrFree(pc
->source_option
);
2003 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2005 _cupsStrFree(map
->pwg
);
2006 _cupsStrFree(map
->ppd
);
2014 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2016 _cupsStrFree(map
->pwg
);
2017 _cupsStrFree(map
->ppd
);
2023 if (pc
->custom_max_keyword
)
2024 _cupsStrFree(pc
->custom_max_keyword
);
2026 if (pc
->custom_min_keyword
)
2027 _cupsStrFree(pc
->custom_min_keyword
);
2029 _cupsStrFree(pc
->product
);
2030 cupsArrayDelete(pc
->filters
);
2031 cupsArrayDelete(pc
->prefilters
);
2032 cupsArrayDelete(pc
->finishings
);
2034 _cupsStrFree(pc
->charge_info_uri
);
2035 _cupsStrFree(pc
->password
);
2037 cupsArrayDelete(pc
->mandatory
);
2039 cupsArrayDelete(pc
->support_files
);
2041 _cupsStrFree(pc
->cups_3d
);
2042 _cupsStrFree(pc
->cups_layer_order
);
2044 cupsArrayDelete(pc
->materials
);
2051 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2055 const char * /* O - output-bin or NULL */
2057 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2058 const char *output_bin
) /* I - PPD OutputBin string */
2060 int i
; /* Looping var */
2064 * Range check input...
2067 if (!pc
|| !output_bin
)
2071 * Look up the OutputBin string...
2075 for (i
= 0; i
< pc
->num_bins
; i
++)
2076 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2077 return (pc
->bins
[i
].pwg
);
2084 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2085 * IPP finishings value(s).
2088 int /* O - New number of options */
2089 _ppdCacheGetFinishingOptions(
2090 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2091 ipp_t
*job
, /* I - Job attributes or NULL */
2092 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2093 int num_options
, /* I - Number of options */
2094 cups_option_t
**options
) /* IO - Options */
2096 int i
; /* Looping var */
2097 _pwg_finishings_t
*f
, /* PWG finishings options */
2098 key
; /* Search key */
2099 ipp_attribute_t
*attr
; /* Finishings attribute */
2100 cups_option_t
*option
; /* Current finishings option */
2104 * Range check input...
2107 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2108 (!job
&& value
== IPP_FINISHINGS_NONE
))
2109 return (num_options
);
2112 * Apply finishing options...
2115 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2117 int num_values
= ippGetCount(attr
); /* Number of values */
2119 for (i
= 0; i
< num_values
; i
++)
2121 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2123 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2125 int j
; /* Another looping var */
2127 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2128 num_options
= cupsAddOption(option
->name
, option
->value
,
2129 num_options
, options
);
2133 else if (value
!= IPP_FINISHINGS_NONE
)
2137 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2139 int j
; /* Another looping var */
2141 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2142 num_options
= cupsAddOption(option
->name
, option
->value
,
2143 num_options
, options
);
2147 return (num_options
);
2152 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2156 int /* O - Number of finishings values */
2157 _ppdCacheGetFinishingValues(
2158 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2159 int num_options
, /* I - Number of options */
2160 cups_option_t
*options
, /* I - Options */
2161 int max_values
, /* I - Maximum number of finishings values */
2162 int *values
) /* O - Finishings values */
2164 int i
, /* Looping var */
2165 num_values
= 0; /* Number of values */
2166 _pwg_finishings_t
*f
; /* Current finishings option */
2167 cups_option_t
*option
; /* Current option */
2168 const char *val
; /* Value for option */
2172 * Range check input...
2175 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2177 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2179 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2184 * Go through the finishings options and see what is set...
2187 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2189 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2191 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2193 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2195 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2197 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2198 _cups_strcasecmp(option
->value
, val
))
2200 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2207 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2209 values
[num_values
++] = f
->value
;
2211 if (num_values
>= max_values
)
2216 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2218 return (num_values
);
2223 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2224 * attributes or a keyword string.
2227 const char * /* O - PPD InputSlot or NULL */
2228 _ppdCacheGetInputSlot(
2229 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2230 ipp_t
*job
, /* I - Job attributes or NULL */
2231 const char *keyword
) /* I - Keyword string or NULL */
2234 * Range check input...
2237 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2240 if (job
&& !keyword
)
2243 * Lookup the media-col attribute and any media-source found there...
2246 ipp_attribute_t
*media_col
, /* media-col attribute */
2247 *media_source
; /* media-source attribute */
2248 pwg_size_t size
; /* Dimensional size */
2249 int margins_set
; /* Were the margins set? */
2251 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2253 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2255 IPP_TAG_KEYWORD
)) != NULL
)
2258 * Use the media-source value from media-col...
2261 keyword
= ippGetString(media_source
, 0, NULL
);
2263 else if (pwgInitSize(&size
, job
, &margins_set
))
2266 * For media <= 5x7, look for a photo tray...
2269 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2276 int i
; /* Looping var */
2278 for (i
= 0; i
< pc
->num_sources
; i
++)
2279 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2280 return (pc
->sources
[i
].ppd
);
2288 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2289 * attributes or a keyword string.
2292 const char * /* O - PPD MediaType or NULL */
2293 _ppdCacheGetMediaType(
2294 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2295 ipp_t
*job
, /* I - Job attributes or NULL */
2296 const char *keyword
) /* I - Keyword string or NULL */
2299 * Range check input...
2302 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2305 if (job
&& !keyword
)
2308 * Lookup the media-col attribute and any media-source found there...
2311 ipp_attribute_t
*media_col
, /* media-col attribute */
2312 *media_type
; /* media-type attribute */
2314 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2317 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2319 IPP_TAG_KEYWORD
)) == NULL
)
2320 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2321 "media-type", IPP_TAG_NAME
);
2324 keyword
= media_type
->values
[0].string
.text
;
2330 int i
; /* Looping var */
2332 for (i
= 0; i
< pc
->num_types
; i
++)
2333 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2334 return (pc
->types
[i
].ppd
);
2342 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2346 const char * /* O - PPD OutputBin or NULL */
2347 _ppdCacheGetOutputBin(
2348 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2349 const char *output_bin
) /* I - Keyword string */
2351 int i
; /* Looping var */
2355 * Range check input...
2358 if (!pc
|| !output_bin
)
2362 * Look up the OutputBin string...
2366 for (i
= 0; i
< pc
->num_bins
; i
++)
2367 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2368 return (pc
->bins
[i
].ppd
);
2375 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2376 * attributes or a keyword string.
2379 const char * /* O - PPD PageSize or NULL */
2380 _ppdCacheGetPageSize(
2381 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2382 ipp_t
*job
, /* I - Job attributes or NULL */
2383 const char *keyword
, /* I - Keyword string or NULL */
2384 int *exact
) /* O - 1 if exact match, 0 otherwise */
2386 int i
; /* Looping var */
2387 pwg_size_t
*size
, /* Current size */
2388 *closest
, /* Closest size */
2389 jobsize
; /* Size data from job */
2390 int margins_set
, /* Were the margins set? */
2391 dwidth
, /* Difference in width */
2392 dlength
, /* Difference in length */
2393 dleft
, /* Difference in left margins */
2394 dright
, /* Difference in right margins */
2395 dbottom
, /* Difference in bottom margins */
2396 dtop
, /* Difference in top margins */
2397 dmin
, /* Minimum difference */
2398 dclosest
; /* Closest difference */
2399 const char *ppd_name
; /* PPD media name */
2402 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2403 pc
, job
, keyword
, exact
));
2406 * Range check input...
2409 if (!pc
|| (!job
&& !keyword
))
2420 * Try getting the PPD media name from the job attributes...
2423 ipp_attribute_t
*attr
; /* Job attribute */
2425 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2426 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2427 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2431 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2432 attr
->name
, ippTagString(attr
->value_tag
)));
2434 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2437 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2438 attr
->value_tag
== IPP_TAG_KEYWORD
))
2439 ppd_name
= attr
->values
[0].string
.text
;
2442 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2447 * Try looking up the named PPD size first...
2450 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2452 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2453 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2455 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2456 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2461 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2463 return (size
->map
.ppd
);
2468 if (job
&& !keyword
)
2471 * Get the size using media-col or media, with the preference being
2475 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2481 * Get the size using a media keyword...
2484 pwg_media_t
*media
; /* Media definition */
2487 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2488 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2489 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2492 jobsize
.width
= media
->width
;
2493 jobsize
.length
= media
->length
;
2498 * Now that we have the dimensions and possibly the margins, look at the
2499 * available sizes and find the match...
2503 dclosest
= 999999999;
2505 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2506 _cups_strncasecmp(ppd_name
, "custom_", 7))
2508 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2511 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2512 * is just about 176/2540ths...
2515 dwidth
= size
->width
- jobsize
.width
;
2516 dlength
= size
->length
- jobsize
.length
;
2518 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2524 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2527 dleft
= size
->left
- jobsize
.left
;
2528 dright
= size
->right
- jobsize
.right
;
2529 dtop
= size
->top
- jobsize
.top
;
2530 dbottom
= size
->bottom
- jobsize
.bottom
;
2532 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2533 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2535 dleft
= dleft
< 0 ? -dleft
: dleft
;
2536 dright
= dright
< 0 ? -dright
: dright
;
2537 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2538 dtop
= dtop
< 0 ? -dtop
: dtop
;
2539 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2541 if (dmin
< dclosest
)
2554 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2556 return (size
->map
.ppd
);
2562 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2565 return (closest
->map
.ppd
);
2569 * If we get here we need to check for custom page size support...
2572 if (jobsize
.width
>= pc
->custom_min_width
&&
2573 jobsize
.width
<= pc
->custom_max_width
&&
2574 jobsize
.length
>= pc
->custom_min_length
&&
2575 jobsize
.length
<= pc
->custom_max_length
)
2578 * In range, format as Custom.WWWWxLLLL (points).
2581 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2582 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2584 if (margins_set
&& exact
)
2586 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2587 dright
= pc
->custom_size
.right
- jobsize
.right
;
2588 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2589 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2591 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2592 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2598 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2599 pc
->custom_ppd_size
));
2601 return (pc
->custom_ppd_size
);
2605 * No custom page size support or the size is out of range - return NULL.
2608 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2615 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2618 pwg_size_t
* /* O - PWG size or NULL */
2620 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2621 const char *page_size
) /* I - PPD PageSize */
2623 int i
; /* Looping var */
2624 pwg_media_t
*media
; /* Media */
2625 pwg_size_t
*size
; /* Current size */
2629 * Range check input...
2632 if (!pc
|| !page_size
)
2635 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2638 * Custom size; size name can be one of the following:
2640 * Custom.WIDTHxLENGTHin - Size in inches
2641 * Custom.WIDTHxLENGTHft - Size in feet
2642 * Custom.WIDTHxLENGTHcm - Size in centimeters
2643 * Custom.WIDTHxLENGTHmm - Size in millimeters
2644 * Custom.WIDTHxLENGTHm - Size in meters
2645 * Custom.WIDTHxLENGTH[pt] - Size in points
2648 double w
, l
; /* Width and length of page */
2649 char *ptr
; /* Pointer into PageSize */
2650 struct lconv
*loc
; /* Locale data */
2653 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2654 if (!ptr
|| *ptr
!= 'x')
2657 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2661 if (!_cups_strcasecmp(ptr
, "in"))
2666 else if (!_cups_strcasecmp(ptr
, "ft"))
2671 else if (!_cups_strcasecmp(ptr
, "mm"))
2676 else if (!_cups_strcasecmp(ptr
, "cm"))
2681 else if (!_cups_strcasecmp(ptr
, "m"))
2692 pc
->custom_size
.width
= (int)w
;
2693 pc
->custom_size
.length
= (int)l
;
2695 return (&(pc
->custom_size
));
2699 * Not a custom size - look it up...
2702 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2703 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2704 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2708 * Look up standard sizes...
2711 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2712 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2713 media
= pwgMediaForPWG(page_size
);
2717 pc
->custom_size
.width
= media
->width
;
2718 pc
->custom_size
.length
= media
->length
;
2720 return (&(pc
->custom_size
));
2728 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2732 const char * /* O - PWG media-source keyword */
2734 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2735 const char *input_slot
) /* I - PPD InputSlot */
2737 int i
; /* Looping var */
2738 pwg_map_t
*source
; /* Current source */
2742 * Range check input...
2745 if (!pc
|| !input_slot
)
2748 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2749 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2750 return (source
->pwg
);
2757 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2761 const char * /* O - PWG media-type keyword */
2763 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2764 const char *media_type
) /* I - PPD MediaType */
2766 int i
; /* Looping var */
2767 pwg_map_t
*type
; /* Current type */
2771 * Range check input...
2774 if (!pc
|| !media_type
)
2777 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2778 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2786 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2789 int /* O - 1 on success, 0 on failure */
2791 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2792 const char *filename
, /* I - File to write */
2793 ipp_t
*attrs
) /* I - Attributes to write, if any */
2795 int i
, j
, k
; /* Looping vars */
2796 cups_file_t
*fp
; /* Output file */
2797 pwg_size_t
*size
; /* Current size */
2798 pwg_map_t
*map
; /* Current map */
2799 _pwg_finishings_t
*f
; /* Current finishing option */
2800 cups_option_t
*option
; /* Current option */
2801 const char *value
; /* Filter/pre-filter value */
2802 char newfile
[1024]; /* New filename */
2803 _pwg_material_t
*m
; /* Material */
2807 * Range check input...
2810 if (!pc
|| !filename
)
2812 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2817 * Open the file and write with compression...
2820 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2821 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2823 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2828 * Standard header...
2831 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2837 if (pc
->num_bins
> 0)
2839 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2840 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2841 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2848 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2849 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2850 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2851 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2852 size
->bottom
, size
->right
, size
->top
);
2853 if (pc
->custom_max_width
> 0)
2854 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2855 pc
->custom_max_width
, pc
->custom_max_length
,
2856 pc
->custom_min_width
, pc
->custom_min_length
,
2857 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2858 pc
->custom_size
.right
, pc
->custom_size
.top
);
2864 if (pc
->source_option
)
2865 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2867 if (pc
->num_sources
> 0)
2869 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2870 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2871 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2878 if (pc
->num_types
> 0)
2880 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2881 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2882 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2889 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2890 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2891 if (pc
->num_presets
[i
][j
])
2893 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2894 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2897 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2898 cupsFilePutChar(fp
, '\n');
2905 if (pc
->sides_option
)
2906 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2908 if (pc
->sides_1sided
)
2909 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2911 if (pc
->sides_2sided_long
)
2912 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2914 if (pc
->sides_2sided_short
)
2915 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2918 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2922 cupsFilePutConf(fp
, "Product", pc
->product
);
2924 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2926 value
= (const char *)cupsArrayNext(pc
->filters
))
2927 cupsFilePutConf(fp
, "Filter", value
);
2929 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2931 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2932 cupsFilePutConf(fp
, "PreFilter", value
);
2934 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2937 * Finishing options...
2940 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2942 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2944 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2945 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2946 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2947 cupsFilePutChar(fp
, '\n');
2954 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2957 * Accounting/quota/PIN/managed printing values...
2960 if (pc
->charge_info_uri
)
2961 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2963 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2964 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2965 pc
->accounting_user_id
? "true" : "false");
2968 cupsFilePutConf(fp
, "Password", pc
->password
);
2970 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2972 value
= (char *)cupsArrayNext(pc
->mandatory
))
2973 cupsFilePutConf(fp
, "Mandatory", value
);
2979 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2981 value
= (char *)cupsArrayNext(pc
->support_files
))
2982 cupsFilePutConf(fp
, "SupportFile", value
);
2989 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2991 if (pc
->cups_layer_order
)
2992 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2994 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2995 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2997 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2998 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
3000 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
3002 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
3004 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
3005 for (i
= 0; i
< m
->num_props
; i
++)
3006 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
3007 cupsFilePuts(fp
, "\n");
3011 * IPP attributes, if any...
3016 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3018 attrs
->state
= IPP_STATE_IDLE
;
3019 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3023 * Close and return...
3026 if (cupsFileClose(fp
))
3033 return (!rename(newfile
, filename
));
3038 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3039 * of an IPP printer.
3042 char * /* O - PPD filename or @code NULL@ on error */
3043 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3044 size_t bufsize
, /* I - Size of filename buffer */
3045 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3047 cups_file_t
*fp
; /* PPD file */
3048 cups_array_t
*sizes
; /* Media sizes we've added */
3049 ipp_attribute_t
*attr
, /* xxx-supported */
3050 *defattr
, /* xxx-default */
3051 *quality
, /* print-quality-supported */
3052 *x_dim
, *y_dim
; /* Media dimensions */
3053 ipp_t
*media_size
; /* Media size collection */
3054 char make
[256], /* Make and model */
3055 *model
, /* Model name */
3056 ppdname
[PPD_MAX_NAME
];
3058 int i
, j
, /* Looping vars */
3059 count
, /* Number of values */
3060 bottom
, /* Largest bottom margin */
3061 left
, /* Largest left margin */
3062 right
, /* Largest right margin */
3063 top
, /* Largest top margin */
3064 is_apple
= 0, /* Does the printer support Apple raster? */
3065 is_pdf
= 0, /* Does the printer support PDF? */
3066 is_pwg
= 0; /* Does the printer support PWG Raster? */
3067 pwg_media_t
*pwg
; /* PWG media size */
3068 int xres
, yres
; /* Resolution values */
3069 cups_lang_t
*lang
= cupsLangDefault();
3070 /* Localization info */
3071 struct lconv
*loc
= localeconv();
3073 static const char * const finishings
[][2] =
3074 { /* Finishings strings */
3075 { "bale", _("Bale") },
3076 { "bind", _("Bind") },
3077 { "bind-bottom", _("Bind (Reverse Landscape)") },
3078 { "bind-left", _("Bind (Portrait)") },
3079 { "bind-right", _("Bind (Reverse Portrait)") },
3080 { "bind-top", _("Bind (Landscape)") },
3081 { "booklet-maker", _("Booklet Maker") },
3082 { "coat", _("Coat") },
3083 { "cover", _("Cover") },
3084 { "edge-stitch", _("Staple Edge") },
3085 { "edge-stitch-bottom", _("Staple Edge (Reverse Landscape)") },
3086 { "edge-stitch-left", _("Staple Edge (Portrait)") },
3087 { "edge-stitch-right", _("Staple Edge (Reverse Portrait)") },
3088 { "edge-stitch-top", _("Staple Edge (Landscape)") },
3089 { "fold", _("Fold") },
3090 { "fold-accordian", _("Accordian Fold") },
3091 { "fold-double-gate", _("Double Gate Fold") },
3092 { "fold-engineering-z", _("Engineering Z Fold") },
3093 { "fold-gate", _("Gate Fold") },
3094 { "fold-half", _("Half Fold") },
3095 { "fold-half-z", _("Half Z Fold") },
3096 { "fold-left-gate", _("Left Gate Fold") },
3097 { "fold-letter", _("Letter Fold") },
3098 { "fold-parallel", _("Parallel Fold") },
3099 { "fold-poster", _("Poster Fold") },
3100 { "fold-right-gate", _("Right Gate Fold") },
3101 { "fold-z", _("Z Fold") },
3102 { "jog-offset", _("Jog") },
3103 { "laminate", _("Laminate") },
3104 { "punch", _("Punch") },
3105 { "punch-bottom-left", _("Single Punch (Reverse Landscape)") },
3106 { "punch-bottom-right", _("Single Punch (Reverse Portrait)") },
3107 { "punch-double-bottom", _("2-Hole Punch (Reverse Portrait)") },
3108 { "punch-double-left", _("2-Hole Punch (Reverse Landscape)") },
3109 { "punch-double-right", _("2-Hole Punch (Landscape)") },
3110 { "punch-double-top", _("2-Hole Punch (Portrait)") },
3111 { "punch-quad-bottom", _("4-Hole Punch (Reverse Landscape)") },
3112 { "punch-quad-left", _("4-Hole Punch (Portrait)") },
3113 { "punch-quad-right", _("4-Hole Punch (Reverse Portrait)") },
3114 { "punch-quad-top", _("4-Hole Punch (Landscape)") },
3115 { "punch-top-left", _("Single Punch (Portrait)") },
3116 { "punch-top-right", _("Single Punch (Landscape)") },
3117 { "punch-triple-bottom", _("3-Hole Punch (Reverse Landscape)") },
3118 { "punch-triple-left", _("3-Hole Punch (Portrait)") },
3119 { "punch-triple-right", _("3-Hole Punch (Reverse Portrait)") },
3120 { "punch-triple-top", _("3-Hole Punch (Landscape)") },
3121 { "punch-multiple-bottom", _("Multi-Hole Punch (Reverse Landscape)") },
3122 { "punch-multiple-left", _("Multi-Hole Punch (Portrait)") },
3123 { "punch-multiple-right", _("Multi-Hole Punch (Reverse Portrait)") },
3124 { "punch-multiple-top", _("Multi-Hole Punch (Landscape)") },
3125 { "saddle-stitch", _("Saddle Stitch") },
3126 { "staple", _("Staple") },
3127 { "staple-bottom-left", _("Single Staple (Reverse Landscape)") },
3128 { "staple-bottom-right", _("Single Staple (Reverse Portrait)") },
3129 { "staple-dual-bottom", _("Double Staple (Reverse Landscape)") },
3130 { "staple-dual-left", _("Double Staple (Portrait)") },
3131 { "staple-dual-right", _("Double Staple (Reverse Portrait)") },
3132 { "staple-dual-top", _("Double Staple (Landscape)") },
3133 { "staple-top-left", _("Single Staple (Portrait)") },
3134 { "staple-top-right", _("Single Staple (Landscape)") },
3135 { "staple-triple-bottom", _("Triple Staple (Reverse Landscape)") },
3136 { "staple-triple-left", _("Triple Staple (Portrait)") },
3137 { "staple-triple-right", _("Triple Staple (Reverse Portrait)") },
3138 { "staple-triple-top", _("Triple Staple (Landscape)") },
3139 { "trim", _("Cut Media") }
3144 * Range check input...
3150 if (!buffer
|| bufsize
< 1)
3152 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3158 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3163 * Open a temporary file for the PPD...
3166 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3168 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3173 * Standard stuff for PPD file...
3176 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3177 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3178 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3179 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3180 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3181 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3182 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3183 cupsFilePuts(fp
, "*FileSystem: False\n");
3184 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3186 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3187 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3189 strlcpy(make
, "Unknown Printer", sizeof(make
));
3191 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3192 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3195 strlcpy(make
, "HP", sizeof(make
));
3197 else if ((model
= strchr(make
, ' ')) != NULL
)
3202 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3203 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3204 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3205 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3206 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3208 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3209 cupsFilePuts(fp
, "*ColorDevice: True\n");
3211 cupsFilePuts(fp
, "*ColorDevice: False\n");
3213 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3214 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3215 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3221 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3223 is_apple
= ippContainsString(attr
, "image/urf");
3224 is_pdf
= ippContainsString(attr
, "application/pdf");
3225 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3227 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3229 const char *format
= ippGetString(attr
, i
, NULL
);
3233 * Write cupsFilter2 lines for supported formats...
3236 if (!_cups_strcasecmp(format
, "application/pdf"))
3237 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3238 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3239 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3240 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3241 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3245 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3249 * PageSize/PageRegion/ImageableArea/PaperDimension
3252 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3254 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3255 if (ippGetInteger(attr
, i
) > bottom
)
3256 bottom
= ippGetInteger(attr
, i
);
3261 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3263 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3264 if (ippGetInteger(attr
, i
) > left
)
3265 left
= ippGetInteger(attr
, i
);
3270 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3272 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3273 if (ippGetInteger(attr
, i
) > right
)
3274 right
= ippGetInteger(attr
, i
);
3279 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3281 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3282 if (ippGetInteger(attr
, i
) > top
)
3283 top
= ippGetInteger(attr
, i
);
3288 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3290 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3292 media_size
= ippGetCollection(attr
, 0);
3293 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3294 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3296 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3297 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3299 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3302 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3304 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3305 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3307 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3309 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
3310 attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
);
3313 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3314 "*OrderDependency: 10 AnySetup *PageSize\n"
3315 "*DefaultPageSize: %s\n", ppdname
);
3317 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3319 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3321 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3323 media_size
= ippGetCollection(attr
, i
);
3324 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3325 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3327 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3330 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3334 char twidth
[256], /* Width string */
3335 tlength
[256]; /* Length string */
3337 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3339 cupsFilePrintf(fp
, "*%% warning: Duplicate size '%s' reported by printer.\n", pwg
->ppd
);
3343 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3345 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3346 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3348 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3351 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3353 cupsArrayDelete(sizes
);
3354 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3356 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3357 "*OrderDependency: 10 AnySetup *PageRegion\n"
3358 "*DefaultPageRegion: %s\n", ppdname
);
3359 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3361 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3363 media_size
= ippGetCollection(attr
, i
);
3364 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3365 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3367 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3370 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3374 char twidth
[256], /* Width string */
3375 tlength
[256]; /* Length string */
3377 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3380 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3382 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3383 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3385 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3388 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3390 cupsArrayDelete(sizes
);
3391 sizes
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3393 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3394 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3395 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3397 if (ippGetValueTag(attr
) == IPP_TAG_BEGIN_COLLECTION
)
3399 media_size
= ippGetCollection(attr
, i
);
3400 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3401 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3403 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3406 pwg
= pwgMediaForPWG(ippGetString(attr
, i
, NULL
));
3410 char tleft
[256], /* Left string */
3411 tbottom
[256], /* Bottom string */
3412 tright
[256], /* Right string */
3413 ttop
[256], /* Top string */
3414 twidth
[256], /* Width string */
3415 tlength
[256]; /* Length string */
3417 if (cupsArrayFind(sizes
, (void *)pwg
->ppd
))
3420 cupsArrayAdd(sizes
, (void *)pwg
->ppd
);
3422 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3423 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3424 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3425 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3426 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3427 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3429 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3430 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3434 cupsArrayDelete(sizes
);
3443 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3444 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3446 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3448 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3450 static const char * const sources
[][2] =
3451 { /* "media-source" strings */
3452 { "Auto", _("Automatic") },
3453 { "Main", _("Main") },
3454 { "Alternate", _("Alternate") },
3455 { "LargeCapacity", _("Large Capacity") },
3456 { "Manual", _("Manual") },
3457 { "Envelope", _("Envelope") },
3458 { "Disc", _("Disc") },
3459 { "Photo", _("Photo") },
3460 { "Hagaki", _("Hagaki") },
3461 { "MainRoll", _("Main Roll") },
3462 { "AlternateRoll", _("Alternate Roll") },
3463 { "Top", _("Top") },
3464 { "Middle", _("Middle") },
3465 { "Bottom", _("Bottom") },
3466 { "Side", _("Side") },
3467 { "Left", _("Left") },
3468 { "Right", _("Right") },
3469 { "Center", _("Center") },
3470 { "Rear", _("Rear") },
3471 { "ByPassTray", _("Multipurpose") },
3472 { "Tray1", _("Tray 1") },
3473 { "Tray2", _("Tray 2") },
3474 { "Tray3", _("Tray 3") },
3475 { "Tray4", _("Tray 4") },
3476 { "Tray5", _("Tray 5") },
3477 { "Tray6", _("Tray 6") },
3478 { "Tray7", _("Tray 7") },
3479 { "Tray8", _("Tray 8") },
3480 { "Tray9", _("Tray 9") },
3481 { "Tray10", _("Tray 10") },
3482 { "Tray11", _("Tray 11") },
3483 { "Tray12", _("Tray 12") },
3484 { "Tray13", _("Tray 13") },
3485 { "Tray14", _("Tray 14") },
3486 { "Tray15", _("Tray 15") },
3487 { "Tray16", _("Tray 16") },
3488 { "Tray17", _("Tray 17") },
3489 { "Tray18", _("Tray 18") },
3490 { "Tray19", _("Tray 19") },
3491 { "Tray20", _("Tray 20") },
3492 { "Roll1", _("Roll 1") },
3493 { "Roll2", _("Roll 2") },
3494 { "Roll3", _("Roll 3") },
3495 { "Roll4", _("Roll 4") },
3496 { "Roll5", _("Roll 5") },
3497 { "Roll6", _("Roll 6") },
3498 { "Roll7", _("Roll 7") },
3499 { "Roll8", _("Roll 8") },
3500 { "Roll9", _("Roll 9") },
3501 { "Roll10", _("Roll 10") }
3504 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3505 "*OrderDependency: 10 AnySetup *InputSlot\n"
3506 "*DefaultInputSlot: %s\n", ppdname
);
3507 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3509 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3511 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3512 if (!strcmp(sources
[j
][0], ppdname
))
3514 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, sources
[j
][1]), j
);
3518 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3525 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3526 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3528 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3530 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3532 static const char * const media_types
[][2] =
3533 { /* "media-type" strings */
3534 { "aluminum", _("Aluminum") },
3535 { "auto", _("Automatic") },
3536 { "back-print-film", _("Back Print Film") },
3537 { "cardboard", _("Cardboard") },
3538 { "cardstock", _("Cardstock") },
3540 { "com.hp.advanced-photo", _("Advanced Photo Paper") }, /* HP */
3541 { "com.hp.brochure-glossy", _("Glossy Brochure Paper") }, /* HP */
3542 { "com.hp.brochure-matte", _("Matte Brochure Paper") }, /* HP */
3543 { "com.hp.cover-matte", _("Matte Cover Paper") }, /* HP */
3544 { "com.hp.ecosmart-lite", _("Office Recycled Paper") }, /* HP */
3545 { "com.hp.everyday-glossy", _("Everyday Glossy Photo Paper") }, /* HP */
3546 { "com.hp.everyday-matte", _("Everyday Matte Paper") }, /* HP */
3547 { "com.hp.extra-heavy", _("Extra Heavyweight Paper") }, /* HP */
3548 { "com.hp.intermediate", _("Multipurpose Paper") }, /* HP */
3549 { "com.hp.mid-weight", _("Mid-Weight Paper") }, /* HP */
3550 { "com.hp.premium-inkjet", _("Premium Inkjet Paper") }, /* HP */
3551 { "com.hp.premium-photo", _("Premium Photo Glossy Paper") }, /* HP */
3552 { "com.hp.premium-presentation-matte", _("Premium Presentation Matte Paper") }, /* HP */
3553 { "continuous", _("Continuous") },
3554 { "continuous-long", _("Continuous Long") },
3555 { "continuous-short", _("Continuous Short") },
3556 { "disc", _("Optical Disc") },
3557 { "disc-glossy", _("Glossy Optical Disc") },
3558 { "disc-high-gloss", _("High Gloss Optical Disc") },
3559 { "disc-matte", _("Matte Optical Disc") },
3560 { "disc-satin", _("Satin Optical Disc") },
3561 { "disc-semi-gloss", _("Semi-Gloss Optical Disc") },
3562 { "double-wall", _("Double Wall Cardboard") },
3563 { "dry-film", _("Dry Film") },
3564 { "dvd", _("DVD") },
3565 { "embossing-foil", _("Embossing Foil") },
3566 { "end-board", _("End Board") },
3567 { "envelope", _("Envelope") },
3568 { "envelope-archival", _("Archival Envelope") },
3569 { "envelope-bond", _("Bond Envelope") },
3570 { "envelope-coated", _("Coated Envelope") },
3571 { "envelope-cotton", _("Cotton Envelope") },
3572 { "envelope-fine", _("Fine Envelope") },
3573 { "envelope-heavyweight", _("Heavyweight Envelope") },
3574 { "envelope-inkjet", _("Inkjet Envelope") },
3575 { "envelope-lightweight", _("Lightweight Envelope") },
3576 { "envelope-plain", _("Plain Envelope") },
3577 { "envelope-preprinted", _("Preprinted Envelope") },
3578 { "envelope-window", _("Windowed Envelope") },
3579 { "fabric", _("Fabric") },
3580 { "fabric-archival", _("Archival Fabric") },
3581 { "fabric-glossy", _("Glossy Fabric") },
3582 { "fabric-high-gloss", _("High Gloss Fabric") },
3583 { "fabric-matte", _("Matte Fabric") },
3584 { "fabric-semi-gloss", _("Semi-Gloss Fabric") },
3585 { "fabric-waterproof", _("Waterproof Fabric") },
3586 { "film", _("Film") },
3587 { "flexo-base", _("Flexo Base") },
3588 { "flexo-photo-polymer", _("Flexo Photo Polymer") },
3589 { "flute", _("Flute") },
3590 { "foil", _("Foil") },
3591 { "full-cut-tabs", _("Full Cut Tabs") },
3592 { "glass", _("Glass") },
3593 { "glass-colored", _("Glass Colored") },
3594 { "glass-opaque", _("Glass Opaque") },
3595 { "glass-surfaced", _("Glass Surfaced") },
3596 { "glass-textured", _("Glass Textured") },
3597 { "gravure-cylinder", _("Gravure Cylinder") },
3598 { "image-setter-paper", _("Image Setter Paper") },
3599 { "imaging-cylinder", _("Imaging Cylinder") },
3600 { "jp.co.canon_photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3601 { "jp.co.canon_photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3602 { "jp.co.canon-photo-paper-plus-glossy-ii", _("Photo Paper Plus Glossy II") }, /* Canon */
3603 { "jp.co.canon-photo-paper-pro-platinum", _("Photo Paper Pro Platinum") }, /* Canon */
3604 { "labels", _("Labels") },
3605 { "labels-colored", _("Colored Labels") },
3606 { "labels-glossy", _("Glossy Labels") },
3607 { "labels-high-gloss", _("High Gloss Labels") },
3608 { "labels-inkjet", _("Inkjet Labels") },
3609 { "labels-matte", _("Matte Labels") },
3610 { "labels-permanent", _("Permanent Labels") },
3611 { "labels-satin", _("Satin Labels") },
3612 { "labels-security", _("Security Labels") },
3613 { "labels-semi-gloss", _("Semi-Gloss Labels") },
3614 { "laminating-foil", _("Laminating Foil") },
3615 { "letterhead", _("Letterhead") },
3616 { "metal", _("Metal") },
3617 { "metal-glossy", _("Metal Glossy") },
3618 { "metal-high-gloss", _("Metal High Gloss") },
3619 { "metal-matte", _("Metal Matte") },
3620 { "metal-satin", _("Metal Satin") },
3621 { "metal-semi-gloss", _("Metal Semi Gloss") },
3622 { "mounting-tape", _("Mounting Tape") },
3623 { "multi-layer", _("Multi Layer") },
3624 { "multi-part-form", _("Multi Part Form") },
3625 { "other", _("Other") },
3626 { "paper", _("Paper") },
3627 { "photo", _("Photo Paper") }, /* HP mis-spelling */
3628 { "photographic", _("Photo Paper") },
3629 { "photographic-archival", _("Archival Photo Paper") },
3630 { "photographic-film", _("Photo Film") },
3631 { "photographic-glossy", _("Glossy Photo Paper") },
3632 { "photographic-high-gloss", _("High Gloss Photo Paper") },
3633 { "photographic-matte", _("Matte Photo Paper") },
3634 { "photographic-satin", _("Satin Photo Paper") },
3635 { "photographic-semi-gloss", _("Semi-Gloss Photo Paper") },
3636 { "plastic", _("Plastic") },
3637 { "plastic-archival", _("Plastic Archival") },
3638 { "plastic-colored", _("Plastic Colored") },
3639 { "plastic-glossy", _("Plastic Glossy") },
3640 { "plastic-high-gloss", _("Plastic High Gloss") },
3641 { "plastic-matte", _("Plastic Matte") },
3642 { "plastic-satin", _("Plastic Satin") },
3643 { "plastic-semi-gloss", _("Plastic Semi Gloss") },
3644 { "plate", _("Plate") },
3645 { "polyester", _("Polyester") },
3646 { "pre-cut-tabs", _("Pre Cut Tabs") },
3647 { "roll", _("Roll") },
3648 { "screen", _("Screen") },
3649 { "screen-paged", _("Screen Paged") },
3650 { "self-adhesive", _("Self Adhesive") },
3651 { "self-adhesive-film", _("Self Adhesive Film") },
3652 { "shrink-foil", _("Shrink Foil") },
3653 { "single-face", _("Single Face") },
3654 { "single-wall", _("Single Wall Cardboard") },
3655 { "sleeve", _("Sleeve") },
3656 { "stationery", _("Plain Paper") },
3657 { "stationery-archival", _("Archival Paper") },
3658 { "stationery-coated", _("Coated Paper") },
3659 { "stationery-cotton", _("Cotton Paper") },
3660 { "stationery-fine", _("Vellum Paper") },
3661 { "stationery-heavyweight", _("Heavyweight Paper") },
3662 { "stationery-heavyweight-coated", _("Heavyweight Coated Paper") },
3663 { "stationery-inkjet", _("Inkjet Paper") },
3664 { "stationery-letterhead", _("Letterhead") },
3665 { "stationery-lightweight", _("Lightweight Paper") },
3666 { "stationery-preprinted", _("Preprinted Paper") },
3667 { "stationery-prepunched", _("Punched Paper") },
3668 { "tab-stock", _("Tab Stock") },
3669 { "tractor", _("Tractor") },
3670 { "transfer", _("Transfer") },
3671 { "transparency", _("Transparency") },
3672 { "triple-wall", _("Triple Wall Cardboard") },
3673 { "wet-film", _("Wet Film") }
3676 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3677 "*OrderDependency: 10 AnySetup *MediaType\n"
3678 "*DefaultMediaType: %s\n", ppdname
);
3679 for (i
= 0; i
< count
; i
++)
3681 const char *keyword
= ippGetString(attr
, i
, NULL
);
3683 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3685 for (j
= 0; j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])); j
++)
3686 if (!strcmp(keyword
, media_types
[j
][0]))
3689 if (j
< (int)(sizeof(media_types
) / sizeof(media_types
[0])))
3690 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, media_types
[j
][1]), ppdname
);
3692 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, keyword
, ppdname
);
3694 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3701 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3702 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3703 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3704 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3708 const char *default_color
= NULL
; /* Default */
3710 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3712 const char *keyword
= ippGetString(attr
, i
, NULL
);
3713 /* Keyword for color/bit depth */
3715 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3718 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3719 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3721 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3724 default_color
= "FastGray";
3726 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3729 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3730 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3732 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3734 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3735 default_color
= "Gray";
3737 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "SRGB24") || !strcmp(keyword
, "color"))
3740 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3741 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3743 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3745 default_color
= "RGB";
3747 else if (!strcmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48"))
3750 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3751 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3753 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3756 default_color
= "AdobeRGB";
3762 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3763 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3771 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3773 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3774 "*OrderDependency: 10 AnySetup *Duplex\n"
3775 "*DefaultDuplex: None\n"
3776 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3777 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3778 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3779 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3781 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3783 const char *keyword
= ippGetString(attr
, 0, NULL
);
3786 if (!strcmp(keyword
, "flipped"))
3787 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3788 else if (!strcmp(keyword
, "manual-tumble"))
3789 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3790 else if (!strcmp(keyword
, "normal"))
3791 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3793 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3795 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3797 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3799 const char *dm
= ippGetString(attr
, i
, NULL
);
3802 if (!_cups_strcasecmp(dm
, "DM1"))
3804 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3807 else if (!_cups_strcasecmp(dm
, "DM2"))
3809 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3812 else if (!_cups_strcasecmp(dm
, "DM3"))
3814 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3817 else if (!_cups_strcasecmp(dm
, "DM4"))
3819 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3830 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3831 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3833 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3835 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3837 static const char * const output_bins
[][2] =
3838 { /* "output-bin" strings */
3839 { "auto", _("Automatic") },
3840 { "bottom", _("Bottom Tray") },
3841 { "center", _("Center Tray") },
3842 { "face-down", _("Face Down") },
3843 { "face-up", _("Face Up") },
3844 { "large-capacity", _("Large Capacity Tray") },
3845 { "left", _("Left Tray") },
3846 { "mailbox-1", _("Mailbox 1") },
3847 { "mailbox-2", _("Mailbox 2") },
3848 { "mailbox-3", _("Mailbox 3") },
3849 { "mailbox-4", _("Mailbox 4") },
3850 { "mailbox-5", _("Mailbox 5") },
3851 { "mailbox-6", _("Mailbox 6") },
3852 { "mailbox-7", _("Mailbox 7") },
3853 { "mailbox-8", _("Mailbox 8") },
3854 { "mailbox-9", _("Mailbox 9") },
3855 { "mailbox-10", _("Mailbox 10") },
3856 { "middle", _("Middle") },
3857 { "my-mailbox", _("My Mailbox") },
3858 { "rear", _("Rear Tray") },
3859 { "right", _("Right Tray") },
3860 { "side", _("Side Tray") },
3861 { "stacker-1", _("Stacker 1") },
3862 { "stacker-2", _("Stacker 2") },
3863 { "stacker-3", _("Stacker 3") },
3864 { "stacker-4", _("Stacker 4") },
3865 { "stacker-5", _("Stacker 5") },
3866 { "stacker-6", _("Stacker 6") },
3867 { "stacker-7", _("Stacker 7") },
3868 { "stacker-8", _("Stacker 8") },
3869 { "stacker-9", _("Stacker 9") },
3870 { "stacker-10", _("Stacker 10") },
3871 { "top", _("Top Tray") },
3872 { "tray-1", _("Tray 1") },
3873 { "tray-2", _("Tray 2") },
3874 { "tray-3", _("Tray 3") },
3875 { "tray-4", _("Tray 4") },
3876 { "tray-5", _("Tray 5") },
3877 { "tray-6", _("Tray 6") },
3878 { "tray-7", _("Tray 7") },
3879 { "tray-8", _("Tray 8") },
3880 { "tray-9", _("Tray 9") },
3881 { "tray-10", _("Tray 10") }
3884 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3885 "*OrderDependency: 10 AnySetup *OutputBin\n"
3886 "*DefaultOutputBin: %s\n", ppdname
);
3887 for (i
= 0; i
< (int)(sizeof(output_bins
) / sizeof(output_bins
[0])); i
++)
3889 if (!ippContainsString(attr
, output_bins
[i
][0]))
3892 pwg_ppdize_name(output_bins
[i
][0], ppdname
, sizeof(ppdname
));
3894 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, _cupsLangString(lang
, output_bins
[i
][1]));
3896 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3900 * Finishing options...
3903 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3905 ipp_t
*col
; /* Collection value */
3906 ipp_attribute_t
*template; /* "finishing-template" member */
3907 const char *name
; /* String name */
3908 int value
; /* Enum value, if any */
3909 cups_array_t
*names
; /* Names we've added */
3911 count
= ippGetCount(attr
);
3912 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3914 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3915 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3916 "*DefaultcupsFinishingTemplate: none\n"
3917 "*cupsFinishingTemplate none/%s: \"\"\n"
3918 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3920 for (i
= 0; i
< count
; i
++)
3922 col
= ippGetCollection(attr
, i
);
3923 template = ippFindAttribute(col
, "finishing-template", IPP_TAG_ZERO
);
3925 if ((name
= ippGetString(template, 0, NULL
)) == NULL
|| !strcmp(name
, "none"))
3928 if (cupsArrayFind(names
, (char *)name
))
3929 continue; /* Already did this finishing template */
3931 cupsArrayAdd(names
, (char *)name
);
3933 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3935 if (!strcmp(finishings
[j
][0], name
))
3937 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3939 value
= ippEnumValue("finishings", name
);
3942 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3948 cupsArrayDelete(names
);
3950 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3952 else if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
&& (count
= ippGetCount(attr
)) > 1 )
3954 const char *name
; /* String name */
3955 int value
; /* Enum value, if any */
3957 count
= ippGetCount(attr
);
3959 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickMany\n"
3960 "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"
3961 "*DefaultcupsFinishingTemplate: none\n"
3962 "*cupsFinishingTemplate none/%s: \"\"\n"
3963 "*cupsIPPFinishings 3/none: \"*cupsFinishingTemplate none\"\n", _cupsLangString(lang
, _("Finishing")), _cupsLangString(lang
, _("No Finishing")));
3965 for (i
= 0; i
< count
; i
++)
3967 if ((value
= ippGetInteger(attr
, i
)) == 3)
3970 name
= ippEnumString("finishings", value
);
3971 for (j
= 0; j
< (int)(sizeof(finishings
) / sizeof(finishings
[0])); j
++)
3973 if (!strcmp(finishings
[j
][0], name
))
3975 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\"\n", name
, _cupsLangString(lang
, finishings
[j
][1]));
3976 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*cupsFinishingTemplate %s\"\n", value
, name
, name
);
3982 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
3986 * cupsPrintQuality and DefaultResolution...
3989 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
3991 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3993 count
= ippGetCount(attr
);
3995 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3996 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3998 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
3999 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4000 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4001 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4003 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4004 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4006 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
4007 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4008 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4011 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
4013 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
4014 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4017 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4019 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4021 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4023 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4025 const char *rs
= ippGetString(attr
, i
, NULL
);
4028 if (_cups_strncasecmp(rs
, "RS", 2))
4031 lowdpi
= atoi(rs
+ 2);
4032 if ((rs
= strrchr(rs
, '-')) != NULL
)
4033 hidpi
= atoi(rs
+ 1);
4042 * Invalid "urf-supported" value...
4050 * Generate print qualities based on low and high DPIs...
4053 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4055 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4056 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4057 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4058 if ((lowdpi
& 1) == 0)
4059 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4060 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4061 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4062 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4063 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4064 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4065 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4068 else if (is_apple
|| is_pwg
)
4072 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4074 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4079 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4082 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4084 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4085 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4086 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4087 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4088 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4089 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4090 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4091 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4092 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4096 * Close up and return...
4104 * If we get here then there was a problem creating the PPD...
4113 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4120 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4124 const char * /* O - InputSlot name */
4125 _pwgInputSlotForSource(
4126 const char *media_source
, /* I - PWG media-source */
4127 char *name
, /* I - Name buffer */
4128 size_t namesize
) /* I - Size of name buffer */
4131 * Range check input...
4134 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4137 if (_cups_strcasecmp(media_source
, "main"))
4138 strlcpy(name
, "Cassette", namesize
);
4139 else if (_cups_strcasecmp(media_source
, "alternate"))
4140 strlcpy(name
, "Multipurpose", namesize
);
4141 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4142 strlcpy(name
, "LargeCapacity", namesize
);
4143 else if (_cups_strcasecmp(media_source
, "bottom"))
4144 strlcpy(name
, "Lower", namesize
);
4145 else if (_cups_strcasecmp(media_source
, "middle"))
4146 strlcpy(name
, "Middle", namesize
);
4147 else if (_cups_strcasecmp(media_source
, "top"))
4148 strlcpy(name
, "Upper", namesize
);
4149 else if (_cups_strcasecmp(media_source
, "rear"))
4150 strlcpy(name
, "Rear", namesize
);
4151 else if (_cups_strcasecmp(media_source
, "side"))
4152 strlcpy(name
, "Side", namesize
);
4153 else if (_cups_strcasecmp(media_source
, "envelope"))
4154 strlcpy(name
, "Envelope", namesize
);
4155 else if (_cups_strcasecmp(media_source
, "main-roll"))
4156 strlcpy(name
, "Roll", namesize
);
4157 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4158 strlcpy(name
, "Roll2", namesize
);
4160 pwg_ppdize_name(media_source
, name
, namesize
);
4167 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4171 const char * /* O - MediaType name */
4172 _pwgMediaTypeForType(
4173 const char *media_type
, /* I - PWG media-type */
4174 char *name
, /* I - Name buffer */
4175 size_t namesize
) /* I - Size of name buffer */
4178 * Range check input...
4181 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4184 if (_cups_strcasecmp(media_type
, "auto"))
4185 strlcpy(name
, "Auto", namesize
);
4186 else if (_cups_strcasecmp(media_type
, "cardstock"))
4187 strlcpy(name
, "Cardstock", namesize
);
4188 else if (_cups_strcasecmp(media_type
, "envelope"))
4189 strlcpy(name
, "Envelope", namesize
);
4190 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4191 strlcpy(name
, "Glossy", namesize
);
4192 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4193 strlcpy(name
, "HighGloss", namesize
);
4194 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4195 strlcpy(name
, "Matte", namesize
);
4196 else if (_cups_strcasecmp(media_type
, "stationery"))
4197 strlcpy(name
, "Plain", namesize
);
4198 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4199 strlcpy(name
, "Coated", namesize
);
4200 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4201 strlcpy(name
, "Inkjet", namesize
);
4202 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4203 strlcpy(name
, "Letterhead", namesize
);
4204 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4205 strlcpy(name
, "Preprinted", namesize
);
4206 else if (_cups_strcasecmp(media_type
, "transparency"))
4207 strlcpy(name
, "Transparency", namesize
);
4209 pwg_ppdize_name(media_type
, name
, namesize
);
4216 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4219 const char * /* O - PageSize name */
4220 _pwgPageSizeForMedia(
4221 pwg_media_t
*media
, /* I - Media */
4222 char *name
, /* I - PageSize name buffer */
4223 size_t namesize
) /* I - Size of name buffer */
4225 const char *sizeptr
, /* Pointer to size in PWG name */
4226 *dimptr
; /* Pointer to dimensions in PWG name */
4230 * Range check input...
4233 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4237 * Copy or generate a PageSize name...
4243 * Use a standard Adobe name...
4246 strlcpy(name
, media
->ppd
, namesize
);
4248 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4249 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4250 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4251 (size_t)(dimptr
- sizeptr
) > namesize
)
4254 * Use a name of the form "wNNNhNNN"...
4257 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4258 (int)PWG_TO_POINTS(media
->length
));
4263 * Copy the size name from class_sizename_dimensions...
4266 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4267 name
[dimptr
- sizeptr
- 1] = '\0';
4275 * 'pwg_add_finishing()' - Add a finishings value.
4280 cups_array_t
*finishings
, /* I - Finishings array */
4281 ipp_finishings_t
template, /* I - Finishing template */
4282 const char *name
, /* I - PPD option */
4283 const char *value
) /* I - PPD choice */
4285 _pwg_finishings_t
*f
; /* New finishings value */
4288 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4290 f
->value
= template;
4291 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4293 cupsArrayAdd(finishings
, f
);
4299 * 'pwg_compare_finishings()' - Compare two finishings values.
4302 static int /* O - Result of comparison */
4303 pwg_compare_finishings(
4304 _pwg_finishings_t
*a
, /* I - First finishings value */
4305 _pwg_finishings_t
*b
) /* I - Second finishings value */
4307 return ((int)b
->value
- (int)a
->value
);
4312 * 'pwg_free_finishings()' - Free a finishings value.
4316 pwg_free_finishings(
4317 _pwg_finishings_t
*f
) /* I - Finishings value */
4319 cupsFreeOptions(f
->num_options
, f
->options
);
4325 * 'pwg_free_material()' - Free a material value.
4329 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
4331 _cupsStrFree(m
->key
);
4332 _cupsStrFree(m
->name
);
4334 cupsFreeOptions(m
->num_props
, m
->props
);
4341 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4345 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4346 char *name
, /* I - Name buffer */
4347 size_t namesize
) /* I - Size of name buffer */
4349 char *ptr
, /* Pointer into name buffer */
4350 *end
; /* End of name buffer */
4359 *name
= (char)toupper(*ipp
++);
4361 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4363 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4366 *ptr
++ = (char)toupper(*ipp
++ & 255);
4377 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4381 pwg_ppdize_resolution(
4382 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4383 int element
, /* I - Element to convert */
4384 int *xres
, /* O - X resolution in DPI */
4385 int *yres
, /* O - Y resolution in DPI */
4386 char *name
, /* I - Name buffer */
4387 size_t namesize
) /* I - Size of name buffer */
4389 ipp_res_t units
; /* Units for resolution */
4392 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4394 if (units
== IPP_RES_PER_CM
)
4396 *xres
= (int)(*xres
* 2.54);
4397 *yres
= (int)(*yres
* 2.54);
4400 if (name
&& namesize
> 4)
4403 snprintf(name
, namesize
, "%ddpi", *xres
);
4405 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4411 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4415 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4416 char *name
, /* I - Name buffer */
4417 size_t namesize
, /* I - Size of name buffer */
4418 const char *dashchars
)/* I - Characters to be replaced by dashes */
4420 char *ptr
, /* Pointer into name buffer */
4421 *end
; /* End of name buffer */
4424 if (_cups_islower(*ppd
))
4427 * Already lowercase name, use as-is?
4430 const char *ppdptr
; /* Pointer into PPD keyword */
4432 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4433 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4438 strlcpy(name
, ppd
, namesize
);
4443 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4445 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4446 *ptr
++ = (char)tolower(*ppd
& 255);
4447 else if (strchr(dashchars
, *ppd
))
4452 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4453 _cups_isupper(ppd
[1]) && ptr
< end
)
4455 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))