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"
26 * Macro to test for two almost-equal PWG measurements.
29 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
36 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
37 _pwg_finishings_t
*b
);
38 static void pwg_free_finishings(_pwg_finishings_t
*f
);
39 static void pwg_free_material(_pwg_material_t
*m
);
40 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
41 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
42 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
43 const char *dashchars
);
47 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
49 * This functions converts PPD and CUPS-specific options to their standard IPP
50 * attributes and values and adds them to the specified IPP request.
53 int /* O - New number of copies */
54 _cupsConvertOptions(ipp_t
*request
, /* I - IPP request */
55 ppd_file_t
*ppd
, /* I - PPD file */
56 _ppd_cache_t
*pc
, /* I - PPD cache info */
57 ipp_attribute_t
*media_col_sup
,
58 /* I - media-col-supported values */
59 ipp_attribute_t
*doc_handling_sup
,
60 /* I - multiple-document-handling-supported values */
61 ipp_attribute_t
*print_color_mode_sup
,
62 /* I - Printer supports print-color-mode */
63 const char *user
, /* I - User info */
64 const char *format
, /* I - document-format value */
65 int copies
, /* I - Number of copies */
66 int num_options
, /* I - Number of options */
67 cups_option_t
*options
) /* I - Options */
69 int i
; /* Looping var */
70 const char *keyword
, /* PWG keyword */
71 *password
; /* Password string */
72 pwg_size_t
*size
; /* PWG media size */
73 ipp_t
*media_col
, /* media-col value */
74 *media_size
; /* media-size value */
75 const char *media_source
, /* media-source value */
76 *media_type
, /* media-type value */
77 *collate_str
, /* multiple-document-handling value */
78 *color_attr_name
, /* Supported color attribute */
79 *mandatory
; /* Mandatory attributes */
80 int num_finishings
= 0, /* Number of finishing values */
81 finishings
[10]; /* Finishing enum values */
82 ppd_choice_t
*choice
; /* Marked choice */
86 * Send standard IPP attributes...
89 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
91 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
93 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
96 if (!strcmp(keyword
, "none"))
99 * Add plain-text job-password...
102 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
107 * Add hashed job-password...
110 unsigned char hash
[64]; /* Hash of password */
111 ssize_t hashlen
; /* Length of hash */
113 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
114 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
118 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
123 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
124 keyword
= cupsGetOption("job-billing", num_options
, options
);
127 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
130 if (pc
->accounting_user_id
)
132 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
136 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
139 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
141 if (strcmp(mandatory
, "copies") &&
142 strcmp(mandatory
, "destination-uris") &&
143 strcmp(mandatory
, "finishings") &&
144 strcmp(mandatory
, "job-account-id") &&
145 strcmp(mandatory
, "job-accounting-user-id") &&
146 strcmp(mandatory
, "job-password") &&
147 strcmp(mandatory
, "job-password-encryption") &&
148 strcmp(mandatory
, "media") &&
149 strncmp(mandatory
, "media-col", 9) &&
150 strcmp(mandatory
, "multiple-document-handling") &&
151 strcmp(mandatory
, "output-bin") &&
152 strcmp(mandatory
, "print-color-mode") &&
153 strcmp(mandatory
, "print-quality") &&
154 strcmp(mandatory
, "sides") &&
155 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
157 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
159 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
164 case IPP_TAG_INTEGER
:
166 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
168 case IPP_TAG_BOOLEAN
:
169 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
173 int lower
, upper
; /* Range */
175 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
176 lower
= upper
= atoi(keyword
);
178 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
181 case IPP_TAG_STRING
:
182 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
185 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
187 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
188 keyword
= "auto-monochrome";
189 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
190 keyword
= "process-monochrome";
193 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
199 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
200 keyword
= cupsGetOption("media", num_options
, options
);
202 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
205 * Add a media-col value...
208 media_size
= ippNew();
209 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
210 "x-dimension", size
->width
);
211 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
212 "y-dimension", size
->length
);
214 media_col
= ippNew();
215 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
217 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
220 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
224 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
226 if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
227 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
228 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
229 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
230 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
231 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
232 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
233 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
234 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
235 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
236 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && media_type
)
237 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
240 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
243 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
245 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
246 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
250 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
252 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
254 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
256 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
258 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
259 keyword
= "monochrome";
265 if (keyword
&& !strcmp(keyword
, "monochrome"))
267 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
268 keyword
= "auto-monochrome";
269 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
270 keyword
= "process-monochrome";
274 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
276 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
277 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
278 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
280 if (!_cups_strcasecmp(choice
->choice
, "draft"))
281 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
282 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
283 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
284 else if (!_cups_strcasecmp(choice
->choice
, "high"))
285 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
288 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
289 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
290 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
292 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
293 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
294 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
295 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
296 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
297 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
304 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
306 if (strstr(keyword
, "uncollated"))
311 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
316 if (!_cups_strcasecmp(format
, "image/gif") ||
317 !_cups_strcasecmp(format
, "image/jp2") ||
318 !_cups_strcasecmp(format
, "image/jpeg") ||
319 !_cups_strcasecmp(format
, "image/png") ||
320 !_cups_strcasecmp(format
, "image/tiff") ||
321 !_cups_strncasecmp(format
, "image/x-", 8))
324 * Collation makes no sense for single page image formats...
329 else if (!_cups_strncasecmp(format
, "image/", 6) ||
330 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
333 * Multi-page image formats will have copies applied by the upstream
341 if (doc_handling_sup
)
343 if (!_cups_strcasecmp(keyword
, "true"))
344 collate_str
= "separate-documents-collated-copies";
346 collate_str
= "separate-documents-uncollated-copies";
348 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
350 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
352 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
357 if (i
>= doc_handling_sup
->num_values
)
362 * Map finishing options...
365 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
366 if (num_finishings
> 0)
368 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
370 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
373 * Send job-pages-per-set attribute to apply finishings correctly...
376 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
385 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
388 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
392 _ppd_cache_t
* /* O - PPD cache and mapping data */
393 _ppdCacheCreateWithFile(
394 const char *filename
, /* I - File to read */
395 ipp_t
**attrs
) /* IO - IPP attributes, if any */
397 cups_file_t
*fp
; /* File */
398 _ppd_cache_t
*pc
; /* PWG mapping data */
399 pwg_size_t
*size
; /* Current size */
400 pwg_map_t
*map
; /* Current map */
401 _pwg_finishings_t
*finishings
; /* Current finishings option */
402 int linenum
, /* Current line number */
403 num_bins
, /* Number of bins in file */
404 num_sizes
, /* Number of sizes in file */
405 num_sources
, /* Number of sources in file */
406 num_types
; /* Number of types in file */
407 char line
[2048], /* Current line */
408 *value
, /* Pointer to value in line */
409 *valueptr
, /* Pointer into value */
410 pwg_keyword
[128], /* PWG keyword */
411 ppd_keyword
[PPD_MAX_NAME
];
413 _pwg_print_color_mode_t print_color_mode
;
414 /* Print color mode for preset */
415 _pwg_print_quality_t print_quality
; /* Print quality for preset */
418 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
421 * Range check input...
429 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
437 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
439 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
444 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
447 if (!cupsFileGets(fp
, line
, sizeof(line
)))
449 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
450 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
455 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
457 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
458 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
463 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
465 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
466 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
467 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
473 * Allocate the mapping data structure...
476 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
478 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
479 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
483 pc
->max_copies
= 9999;
495 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
497 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
498 "linenum=%d", line
, value
, linenum
));
502 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
507 else if (!_cups_strcasecmp(line
, "3D"))
509 pc
->cups_3d
= _cupsStrAlloc(value
);
511 else if (!_cups_strcasecmp(line
, "LayerOrder"))
513 pc
->cups_layer_order
= _cupsStrAlloc(value
);
515 else if (!_cups_strcasecmp(line
, "Accuracy"))
517 sscanf(value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
519 else if (!_cups_strcasecmp(line
, "Volume"))
521 sscanf(value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
523 else if (!_cups_strcasecmp(line
, "Material"))
526 * Material key "name" name=value ... name=value
529 if ((valueptr
= strchr(value
, ' ')) != NULL
)
531 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
535 material
->key
= _cupsStrAlloc(value
);
537 if (*valueptr
== '\"')
539 value
= valueptr
+ 1;
540 if ((valueptr
= strchr(value
, '\"')) != NULL
)
543 material
->name
= _cupsStrAlloc(value
);
544 material
->num_props
= cupsParseOptions(valueptr
, 0, &material
->props
);
549 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
551 cupsArrayAdd(pc
->materials
, material
);
554 else if (!_cups_strcasecmp(line
, "Filter"))
557 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
558 (cups_acopy_func_t
)_cupsStrAlloc
,
559 (cups_afree_func_t
)_cupsStrFree
);
561 cupsArrayAdd(pc
->filters
, value
);
563 else if (!_cups_strcasecmp(line
, "PreFilter"))
566 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
567 (cups_acopy_func_t
)_cupsStrAlloc
,
568 (cups_afree_func_t
)_cupsStrFree
);
570 cupsArrayAdd(pc
->prefilters
, value
);
572 else if (!_cups_strcasecmp(line
, "Product"))
574 pc
->product
= _cupsStrAlloc(value
);
576 else if (!_cups_strcasecmp(line
, "SingleFile"))
578 pc
->single_file
= !_cups_strcasecmp(value
, "true");
580 else if (!_cups_strcasecmp(line
, "IPP"))
582 off_t pos
= cupsFileTell(fp
), /* Position in file */
583 length
= strtol(value
, NULL
, 10);
584 /* Length of IPP attributes */
588 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
592 else if (length
<= 0)
594 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
595 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
602 * Read IPP attributes into the provided variable...
607 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
608 *attrs
) != IPP_STATE_DATA
)
610 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
611 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
618 * Skip the IPP data entirely...
621 cupsFileSeek(fp
, pos
+ length
);
624 if (cupsFileTell(fp
) != (pos
+ length
))
626 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
627 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
631 else if (!_cups_strcasecmp(line
, "NumBins"))
635 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
636 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
640 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
642 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
643 "%d.", num_sizes
, linenum
));
644 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
648 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
650 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
652 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
656 else if (!_cups_strcasecmp(line
, "Bin"))
658 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
660 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 if (pc
->num_bins
>= num_bins
)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 map
= pc
->bins
+ pc
->num_bins
;
674 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
675 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
679 else if (!_cups_strcasecmp(line
, "NumSizes"))
683 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
684 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
688 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
690 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
691 "%d.", num_sizes
, linenum
));
692 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
698 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
700 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
702 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
707 else if (!_cups_strcasecmp(line
, "Size"))
709 if (pc
->num_sizes
>= num_sizes
)
711 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
713 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
717 size
= pc
->sizes
+ pc
->num_sizes
;
719 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
720 &(size
->width
), &(size
->length
), &(size
->left
),
721 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
723 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
725 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
729 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
730 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
734 else if (!_cups_strcasecmp(line
, "CustomSize"))
736 if (pc
->custom_max_width
> 0)
738 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
740 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
744 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
745 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
746 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
747 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
748 &(pc
->custom_size
.top
)) != 8)
750 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
757 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
758 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
760 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
761 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
762 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
764 else if (!_cups_strcasecmp(line
, "SourceOption"))
766 pc
->source_option
= _cupsStrAlloc(value
);
768 else if (!_cups_strcasecmp(line
, "NumSources"))
772 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
774 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
778 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
780 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
781 "line %d.", num_sources
, linenum
));
782 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
786 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
788 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
790 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
794 else if (!_cups_strcasecmp(line
, "Source"))
796 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
798 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
800 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
804 if (pc
->num_sources
>= num_sources
)
806 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
808 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
812 map
= pc
->sources
+ pc
->num_sources
;
813 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
814 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
818 else if (!_cups_strcasecmp(line
, "NumTypes"))
822 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
823 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
827 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
829 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
830 "line %d.", num_types
, linenum
));
831 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
835 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
837 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
839 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
843 else if (!_cups_strcasecmp(line
, "Type"))
845 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
847 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
849 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
853 if (pc
->num_types
>= num_types
)
855 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
857 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
861 map
= pc
->types
+ pc
->num_types
;
862 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
863 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
867 else if (!_cups_strcasecmp(line
, "Preset"))
870 * Preset output-mode print-quality name=value ...
873 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
874 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
876 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
877 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
878 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
879 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
880 valueptr
== value
|| !*valueptr
)
882 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
884 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
888 pc
->num_presets
[print_color_mode
][print_quality
] =
889 cupsParseOptions(valueptr
, 0,
890 pc
->presets
[print_color_mode
] + print_quality
);
892 else if (!_cups_strcasecmp(line
, "SidesOption"))
893 pc
->sides_option
= _cupsStrAlloc(value
);
894 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
895 pc
->sides_1sided
= _cupsStrAlloc(value
);
896 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
897 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
898 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
899 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
900 else if (!_cups_strcasecmp(line
, "Finishings"))
904 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
906 (cups_afree_func_t
)pwg_free_finishings
);
908 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
911 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
912 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
913 &(finishings
->options
));
915 cupsArrayAdd(pc
->finishings
, finishings
);
917 else if (!_cups_strcasecmp(line
, "MaxCopies"))
918 pc
->max_copies
= atoi(value
);
919 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
920 pc
->charge_info_uri
= _cupsStrAlloc(value
);
921 else if (!_cups_strcasecmp(line
, "JobAccountId"))
922 pc
->account_id
= !_cups_strcasecmp(value
, "true");
923 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
924 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
925 else if (!_cups_strcasecmp(line
, "JobPassword"))
926 pc
->password
= _cupsStrAlloc(value
);
927 else if (!_cups_strcasecmp(line
, "Mandatory"))
930 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
932 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
934 else if (!_cups_strcasecmp(line
, "SupportFile"))
936 if (!pc
->support_files
)
937 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
938 (cups_acopy_func_t
)_cupsStrAlloc
,
939 (cups_afree_func_t
)_cupsStrFree
);
941 cupsArrayAdd(pc
->support_files
, value
);
945 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
950 if (pc
->num_sizes
< num_sizes
)
952 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
953 pc
->num_sizes
, num_sizes
));
954 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
958 if (pc
->num_sources
< num_sources
)
960 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
961 pc
->num_sources
, num_sources
));
962 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
966 if (pc
->num_types
< num_types
)
968 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
969 pc
->num_types
, num_types
));
970 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
979 * If we get here the file was bad - free any data and return...
985 _ppdCacheDestroy(pc
);
998 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
1001 _ppd_cache_t
* /* O - PPD cache and mapping data */
1002 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
1004 int i
, j
, k
; /* Looping vars */
1005 _ppd_cache_t
*pc
; /* PWG mapping data */
1006 ppd_option_t
*input_slot
, /* InputSlot option */
1007 *media_type
, /* MediaType option */
1008 *output_bin
, /* OutputBin option */
1009 *color_model
, /* ColorModel option */
1010 *duplex
; /* Duplex option */
1011 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
1012 pwg_map_t
*map
; /* Current source/type map */
1013 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
1014 int num_options
; /* Number of preset options and props */
1015 cups_option_t
*options
; /* Preset options and properties */
1016 ppd_size_t
*ppd_size
; /* Current PPD size */
1017 pwg_size_t
*pwg_size
; /* Current PWG size */
1018 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1019 /* PWG keyword string */
1020 ppd_name
[PPD_MAX_NAME
];
1021 /* Normalized PPD name */
1022 const char *pwg_name
; /* Standard PWG media name */
1023 pwg_media_t
*pwg_media
; /* PWG media data */
1024 _pwg_print_color_mode_t pwg_print_color_mode
;
1025 /* print-color-mode index */
1026 _pwg_print_quality_t pwg_print_quality
;
1027 /* print-quality index */
1028 int similar
; /* Are the old and new size similar? */
1029 pwg_size_t
*old_size
; /* Current old size */
1030 int old_imageable
, /* Old imageable length in 2540ths */
1031 old_borderless
, /* Old borderless state */
1032 old_known_pwg
; /* Old PWG name is well-known */
1033 int new_width
, /* New width in 2540ths */
1034 new_length
, /* New length in 2540ths */
1035 new_left
, /* New left margin in 2540ths */
1036 new_bottom
, /* New bottom margin in 2540ths */
1037 new_right
, /* New right margin in 2540ths */
1038 new_top
, /* New top margin in 2540ths */
1039 new_imageable
, /* New imageable length in 2540ths */
1040 new_borderless
, /* New borderless state */
1041 new_known_pwg
; /* New PWG name is well-known */
1042 pwg_size_t
*new_size
; /* New size to add, if any */
1043 const char *filter
; /* Current filter */
1044 _pwg_finishings_t
*finishings
; /* Current finishings value */
1047 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1050 * Range check input...
1057 * Allocate memory...
1060 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1062 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1067 * Copy and convert size data...
1070 if (ppd
->num_sizes
> 0)
1072 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1074 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1075 "pwg_size_t's.", ppd
->num_sizes
));
1079 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1084 * Don't copy over custom size...
1087 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1091 * Convert the PPD size name to the corresponding PWG keyword name.
1094 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1097 * Standard name, do we have conflicts?
1100 for (j
= 0; j
< pc
->num_sizes
; j
++)
1101 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1111 * Standard name and no conflicts, use it!
1114 pwg_name
= pwg_media
->pwg
;
1120 * Not a standard name; convert it to a PWG vendor name of the form:
1122 * pp_lowerppd_WIDTHxHEIGHTuu
1125 pwg_name
= pwg_keyword
;
1128 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1129 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1130 PWG_FROM_POINTS(ppd_size
->width
),
1131 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1135 * If we have a similar paper with non-zero margins then we only want to
1136 * keep it if it has a larger imageable area length. The NULL check is for
1137 * dimensions that are <= 0...
1140 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1141 PWG_FROM_POINTS(ppd_size
->length
),
1145 new_width
= pwg_media
->width
;
1146 new_length
= pwg_media
->length
;
1147 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1148 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1149 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1150 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1151 new_imageable
= new_length
- new_top
- new_bottom
;
1152 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1153 new_left
== 0 && new_right
== 0;
1155 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1159 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1160 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1161 old_size
->right
== 0 && old_size
->top
== 0;
1162 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1163 strncmp(old_size
->map
.pwg
, "om_", 3);
1165 similar
= old_borderless
== new_borderless
&&
1166 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1167 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1170 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1173 * The new paper has a larger imageable area so it could replace
1174 * the older paper. Regardless of the imageable area, we always
1175 * prefer the size with a well-known PWG name.
1178 new_size
= old_size
;
1179 _cupsStrFree(old_size
->map
.ppd
);
1180 _cupsStrFree(old_size
->map
.pwg
);
1187 * The paper was unique enough to deserve its own entry so add it to the
1191 new_size
= pwg_size
++;
1201 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1202 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1203 new_size
->width
= new_width
;
1204 new_size
->length
= new_length
;
1205 new_size
->left
= new_left
;
1206 new_size
->bottom
= new_bottom
;
1207 new_size
->right
= new_right
;
1208 new_size
->top
= new_top
;
1213 if (ppd
->variable_sizes
)
1216 * Generate custom size data...
1219 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1220 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1221 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1222 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1223 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1224 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1226 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1227 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1228 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1229 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1230 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1231 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1233 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1234 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1235 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1236 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1240 * Copy and convert InputSlot data...
1243 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1244 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1248 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1250 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1252 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1253 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1257 pc
->num_sources
= input_slot
->num_choices
;
1259 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1262 i
--, choice
++, map
++)
1264 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1265 !_cups_strcasecmp(choice
->choice
, "Default"))
1267 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1269 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1271 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1273 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1274 !_cups_strcasecmp(choice
->choice
, "MP") ||
1275 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1276 pwg_name
= "by-pass-tray";
1277 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1278 pwg_name
= "large-capacity";
1279 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1280 pwg_name
= "bottom";
1281 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1282 pwg_name
= "middle";
1283 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1285 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1287 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1288 pwg_name
= "main-roll";
1292 * Convert PPD name to lowercase...
1295 pwg_name
= pwg_keyword
;
1296 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1300 map
->pwg
= _cupsStrAlloc(pwg_name
);
1301 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1306 * Copy and convert MediaType data...
1309 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1311 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1313 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1314 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1318 pc
->num_types
= media_type
->num_choices
;
1320 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1323 i
--, choice
++, map
++)
1325 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1326 !_cups_strcasecmp(choice
->choice
, "Any") ||
1327 !_cups_strcasecmp(choice
->choice
, "Default"))
1329 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1330 pwg_name
= "cardstock";
1331 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1332 pwg_name
= "envelope";
1333 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1334 pwg_name
= "photographic-glossy";
1335 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1336 pwg_name
= "photographic-high-gloss";
1337 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1338 pwg_name
= "photographic-matte";
1339 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1340 pwg_name
= "stationery";
1341 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1342 pwg_name
= "stationery-coated";
1343 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1344 pwg_name
= "stationery-inkjet";
1345 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1346 pwg_name
= "stationery-letterhead";
1347 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1348 pwg_name
= "stationery-preprinted";
1349 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1350 pwg_name
= "stationery-recycled";
1351 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1352 pwg_name
= "transparency";
1356 * Convert PPD name to lowercase...
1359 pwg_name
= pwg_keyword
;
1360 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1364 map
->pwg
= _cupsStrAlloc(pwg_name
);
1365 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1370 * Copy and convert OutputBin data...
1373 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1375 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1377 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1378 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1382 pc
->num_bins
= output_bin
->num_choices
;
1384 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1387 i
--, choice
++, map
++)
1389 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1391 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1392 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1396 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1399 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1402 const char *quality
, /* com.apple.print.preset.quality value */
1403 *output_mode
, /* com.apple.print.preset.output-mode value */
1404 *color_model_val
, /* ColorModel choice */
1405 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1406 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1410 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1413 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1414 num_options
, options
)) != NULL
)
1417 * Get the print-quality for this preset...
1420 if (!strcmp(quality
, "low"))
1421 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1422 else if (!strcmp(quality
, "high"))
1423 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1425 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1428 * Ignore graphicsType "Photo" presets that are not high quality.
1431 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1432 num_options
, options
);
1434 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1435 !strcmp(graphicsType
, "Photo"))
1439 * Ignore presets for normal and draft quality where the coating
1440 * isn't "none" or "autodetect".
1443 media_front_coating
= cupsGetOption(
1444 "com.apple.print.preset.media-front-coating",
1445 num_options
, options
);
1447 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1448 media_front_coating
&&
1449 strcmp(media_front_coating
, "none") &&
1450 strcmp(media_front_coating
, "autodetect"))
1454 * Get the output mode for this preset...
1457 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1458 num_options
, options
);
1459 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1463 if (!strcmp(output_mode
, "monochrome"))
1464 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1466 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1468 else if (color_model_val
)
1470 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1471 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1473 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1476 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1479 * Save the options for this combination as needed...
1482 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1483 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1484 _ppdParseOptions(ppd_attr
->value
, 0,
1485 pc
->presets
[pwg_print_color_mode
] +
1486 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1489 cupsFreeOptions(num_options
, options
);
1491 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1494 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1495 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1496 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1499 * Try adding some common color options to create grayscale presets. These
1500 * are listed in order of popularity...
1503 const char *color_option
= NULL
, /* Color control option */
1504 *gray_choice
= NULL
; /* Choice to select grayscale */
1506 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1507 ppdFindChoice(color_model
, "Gray"))
1509 color_option
= "ColorModel";
1510 gray_choice
= "Gray";
1512 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1513 ppdFindChoice(color_model
, "grayscale"))
1515 color_option
= "HPColorMode";
1516 gray_choice
= "grayscale";
1518 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1519 ppdFindChoice(color_model
, "Mono"))
1521 color_option
= "BRMonoColor";
1522 gray_choice
= "Mono";
1524 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1525 ppdFindChoice(color_model
, "1"))
1527 color_option
= "CNIJSGrayScale";
1530 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1531 ppdFindChoice(color_model
, "True"))
1533 color_option
= "HPColorAsGray";
1534 gray_choice
= "True";
1537 if (color_option
&& gray_choice
)
1540 * Copy and convert ColorModel (output-mode) data...
1543 cups_option_t
*coption
, /* Color option */
1544 *moption
; /* Monochrome option */
1546 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1547 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1548 pwg_print_quality
++)
1550 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1553 * Copy the color options...
1556 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1557 [pwg_print_quality
];
1558 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1562 for (i
= num_options
, moption
= options
,
1563 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1564 [pwg_print_quality
];
1566 i
--, moption
++, coption
++)
1568 moption
->name
= _cupsStrRetain(coption
->name
);
1569 moption
->value
= _cupsStrRetain(coption
->value
);
1572 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1574 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1578 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1582 * Add the grayscale option to the preset...
1585 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1586 cupsAddOption(color_option
, gray_choice
,
1587 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1588 [pwg_print_quality
],
1589 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1596 * Copy and convert Duplex (sides) data...
1599 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1600 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1601 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1602 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1603 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1607 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1609 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1613 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1614 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1615 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1616 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1617 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1618 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1619 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1620 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1621 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1622 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1623 !pc
->sides_2sided_short
)
1624 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1629 * Copy filters and pre-filters...
1632 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1633 (cups_acopy_func_t
)_cupsStrAlloc
,
1634 (cups_afree_func_t
)_cupsStrFree
);
1636 cupsArrayAdd(pc
->filters
,
1637 "application/vnd.cups-raw application/octet-stream 0 -");
1639 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1643 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1645 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1647 else if (ppd
->num_filters
> 0)
1649 for (i
= 0; i
< ppd
->num_filters
; i
++)
1650 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1653 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1656 * See if we have a command filter...
1659 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1661 filter
= (const char *)cupsArrayNext(pc
->filters
))
1662 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1663 _cups_isspace(filter
[28]))
1667 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1668 _cups_strcasecmp(ppd_attr
->value
, "none")))
1671 * No command filter and no cupsCommands keyword telling us not to use one.
1672 * See if this is a PostScript printer, and if so add a PostScript command
1676 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1678 filter
= (const char *)cupsArrayNext(pc
->filters
))
1679 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1680 _cups_isspace(filter
[31]))
1684 cupsArrayAdd(pc
->filters
,
1685 "application/vnd.cups-command application/postscript 100 "
1689 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1691 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1692 (cups_acopy_func_t
)_cupsStrAlloc
,
1693 (cups_afree_func_t
)_cupsStrFree
);
1697 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1699 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1702 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1703 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1706 * Copy the product string, if any...
1710 pc
->product
= _cupsStrAlloc(ppd
->product
);
1713 * Copy finishings mapping data...
1716 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1718 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1719 NULL
, NULL
, 0, NULL
,
1720 (cups_afree_func_t
)pwg_free_finishings
);
1724 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1727 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1728 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1729 &(finishings
->options
),
1730 _PPD_PARSE_OPTIONS
);
1732 cupsArrayAdd(pc
->finishings
, finishings
);
1734 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1742 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1743 pc
->max_copies
= atoi(ppd_attr
->value
);
1744 else if (ppd
->manual_copies
)
1747 pc
->max_copies
= 9999;
1750 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1751 * cupsJobPassword, and cupsMandatory.
1754 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1755 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1757 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1758 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1760 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1761 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1763 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1764 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1766 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1767 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1773 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1774 (cups_acopy_func_t
)_cupsStrAlloc
,
1775 (cups_afree_func_t
)_cupsStrFree
);
1777 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1779 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1780 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1782 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1783 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1789 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1790 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1792 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1793 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1795 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1796 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1798 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1799 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1801 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1803 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1806 * *cupsMaterial key/name: "name=value ... name=value"
1809 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1811 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1812 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1813 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1816 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1818 cupsArrayAdd(pc
->materials
, material
);
1822 * Return the cache data...
1828 * If we get here we need to destroy the PWG mapping data and return NULL...
1833 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1834 _ppdCacheDestroy(pc
);
1841 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1845 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1847 int i
; /* Looping var */
1848 pwg_map_t
*map
; /* Current map */
1849 pwg_size_t
*size
; /* Current size */
1853 * Range check input...
1860 * Free memory as needed...
1865 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1867 _cupsStrFree(map
->pwg
);
1868 _cupsStrFree(map
->ppd
);
1876 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1878 _cupsStrFree(size
->map
.pwg
);
1879 _cupsStrFree(size
->map
.ppd
);
1885 if (pc
->source_option
)
1886 _cupsStrFree(pc
->source_option
);
1890 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1892 _cupsStrFree(map
->pwg
);
1893 _cupsStrFree(map
->ppd
);
1901 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1903 _cupsStrFree(map
->pwg
);
1904 _cupsStrFree(map
->ppd
);
1910 if (pc
->custom_max_keyword
)
1911 _cupsStrFree(pc
->custom_max_keyword
);
1913 if (pc
->custom_min_keyword
)
1914 _cupsStrFree(pc
->custom_min_keyword
);
1916 _cupsStrFree(pc
->product
);
1917 cupsArrayDelete(pc
->filters
);
1918 cupsArrayDelete(pc
->prefilters
);
1919 cupsArrayDelete(pc
->finishings
);
1921 _cupsStrFree(pc
->charge_info_uri
);
1922 _cupsStrFree(pc
->password
);
1924 cupsArrayDelete(pc
->mandatory
);
1926 cupsArrayDelete(pc
->support_files
);
1928 _cupsStrFree(pc
->cups_3d
);
1929 _cupsStrFree(pc
->cups_layer_order
);
1931 cupsArrayDelete(pc
->materials
);
1938 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1942 const char * /* O - output-bin or NULL */
1944 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1945 const char *output_bin
) /* I - PPD OutputBin string */
1947 int i
; /* Looping var */
1951 * Range check input...
1954 if (!pc
|| !output_bin
)
1958 * Look up the OutputBin string...
1962 for (i
= 0; i
< pc
->num_bins
; i
++)
1963 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1964 return (pc
->bins
[i
].pwg
);
1971 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1972 * IPP finishings value(s).
1975 int /* O - New number of options */
1976 _ppdCacheGetFinishingOptions(
1977 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1978 ipp_t
*job
, /* I - Job attributes or NULL */
1979 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1980 int num_options
, /* I - Number of options */
1981 cups_option_t
**options
) /* IO - Options */
1983 int i
; /* Looping var */
1984 _pwg_finishings_t
*f
, /* PWG finishings options */
1985 key
; /* Search key */
1986 ipp_attribute_t
*attr
; /* Finishings attribute */
1987 cups_option_t
*option
; /* Current finishings option */
1991 * Range check input...
1994 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1995 (!job
&& value
== IPP_FINISHINGS_NONE
))
1996 return (num_options
);
1999 * Apply finishing options...
2002 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2004 int num_values
= ippGetCount(attr
); /* Number of values */
2006 for (i
= 0; i
< num_values
; i
++)
2008 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2010 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2012 int j
; /* Another looping var */
2014 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2015 num_options
= cupsAddOption(option
->name
, option
->value
,
2016 num_options
, options
);
2020 else if (value
!= IPP_FINISHINGS_NONE
)
2024 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2026 int j
; /* Another looping var */
2028 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2029 num_options
= cupsAddOption(option
->name
, option
->value
,
2030 num_options
, options
);
2034 return (num_options
);
2039 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2043 int /* O - Number of finishings values */
2044 _ppdCacheGetFinishingValues(
2045 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2046 int num_options
, /* I - Number of options */
2047 cups_option_t
*options
, /* I - Options */
2048 int max_values
, /* I - Maximum number of finishings values */
2049 int *values
) /* O - Finishings values */
2051 int i
, /* Looping var */
2052 num_values
= 0; /* Number of values */
2053 _pwg_finishings_t
*f
; /* Current finishings option */
2054 cups_option_t
*option
; /* Current option */
2055 const char *val
; /* Value for option */
2059 * Range check input...
2062 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2064 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2066 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2071 * Go through the finishings options and see what is set...
2074 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2076 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2078 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2080 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2082 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2084 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2085 _cups_strcasecmp(option
->value
, val
))
2087 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2094 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2096 values
[num_values
++] = f
->value
;
2098 if (num_values
>= max_values
)
2103 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2105 return (num_values
);
2110 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2111 * attributes or a keyword string.
2114 const char * /* O - PPD InputSlot or NULL */
2115 _ppdCacheGetInputSlot(
2116 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2117 ipp_t
*job
, /* I - Job attributes or NULL */
2118 const char *keyword
) /* I - Keyword string or NULL */
2121 * Range check input...
2124 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2127 if (job
&& !keyword
)
2130 * Lookup the media-col attribute and any media-source found there...
2133 ipp_attribute_t
*media_col
, /* media-col attribute */
2134 *media_source
; /* media-source attribute */
2135 pwg_size_t size
; /* Dimensional size */
2136 int margins_set
; /* Were the margins set? */
2138 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2140 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2142 IPP_TAG_KEYWORD
)) != NULL
)
2145 * Use the media-source value from media-col...
2148 keyword
= ippGetString(media_source
, 0, NULL
);
2150 else if (pwgInitSize(&size
, job
, &margins_set
))
2153 * For media <= 5x7, look for a photo tray...
2156 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2163 int i
; /* Looping var */
2165 for (i
= 0; i
< pc
->num_sources
; i
++)
2166 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2167 return (pc
->sources
[i
].ppd
);
2175 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2176 * attributes or a keyword string.
2179 const char * /* O - PPD MediaType or NULL */
2180 _ppdCacheGetMediaType(
2181 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2182 ipp_t
*job
, /* I - Job attributes or NULL */
2183 const char *keyword
) /* I - Keyword string or NULL */
2186 * Range check input...
2189 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2192 if (job
&& !keyword
)
2195 * Lookup the media-col attribute and any media-source found there...
2198 ipp_attribute_t
*media_col
, /* media-col attribute */
2199 *media_type
; /* media-type attribute */
2201 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2204 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2206 IPP_TAG_KEYWORD
)) == NULL
)
2207 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2208 "media-type", IPP_TAG_NAME
);
2211 keyword
= media_type
->values
[0].string
.text
;
2217 int i
; /* Looping var */
2219 for (i
= 0; i
< pc
->num_types
; i
++)
2220 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2221 return (pc
->types
[i
].ppd
);
2229 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2233 const char * /* O - PPD OutputBin or NULL */
2234 _ppdCacheGetOutputBin(
2235 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2236 const char *output_bin
) /* I - Keyword string */
2238 int i
; /* Looping var */
2242 * Range check input...
2245 if (!pc
|| !output_bin
)
2249 * Look up the OutputBin string...
2253 for (i
= 0; i
< pc
->num_bins
; i
++)
2254 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2255 return (pc
->bins
[i
].ppd
);
2262 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2263 * attributes or a keyword string.
2266 const char * /* O - PPD PageSize or NULL */
2267 _ppdCacheGetPageSize(
2268 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2269 ipp_t
*job
, /* I - Job attributes or NULL */
2270 const char *keyword
, /* I - Keyword string or NULL */
2271 int *exact
) /* O - 1 if exact match, 0 otherwise */
2273 int i
; /* Looping var */
2274 pwg_size_t
*size
, /* Current size */
2275 *closest
, /* Closest size */
2276 jobsize
; /* Size data from job */
2277 int margins_set
, /* Were the margins set? */
2278 dwidth
, /* Difference in width */
2279 dlength
, /* Difference in length */
2280 dleft
, /* Difference in left margins */
2281 dright
, /* Difference in right margins */
2282 dbottom
, /* Difference in bottom margins */
2283 dtop
, /* Difference in top margins */
2284 dmin
, /* Minimum difference */
2285 dclosest
; /* Closest difference */
2286 const char *ppd_name
; /* PPD media name */
2289 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2290 pc
, job
, keyword
, exact
));
2293 * Range check input...
2296 if (!pc
|| (!job
&& !keyword
))
2307 * Try getting the PPD media name from the job attributes...
2310 ipp_attribute_t
*attr
; /* Job attribute */
2312 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2313 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2314 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2318 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2319 attr
->name
, ippTagString(attr
->value_tag
)));
2321 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2324 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2325 attr
->value_tag
== IPP_TAG_KEYWORD
))
2326 ppd_name
= attr
->values
[0].string
.text
;
2329 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2334 * Try looking up the named PPD size first...
2337 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2339 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2340 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2342 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2343 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2348 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2350 return (size
->map
.ppd
);
2355 if (job
&& !keyword
)
2358 * Get the size using media-col or media, with the preference being
2362 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2368 * Get the size using a media keyword...
2371 pwg_media_t
*media
; /* Media definition */
2374 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2375 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2376 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2379 jobsize
.width
= media
->width
;
2380 jobsize
.length
= media
->length
;
2385 * Now that we have the dimensions and possibly the margins, look at the
2386 * available sizes and find the match...
2390 dclosest
= 999999999;
2392 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2393 _cups_strncasecmp(ppd_name
, "custom_", 7))
2395 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2398 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2399 * is just about 176/2540ths...
2402 dwidth
= size
->width
- jobsize
.width
;
2403 dlength
= size
->length
- jobsize
.length
;
2405 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2411 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2414 dleft
= size
->left
- jobsize
.left
;
2415 dright
= size
->right
- jobsize
.right
;
2416 dtop
= size
->top
- jobsize
.top
;
2417 dbottom
= size
->bottom
- jobsize
.bottom
;
2419 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2420 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2422 dleft
= dleft
< 0 ? -dleft
: dleft
;
2423 dright
= dright
< 0 ? -dright
: dright
;
2424 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2425 dtop
= dtop
< 0 ? -dtop
: dtop
;
2426 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2428 if (dmin
< dclosest
)
2441 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2443 return (size
->map
.ppd
);
2449 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2452 return (closest
->map
.ppd
);
2456 * If we get here we need to check for custom page size support...
2459 if (jobsize
.width
>= pc
->custom_min_width
&&
2460 jobsize
.width
<= pc
->custom_max_width
&&
2461 jobsize
.length
>= pc
->custom_min_length
&&
2462 jobsize
.length
<= pc
->custom_max_length
)
2465 * In range, format as Custom.WWWWxLLLL (points).
2468 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2469 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2471 if (margins_set
&& exact
)
2473 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2474 dright
= pc
->custom_size
.right
- jobsize
.right
;
2475 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2476 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2478 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2479 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2485 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2486 pc
->custom_ppd_size
));
2488 return (pc
->custom_ppd_size
);
2492 * No custom page size support or the size is out of range - return NULL.
2495 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2502 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2505 pwg_size_t
* /* O - PWG size or NULL */
2507 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2508 const char *page_size
) /* I - PPD PageSize */
2510 int i
; /* Looping var */
2511 pwg_media_t
*media
; /* Media */
2512 pwg_size_t
*size
; /* Current size */
2516 * Range check input...
2519 if (!pc
|| !page_size
)
2522 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2525 * Custom size; size name can be one of the following:
2527 * Custom.WIDTHxLENGTHin - Size in inches
2528 * Custom.WIDTHxLENGTHft - Size in feet
2529 * Custom.WIDTHxLENGTHcm - Size in centimeters
2530 * Custom.WIDTHxLENGTHmm - Size in millimeters
2531 * Custom.WIDTHxLENGTHm - Size in meters
2532 * Custom.WIDTHxLENGTH[pt] - Size in points
2535 double w
, l
; /* Width and length of page */
2536 char *ptr
; /* Pointer into PageSize */
2537 struct lconv
*loc
; /* Locale data */
2540 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2541 if (!ptr
|| *ptr
!= 'x')
2544 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2548 if (!_cups_strcasecmp(ptr
, "in"))
2553 else if (!_cups_strcasecmp(ptr
, "ft"))
2558 else if (!_cups_strcasecmp(ptr
, "mm"))
2563 else if (!_cups_strcasecmp(ptr
, "cm"))
2568 else if (!_cups_strcasecmp(ptr
, "m"))
2579 pc
->custom_size
.width
= (int)w
;
2580 pc
->custom_size
.length
= (int)l
;
2582 return (&(pc
->custom_size
));
2586 * Not a custom size - look it up...
2589 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2590 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2591 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2595 * Look up standard sizes...
2598 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2599 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2600 media
= pwgMediaForPWG(page_size
);
2604 pc
->custom_size
.width
= media
->width
;
2605 pc
->custom_size
.length
= media
->length
;
2607 return (&(pc
->custom_size
));
2615 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2619 const char * /* O - PWG media-source keyword */
2621 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2622 const char *input_slot
) /* I - PPD InputSlot */
2624 int i
; /* Looping var */
2625 pwg_map_t
*source
; /* Current source */
2629 * Range check input...
2632 if (!pc
|| !input_slot
)
2635 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2636 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2637 return (source
->pwg
);
2644 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2648 const char * /* O - PWG media-type keyword */
2650 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2651 const char *media_type
) /* I - PPD MediaType */
2653 int i
; /* Looping var */
2654 pwg_map_t
*type
; /* Current type */
2658 * Range check input...
2661 if (!pc
|| !media_type
)
2664 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2665 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2673 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2676 int /* O - 1 on success, 0 on failure */
2678 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2679 const char *filename
, /* I - File to write */
2680 ipp_t
*attrs
) /* I - Attributes to write, if any */
2682 int i
, j
, k
; /* Looping vars */
2683 cups_file_t
*fp
; /* Output file */
2684 pwg_size_t
*size
; /* Current size */
2685 pwg_map_t
*map
; /* Current map */
2686 _pwg_finishings_t
*f
; /* Current finishing option */
2687 cups_option_t
*option
; /* Current option */
2688 const char *value
; /* Filter/pre-filter value */
2689 char newfile
[1024]; /* New filename */
2690 _pwg_material_t
*m
; /* Material */
2694 * Range check input...
2697 if (!pc
|| !filename
)
2699 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2704 * Open the file and write with compression...
2707 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2708 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2710 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2715 * Standard header...
2718 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2724 if (pc
->num_bins
> 0)
2726 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2727 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2728 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2735 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2736 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2737 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2738 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2739 size
->bottom
, size
->right
, size
->top
);
2740 if (pc
->custom_max_width
> 0)
2741 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2742 pc
->custom_max_width
, pc
->custom_max_length
,
2743 pc
->custom_min_width
, pc
->custom_min_length
,
2744 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2745 pc
->custom_size
.right
, pc
->custom_size
.top
);
2751 if (pc
->source_option
)
2752 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2754 if (pc
->num_sources
> 0)
2756 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2757 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2758 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2765 if (pc
->num_types
> 0)
2767 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2768 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2769 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2776 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2777 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2778 if (pc
->num_presets
[i
][j
])
2780 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2781 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2784 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2785 cupsFilePutChar(fp
, '\n');
2792 if (pc
->sides_option
)
2793 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2795 if (pc
->sides_1sided
)
2796 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2798 if (pc
->sides_2sided_long
)
2799 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2801 if (pc
->sides_2sided_short
)
2802 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2805 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2809 cupsFilePutConf(fp
, "Product", pc
->product
);
2811 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2813 value
= (const char *)cupsArrayNext(pc
->filters
))
2814 cupsFilePutConf(fp
, "Filter", value
);
2816 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2818 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2819 cupsFilePutConf(fp
, "PreFilter", value
);
2821 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2824 * Finishing options...
2827 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2829 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2831 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2832 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2833 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2834 cupsFilePutChar(fp
, '\n');
2841 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2844 * Accounting/quota/PIN/managed printing values...
2847 if (pc
->charge_info_uri
)
2848 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2850 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2851 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2852 pc
->accounting_user_id
? "true" : "false");
2855 cupsFilePutConf(fp
, "Password", pc
->password
);
2857 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2859 value
= (char *)cupsArrayNext(pc
->mandatory
))
2860 cupsFilePutConf(fp
, "Mandatory", value
);
2866 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2868 value
= (char *)cupsArrayNext(pc
->support_files
))
2869 cupsFilePutConf(fp
, "SupportFile", value
);
2876 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2878 if (pc
->cups_layer_order
)
2879 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2881 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2882 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2884 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2885 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
2887 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
2889 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
2891 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
2892 for (i
= 0; i
< m
->num_props
; i
++)
2893 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
2894 cupsFilePuts(fp
, "\n");
2898 * IPP attributes, if any...
2903 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2905 attrs
->state
= IPP_STATE_IDLE
;
2906 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2910 * Close and return...
2913 if (cupsFileClose(fp
))
2920 return (!rename(newfile
, filename
));
2925 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2926 * of an IPP printer.
2929 char * /* O - PPD filename or NULL on error */
2930 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2931 size_t bufsize
, /* I - Size of filename buffer */
2932 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2934 cups_file_t
*fp
; /* PPD file */
2935 ipp_attribute_t
*attr
, /* xxx-supported */
2936 *defattr
, /* xxx-default */
2937 *x_dim
, *y_dim
; /* Media dimensions */
2938 ipp_t
*media_size
; /* Media size collection */
2939 char make
[256], /* Make and model */
2940 *model
, /* Model name */
2941 ppdname
[PPD_MAX_NAME
];
2943 int i
, j
, /* Looping vars */
2944 count
, /* Number of values */
2945 bottom
, /* Largest bottom margin */
2946 left
, /* Largest left margin */
2947 right
, /* Largest right margin */
2948 top
; /* Largest top margin */
2949 pwg_media_t
*pwg
; /* PWG media size */
2950 int xres
, yres
; /* Resolution values */
2951 struct lconv
*loc
= localeconv();
2956 * Range check input...
2962 if (!buffer
|| bufsize
< 1 || !response
)
2966 * Open a temporary file for the PPD...
2969 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
2973 * Standard stuff for PPD file...
2976 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
2977 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
2978 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2979 cupsFilePuts(fp
, "*LanguageVersion: English\n");
2980 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
2981 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
2982 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
2983 cupsFilePuts(fp
, "*FileSystem: False\n");
2984 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
2986 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
2987 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
2989 strlcpy(make
, "Unknown Printer", sizeof(make
));
2991 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
2992 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
2995 strlcpy(make
, "HP", sizeof(make
));
2997 else if ((model
= strchr(make
, ' ')) != NULL
)
3002 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3003 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3004 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3005 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3006 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3008 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3009 cupsFilePuts(fp
, "*ColorDevice: True\n");
3011 cupsFilePuts(fp
, "*ColorDevice: False\n");
3013 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3014 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3015 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
3021 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3023 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3025 const char *format
= ippGetString(attr
, i
, NULL
);
3028 if (!_cups_strcasecmp(format
, "application/pdf"))
3029 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3030 else if (!_cups_strcasecmp(format
, "application/postscript"))
3031 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-postscript application/postscript 10 -\"\n");
3032 else if (_cups_strcasecmp(format
, "application/octet-stream") && _cups_strcasecmp(format
, "application/vnd.hp-pcl") && _cups_strcasecmp(format
, "text/plain"))
3033 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 10 -\"\n", format
, format
);
3038 * PageSize/PageRegion/ImageableArea/PaperDimension
3041 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3043 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3044 if (ippGetInteger(attr
, i
) > bottom
)
3045 bottom
= ippGetInteger(attr
, i
);
3050 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3052 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3053 if (ippGetInteger(attr
, i
) > left
)
3054 left
= ippGetInteger(attr
, i
);
3059 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3061 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3062 if (ippGetInteger(attr
, i
) > right
)
3063 right
= ippGetInteger(attr
, i
);
3068 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3070 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3071 if (ippGetInteger(attr
, i
) > top
)
3072 top
= ippGetInteger(attr
, i
);
3077 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3079 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3081 media_size
= ippGetCollection(attr
, 0);
3082 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3083 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3087 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3088 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3091 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3094 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3097 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3099 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3100 "*OrderDependency: 10 AnySetup *PageSize\n"
3101 "*DefaultPageSize: %s\n", ppdname
);
3102 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3104 media_size
= ippGetCollection(attr
, i
);
3105 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3106 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3110 char twidth
[256], /* Width string */
3111 tlength
[256]; /* Length string */
3113 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3115 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3116 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3118 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3121 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3123 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3124 "*OrderDependency: 10 AnySetup *PageRegion\n"
3125 "*DefaultPageRegion: %s\n", ppdname
);
3126 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3128 media_size
= ippGetCollection(attr
, i
);
3129 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3130 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3134 char twidth
[256], /* Width string */
3135 tlength
[256]; /* Length string */
3137 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3139 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3140 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3142 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3145 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3147 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3148 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3149 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3151 media_size
= ippGetCollection(attr
, i
);
3152 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3153 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3157 char tleft
[256], /* Left string */
3158 tbottom
[256], /* Bottom string */
3159 tright
[256], /* Right string */
3160 ttop
[256], /* Top string */
3161 twidth
[256], /* Width string */
3162 tlength
[256]; /* Length string */
3164 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3166 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3167 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3168 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3169 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3170 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3171 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3173 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3174 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3183 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_KEYWORD
)) != NULL
)
3184 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3186 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3188 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3190 static const char * const sources
[][2] =
3192 { "Auto", "Automatic" },
3194 { "Alternate", "Alternate" },
3195 { "LargeCapacity", "Large Capacity" },
3196 { "Manual", "Manual" },
3197 { "Envelope", "Envelope" },
3199 { "Photo", "Photo" },
3200 { "Hagaki", "Hagaki" },
3201 { "MainRoll", "Main Roll" },
3202 { "AlternateRoll", "Alternate Roll" },
3204 { "Middle", "Middle" },
3205 { "Bottom", "Bottom" },
3208 { "Right", "Right" },
3209 { "Center", "Center" },
3211 { "ByPassTray", "Multipurpose" },
3212 { "Tray1", "Tray 1" },
3213 { "Tray2", "Tray 2" },
3214 { "Tray3", "Tray 3" },
3215 { "Tray4", "Tray 4" },
3216 { "Tray5", "Tray 5" },
3217 { "Tray6", "Tray 6" },
3218 { "Tray7", "Tray 7" },
3219 { "Tray8", "Tray 8" },
3220 { "Tray9", "Tray 9" },
3221 { "Tray10", "Tray 10" },
3222 { "Tray11", "Tray 11" },
3223 { "Tray12", "Tray 12" },
3224 { "Tray13", "Tray 13" },
3225 { "Tray14", "Tray 14" },
3226 { "Tray15", "Tray 15" },
3227 { "Tray16", "Tray 16" },
3228 { "Tray17", "Tray 17" },
3229 { "Tray18", "Tray 18" },
3230 { "Tray19", "Tray 19" },
3231 { "Tray20", "Tray 20" },
3232 { "Roll1", "Roll 1" },
3233 { "Roll2", "Roll 2" },
3234 { "Roll3", "Roll 3" },
3235 { "Roll4", "Roll 4" },
3236 { "Roll5", "Roll 5" },
3237 { "Roll6", "Roll 6" },
3238 { "Roll7", "Roll 7" },
3239 { "Roll8", "Roll 8" },
3240 { "Roll9", "Roll 9" },
3241 { "Roll10", "Roll 10" }
3244 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3245 "*OrderDependency: 10 AnySetup *InputSlot\n"
3246 "*DefaultInputSlot: %s\n", ppdname
);
3247 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3249 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3251 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3252 if (!strcmp(sources
[j
][0], ppdname
))
3254 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, sources
[j
][1], j
);
3258 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3265 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_KEYWORD
)) != NULL
)
3266 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3268 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3270 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3272 static const char * const types
[][2] =
3273 { /* Media type strings (far from complete) */
3274 { "Auto", "Automatic" },
3275 { "Cardstock", "Cardstock" },
3276 { "Disc", "CD/DVD/Bluray" },
3277 { "Envelope", "Envelope" },
3278 { "Labels", "Label" },
3279 { "Other", "Other" },
3280 { "Photographic", "Photo" },
3281 { "PhotographicGlossy", "Glossy Photo" },
3282 { "PhotographicHighGloss", "High-Gloss Photo" },
3283 { "PhotographicMatte", "Matte Photo" },
3284 { "PhotographicSatin", "Satin Photo" },
3285 { "PhotographicSemiGloss", "Semi-Gloss Photo" },
3286 { "Stationery", "Plain Paper" },
3287 { "StationeryLetterhead", "Letterhead" },
3288 { "Transparency", "Transparency" }
3291 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3292 "*OrderDependency: 10 AnySetup *MediaType\n"
3293 "*DefaultMediaType: %s\n", ppdname
);
3294 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3296 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3298 for (j
= 0; j
< (int)(sizeof(types
) / sizeof(types
[0])); j
++)
3299 if (!strcmp(types
[j
][0], ppdname
))
3301 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, types
[j
][1], ppdname
);
3305 if (j
>= (int)(sizeof(types
) / sizeof(types
[0])))
3306 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3309 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3316 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3317 attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
);
3321 const char *default_color
= NULL
; /* Default */
3323 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3325 const char *keyword
= ippGetString(attr
, i
, NULL
);
3326 /* Keyword for color/bit depth */
3328 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3331 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3332 "*OrderDependency: 10 AnySetup *ColorModel\n");
3334 cupsFilePuts(fp
, "*ColorModel FastGray/Fast Grayscale: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3337 default_color
= "FastGray";
3339 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3342 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3343 "*OrderDependency: 10 AnySetup *ColorModel\n");
3345 cupsFilePuts(fp
, "*ColorModel Gray/Grayscale: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3347 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3348 default_color
= "Gray";
3350 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "color"))
3353 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3354 "*OrderDependency: 10 AnySetup *ColorModel\n");
3356 cupsFilePuts(fp
, "*ColorModel RGB/Color: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3358 default_color
= "RGB";
3364 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3365 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3373 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3375 cupsFilePuts(fp
, "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
3376 "*OrderDependency: 10 AnySetup *Duplex\n"
3377 "*DefaultDuplex: None\n"
3378 "*Duplex None/Off (1-Sided): \"<</Duplex false>>setpagedevice\"\n"
3379 "*Duplex DuplexNoTumble/Long-Edge (Portrait): \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3380 "*Duplex DuplexTumble/Short-Edge (Landscape): \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3381 "*CloseUI: *Duplex\n");
3383 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3385 const char *keyword
= ippGetString(attr
, 0, NULL
);
3388 if (!strcmp(keyword
, "flipped"))
3389 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3390 else if (!strcmp(keyword
, "manual-tumble"))
3391 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3392 else if (!strcmp(keyword
, "normal"))
3393 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3395 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3397 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3399 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3401 const char *dm
= ippGetString(attr
, i
, NULL
);
3404 if (!_cups_strcasecmp(dm
, "DM1"))
3406 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3409 else if (!_cups_strcasecmp(dm
, "DM2"))
3411 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3414 else if (!_cups_strcasecmp(dm
, "DM3"))
3416 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3419 else if (!_cups_strcasecmp(dm
, "DM4"))
3421 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3429 * cupsPrintQuality and DefaultResolution...
3432 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3434 count
= ippGetCount(attr
);
3436 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3437 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3439 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3440 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3441 "*DefaultcupsPrintQuality: Normal\n");
3444 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3445 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3447 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3448 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3451 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3452 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3455 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3457 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3459 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3461 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3463 const char *rs
= ippGetString(attr
, i
, NULL
);
3466 if (_cups_strncasecmp(rs
, "RS", 2))
3469 lowdpi
= atoi(rs
+ 2);
3470 if ((rs
= strrchr(rs
, '-')) != NULL
)
3471 hidpi
= atoi(rs
+ 1);
3480 * Invalid "urf-supported" value...
3483 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3488 * Generate print qualities based on low and high DPIs...
3491 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
3493 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3494 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3495 "*DefaultcupsPrintQuality: Normal\n");
3496 if ((lowdpi
& 1) == 0)
3497 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
/ 2);
3498 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
);
3500 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", hidpi
, hidpi
);
3501 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3504 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
3506 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3507 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3510 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3513 * Close up and return...
3523 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
3527 const char * /* O - InputSlot name */
3528 _pwgInputSlotForSource(
3529 const char *media_source
, /* I - PWG media-source */
3530 char *name
, /* I - Name buffer */
3531 size_t namesize
) /* I - Size of name buffer */
3534 * Range check input...
3537 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
3540 if (_cups_strcasecmp(media_source
, "main"))
3541 strlcpy(name
, "Cassette", namesize
);
3542 else if (_cups_strcasecmp(media_source
, "alternate"))
3543 strlcpy(name
, "Multipurpose", namesize
);
3544 else if (_cups_strcasecmp(media_source
, "large-capacity"))
3545 strlcpy(name
, "LargeCapacity", namesize
);
3546 else if (_cups_strcasecmp(media_source
, "bottom"))
3547 strlcpy(name
, "Lower", namesize
);
3548 else if (_cups_strcasecmp(media_source
, "middle"))
3549 strlcpy(name
, "Middle", namesize
);
3550 else if (_cups_strcasecmp(media_source
, "top"))
3551 strlcpy(name
, "Upper", namesize
);
3552 else if (_cups_strcasecmp(media_source
, "rear"))
3553 strlcpy(name
, "Rear", namesize
);
3554 else if (_cups_strcasecmp(media_source
, "side"))
3555 strlcpy(name
, "Side", namesize
);
3556 else if (_cups_strcasecmp(media_source
, "envelope"))
3557 strlcpy(name
, "Envelope", namesize
);
3558 else if (_cups_strcasecmp(media_source
, "main-roll"))
3559 strlcpy(name
, "Roll", namesize
);
3560 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
3561 strlcpy(name
, "Roll2", namesize
);
3563 pwg_ppdize_name(media_source
, name
, namesize
);
3570 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
3574 const char * /* O - MediaType name */
3575 _pwgMediaTypeForType(
3576 const char *media_type
, /* I - PWG media-type */
3577 char *name
, /* I - Name buffer */
3578 size_t namesize
) /* I - Size of name buffer */
3581 * Range check input...
3584 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
3587 if (_cups_strcasecmp(media_type
, "auto"))
3588 strlcpy(name
, "Auto", namesize
);
3589 else if (_cups_strcasecmp(media_type
, "cardstock"))
3590 strlcpy(name
, "Cardstock", namesize
);
3591 else if (_cups_strcasecmp(media_type
, "envelope"))
3592 strlcpy(name
, "Envelope", namesize
);
3593 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
3594 strlcpy(name
, "Glossy", namesize
);
3595 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
3596 strlcpy(name
, "HighGloss", namesize
);
3597 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
3598 strlcpy(name
, "Matte", namesize
);
3599 else if (_cups_strcasecmp(media_type
, "stationery"))
3600 strlcpy(name
, "Plain", namesize
);
3601 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
3602 strlcpy(name
, "Coated", namesize
);
3603 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
3604 strlcpy(name
, "Inkjet", namesize
);
3605 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
3606 strlcpy(name
, "Letterhead", namesize
);
3607 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
3608 strlcpy(name
, "Preprinted", namesize
);
3609 else if (_cups_strcasecmp(media_type
, "transparency"))
3610 strlcpy(name
, "Transparency", namesize
);
3612 pwg_ppdize_name(media_type
, name
, namesize
);
3619 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
3622 const char * /* O - PageSize name */
3623 _pwgPageSizeForMedia(
3624 pwg_media_t
*media
, /* I - Media */
3625 char *name
, /* I - PageSize name buffer */
3626 size_t namesize
) /* I - Size of name buffer */
3628 const char *sizeptr
, /* Pointer to size in PWG name */
3629 *dimptr
; /* Pointer to dimensions in PWG name */
3633 * Range check input...
3636 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
3640 * Copy or generate a PageSize name...
3646 * Use a standard Adobe name...
3649 strlcpy(name
, media
->ppd
, namesize
);
3651 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
3652 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
3653 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
3654 (size_t)(dimptr
- sizeptr
) > namesize
)
3657 * Use a name of the form "wNNNhNNN"...
3660 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
3661 (int)PWG_TO_POINTS(media
->length
));
3666 * Copy the size name from class_sizename_dimensions...
3669 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
3670 name
[dimptr
- sizeptr
- 1] = '\0';
3678 * 'pwg_compare_finishings()' - Compare two finishings values.
3681 static int /* O- Result of comparison */
3682 pwg_compare_finishings(
3683 _pwg_finishings_t
*a
, /* I - First finishings value */
3684 _pwg_finishings_t
*b
) /* I - Second finishings value */
3686 return ((int)b
->value
- (int)a
->value
);
3691 * 'pwg_free_finishings()' - Free a finishings value.
3695 pwg_free_finishings(
3696 _pwg_finishings_t
*f
) /* I - Finishings value */
3698 cupsFreeOptions(f
->num_options
, f
->options
);
3704 * 'pwg_free_material()' - Free a material value.
3708 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
3710 _cupsStrFree(m
->key
);
3711 _cupsStrFree(m
->name
);
3713 cupsFreeOptions(m
->num_props
, m
->props
);
3720 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
3724 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
3725 char *name
, /* I - Name buffer */
3726 size_t namesize
) /* I - Size of name buffer */
3728 char *ptr
, /* Pointer into name buffer */
3729 *end
; /* End of name buffer */
3732 *name
= (char)toupper(*ipp
++);
3734 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
3736 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
3739 *ptr
++ = (char)toupper(*ipp
++ & 255);
3750 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
3754 pwg_ppdize_resolution(
3755 ipp_attribute_t
*attr
, /* I - Attribute to convert */
3756 int element
, /* I - Element to convert */
3757 int *xres
, /* O - X resolution in DPI */
3758 int *yres
, /* O - Y resolution in DPI */
3759 char *name
, /* I - Name buffer */
3760 size_t namesize
) /* I - Size of name buffer */
3762 ipp_res_t units
; /* Units for resolution */
3765 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
3767 if (units
== IPP_RES_PER_CM
)
3769 *xres
= (int)(*xres
* 2.54);
3770 *yres
= (int)(*yres
* 2.54);
3773 if (name
&& namesize
> 4)
3776 snprintf(name
, namesize
, "%ddpi", *xres
);
3778 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
3784 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
3788 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
3789 char *name
, /* I - Name buffer */
3790 size_t namesize
, /* I - Size of name buffer */
3791 const char *dashchars
)/* I - Characters to be replaced by dashes */
3793 char *ptr
, /* Pointer into name buffer */
3794 *end
; /* End of name buffer */
3797 if (_cups_islower(*ppd
))
3800 * Already lowercase name, use as-is?
3803 const char *ppdptr
; /* Pointer into PPD keyword */
3805 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
3806 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
3811 strlcpy(name
, ppd
, namesize
);
3816 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
3818 if (_cups_isalnum(*ppd
) || *ppd
== '-')
3819 *ptr
++ = (char)tolower(*ppd
& 255);
3820 else if (strchr(dashchars
, *ppd
))
3825 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
3826 _cups_isupper(ppd
[1]) && ptr
< end
)
3828 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))