4 * PPD cache implementation for CUPS.
6 * Copyright 2010-2015 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * Include necessary headers...
21 #include "cups-private.h"
22 #include "ppd-private.h"
27 * Macro to test for two almost-equal PWG measurements.
30 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
37 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
38 _pwg_finishings_t
*b
);
39 static void pwg_free_finishings(_pwg_finishings_t
*f
);
40 static void pwg_free_material(_pwg_material_t
*m
);
41 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
42 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
43 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
44 const char *dashchars
);
48 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
50 * This functions converts PPD and CUPS-specific options to their standard IPP
51 * attributes and values and adds them to the specified IPP request.
54 int /* O - New number of copies */
55 _cupsConvertOptions(ipp_t
*request
, /* I - IPP request */
56 ppd_file_t
*ppd
, /* I - PPD file */
57 _ppd_cache_t
*pc
, /* I - PPD cache info */
58 ipp_attribute_t
*media_col_sup
,
59 /* I - media-col-supported values */
60 ipp_attribute_t
*doc_handling_sup
,
61 /* I - multiple-document-handling-supported values */
62 ipp_attribute_t
*print_color_mode_sup
,
63 /* I - Printer supports print-color-mode */
64 const char *user
, /* I - User info */
65 const char *format
, /* I - document-format value */
66 int copies
, /* I - Number of copies */
67 int num_options
, /* I - Number of options */
68 cups_option_t
*options
) /* I - Options */
70 int i
; /* Looping var */
71 const char *keyword
, /* PWG keyword */
72 *password
; /* Password string */
73 pwg_size_t
*size
; /* PWG media size */
74 ipp_t
*media_col
, /* media-col value */
75 *media_size
; /* media-size value */
76 const char *media_source
, /* media-source value */
77 *media_type
, /* media-type value */
78 *collate_str
, /* multiple-document-handling value */
79 *color_attr_name
, /* Supported color attribute */
80 *mandatory
; /* Mandatory attributes */
81 int num_finishings
= 0, /* Number of finishing values */
82 finishings
[10]; /* Finishing enum values */
83 ppd_choice_t
*choice
; /* Marked choice */
87 * Send standard IPP attributes...
90 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
92 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
94 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
97 if (!strcmp(keyword
, "none"))
100 * Add plain-text job-password...
103 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
108 * Add hashed job-password...
111 unsigned char hash
[64]; /* Hash of password */
112 ssize_t hashlen
; /* Length of hash */
114 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
115 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
119 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
124 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
125 keyword
= cupsGetOption("job-billing", num_options
, options
);
128 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
131 if (pc
->accounting_user_id
)
133 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
137 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
140 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
142 if (strcmp(mandatory
, "copies") &&
143 strcmp(mandatory
, "destination-uris") &&
144 strcmp(mandatory
, "finishings") &&
145 strcmp(mandatory
, "job-account-id") &&
146 strcmp(mandatory
, "job-accounting-user-id") &&
147 strcmp(mandatory
, "job-password") &&
148 strcmp(mandatory
, "job-password-encryption") &&
149 strcmp(mandatory
, "media") &&
150 strncmp(mandatory
, "media-col", 9) &&
151 strcmp(mandatory
, "multiple-document-handling") &&
152 strcmp(mandatory
, "output-bin") &&
153 strcmp(mandatory
, "print-color-mode") &&
154 strcmp(mandatory
, "print-quality") &&
155 strcmp(mandatory
, "sides") &&
156 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
158 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
160 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
165 case IPP_TAG_INTEGER
:
167 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
169 case IPP_TAG_BOOLEAN
:
170 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
174 int lower
, upper
; /* Range */
176 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
177 lower
= upper
= atoi(keyword
);
179 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
182 case IPP_TAG_STRING
:
183 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
186 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
188 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
189 keyword
= "auto-monochrome";
190 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
191 keyword
= "process-monochrome";
194 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
200 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
201 keyword
= cupsGetOption("media", num_options
, options
);
203 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
206 * Add a media-col value...
209 media_size
= ippNew();
210 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
211 "x-dimension", size
->width
);
212 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
213 "y-dimension", size
->length
);
215 media_col
= ippNew();
216 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
218 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
221 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
225 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
227 if (!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 (!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 (!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 (!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 (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
237 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && 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
)
1719 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1720 NULL
, NULL
, 0, NULL
,
1721 (cups_afree_func_t
)pwg_free_finishings
);
1725 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1728 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1729 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1730 &(finishings
->options
),
1731 _PPD_PARSE_OPTIONS
);
1733 cupsArrayAdd(pc
->finishings
, finishings
);
1735 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1743 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1744 pc
->max_copies
= atoi(ppd_attr
->value
);
1745 else if (ppd
->manual_copies
)
1748 pc
->max_copies
= 9999;
1751 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1752 * cupsJobPassword, and cupsMandatory.
1755 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1756 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1758 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1759 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1761 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1762 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1764 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1765 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1767 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1768 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1774 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1775 (cups_acopy_func_t
)_cupsStrAlloc
,
1776 (cups_afree_func_t
)_cupsStrFree
);
1778 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1780 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1781 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1783 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1784 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1790 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1791 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1793 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1794 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1796 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1797 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1799 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1800 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1802 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1804 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1807 * *cupsMaterial key/name: "name=value ... name=value"
1810 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1812 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1813 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1814 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1817 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1819 cupsArrayAdd(pc
->materials
, material
);
1823 * Return the cache data...
1829 * If we get here we need to destroy the PWG mapping data and return NULL...
1834 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1835 _ppdCacheDestroy(pc
);
1842 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1846 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1848 int i
; /* Looping var */
1849 pwg_map_t
*map
; /* Current map */
1850 pwg_size_t
*size
; /* Current size */
1854 * Range check input...
1861 * Free memory as needed...
1866 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1868 _cupsStrFree(map
->pwg
);
1869 _cupsStrFree(map
->ppd
);
1877 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1879 _cupsStrFree(size
->map
.pwg
);
1880 _cupsStrFree(size
->map
.ppd
);
1886 if (pc
->source_option
)
1887 _cupsStrFree(pc
->source_option
);
1891 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1893 _cupsStrFree(map
->pwg
);
1894 _cupsStrFree(map
->ppd
);
1902 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1904 _cupsStrFree(map
->pwg
);
1905 _cupsStrFree(map
->ppd
);
1911 if (pc
->custom_max_keyword
)
1912 _cupsStrFree(pc
->custom_max_keyword
);
1914 if (pc
->custom_min_keyword
)
1915 _cupsStrFree(pc
->custom_min_keyword
);
1917 _cupsStrFree(pc
->product
);
1918 cupsArrayDelete(pc
->filters
);
1919 cupsArrayDelete(pc
->prefilters
);
1920 cupsArrayDelete(pc
->finishings
);
1922 _cupsStrFree(pc
->charge_info_uri
);
1923 _cupsStrFree(pc
->password
);
1925 cupsArrayDelete(pc
->mandatory
);
1927 cupsArrayDelete(pc
->support_files
);
1929 _cupsStrFree(pc
->cups_3d
);
1930 _cupsStrFree(pc
->cups_layer_order
);
1932 cupsArrayDelete(pc
->materials
);
1939 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1943 const char * /* O - output-bin or NULL */
1945 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1946 const char *output_bin
) /* I - PPD OutputBin string */
1948 int i
; /* Looping var */
1952 * Range check input...
1955 if (!pc
|| !output_bin
)
1959 * Look up the OutputBin string...
1963 for (i
= 0; i
< pc
->num_bins
; i
++)
1964 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1965 return (pc
->bins
[i
].pwg
);
1972 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1973 * IPP finishings value(s).
1976 int /* O - New number of options */
1977 _ppdCacheGetFinishingOptions(
1978 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1979 ipp_t
*job
, /* I - Job attributes or NULL */
1980 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1981 int num_options
, /* I - Number of options */
1982 cups_option_t
**options
) /* IO - Options */
1984 int i
; /* Looping var */
1985 _pwg_finishings_t
*f
, /* PWG finishings options */
1986 key
; /* Search key */
1987 ipp_attribute_t
*attr
; /* Finishings attribute */
1988 cups_option_t
*option
; /* Current finishings option */
1992 * Range check input...
1995 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1996 (!job
&& value
== IPP_FINISHINGS_NONE
))
1997 return (num_options
);
2000 * Apply finishing options...
2003 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2005 int num_values
= ippGetCount(attr
); /* Number of values */
2007 for (i
= 0; i
< num_values
; i
++)
2009 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2011 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2013 int j
; /* Another looping var */
2015 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2016 num_options
= cupsAddOption(option
->name
, option
->value
,
2017 num_options
, options
);
2021 else if (value
!= IPP_FINISHINGS_NONE
)
2025 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2027 int j
; /* Another looping var */
2029 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2030 num_options
= cupsAddOption(option
->name
, option
->value
,
2031 num_options
, options
);
2035 return (num_options
);
2040 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2044 int /* O - Number of finishings values */
2045 _ppdCacheGetFinishingValues(
2046 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2047 int num_options
, /* I - Number of options */
2048 cups_option_t
*options
, /* I - Options */
2049 int max_values
, /* I - Maximum number of finishings values */
2050 int *values
) /* O - Finishings values */
2052 int i
, /* Looping var */
2053 num_values
= 0; /* Number of values */
2054 _pwg_finishings_t
*f
; /* Current finishings option */
2055 cups_option_t
*option
; /* Current option */
2056 const char *val
; /* Value for option */
2060 * Range check input...
2063 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2065 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2067 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2072 * Go through the finishings options and see what is set...
2075 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2077 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2079 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2081 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2083 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2085 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2086 _cups_strcasecmp(option
->value
, val
))
2088 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2095 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2097 values
[num_values
++] = f
->value
;
2099 if (num_values
>= max_values
)
2104 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2106 return (num_values
);
2111 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2112 * attributes or a keyword string.
2115 const char * /* O - PPD InputSlot or NULL */
2116 _ppdCacheGetInputSlot(
2117 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2118 ipp_t
*job
, /* I - Job attributes or NULL */
2119 const char *keyword
) /* I - Keyword string or NULL */
2122 * Range check input...
2125 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2128 if (job
&& !keyword
)
2131 * Lookup the media-col attribute and any media-source found there...
2134 ipp_attribute_t
*media_col
, /* media-col attribute */
2135 *media_source
; /* media-source attribute */
2136 pwg_size_t size
; /* Dimensional size */
2137 int margins_set
; /* Were the margins set? */
2139 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2141 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2143 IPP_TAG_KEYWORD
)) != NULL
)
2146 * Use the media-source value from media-col...
2149 keyword
= ippGetString(media_source
, 0, NULL
);
2151 else if (pwgInitSize(&size
, job
, &margins_set
))
2154 * For media <= 5x7, look for a photo tray...
2157 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2164 int i
; /* Looping var */
2166 for (i
= 0; i
< pc
->num_sources
; i
++)
2167 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2168 return (pc
->sources
[i
].ppd
);
2176 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2177 * attributes or a keyword string.
2180 const char * /* O - PPD MediaType or NULL */
2181 _ppdCacheGetMediaType(
2182 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2183 ipp_t
*job
, /* I - Job attributes or NULL */
2184 const char *keyword
) /* I - Keyword string or NULL */
2187 * Range check input...
2190 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2193 if (job
&& !keyword
)
2196 * Lookup the media-col attribute and any media-source found there...
2199 ipp_attribute_t
*media_col
, /* media-col attribute */
2200 *media_type
; /* media-type attribute */
2202 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2205 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2207 IPP_TAG_KEYWORD
)) == NULL
)
2208 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2209 "media-type", IPP_TAG_NAME
);
2212 keyword
= media_type
->values
[0].string
.text
;
2218 int i
; /* Looping var */
2220 for (i
= 0; i
< pc
->num_types
; i
++)
2221 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2222 return (pc
->types
[i
].ppd
);
2230 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2234 const char * /* O - PPD OutputBin or NULL */
2235 _ppdCacheGetOutputBin(
2236 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2237 const char *output_bin
) /* I - Keyword string */
2239 int i
; /* Looping var */
2243 * Range check input...
2246 if (!pc
|| !output_bin
)
2250 * Look up the OutputBin string...
2254 for (i
= 0; i
< pc
->num_bins
; i
++)
2255 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2256 return (pc
->bins
[i
].ppd
);
2263 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2264 * attributes or a keyword string.
2267 const char * /* O - PPD PageSize or NULL */
2268 _ppdCacheGetPageSize(
2269 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2270 ipp_t
*job
, /* I - Job attributes or NULL */
2271 const char *keyword
, /* I - Keyword string or NULL */
2272 int *exact
) /* O - 1 if exact match, 0 otherwise */
2274 int i
; /* Looping var */
2275 pwg_size_t
*size
, /* Current size */
2276 *closest
, /* Closest size */
2277 jobsize
; /* Size data from job */
2278 int margins_set
, /* Were the margins set? */
2279 dwidth
, /* Difference in width */
2280 dlength
, /* Difference in length */
2281 dleft
, /* Difference in left margins */
2282 dright
, /* Difference in right margins */
2283 dbottom
, /* Difference in bottom margins */
2284 dtop
, /* Difference in top margins */
2285 dmin
, /* Minimum difference */
2286 dclosest
; /* Closest difference */
2287 const char *ppd_name
; /* PPD media name */
2290 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2291 pc
, job
, keyword
, exact
));
2294 * Range check input...
2297 if (!pc
|| (!job
&& !keyword
))
2308 * Try getting the PPD media name from the job attributes...
2311 ipp_attribute_t
*attr
; /* Job attribute */
2313 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2314 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2315 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2319 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2320 attr
->name
, ippTagString(attr
->value_tag
)));
2322 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2325 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2326 attr
->value_tag
== IPP_TAG_KEYWORD
))
2327 ppd_name
= attr
->values
[0].string
.text
;
2330 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2335 * Try looking up the named PPD size first...
2338 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2340 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2341 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2343 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2344 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2349 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2351 return (size
->map
.ppd
);
2356 if (job
&& !keyword
)
2359 * Get the size using media-col or media, with the preference being
2363 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2369 * Get the size using a media keyword...
2372 pwg_media_t
*media
; /* Media definition */
2375 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2376 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2377 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2380 jobsize
.width
= media
->width
;
2381 jobsize
.length
= media
->length
;
2386 * Now that we have the dimensions and possibly the margins, look at the
2387 * available sizes and find the match...
2391 dclosest
= 999999999;
2393 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2394 _cups_strncasecmp(ppd_name
, "custom_", 7))
2396 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2399 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2400 * is just about 176/2540ths...
2403 dwidth
= size
->width
- jobsize
.width
;
2404 dlength
= size
->length
- jobsize
.length
;
2406 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2412 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2415 dleft
= size
->left
- jobsize
.left
;
2416 dright
= size
->right
- jobsize
.right
;
2417 dtop
= size
->top
- jobsize
.top
;
2418 dbottom
= size
->bottom
- jobsize
.bottom
;
2420 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2421 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2423 dleft
= dleft
< 0 ? -dleft
: dleft
;
2424 dright
= dright
< 0 ? -dright
: dright
;
2425 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2426 dtop
= dtop
< 0 ? -dtop
: dtop
;
2427 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2429 if (dmin
< dclosest
)
2442 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2444 return (size
->map
.ppd
);
2450 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2453 return (closest
->map
.ppd
);
2457 * If we get here we need to check for custom page size support...
2460 if (jobsize
.width
>= pc
->custom_min_width
&&
2461 jobsize
.width
<= pc
->custom_max_width
&&
2462 jobsize
.length
>= pc
->custom_min_length
&&
2463 jobsize
.length
<= pc
->custom_max_length
)
2466 * In range, format as Custom.WWWWxLLLL (points).
2469 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2470 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2472 if (margins_set
&& exact
)
2474 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2475 dright
= pc
->custom_size
.right
- jobsize
.right
;
2476 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2477 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2479 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2480 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2486 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2487 pc
->custom_ppd_size
));
2489 return (pc
->custom_ppd_size
);
2493 * No custom page size support or the size is out of range - return NULL.
2496 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2503 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2506 pwg_size_t
* /* O - PWG size or NULL */
2508 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2509 const char *page_size
) /* I - PPD PageSize */
2511 int i
; /* Looping var */
2512 pwg_media_t
*media
; /* Media */
2513 pwg_size_t
*size
; /* Current size */
2517 * Range check input...
2520 if (!pc
|| !page_size
)
2523 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2526 * Custom size; size name can be one of the following:
2528 * Custom.WIDTHxLENGTHin - Size in inches
2529 * Custom.WIDTHxLENGTHft - Size in feet
2530 * Custom.WIDTHxLENGTHcm - Size in centimeters
2531 * Custom.WIDTHxLENGTHmm - Size in millimeters
2532 * Custom.WIDTHxLENGTHm - Size in meters
2533 * Custom.WIDTHxLENGTH[pt] - Size in points
2536 double w
, l
; /* Width and length of page */
2537 char *ptr
; /* Pointer into PageSize */
2538 struct lconv
*loc
; /* Locale data */
2541 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2542 if (!ptr
|| *ptr
!= 'x')
2545 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2549 if (!_cups_strcasecmp(ptr
, "in"))
2554 else if (!_cups_strcasecmp(ptr
, "ft"))
2559 else if (!_cups_strcasecmp(ptr
, "mm"))
2564 else if (!_cups_strcasecmp(ptr
, "cm"))
2569 else if (!_cups_strcasecmp(ptr
, "m"))
2580 pc
->custom_size
.width
= (int)w
;
2581 pc
->custom_size
.length
= (int)l
;
2583 return (&(pc
->custom_size
));
2587 * Not a custom size - look it up...
2590 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2591 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2592 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2596 * Look up standard sizes...
2599 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2600 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2601 media
= pwgMediaForPWG(page_size
);
2605 pc
->custom_size
.width
= media
->width
;
2606 pc
->custom_size
.length
= media
->length
;
2608 return (&(pc
->custom_size
));
2616 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2620 const char * /* O - PWG media-source keyword */
2622 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2623 const char *input_slot
) /* I - PPD InputSlot */
2625 int i
; /* Looping var */
2626 pwg_map_t
*source
; /* Current source */
2630 * Range check input...
2633 if (!pc
|| !input_slot
)
2636 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2637 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2638 return (source
->pwg
);
2645 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2649 const char * /* O - PWG media-type keyword */
2651 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2652 const char *media_type
) /* I - PPD MediaType */
2654 int i
; /* Looping var */
2655 pwg_map_t
*type
; /* Current type */
2659 * Range check input...
2662 if (!pc
|| !media_type
)
2665 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2666 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2674 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2677 int /* O - 1 on success, 0 on failure */
2679 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2680 const char *filename
, /* I - File to write */
2681 ipp_t
*attrs
) /* I - Attributes to write, if any */
2683 int i
, j
, k
; /* Looping vars */
2684 cups_file_t
*fp
; /* Output file */
2685 pwg_size_t
*size
; /* Current size */
2686 pwg_map_t
*map
; /* Current map */
2687 _pwg_finishings_t
*f
; /* Current finishing option */
2688 cups_option_t
*option
; /* Current option */
2689 const char *value
; /* Filter/pre-filter value */
2690 char newfile
[1024]; /* New filename */
2691 _pwg_material_t
*m
; /* Material */
2695 * Range check input...
2698 if (!pc
|| !filename
)
2700 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2705 * Open the file and write with compression...
2708 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2709 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2711 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2716 * Standard header...
2719 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2725 if (pc
->num_bins
> 0)
2727 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2728 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2729 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2736 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2737 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2738 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2739 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2740 size
->bottom
, size
->right
, size
->top
);
2741 if (pc
->custom_max_width
> 0)
2742 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2743 pc
->custom_max_width
, pc
->custom_max_length
,
2744 pc
->custom_min_width
, pc
->custom_min_length
,
2745 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2746 pc
->custom_size
.right
, pc
->custom_size
.top
);
2752 if (pc
->source_option
)
2753 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2755 if (pc
->num_sources
> 0)
2757 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2758 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2759 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2766 if (pc
->num_types
> 0)
2768 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2769 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2770 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2777 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2778 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2779 if (pc
->num_presets
[i
][j
])
2781 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2782 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2785 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2786 cupsFilePutChar(fp
, '\n');
2793 if (pc
->sides_option
)
2794 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2796 if (pc
->sides_1sided
)
2797 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2799 if (pc
->sides_2sided_long
)
2800 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2802 if (pc
->sides_2sided_short
)
2803 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2806 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2810 cupsFilePutConf(fp
, "Product", pc
->product
);
2812 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2814 value
= (const char *)cupsArrayNext(pc
->filters
))
2815 cupsFilePutConf(fp
, "Filter", value
);
2817 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2819 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2820 cupsFilePutConf(fp
, "PreFilter", value
);
2822 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2825 * Finishing options...
2828 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2830 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2832 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2833 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2834 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2835 cupsFilePutChar(fp
, '\n');
2842 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2845 * Accounting/quota/PIN/managed printing values...
2848 if (pc
->charge_info_uri
)
2849 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2851 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2852 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2853 pc
->accounting_user_id
? "true" : "false");
2856 cupsFilePutConf(fp
, "Password", pc
->password
);
2858 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2860 value
= (char *)cupsArrayNext(pc
->mandatory
))
2861 cupsFilePutConf(fp
, "Mandatory", value
);
2867 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2869 value
= (char *)cupsArrayNext(pc
->support_files
))
2870 cupsFilePutConf(fp
, "SupportFile", value
);
2877 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2879 if (pc
->cups_layer_order
)
2880 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2882 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2883 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2885 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2886 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
2888 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
2890 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
2892 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
2893 for (i
= 0; i
< m
->num_props
; i
++)
2894 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
2895 cupsFilePuts(fp
, "\n");
2899 * IPP attributes, if any...
2904 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2906 attrs
->state
= IPP_STATE_IDLE
;
2907 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2911 * Close and return...
2914 if (cupsFileClose(fp
))
2921 return (!rename(newfile
, filename
));
2926 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2927 * of an IPP printer.
2930 char * /* O - PPD filename or NULL on error */
2931 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2932 size_t bufsize
, /* I - Size of filename buffer */
2933 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2935 cups_file_t
*fp
; /* PPD file */
2936 ipp_attribute_t
*attr
, /* xxx-supported */
2937 *defattr
, /* xxx-default */
2938 *x_dim
, *y_dim
; /* Media dimensions */
2939 ipp_t
*media_size
; /* Media size collection */
2940 char make
[256], /* Make and model */
2941 *model
, /* Model name */
2942 ppdname
[PPD_MAX_NAME
];
2944 int i
, j
, /* Looping vars */
2945 count
, /* Number of values */
2946 bottom
, /* Largest bottom margin */
2947 left
, /* Largest left margin */
2948 right
, /* Largest right margin */
2949 top
; /* Largest top margin */
2950 pwg_media_t
*pwg
; /* PWG media size */
2951 int xres
, yres
; /* Resolution values */
2952 struct lconv
*loc
= localeconv();
2957 * Range check input...
2963 if (!buffer
|| bufsize
< 1 || !response
)
2967 * Open a temporary file for the PPD...
2970 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
2974 * Standard stuff for PPD file...
2977 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
2978 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
2979 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2980 cupsFilePuts(fp
, "*LanguageVersion: English\n");
2981 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
2982 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
2983 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
2984 cupsFilePuts(fp
, "*FileSystem: False\n");
2985 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
2987 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
2988 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
2990 strlcpy(make
, "Unknown Printer", sizeof(make
));
2992 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
2993 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
2996 strlcpy(make
, "HP", sizeof(make
));
2998 else if ((model
= strchr(make
, ' ')) != NULL
)
3003 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3004 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3005 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3006 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3007 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3009 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3010 cupsFilePuts(fp
, "*ColorDevice: True\n");
3012 cupsFilePuts(fp
, "*ColorDevice: False\n");
3014 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3015 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3016 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3022 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3024 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3026 const char *format
= ippGetString(attr
, i
, NULL
);
3029 if (!_cups_strcasecmp(format
, "application/pdf"))
3030 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3031 else if (!_cups_strcasecmp(format
, "application/postscript"))
3032 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-postscript application/postscript 10 -\"\n");
3033 else if (_cups_strcasecmp(format
, "application/octet-stream") && _cups_strcasecmp(format
, "application/vnd.hp-pcl") && _cups_strcasecmp(format
, "text/plain"))
3034 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 10 -\"\n", format
, format
);
3039 * PageSize/PageRegion/ImageableArea/PaperDimension
3042 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3044 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3045 if (ippGetInteger(attr
, i
) > bottom
)
3046 bottom
= ippGetInteger(attr
, i
);
3051 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3053 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3054 if (ippGetInteger(attr
, i
) > left
)
3055 left
= ippGetInteger(attr
, i
);
3060 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3062 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3063 if (ippGetInteger(attr
, i
) > right
)
3064 right
= ippGetInteger(attr
, i
);
3069 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3071 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3072 if (ippGetInteger(attr
, i
) > top
)
3073 top
= ippGetInteger(attr
, i
);
3078 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3080 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3082 media_size
= ippGetCollection(attr
, 0);
3083 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3084 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3088 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3089 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3092 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3095 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3098 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3100 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3101 "*OrderDependency: 10 AnySetup *PageSize\n"
3102 "*DefaultPageSize: %s\n", ppdname
);
3103 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3105 media_size
= ippGetCollection(attr
, i
);
3106 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3107 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3111 char twidth
[256], /* Width string */
3112 tlength
[256]; /* Length string */
3114 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3116 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3117 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3119 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3122 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3124 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3125 "*OrderDependency: 10 AnySetup *PageRegion\n"
3126 "*DefaultPageRegion: %s\n", ppdname
);
3127 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3129 media_size
= ippGetCollection(attr
, i
);
3130 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3131 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3135 char twidth
[256], /* Width string */
3136 tlength
[256]; /* Length string */
3138 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3140 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3141 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3143 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3146 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3148 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3149 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3150 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3152 media_size
= ippGetCollection(attr
, i
);
3153 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3154 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3158 char tleft
[256], /* Left string */
3159 tbottom
[256], /* Bottom string */
3160 tright
[256], /* Right string */
3161 ttop
[256], /* Top string */
3162 twidth
[256], /* Width string */
3163 tlength
[256]; /* Length string */
3165 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3167 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3168 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3169 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3170 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3171 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3172 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3174 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3175 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3184 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_KEYWORD
)) != NULL
)
3185 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3187 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3189 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3191 static const char * const sources
[][2] =
3193 { "Auto", "Automatic" },
3195 { "Alternate", "Alternate" },
3196 { "LargeCapacity", "Large Capacity" },
3197 { "Manual", "Manual" },
3198 { "Envelope", "Envelope" },
3200 { "Photo", "Photo" },
3201 { "Hagaki", "Hagaki" },
3202 { "MainRoll", "Main Roll" },
3203 { "AlternateRoll", "Alternate Roll" },
3205 { "Middle", "Middle" },
3206 { "Bottom", "Bottom" },
3209 { "Right", "Right" },
3210 { "Center", "Center" },
3212 { "ByPassTray", "Multipurpose" },
3213 { "Tray1", "Tray 1" },
3214 { "Tray2", "Tray 2" },
3215 { "Tray3", "Tray 3" },
3216 { "Tray4", "Tray 4" },
3217 { "Tray5", "Tray 5" },
3218 { "Tray6", "Tray 6" },
3219 { "Tray7", "Tray 7" },
3220 { "Tray8", "Tray 8" },
3221 { "Tray9", "Tray 9" },
3222 { "Tray10", "Tray 10" },
3223 { "Tray11", "Tray 11" },
3224 { "Tray12", "Tray 12" },
3225 { "Tray13", "Tray 13" },
3226 { "Tray14", "Tray 14" },
3227 { "Tray15", "Tray 15" },
3228 { "Tray16", "Tray 16" },
3229 { "Tray17", "Tray 17" },
3230 { "Tray18", "Tray 18" },
3231 { "Tray19", "Tray 19" },
3232 { "Tray20", "Tray 20" },
3233 { "Roll1", "Roll 1" },
3234 { "Roll2", "Roll 2" },
3235 { "Roll3", "Roll 3" },
3236 { "Roll4", "Roll 4" },
3237 { "Roll5", "Roll 5" },
3238 { "Roll6", "Roll 6" },
3239 { "Roll7", "Roll 7" },
3240 { "Roll8", "Roll 8" },
3241 { "Roll9", "Roll 9" },
3242 { "Roll10", "Roll 10" }
3245 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3246 "*OrderDependency: 10 AnySetup *InputSlot\n"
3247 "*DefaultInputSlot: %s\n", ppdname
);
3248 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3250 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3252 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3253 if (!strcmp(sources
[j
][0], ppdname
))
3255 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, sources
[j
][1], j
);
3259 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3266 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_KEYWORD
)) != NULL
)
3267 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3269 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3271 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3273 static const char * const types
[][2] =
3274 { /* Media type strings (far from complete) */
3275 { "Auto", "Automatic" },
3276 { "Cardstock", "Cardstock" },
3277 { "Disc", "CD/DVD/Bluray" },
3278 { "Envelope", "Envelope" },
3279 { "Labels", "Label" },
3280 { "Other", "Other" },
3281 { "Photographic", "Photo" },
3282 { "PhotographicGlossy", "Glossy Photo" },
3283 { "PhotographicHighGloss", "High-Gloss Photo" },
3284 { "PhotographicMatte", "Matte Photo" },
3285 { "PhotographicSatin", "Satin Photo" },
3286 { "PhotographicSemiGloss", "Semi-Gloss Photo" },
3287 { "Stationery", "Plain Paper" },
3288 { "StationeryLetterhead", "Letterhead" },
3289 { "Transparency", "Transparency" }
3292 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3293 "*OrderDependency: 10 AnySetup *MediaType\n"
3294 "*DefaultMediaType: %s\n", ppdname
);
3295 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3297 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3299 for (j
= 0; j
< (int)(sizeof(types
) / sizeof(types
[0])); j
++)
3300 if (!strcmp(types
[j
][0], ppdname
))
3302 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, types
[j
][1], ppdname
);
3306 if (j
>= (int)(sizeof(types
) / sizeof(types
[0])))
3307 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3310 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3317 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3318 attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
);
3322 const char *default_color
= NULL
; /* Default */
3324 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3326 const char *keyword
= ippGetString(attr
, i
, NULL
);
3327 /* Keyword for color/bit depth */
3329 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3332 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3333 "*OrderDependency: 10 AnySetup *ColorModel\n");
3335 cupsFilePuts(fp
, "*ColorModel FastGray/Fast Grayscale: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3338 default_color
= "FastGray";
3340 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3343 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3344 "*OrderDependency: 10 AnySetup *ColorModel\n");
3346 cupsFilePuts(fp
, "*ColorModel Gray/Grayscale: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3348 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3349 default_color
= "Gray";
3351 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "color"))
3354 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3355 "*OrderDependency: 10 AnySetup *ColorModel\n");
3357 cupsFilePuts(fp
, "*ColorModel RGB/Color: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3359 default_color
= "RGB";
3365 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3366 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3374 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3376 cupsFilePuts(fp
, "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
3377 "*OrderDependency: 10 AnySetup *Duplex\n"
3378 "*DefaultDuplex: None\n"
3379 "*Duplex None/Off (1-Sided): \"<</Duplex false>>setpagedevice\"\n"
3380 "*Duplex DuplexNoTumble/Long-Edge (Portrait): \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3381 "*Duplex DuplexTumble/Short-Edge (Landscape): \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3382 "*CloseUI: *Duplex\n");
3384 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3386 const char *keyword
= ippGetString(attr
, 0, NULL
);
3389 if (!strcmp(keyword
, "flipped"))
3390 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3391 else if (!strcmp(keyword
, "manual-tumble"))
3392 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3393 else if (!strcmp(keyword
, "normal"))
3394 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3396 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3398 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3400 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3402 const char *dm
= ippGetString(attr
, i
, NULL
);
3405 if (!_cups_strcasecmp(dm
, "DM1"))
3407 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3410 else if (!_cups_strcasecmp(dm
, "DM2"))
3412 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3415 else if (!_cups_strcasecmp(dm
, "DM3"))
3417 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3420 else if (!_cups_strcasecmp(dm
, "DM4"))
3422 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3430 * cupsPrintQuality and DefaultResolution...
3433 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3435 count
= ippGetCount(attr
);
3437 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3438 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3440 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3441 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3442 "*DefaultcupsPrintQuality: Normal\n");
3445 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3446 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3448 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3449 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3452 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3453 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3456 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3458 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3460 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3462 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3464 const char *rs
= ippGetString(attr
, i
, NULL
);
3467 if (_cups_strncasecmp(rs
, "RS", 2))
3470 lowdpi
= atoi(rs
+ 2);
3471 if ((rs
= strrchr(rs
, '-')) != NULL
)
3472 hidpi
= atoi(rs
+ 1);
3481 * Invalid "urf-supported" value...
3484 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3489 * Generate print qualities based on low and high DPIs...
3492 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
3494 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3495 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3496 "*DefaultcupsPrintQuality: Normal\n");
3497 if ((lowdpi
& 1) == 0)
3498 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
/ 2);
3499 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
);
3501 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", hidpi
, hidpi
);
3502 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3505 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
3507 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3508 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3511 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3514 * Close up and return...
3524 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
3528 const char * /* O - InputSlot name */
3529 _pwgInputSlotForSource(
3530 const char *media_source
, /* I - PWG media-source */
3531 char *name
, /* I - Name buffer */
3532 size_t namesize
) /* I - Size of name buffer */
3535 * Range check input...
3538 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
3541 if (_cups_strcasecmp(media_source
, "main"))
3542 strlcpy(name
, "Cassette", namesize
);
3543 else if (_cups_strcasecmp(media_source
, "alternate"))
3544 strlcpy(name
, "Multipurpose", namesize
);
3545 else if (_cups_strcasecmp(media_source
, "large-capacity"))
3546 strlcpy(name
, "LargeCapacity", namesize
);
3547 else if (_cups_strcasecmp(media_source
, "bottom"))
3548 strlcpy(name
, "Lower", namesize
);
3549 else if (_cups_strcasecmp(media_source
, "middle"))
3550 strlcpy(name
, "Middle", namesize
);
3551 else if (_cups_strcasecmp(media_source
, "top"))
3552 strlcpy(name
, "Upper", namesize
);
3553 else if (_cups_strcasecmp(media_source
, "rear"))
3554 strlcpy(name
, "Rear", namesize
);
3555 else if (_cups_strcasecmp(media_source
, "side"))
3556 strlcpy(name
, "Side", namesize
);
3557 else if (_cups_strcasecmp(media_source
, "envelope"))
3558 strlcpy(name
, "Envelope", namesize
);
3559 else if (_cups_strcasecmp(media_source
, "main-roll"))
3560 strlcpy(name
, "Roll", namesize
);
3561 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
3562 strlcpy(name
, "Roll2", namesize
);
3564 pwg_ppdize_name(media_source
, name
, namesize
);
3571 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
3575 const char * /* O - MediaType name */
3576 _pwgMediaTypeForType(
3577 const char *media_type
, /* I - PWG media-type */
3578 char *name
, /* I - Name buffer */
3579 size_t namesize
) /* I - Size of name buffer */
3582 * Range check input...
3585 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
3588 if (_cups_strcasecmp(media_type
, "auto"))
3589 strlcpy(name
, "Auto", namesize
);
3590 else if (_cups_strcasecmp(media_type
, "cardstock"))
3591 strlcpy(name
, "Cardstock", namesize
);
3592 else if (_cups_strcasecmp(media_type
, "envelope"))
3593 strlcpy(name
, "Envelope", namesize
);
3594 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
3595 strlcpy(name
, "Glossy", namesize
);
3596 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
3597 strlcpy(name
, "HighGloss", namesize
);
3598 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
3599 strlcpy(name
, "Matte", namesize
);
3600 else if (_cups_strcasecmp(media_type
, "stationery"))
3601 strlcpy(name
, "Plain", namesize
);
3602 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
3603 strlcpy(name
, "Coated", namesize
);
3604 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
3605 strlcpy(name
, "Inkjet", namesize
);
3606 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
3607 strlcpy(name
, "Letterhead", namesize
);
3608 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
3609 strlcpy(name
, "Preprinted", namesize
);
3610 else if (_cups_strcasecmp(media_type
, "transparency"))
3611 strlcpy(name
, "Transparency", namesize
);
3613 pwg_ppdize_name(media_type
, name
, namesize
);
3620 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
3623 const char * /* O - PageSize name */
3624 _pwgPageSizeForMedia(
3625 pwg_media_t
*media
, /* I - Media */
3626 char *name
, /* I - PageSize name buffer */
3627 size_t namesize
) /* I - Size of name buffer */
3629 const char *sizeptr
, /* Pointer to size in PWG name */
3630 *dimptr
; /* Pointer to dimensions in PWG name */
3634 * Range check input...
3637 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
3641 * Copy or generate a PageSize name...
3647 * Use a standard Adobe name...
3650 strlcpy(name
, media
->ppd
, namesize
);
3652 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
3653 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
3654 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
3655 (size_t)(dimptr
- sizeptr
) > namesize
)
3658 * Use a name of the form "wNNNhNNN"...
3661 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
3662 (int)PWG_TO_POINTS(media
->length
));
3667 * Copy the size name from class_sizename_dimensions...
3670 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
3671 name
[dimptr
- sizeptr
- 1] = '\0';
3679 * 'pwg_compare_finishings()' - Compare two finishings values.
3682 static int /* O- Result of comparison */
3683 pwg_compare_finishings(
3684 _pwg_finishings_t
*a
, /* I - First finishings value */
3685 _pwg_finishings_t
*b
) /* I - Second finishings value */
3687 return ((int)b
->value
- (int)a
->value
);
3692 * 'pwg_free_finishings()' - Free a finishings value.
3696 pwg_free_finishings(
3697 _pwg_finishings_t
*f
) /* I - Finishings value */
3699 cupsFreeOptions(f
->num_options
, f
->options
);
3705 * 'pwg_free_material()' - Free a material value.
3709 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
3711 _cupsStrFree(m
->key
);
3712 _cupsStrFree(m
->name
);
3714 cupsFreeOptions(m
->num_props
, m
->props
);
3721 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
3725 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
3726 char *name
, /* I - Name buffer */
3727 size_t namesize
) /* I - Size of name buffer */
3729 char *ptr
, /* Pointer into name buffer */
3730 *end
; /* End of name buffer */
3733 *name
= (char)toupper(*ipp
++);
3735 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
3737 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
3740 *ptr
++ = (char)toupper(*ipp
++ & 255);
3751 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
3755 pwg_ppdize_resolution(
3756 ipp_attribute_t
*attr
, /* I - Attribute to convert */
3757 int element
, /* I - Element to convert */
3758 int *xres
, /* O - X resolution in DPI */
3759 int *yres
, /* O - Y resolution in DPI */
3760 char *name
, /* I - Name buffer */
3761 size_t namesize
) /* I - Size of name buffer */
3763 ipp_res_t units
; /* Units for resolution */
3766 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
3768 if (units
== IPP_RES_PER_CM
)
3770 *xres
= (int)(*xres
* 2.54);
3771 *yres
= (int)(*yres
* 2.54);
3774 if (name
&& namesize
> 4)
3777 snprintf(name
, namesize
, "%ddpi", *xres
);
3779 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
3785 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
3789 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
3790 char *name
, /* I - Name buffer */
3791 size_t namesize
, /* I - Size of name buffer */
3792 const char *dashchars
)/* I - Characters to be replaced by dashes */
3794 char *ptr
, /* Pointer into name buffer */
3795 *end
; /* End of name buffer */
3798 if (_cups_islower(*ppd
))
3801 * Already lowercase name, use as-is?
3804 const char *ppdptr
; /* Pointer into PPD keyword */
3806 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
3807 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
3812 strlcpy(name
, ppd
, namesize
);
3817 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
3819 if (_cups_isalnum(*ppd
) || *ppd
== '-')
3820 *ptr
++ = (char)tolower(*ppd
& 255);
3821 else if (strchr(dashchars
, *ppd
))
3826 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
3827 _cups_isupper(ppd
[1]) && ptr
< end
)
3829 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))