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 pwg_size_t
*size
; /* PWG media size */
72 ipp_t
*media_col
, /* media-col value */
73 *media_size
; /* media-size value */
74 const char *media_source
, /* media-source value */
75 *media_type
, /* media-type value */
76 *collate_str
, /* multiple-document-handling value */
77 *color_attr_name
, /* Supported color attribute */
78 *mandatory
; /* Mandatory attributes */
79 int num_finishings
= 0, /* Number of finishing values */
80 finishings
[10]; /* Finishing enum values */
81 ppd_choice_t
*choice
; /* Marked choice */
85 * Send standard IPP attributes...
88 if (pc
->password
&& (keyword
= cupsGetOption("job-password", num_options
, options
)) != NULL
)
90 ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", keyword
, (int)strlen(keyword
));
92 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
95 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
100 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
101 keyword
= cupsGetOption("job-billing", num_options
, options
);
104 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
107 if (pc
->accounting_user_id
)
109 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
113 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
116 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
118 if (strcmp(mandatory
, "copies") &&
119 strcmp(mandatory
, "destination-uris") &&
120 strcmp(mandatory
, "finishings") &&
121 strcmp(mandatory
, "job-account-id") &&
122 strcmp(mandatory
, "job-accounting-user-id") &&
123 strcmp(mandatory
, "job-password") &&
124 strcmp(mandatory
, "job-password-encryption") &&
125 strcmp(mandatory
, "media") &&
126 strncmp(mandatory
, "media-col", 9) &&
127 strcmp(mandatory
, "multiple-document-handling") &&
128 strcmp(mandatory
, "output-bin") &&
129 strcmp(mandatory
, "print-color-mode") &&
130 strcmp(mandatory
, "print-quality") &&
131 strcmp(mandatory
, "sides") &&
132 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
134 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
136 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
141 case IPP_TAG_INTEGER
:
143 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
145 case IPP_TAG_BOOLEAN
:
146 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
150 int lower
, upper
; /* Range */
152 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
153 lower
= upper
= atoi(keyword
);
155 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
158 case IPP_TAG_STRING
:
159 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
162 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
164 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
165 keyword
= "auto-monochrome";
166 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
167 keyword
= "process-monochrome";
170 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
176 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
177 keyword
= cupsGetOption("media", num_options
, options
);
179 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
182 * Add a media-col value...
185 media_size
= ippNew();
186 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
187 "x-dimension", size
->width
);
188 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
189 "y-dimension", size
->length
);
191 media_col
= ippNew();
192 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
194 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
197 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
201 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
203 if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
204 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
205 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
206 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
207 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
208 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
209 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
210 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
211 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
212 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
213 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && media_type
)
214 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
217 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
220 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
222 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
223 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
227 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
229 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
231 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
233 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
235 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
236 keyword
= "monochrome";
242 if (keyword
&& !strcmp(keyword
, "monochrome"))
244 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
245 keyword
= "auto-monochrome";
246 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
247 keyword
= "process-monochrome";
251 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
253 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
254 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
255 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
257 if (!_cups_strcasecmp(choice
->choice
, "draft"))
258 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
259 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
260 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
261 else if (!_cups_strcasecmp(choice
->choice
, "high"))
262 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
265 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
266 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
267 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
269 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
270 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
271 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
272 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
273 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
274 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
281 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
283 if (strstr(keyword
, "uncollated"))
288 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
293 if (!_cups_strcasecmp(format
, "image/gif") ||
294 !_cups_strcasecmp(format
, "image/jp2") ||
295 !_cups_strcasecmp(format
, "image/jpeg") ||
296 !_cups_strcasecmp(format
, "image/png") ||
297 !_cups_strcasecmp(format
, "image/tiff") ||
298 !_cups_strncasecmp(format
, "image/x-", 8))
301 * Collation makes no sense for single page image formats...
306 else if (!_cups_strncasecmp(format
, "image/", 6) ||
307 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
310 * Multi-page image formats will have copies applied by the upstream
318 if (doc_handling_sup
)
320 if (!_cups_strcasecmp(keyword
, "true"))
321 collate_str
= "separate-documents-collated-copies";
323 collate_str
= "separate-documents-uncollated-copies";
325 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
327 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
329 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
334 if (i
>= doc_handling_sup
->num_values
)
339 * Map finishing options...
342 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
343 if (num_finishings
> 0)
345 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
347 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
350 * Send job-pages-per-set attribute to apply finishings correctly...
353 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
362 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
365 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
369 _ppd_cache_t
* /* O - PPD cache and mapping data */
370 _ppdCacheCreateWithFile(
371 const char *filename
, /* I - File to read */
372 ipp_t
**attrs
) /* IO - IPP attributes, if any */
374 cups_file_t
*fp
; /* File */
375 _ppd_cache_t
*pc
; /* PWG mapping data */
376 pwg_size_t
*size
; /* Current size */
377 pwg_map_t
*map
; /* Current map */
378 _pwg_finishings_t
*finishings
; /* Current finishings option */
379 int linenum
, /* Current line number */
380 num_bins
, /* Number of bins in file */
381 num_sizes
, /* Number of sizes in file */
382 num_sources
, /* Number of sources in file */
383 num_types
; /* Number of types in file */
384 char line
[2048], /* Current line */
385 *value
, /* Pointer to value in line */
386 *valueptr
, /* Pointer into value */
387 pwg_keyword
[128], /* PWG keyword */
388 ppd_keyword
[PPD_MAX_NAME
];
390 _pwg_print_color_mode_t print_color_mode
;
391 /* Print color mode for preset */
392 _pwg_print_quality_t print_quality
; /* Print quality for preset */
395 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
398 * Range check input...
406 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
414 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
416 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
421 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
424 if (!cupsFileGets(fp
, line
, sizeof(line
)))
426 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
427 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
432 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
434 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
435 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
440 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
442 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
443 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
444 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
450 * Allocate the mapping data structure...
453 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
455 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
456 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
460 pc
->max_copies
= 9999;
472 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
474 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
475 "linenum=%d", line
, value
, linenum
));
479 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
481 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
484 else if (!_cups_strcasecmp(line
, "3D"))
486 pc
->cups_3d
= _cupsStrAlloc(value
);
488 else if (!_cups_strcasecmp(line
, "LayerOrder"))
490 pc
->cups_layer_order
= _cupsStrAlloc(value
);
492 else if (!_cups_strcasecmp(line
, "Accuracy"))
494 sscanf(value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
496 else if (!_cups_strcasecmp(line
, "Volume"))
498 sscanf(value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
500 else if (!_cups_strcasecmp(line
, "Material"))
503 * Material key "name" name=value ... name=value
506 if ((valueptr
= strchr(value
, ' ')) != NULL
)
508 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
512 material
->key
= _cupsStrAlloc(value
);
514 if (*valueptr
== '\"')
516 value
= valueptr
+ 1;
517 if ((valueptr
= strchr(value
, '\"')) != NULL
)
520 material
->name
= _cupsStrAlloc(value
);
521 material
->num_props
= cupsParseOptions(valueptr
, 0, &material
->props
);
526 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
528 cupsArrayAdd(pc
->materials
, material
);
531 else if (!_cups_strcasecmp(line
, "Filter"))
534 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
535 (cups_acopy_func_t
)_cupsStrAlloc
,
536 (cups_afree_func_t
)_cupsStrFree
);
538 cupsArrayAdd(pc
->filters
, value
);
540 else if (!_cups_strcasecmp(line
, "PreFilter"))
543 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
544 (cups_acopy_func_t
)_cupsStrAlloc
,
545 (cups_afree_func_t
)_cupsStrFree
);
547 cupsArrayAdd(pc
->prefilters
, value
);
549 else if (!_cups_strcasecmp(line
, "Product"))
551 pc
->product
= _cupsStrAlloc(value
);
553 else if (!_cups_strcasecmp(line
, "SingleFile"))
555 pc
->single_file
= !_cups_strcasecmp(value
, "true");
557 else if (!_cups_strcasecmp(line
, "IPP"))
559 off_t pos
= cupsFileTell(fp
), /* Position in file */
560 length
= strtol(value
, NULL
, 10);
561 /* Length of IPP attributes */
565 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
566 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
569 else if (length
<= 0)
571 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
572 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
579 * Read IPP attributes into the provided variable...
584 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
585 *attrs
) != IPP_STATE_DATA
)
587 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
588 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
595 * Skip the IPP data entirely...
598 cupsFileSeek(fp
, pos
+ length
);
601 if (cupsFileTell(fp
) != (pos
+ length
))
603 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
604 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
608 else if (!_cups_strcasecmp(line
, "NumBins"))
612 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
613 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
617 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
619 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
620 "%d.", num_sizes
, linenum
));
621 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
625 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
627 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
629 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
633 else if (!_cups_strcasecmp(line
, "Bin"))
635 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
637 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
638 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
642 if (pc
->num_bins
>= num_bins
)
644 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
646 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
650 map
= pc
->bins
+ pc
->num_bins
;
651 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
652 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
656 else if (!_cups_strcasecmp(line
, "NumSizes"))
660 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
668 "%d.", num_sizes
, linenum
));
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
675 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
677 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
679 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
684 else if (!_cups_strcasecmp(line
, "Size"))
686 if (pc
->num_sizes
>= num_sizes
)
688 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
690 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
694 size
= pc
->sizes
+ pc
->num_sizes
;
696 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
697 &(size
->width
), &(size
->length
), &(size
->left
),
698 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
700 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
702 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
706 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
707 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
711 else if (!_cups_strcasecmp(line
, "CustomSize"))
713 if (pc
->custom_max_width
> 0)
715 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
717 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
721 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
722 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
723 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
724 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
725 &(pc
->custom_size
.top
)) != 8)
727 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
729 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
733 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
734 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
735 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
737 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
738 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
739 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
741 else if (!_cups_strcasecmp(line
, "SourceOption"))
743 pc
->source_option
= _cupsStrAlloc(value
);
745 else if (!_cups_strcasecmp(line
, "NumSources"))
749 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
751 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
755 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
757 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
758 "line %d.", num_sources
, linenum
));
759 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
763 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
765 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
767 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
771 else if (!_cups_strcasecmp(line
, "Source"))
773 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
775 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
777 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
781 if (pc
->num_sources
>= num_sources
)
783 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
785 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
789 map
= pc
->sources
+ pc
->num_sources
;
790 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
791 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
795 else if (!_cups_strcasecmp(line
, "NumTypes"))
799 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
800 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
804 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
806 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
807 "line %d.", num_types
, linenum
));
808 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
812 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
814 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
816 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
820 else if (!_cups_strcasecmp(line
, "Type"))
822 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
824 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
826 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
830 if (pc
->num_types
>= num_types
)
832 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
834 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
838 map
= pc
->types
+ pc
->num_types
;
839 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
840 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
844 else if (!_cups_strcasecmp(line
, "Preset"))
847 * Preset output-mode print-quality name=value ...
850 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
851 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
853 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
854 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
855 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
856 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
857 valueptr
== value
|| !*valueptr
)
859 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
861 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
865 pc
->num_presets
[print_color_mode
][print_quality
] =
866 cupsParseOptions(valueptr
, 0,
867 pc
->presets
[print_color_mode
] + print_quality
);
869 else if (!_cups_strcasecmp(line
, "SidesOption"))
870 pc
->sides_option
= _cupsStrAlloc(value
);
871 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
872 pc
->sides_1sided
= _cupsStrAlloc(value
);
873 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
874 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
876 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
877 else if (!_cups_strcasecmp(line
, "Finishings"))
881 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
883 (cups_afree_func_t
)pwg_free_finishings
);
885 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
888 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
889 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
890 &(finishings
->options
));
892 cupsArrayAdd(pc
->finishings
, finishings
);
894 else if (!_cups_strcasecmp(line
, "MaxCopies"))
895 pc
->max_copies
= atoi(value
);
896 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
897 pc
->charge_info_uri
= _cupsStrAlloc(value
);
898 else if (!_cups_strcasecmp(line
, "JobAccountId"))
899 pc
->account_id
= !_cups_strcasecmp(value
, "true");
900 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
901 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
902 else if (!_cups_strcasecmp(line
, "JobPassword"))
903 pc
->password
= _cupsStrAlloc(value
);
904 else if (!_cups_strcasecmp(line
, "Mandatory"))
907 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
909 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
911 else if (!_cups_strcasecmp(line
, "SupportFile"))
913 if (!pc
->support_files
)
914 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
915 (cups_acopy_func_t
)_cupsStrAlloc
,
916 (cups_afree_func_t
)_cupsStrFree
);
918 cupsArrayAdd(pc
->support_files
, value
);
922 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
927 if (pc
->num_sizes
< num_sizes
)
929 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
930 pc
->num_sizes
, num_sizes
));
931 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
935 if (pc
->num_sources
< num_sources
)
937 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
938 pc
->num_sources
, num_sources
));
939 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
943 if (pc
->num_types
< num_types
)
945 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
946 pc
->num_types
, num_types
));
947 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
956 * If we get here the file was bad - free any data and return...
962 _ppdCacheDestroy(pc
);
975 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
978 _ppd_cache_t
* /* O - PPD cache and mapping data */
979 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
981 int i
, j
, k
; /* Looping vars */
982 _ppd_cache_t
*pc
; /* PWG mapping data */
983 ppd_option_t
*input_slot
, /* InputSlot option */
984 *media_type
, /* MediaType option */
985 *output_bin
, /* OutputBin option */
986 *color_model
, /* ColorModel option */
987 *duplex
; /* Duplex option */
988 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
989 pwg_map_t
*map
; /* Current source/type map */
990 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
991 int num_options
; /* Number of preset options and props */
992 cups_option_t
*options
; /* Preset options and properties */
993 ppd_size_t
*ppd_size
; /* Current PPD size */
994 pwg_size_t
*pwg_size
; /* Current PWG size */
995 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
996 /* PWG keyword string */
997 ppd_name
[PPD_MAX_NAME
];
998 /* Normalized PPD name */
999 const char *pwg_name
; /* Standard PWG media name */
1000 pwg_media_t
*pwg_media
; /* PWG media data */
1001 _pwg_print_color_mode_t pwg_print_color_mode
;
1002 /* print-color-mode index */
1003 _pwg_print_quality_t pwg_print_quality
;
1004 /* print-quality index */
1005 int similar
; /* Are the old and new size similar? */
1006 pwg_size_t
*old_size
; /* Current old size */
1007 int old_imageable
, /* Old imageable length in 2540ths */
1008 old_borderless
, /* Old borderless state */
1009 old_known_pwg
; /* Old PWG name is well-known */
1010 int new_width
, /* New width in 2540ths */
1011 new_length
, /* New length in 2540ths */
1012 new_left
, /* New left margin in 2540ths */
1013 new_bottom
, /* New bottom margin in 2540ths */
1014 new_right
, /* New right margin in 2540ths */
1015 new_top
, /* New top margin in 2540ths */
1016 new_imageable
, /* New imageable length in 2540ths */
1017 new_borderless
, /* New borderless state */
1018 new_known_pwg
; /* New PWG name is well-known */
1019 pwg_size_t
*new_size
; /* New size to add, if any */
1020 const char *filter
; /* Current filter */
1021 _pwg_finishings_t
*finishings
; /* Current finishings value */
1024 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1027 * Range check input...
1034 * Allocate memory...
1037 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1039 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1044 * Copy and convert size data...
1047 if (ppd
->num_sizes
> 0)
1049 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1051 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1052 "pwg_size_t's.", ppd
->num_sizes
));
1056 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1061 * Don't copy over custom size...
1064 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1068 * Convert the PPD size name to the corresponding PWG keyword name.
1071 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1074 * Standard name, do we have conflicts?
1077 for (j
= 0; j
< pc
->num_sizes
; j
++)
1078 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1088 * Standard name and no conflicts, use it!
1091 pwg_name
= pwg_media
->pwg
;
1097 * Not a standard name; convert it to a PWG vendor name of the form:
1099 * pp_lowerppd_WIDTHxHEIGHTuu
1102 pwg_name
= pwg_keyword
;
1105 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1106 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1107 PWG_FROM_POINTS(ppd_size
->width
),
1108 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1112 * If we have a similar paper with non-zero margins then we only want to
1113 * keep it if it has a larger imageable area length. The NULL check is for
1114 * dimensions that are <= 0...
1117 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1118 PWG_FROM_POINTS(ppd_size
->length
),
1122 new_width
= pwg_media
->width
;
1123 new_length
= pwg_media
->length
;
1124 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1125 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1126 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1127 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1128 new_imageable
= new_length
- new_top
- new_bottom
;
1129 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1130 new_left
== 0 && new_right
== 0;
1132 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1136 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1137 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1138 old_size
->right
== 0 && old_size
->top
== 0;
1139 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1140 strncmp(old_size
->map
.pwg
, "om_", 3);
1142 similar
= old_borderless
== new_borderless
&&
1143 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1144 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1147 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1150 * The new paper has a larger imageable area so it could replace
1151 * the older paper. Regardless of the imageable area, we always
1152 * prefer the size with a well-known PWG name.
1155 new_size
= old_size
;
1156 _cupsStrFree(old_size
->map
.ppd
);
1157 _cupsStrFree(old_size
->map
.pwg
);
1164 * The paper was unique enough to deserve its own entry so add it to the
1168 new_size
= pwg_size
++;
1178 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1179 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1180 new_size
->width
= new_width
;
1181 new_size
->length
= new_length
;
1182 new_size
->left
= new_left
;
1183 new_size
->bottom
= new_bottom
;
1184 new_size
->right
= new_right
;
1185 new_size
->top
= new_top
;
1190 if (ppd
->variable_sizes
)
1193 * Generate custom size data...
1196 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1197 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1198 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1199 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1200 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1201 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1203 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1204 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1205 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1206 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1207 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1208 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1210 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1211 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1212 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1213 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1217 * Copy and convert InputSlot data...
1220 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1221 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1225 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1227 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1229 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1230 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1234 pc
->num_sources
= input_slot
->num_choices
;
1236 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1239 i
--, choice
++, map
++)
1241 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1242 !_cups_strcasecmp(choice
->choice
, "Default"))
1244 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1246 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1248 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1250 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1251 !_cups_strcasecmp(choice
->choice
, "MP") ||
1252 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1253 pwg_name
= "by-pass-tray";
1254 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1255 pwg_name
= "large-capacity";
1256 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1257 pwg_name
= "bottom";
1258 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1259 pwg_name
= "middle";
1260 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1262 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1264 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1265 pwg_name
= "main-roll";
1269 * Convert PPD name to lowercase...
1272 pwg_name
= pwg_keyword
;
1273 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1277 map
->pwg
= _cupsStrAlloc(pwg_name
);
1278 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1283 * Copy and convert MediaType data...
1286 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1288 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1290 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1291 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1295 pc
->num_types
= media_type
->num_choices
;
1297 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1300 i
--, choice
++, map
++)
1302 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1303 !_cups_strcasecmp(choice
->choice
, "Any") ||
1304 !_cups_strcasecmp(choice
->choice
, "Default"))
1306 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1307 pwg_name
= "cardstock";
1308 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1309 pwg_name
= "envelope";
1310 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1311 pwg_name
= "photographic-glossy";
1312 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1313 pwg_name
= "photographic-high-gloss";
1314 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1315 pwg_name
= "photographic-matte";
1316 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1317 pwg_name
= "stationery";
1318 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1319 pwg_name
= "stationery-coated";
1320 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1321 pwg_name
= "stationery-inkjet";
1322 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1323 pwg_name
= "stationery-letterhead";
1324 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1325 pwg_name
= "stationery-preprinted";
1326 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1327 pwg_name
= "stationery-recycled";
1328 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1329 pwg_name
= "transparency";
1333 * Convert PPD name to lowercase...
1336 pwg_name
= pwg_keyword
;
1337 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1341 map
->pwg
= _cupsStrAlloc(pwg_name
);
1342 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1347 * Copy and convert OutputBin data...
1350 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1352 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1354 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1355 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1359 pc
->num_bins
= output_bin
->num_choices
;
1361 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1364 i
--, choice
++, map
++)
1366 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1368 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1369 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1373 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1376 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1379 const char *quality
, /* com.apple.print.preset.quality value */
1380 *output_mode
, /* com.apple.print.preset.output-mode value */
1381 *color_model_val
, /* ColorModel choice */
1382 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1383 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1387 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1390 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1391 num_options
, options
)) != NULL
)
1394 * Get the print-quality for this preset...
1397 if (!strcmp(quality
, "low"))
1398 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1399 else if (!strcmp(quality
, "high"))
1400 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1402 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1405 * Ignore graphicsType "Photo" presets that are not high quality.
1408 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1409 num_options
, options
);
1411 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1412 !strcmp(graphicsType
, "Photo"))
1416 * Ignore presets for normal and draft quality where the coating
1417 * isn't "none" or "autodetect".
1420 media_front_coating
= cupsGetOption(
1421 "com.apple.print.preset.media-front-coating",
1422 num_options
, options
);
1424 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1425 media_front_coating
&&
1426 strcmp(media_front_coating
, "none") &&
1427 strcmp(media_front_coating
, "autodetect"))
1431 * Get the output mode for this preset...
1434 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1435 num_options
, options
);
1436 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1440 if (!strcmp(output_mode
, "monochrome"))
1441 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1443 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1445 else if (color_model_val
)
1447 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1448 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1450 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1453 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1456 * Save the options for this combination as needed...
1459 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1460 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1461 _ppdParseOptions(ppd_attr
->value
, 0,
1462 pc
->presets
[pwg_print_color_mode
] +
1463 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1466 cupsFreeOptions(num_options
, options
);
1468 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1471 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1472 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1473 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1476 * Try adding some common color options to create grayscale presets. These
1477 * are listed in order of popularity...
1480 const char *color_option
= NULL
, /* Color control option */
1481 *gray_choice
= NULL
; /* Choice to select grayscale */
1483 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1484 ppdFindChoice(color_model
, "Gray"))
1486 color_option
= "ColorModel";
1487 gray_choice
= "Gray";
1489 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1490 ppdFindChoice(color_model
, "grayscale"))
1492 color_option
= "HPColorMode";
1493 gray_choice
= "grayscale";
1495 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1496 ppdFindChoice(color_model
, "Mono"))
1498 color_option
= "BRMonoColor";
1499 gray_choice
= "Mono";
1501 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1502 ppdFindChoice(color_model
, "1"))
1504 color_option
= "CNIJSGrayScale";
1507 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1508 ppdFindChoice(color_model
, "True"))
1510 color_option
= "HPColorAsGray";
1511 gray_choice
= "True";
1514 if (color_option
&& gray_choice
)
1517 * Copy and convert ColorModel (output-mode) data...
1520 cups_option_t
*coption
, /* Color option */
1521 *moption
; /* Monochrome option */
1523 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1524 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1525 pwg_print_quality
++)
1527 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1530 * Copy the color options...
1533 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1534 [pwg_print_quality
];
1535 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1539 for (i
= num_options
, moption
= options
,
1540 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1541 [pwg_print_quality
];
1543 i
--, moption
++, coption
++)
1545 moption
->name
= _cupsStrRetain(coption
->name
);
1546 moption
->value
= _cupsStrRetain(coption
->value
);
1549 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1551 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1555 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1559 * Add the grayscale option to the preset...
1562 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1563 cupsAddOption(color_option
, gray_choice
,
1564 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1565 [pwg_print_quality
],
1566 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1573 * Copy and convert Duplex (sides) data...
1576 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1577 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1578 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1579 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1580 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1584 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1586 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1590 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1591 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1592 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1593 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1594 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1595 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1596 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1597 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1598 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1599 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1600 !pc
->sides_2sided_short
)
1601 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1606 * Copy filters and pre-filters...
1609 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1610 (cups_acopy_func_t
)_cupsStrAlloc
,
1611 (cups_afree_func_t
)_cupsStrFree
);
1613 cupsArrayAdd(pc
->filters
,
1614 "application/vnd.cups-raw application/octet-stream 0 -");
1616 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1620 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1622 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1624 else if (ppd
->num_filters
> 0)
1626 for (i
= 0; i
< ppd
->num_filters
; i
++)
1627 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1630 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1633 * See if we have a command filter...
1636 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1638 filter
= (const char *)cupsArrayNext(pc
->filters
))
1639 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1640 _cups_isspace(filter
[28]))
1644 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1645 _cups_strcasecmp(ppd_attr
->value
, "none")))
1648 * No command filter and no cupsCommands keyword telling us not to use one.
1649 * See if this is a PostScript printer, and if so add a PostScript command
1653 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1655 filter
= (const char *)cupsArrayNext(pc
->filters
))
1656 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1657 _cups_isspace(filter
[31]))
1661 cupsArrayAdd(pc
->filters
,
1662 "application/vnd.cups-command application/postscript 100 "
1666 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1668 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1669 (cups_acopy_func_t
)_cupsStrAlloc
,
1670 (cups_afree_func_t
)_cupsStrFree
);
1674 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1676 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1679 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1680 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1683 * Copy the product string, if any...
1687 pc
->product
= _cupsStrAlloc(ppd
->product
);
1690 * Copy finishings mapping data...
1693 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1695 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1696 NULL
, NULL
, 0, NULL
,
1697 (cups_afree_func_t
)pwg_free_finishings
);
1701 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1704 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1705 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1706 &(finishings
->options
),
1707 _PPD_PARSE_OPTIONS
);
1709 cupsArrayAdd(pc
->finishings
, finishings
);
1711 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1719 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1720 pc
->max_copies
= atoi(ppd_attr
->value
);
1721 else if (ppd
->manual_copies
)
1724 pc
->max_copies
= 9999;
1727 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1728 * cupsJobPassword, and cupsMandatory.
1731 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1732 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1734 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1735 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1737 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1738 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1740 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1741 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1743 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1744 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1750 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1751 (cups_acopy_func_t
)_cupsStrAlloc
,
1752 (cups_afree_func_t
)_cupsStrFree
);
1754 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1756 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1757 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1759 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1760 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1766 if ((ppd_attr
= ppdFindAttr(ppd
, "cups3D", NULL
)) != NULL
)
1767 pc
->cups_3d
= _cupsStrAlloc(ppd_attr
->value
);
1769 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsLayerOrder", NULL
)) != NULL
)
1770 pc
->cups_layer_order
= _cupsStrAlloc(ppd_attr
->value
);
1772 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsAccuracy", NULL
)) != NULL
)
1773 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_accuracy
+ 0, pc
->cups_accuracy
+ 1, pc
->cups_accuracy
+ 2);
1775 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsVolume", NULL
)) != NULL
)
1776 sscanf(ppd_attr
->value
, "%d%d%d", pc
->cups_volume
+ 0, pc
->cups_volume
+ 1, pc
->cups_volume
+ 2);
1778 for (ppd_attr
= ppdFindAttr(ppd
, "cupsMaterial", NULL
);
1780 ppd_attr
= ppdFindNextAttr(ppd
, "cupsMaterial", NULL
))
1783 * *cupsMaterial key/name: "name=value ... name=value"
1786 _pwg_material_t
*material
= (_pwg_material_t
*)calloc(1, sizeof(_pwg_material_t
));
1788 material
->key
= _cupsStrAlloc(ppd_attr
->name
);
1789 material
->name
= _cupsStrAlloc(ppd_attr
->text
);
1790 material
->num_props
= cupsParseOptions(ppd_attr
->value
, 0, &material
->props
);
1793 pc
->materials
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_material
);
1795 cupsArrayAdd(pc
->materials
, material
);
1799 * Return the cache data...
1805 * If we get here we need to destroy the PWG mapping data and return NULL...
1810 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1811 _ppdCacheDestroy(pc
);
1818 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1822 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1824 int i
; /* Looping var */
1825 pwg_map_t
*map
; /* Current map */
1826 pwg_size_t
*size
; /* Current size */
1830 * Range check input...
1837 * Free memory as needed...
1842 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1844 _cupsStrFree(map
->pwg
);
1845 _cupsStrFree(map
->ppd
);
1853 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1855 _cupsStrFree(size
->map
.pwg
);
1856 _cupsStrFree(size
->map
.ppd
);
1862 if (pc
->source_option
)
1863 _cupsStrFree(pc
->source_option
);
1867 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1869 _cupsStrFree(map
->pwg
);
1870 _cupsStrFree(map
->ppd
);
1878 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1880 _cupsStrFree(map
->pwg
);
1881 _cupsStrFree(map
->ppd
);
1887 if (pc
->custom_max_keyword
)
1888 _cupsStrFree(pc
->custom_max_keyword
);
1890 if (pc
->custom_min_keyword
)
1891 _cupsStrFree(pc
->custom_min_keyword
);
1893 _cupsStrFree(pc
->product
);
1894 cupsArrayDelete(pc
->filters
);
1895 cupsArrayDelete(pc
->prefilters
);
1896 cupsArrayDelete(pc
->finishings
);
1898 _cupsStrFree(pc
->charge_info_uri
);
1899 _cupsStrFree(pc
->password
);
1901 cupsArrayDelete(pc
->mandatory
);
1903 cupsArrayDelete(pc
->support_files
);
1905 _cupsStrFree(pc
->cups_3d
);
1906 _cupsStrFree(pc
->cups_layer_order
);
1908 cupsArrayDelete(pc
->materials
);
1915 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1919 const char * /* O - output-bin or NULL */
1921 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1922 const char *output_bin
) /* I - PPD OutputBin string */
1924 int i
; /* Looping var */
1928 * Range check input...
1931 if (!pc
|| !output_bin
)
1935 * Look up the OutputBin string...
1939 for (i
= 0; i
< pc
->num_bins
; i
++)
1940 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1941 return (pc
->bins
[i
].pwg
);
1948 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1949 * IPP finishings value(s).
1952 int /* O - New number of options */
1953 _ppdCacheGetFinishingOptions(
1954 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1955 ipp_t
*job
, /* I - Job attributes or NULL */
1956 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1957 int num_options
, /* I - Number of options */
1958 cups_option_t
**options
) /* IO - Options */
1960 int i
; /* Looping var */
1961 _pwg_finishings_t
*f
, /* PWG finishings options */
1962 key
; /* Search key */
1963 ipp_attribute_t
*attr
; /* Finishings attribute */
1964 cups_option_t
*option
; /* Current finishings option */
1968 * Range check input...
1971 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1972 (!job
&& value
== IPP_FINISHINGS_NONE
))
1973 return (num_options
);
1976 * Apply finishing options...
1979 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
1981 int num_values
= ippGetCount(attr
); /* Number of values */
1983 for (i
= 0; i
< num_values
; i
++)
1985 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
1987 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
1989 int j
; /* Another looping var */
1991 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
1992 num_options
= cupsAddOption(option
->name
, option
->value
,
1993 num_options
, options
);
1997 else if (value
!= IPP_FINISHINGS_NONE
)
2001 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2003 int j
; /* Another looping var */
2005 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2006 num_options
= cupsAddOption(option
->name
, option
->value
,
2007 num_options
, options
);
2011 return (num_options
);
2016 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2020 int /* O - Number of finishings values */
2021 _ppdCacheGetFinishingValues(
2022 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2023 int num_options
, /* I - Number of options */
2024 cups_option_t
*options
, /* I - Options */
2025 int max_values
, /* I - Maximum number of finishings values */
2026 int *values
) /* O - Finishings values */
2028 int i
, /* Looping var */
2029 num_values
= 0; /* Number of values */
2030 _pwg_finishings_t
*f
; /* Current finishings option */
2031 cups_option_t
*option
; /* Current option */
2032 const char *val
; /* Value for option */
2036 * Range check input...
2039 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
2041 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
2043 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2048 * Go through the finishings options and see what is set...
2051 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2053 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2055 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2057 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2059 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2061 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
2062 _cups_strcasecmp(option
->value
, val
))
2064 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2071 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
2073 values
[num_values
++] = f
->value
;
2075 if (num_values
>= max_values
)
2080 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2082 return (num_values
);
2087 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2088 * attributes or a keyword string.
2091 const char * /* O - PPD InputSlot or NULL */
2092 _ppdCacheGetInputSlot(
2093 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2094 ipp_t
*job
, /* I - Job attributes or NULL */
2095 const char *keyword
) /* I - Keyword string or NULL */
2098 * Range check input...
2101 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2104 if (job
&& !keyword
)
2107 * Lookup the media-col attribute and any media-source found there...
2110 ipp_attribute_t
*media_col
, /* media-col attribute */
2111 *media_source
; /* media-source attribute */
2112 pwg_size_t size
; /* Dimensional size */
2113 int margins_set
; /* Were the margins set? */
2115 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2117 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2119 IPP_TAG_KEYWORD
)) != NULL
)
2122 * Use the media-source value from media-col...
2125 keyword
= ippGetString(media_source
, 0, NULL
);
2127 else if (pwgInitSize(&size
, job
, &margins_set
))
2130 * For media <= 5x7, look for a photo tray...
2133 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2140 int i
; /* Looping var */
2142 for (i
= 0; i
< pc
->num_sources
; i
++)
2143 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2144 return (pc
->sources
[i
].ppd
);
2152 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2153 * attributes or a keyword string.
2156 const char * /* O - PPD MediaType or NULL */
2157 _ppdCacheGetMediaType(
2158 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2159 ipp_t
*job
, /* I - Job attributes or NULL */
2160 const char *keyword
) /* I - Keyword string or NULL */
2163 * Range check input...
2166 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2169 if (job
&& !keyword
)
2172 * Lookup the media-col attribute and any media-source found there...
2175 ipp_attribute_t
*media_col
, /* media-col attribute */
2176 *media_type
; /* media-type attribute */
2178 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2181 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2183 IPP_TAG_KEYWORD
)) == NULL
)
2184 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2185 "media-type", IPP_TAG_NAME
);
2188 keyword
= media_type
->values
[0].string
.text
;
2194 int i
; /* Looping var */
2196 for (i
= 0; i
< pc
->num_types
; i
++)
2197 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2198 return (pc
->types
[i
].ppd
);
2206 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2210 const char * /* O - PPD OutputBin or NULL */
2211 _ppdCacheGetOutputBin(
2212 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2213 const char *output_bin
) /* I - Keyword string */
2215 int i
; /* Looping var */
2219 * Range check input...
2222 if (!pc
|| !output_bin
)
2226 * Look up the OutputBin string...
2230 for (i
= 0; i
< pc
->num_bins
; i
++)
2231 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2232 return (pc
->bins
[i
].ppd
);
2239 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2240 * attributes or a keyword string.
2243 const char * /* O - PPD PageSize or NULL */
2244 _ppdCacheGetPageSize(
2245 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2246 ipp_t
*job
, /* I - Job attributes or NULL */
2247 const char *keyword
, /* I - Keyword string or NULL */
2248 int *exact
) /* O - 1 if exact match, 0 otherwise */
2250 int i
; /* Looping var */
2251 pwg_size_t
*size
, /* Current size */
2252 *closest
, /* Closest size */
2253 jobsize
; /* Size data from job */
2254 int margins_set
, /* Were the margins set? */
2255 dwidth
, /* Difference in width */
2256 dlength
, /* Difference in length */
2257 dleft
, /* Difference in left margins */
2258 dright
, /* Difference in right margins */
2259 dbottom
, /* Difference in bottom margins */
2260 dtop
, /* Difference in top margins */
2261 dmin
, /* Minimum difference */
2262 dclosest
; /* Closest difference */
2263 const char *ppd_name
; /* PPD media name */
2266 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2267 pc
, job
, keyword
, exact
));
2270 * Range check input...
2273 if (!pc
|| (!job
&& !keyword
))
2284 * Try getting the PPD media name from the job attributes...
2287 ipp_attribute_t
*attr
; /* Job attribute */
2289 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2290 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2291 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2295 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2296 attr
->name
, ippTagString(attr
->value_tag
)));
2298 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2301 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2302 attr
->value_tag
== IPP_TAG_KEYWORD
))
2303 ppd_name
= attr
->values
[0].string
.text
;
2306 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2311 * Try looking up the named PPD size first...
2314 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2316 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2317 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2319 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2320 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2325 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2327 return (size
->map
.ppd
);
2332 if (job
&& !keyword
)
2335 * Get the size using media-col or media, with the preference being
2339 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2345 * Get the size using a media keyword...
2348 pwg_media_t
*media
; /* Media definition */
2351 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2352 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2353 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2356 jobsize
.width
= media
->width
;
2357 jobsize
.length
= media
->length
;
2362 * Now that we have the dimensions and possibly the margins, look at the
2363 * available sizes and find the match...
2367 dclosest
= 999999999;
2369 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2370 _cups_strncasecmp(ppd_name
, "custom_", 7))
2372 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2375 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2376 * is just about 176/2540ths...
2379 dwidth
= size
->width
- jobsize
.width
;
2380 dlength
= size
->length
- jobsize
.length
;
2382 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2388 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2391 dleft
= size
->left
- jobsize
.left
;
2392 dright
= size
->right
- jobsize
.right
;
2393 dtop
= size
->top
- jobsize
.top
;
2394 dbottom
= size
->bottom
- jobsize
.bottom
;
2396 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2397 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2399 dleft
= dleft
< 0 ? -dleft
: dleft
;
2400 dright
= dright
< 0 ? -dright
: dright
;
2401 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2402 dtop
= dtop
< 0 ? -dtop
: dtop
;
2403 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2405 if (dmin
< dclosest
)
2418 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2420 return (size
->map
.ppd
);
2426 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2429 return (closest
->map
.ppd
);
2433 * If we get here we need to check for custom page size support...
2436 if (jobsize
.width
>= pc
->custom_min_width
&&
2437 jobsize
.width
<= pc
->custom_max_width
&&
2438 jobsize
.length
>= pc
->custom_min_length
&&
2439 jobsize
.length
<= pc
->custom_max_length
)
2442 * In range, format as Custom.WWWWxLLLL (points).
2445 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2446 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2448 if (margins_set
&& exact
)
2450 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2451 dright
= pc
->custom_size
.right
- jobsize
.right
;
2452 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2453 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2455 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2456 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2462 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2463 pc
->custom_ppd_size
));
2465 return (pc
->custom_ppd_size
);
2469 * No custom page size support or the size is out of range - return NULL.
2472 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2479 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2482 pwg_size_t
* /* O - PWG size or NULL */
2484 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2485 const char *page_size
) /* I - PPD PageSize */
2487 int i
; /* Looping var */
2488 pwg_media_t
*media
; /* Media */
2489 pwg_size_t
*size
; /* Current size */
2493 * Range check input...
2496 if (!pc
|| !page_size
)
2499 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2502 * Custom size; size name can be one of the following:
2504 * Custom.WIDTHxLENGTHin - Size in inches
2505 * Custom.WIDTHxLENGTHft - Size in feet
2506 * Custom.WIDTHxLENGTHcm - Size in centimeters
2507 * Custom.WIDTHxLENGTHmm - Size in millimeters
2508 * Custom.WIDTHxLENGTHm - Size in meters
2509 * Custom.WIDTHxLENGTH[pt] - Size in points
2512 double w
, l
; /* Width and length of page */
2513 char *ptr
; /* Pointer into PageSize */
2514 struct lconv
*loc
; /* Locale data */
2517 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2518 if (!ptr
|| *ptr
!= 'x')
2521 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2525 if (!_cups_strcasecmp(ptr
, "in"))
2530 else if (!_cups_strcasecmp(ptr
, "ft"))
2535 else if (!_cups_strcasecmp(ptr
, "mm"))
2540 else if (!_cups_strcasecmp(ptr
, "cm"))
2545 else if (!_cups_strcasecmp(ptr
, "m"))
2556 pc
->custom_size
.width
= (int)w
;
2557 pc
->custom_size
.length
= (int)l
;
2559 return (&(pc
->custom_size
));
2563 * Not a custom size - look it up...
2566 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2567 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2568 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2572 * Look up standard sizes...
2575 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2576 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2577 media
= pwgMediaForPWG(page_size
);
2581 pc
->custom_size
.width
= media
->width
;
2582 pc
->custom_size
.length
= media
->length
;
2584 return (&(pc
->custom_size
));
2592 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2596 const char * /* O - PWG media-source keyword */
2598 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2599 const char *input_slot
) /* I - PPD InputSlot */
2601 int i
; /* Looping var */
2602 pwg_map_t
*source
; /* Current source */
2606 * Range check input...
2609 if (!pc
|| !input_slot
)
2612 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2613 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2614 return (source
->pwg
);
2621 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2625 const char * /* O - PWG media-type keyword */
2627 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2628 const char *media_type
) /* I - PPD MediaType */
2630 int i
; /* Looping var */
2631 pwg_map_t
*type
; /* Current type */
2635 * Range check input...
2638 if (!pc
|| !media_type
)
2641 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2642 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2650 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2653 int /* O - 1 on success, 0 on failure */
2655 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2656 const char *filename
, /* I - File to write */
2657 ipp_t
*attrs
) /* I - Attributes to write, if any */
2659 int i
, j
, k
; /* Looping vars */
2660 cups_file_t
*fp
; /* Output file */
2661 pwg_size_t
*size
; /* Current size */
2662 pwg_map_t
*map
; /* Current map */
2663 _pwg_finishings_t
*f
; /* Current finishing option */
2664 cups_option_t
*option
; /* Current option */
2665 const char *value
; /* Filter/pre-filter value */
2666 char newfile
[1024]; /* New filename */
2667 _pwg_material_t
*m
; /* Material */
2671 * Range check input...
2674 if (!pc
|| !filename
)
2676 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2681 * Open the file and write with compression...
2684 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2685 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2687 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2692 * Standard header...
2695 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2701 if (pc
->num_bins
> 0)
2703 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2704 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2705 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2712 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2713 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2714 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2715 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2716 size
->bottom
, size
->right
, size
->top
);
2717 if (pc
->custom_max_width
> 0)
2718 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2719 pc
->custom_max_width
, pc
->custom_max_length
,
2720 pc
->custom_min_width
, pc
->custom_min_length
,
2721 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2722 pc
->custom_size
.right
, pc
->custom_size
.top
);
2728 if (pc
->source_option
)
2729 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2731 if (pc
->num_sources
> 0)
2733 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2734 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2735 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2742 if (pc
->num_types
> 0)
2744 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2745 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2746 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2753 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2754 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2755 if (pc
->num_presets
[i
][j
])
2757 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2758 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2761 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2762 cupsFilePutChar(fp
, '\n');
2769 if (pc
->sides_option
)
2770 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2772 if (pc
->sides_1sided
)
2773 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2775 if (pc
->sides_2sided_long
)
2776 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2778 if (pc
->sides_2sided_short
)
2779 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2782 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2786 cupsFilePutConf(fp
, "Product", pc
->product
);
2788 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2790 value
= (const char *)cupsArrayNext(pc
->filters
))
2791 cupsFilePutConf(fp
, "Filter", value
);
2793 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2795 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2796 cupsFilePutConf(fp
, "PreFilter", value
);
2798 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2801 * Finishing options...
2804 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2806 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2808 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2809 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2810 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2811 cupsFilePutChar(fp
, '\n');
2818 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2821 * Accounting/quota/PIN/managed printing values...
2824 if (pc
->charge_info_uri
)
2825 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2827 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2828 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2829 pc
->accounting_user_id
? "true" : "false");
2832 cupsFilePutConf(fp
, "Password", pc
->password
);
2834 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2836 value
= (char *)cupsArrayNext(pc
->mandatory
))
2837 cupsFilePutConf(fp
, "Mandatory", value
);
2843 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2845 value
= (char *)cupsArrayNext(pc
->support_files
))
2846 cupsFilePutConf(fp
, "SupportFile", value
);
2853 cupsFilePutConf(fp
, "3D", pc
->cups_3d
);
2855 if (pc
->cups_layer_order
)
2856 cupsFilePutConf(fp
, "LayerOrder", pc
->cups_layer_order
);
2858 if (pc
->cups_accuracy
[0] || pc
->cups_accuracy
[0] || pc
->cups_accuracy
[2])
2859 cupsFilePrintf(fp
, "Accuracy %d %d %d\n", pc
->cups_accuracy
[0], pc
->cups_accuracy
[1], pc
->cups_accuracy
[2]);
2861 if (pc
->cups_volume
[0] || pc
->cups_volume
[0] || pc
->cups_volume
[2])
2862 cupsFilePrintf(fp
, "Volume %d %d %d\n", pc
->cups_volume
[0], pc
->cups_volume
[1], pc
->cups_volume
[2]);
2864 for (m
= (_pwg_material_t
*)cupsArrayFirst(pc
->materials
);
2866 m
= (_pwg_material_t
*)cupsArrayNext(pc
->materials
))
2868 cupsFilePrintf(fp
, "Material %s \"%s\"", m
->key
, m
->name
);
2869 for (i
= 0; i
< m
->num_props
; i
++)
2870 cupsFilePrintf(fp
, " %s=%s", m
->props
[i
].name
, m
->props
[i
].value
);
2871 cupsFilePuts(fp
, "\n");
2875 * IPP attributes, if any...
2880 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2882 attrs
->state
= IPP_STATE_IDLE
;
2883 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2887 * Close and return...
2890 if (cupsFileClose(fp
))
2897 return (!rename(newfile
, filename
));
2902 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2903 * of an IPP printer.
2906 char * /* O - PPD filename or NULL on error */
2907 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2908 size_t bufsize
, /* I - Size of filename buffer */
2909 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2911 cups_file_t
*fp
; /* PPD file */
2912 ipp_attribute_t
*attr
, /* xxx-supported */
2913 *defattr
, /* xxx-default */
2914 *x_dim
, *y_dim
; /* Media dimensions */
2915 ipp_t
*media_size
; /* Media size collection */
2916 char make
[256], /* Make and model */
2917 *model
, /* Model name */
2918 ppdname
[PPD_MAX_NAME
];
2920 int i
, j
, /* Looping vars */
2921 count
, /* Number of values */
2922 bottom
, /* Largest bottom margin */
2923 left
, /* Largest left margin */
2924 right
, /* Largest right margin */
2925 top
; /* Largest top margin */
2926 pwg_media_t
*pwg
; /* PWG media size */
2927 int xres
, yres
; /* Resolution values */
2928 struct lconv
*loc
= localeconv();
2933 * Range check input...
2939 if (!buffer
|| bufsize
< 1 || !response
)
2943 * Open a temporary file for the PPD...
2946 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
2950 * Standard stuff for PPD file...
2953 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
2954 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
2955 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2956 cupsFilePuts(fp
, "*LanguageVersion: English\n");
2957 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
2958 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
2959 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
2960 cupsFilePuts(fp
, "*FileSystem: False\n");
2961 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
2963 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
2964 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
2966 strlcpy(make
, "Unknown Printer", sizeof(make
));
2968 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
2969 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
2972 strlcpy(make
, "HP", sizeof(make
));
2974 else if ((model
= strchr(make
, ' ')) != NULL
)
2979 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
2980 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
2981 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
2982 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
2983 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
2985 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
2986 cupsFilePuts(fp
, "*ColorDevice: True\n");
2988 cupsFilePuts(fp
, "*ColorDevice: False\n");
2990 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2991 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
2992 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
2998 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3000 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3002 const char *format
= ippGetString(attr
, i
, NULL
);
3005 if (!_cups_strcasecmp(format
, "application/pdf"))
3006 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3007 else if (!_cups_strcasecmp(format
, "application/postscript"))
3008 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-postscript application/postscript 10 -\"\n");
3009 else if (_cups_strcasecmp(format
, "application/octet-stream") && _cups_strcasecmp(format
, "application/vnd.hp-pcl") && _cups_strcasecmp(format
, "text/plain"))
3010 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 10 -\"\n", format
, format
);
3015 * PageSize/PageRegion/ImageableArea/PaperDimension
3018 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3020 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3021 if (ippGetInteger(attr
, i
) > bottom
)
3022 bottom
= ippGetInteger(attr
, i
);
3027 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3029 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3030 if (ippGetInteger(attr
, i
) > left
)
3031 left
= ippGetInteger(attr
, i
);
3036 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3038 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3039 if (ippGetInteger(attr
, i
) > right
)
3040 right
= ippGetInteger(attr
, i
);
3045 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3047 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3048 if (ippGetInteger(attr
, i
) > top
)
3049 top
= ippGetInteger(attr
, i
);
3054 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3056 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3058 media_size
= ippGetCollection(attr
, 0);
3059 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3060 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3064 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3065 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3068 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3071 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3074 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3076 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3077 "*OrderDependency: 10 AnySetup *PageSize\n"
3078 "*DefaultPageSize: %s\n", ppdname
);
3079 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3081 media_size
= ippGetCollection(attr
, i
);
3082 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3083 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3087 char twidth
[256], /* Width string */
3088 tlength
[256]; /* Length string */
3090 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3092 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3093 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3095 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3098 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3100 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3101 "*OrderDependency: 10 AnySetup *PageRegion\n"
3102 "*DefaultPageRegion: %s\n", ppdname
);
3103 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3105 media_size
= ippGetCollection(attr
, i
);
3106 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3107 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3111 char twidth
[256], /* Width string */
3112 tlength
[256]; /* Length string */
3114 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3116 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3117 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3119 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
3122 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3124 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3125 "*DefaultPaperDimension: %s\n", ppdname
, 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 tleft
[256], /* Left string */
3135 tbottom
[256], /* Bottom string */
3136 tright
[256], /* Right string */
3137 ttop
[256], /* Top string */
3138 twidth
[256], /* Width string */
3139 tlength
[256]; /* Length string */
3141 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3143 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3144 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3145 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3146 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3147 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3148 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3150 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3151 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3160 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_KEYWORD
)) != NULL
)
3161 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3163 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3165 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3167 static const char * const sources
[][2] =
3169 { "Auto", "Automatic" },
3171 { "Alternate", "Alternate" },
3172 { "LargeCapacity", "Large Capacity" },
3173 { "Manual", "Manual" },
3174 { "Envelope", "Envelope" },
3176 { "Photo", "Photo" },
3177 { "Hagaki", "Hagaki" },
3178 { "MainRoll", "Main Roll" },
3179 { "AlternateRoll", "Alternate Roll" },
3181 { "Middle", "Middle" },
3182 { "Bottom", "Bottom" },
3185 { "Right", "Right" },
3186 { "Center", "Center" },
3188 { "ByPassTray", "Multipurpose" },
3189 { "Tray1", "Tray 1" },
3190 { "Tray2", "Tray 2" },
3191 { "Tray3", "Tray 3" },
3192 { "Tray4", "Tray 4" },
3193 { "Tray5", "Tray 5" },
3194 { "Tray6", "Tray 6" },
3195 { "Tray7", "Tray 7" },
3196 { "Tray8", "Tray 8" },
3197 { "Tray9", "Tray 9" },
3198 { "Tray10", "Tray 10" },
3199 { "Tray11", "Tray 11" },
3200 { "Tray12", "Tray 12" },
3201 { "Tray13", "Tray 13" },
3202 { "Tray14", "Tray 14" },
3203 { "Tray15", "Tray 15" },
3204 { "Tray16", "Tray 16" },
3205 { "Tray17", "Tray 17" },
3206 { "Tray18", "Tray 18" },
3207 { "Tray19", "Tray 19" },
3208 { "Tray20", "Tray 20" },
3209 { "Roll1", "Roll 1" },
3210 { "Roll2", "Roll 2" },
3211 { "Roll3", "Roll 3" },
3212 { "Roll4", "Roll 4" },
3213 { "Roll5", "Roll 5" },
3214 { "Roll6", "Roll 6" },
3215 { "Roll7", "Roll 7" },
3216 { "Roll8", "Roll 8" },
3217 { "Roll9", "Roll 9" },
3218 { "Roll10", "Roll 10" }
3221 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3222 "*OrderDependency: 10 AnySetup *InputSlot\n"
3223 "*DefaultInputSlot: %s\n", ppdname
);
3224 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3226 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3228 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3229 if (!strcmp(sources
[j
][0], ppdname
))
3231 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, sources
[j
][1], j
);
3235 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3242 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_KEYWORD
)) != NULL
)
3243 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3245 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3247 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3249 static const char * const types
[][2] =
3250 { /* Media type strings (far from complete) */
3251 { "Auto", "Automatic" },
3252 { "Cardstock", "Cardstock" },
3253 { "Disc", "CD/DVD/Bluray" },
3254 { "Envelope", "Envelope" },
3255 { "Labels", "Label" },
3256 { "Other", "Other" },
3257 { "Photographic", "Photo" },
3258 { "PhotographicGlossy", "Glossy Photo" },
3259 { "PhotographicHighGloss", "High-Gloss Photo" },
3260 { "PhotographicMatte", "Matte Photo" },
3261 { "PhotographicSatin", "Satin Photo" },
3262 { "PhotographicSemiGloss", "Semi-Gloss Photo" },
3263 { "Stationery", "Plain Paper" },
3264 { "StationeryLetterhead", "Letterhead" },
3265 { "Transparency", "Transparency" }
3268 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3269 "*OrderDependency: 10 AnySetup *MediaType\n"
3270 "*DefaultMediaType: %s\n", ppdname
);
3271 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3273 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3275 for (j
= 0; j
< (int)(sizeof(types
) / sizeof(types
[0])); j
++)
3276 if (!strcmp(types
[j
][0], ppdname
))
3278 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, types
[j
][1], ppdname
);
3282 if (j
>= (int)(sizeof(types
) / sizeof(types
[0])))
3283 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3286 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3293 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3294 attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
);
3298 const char *default_color
= NULL
; /* Default */
3300 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3302 const char *keyword
= ippGetString(attr
, i
, NULL
);
3303 /* Keyword for color/bit depth */
3305 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3308 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3309 "*OrderDependency: 10 AnySetup *ColorModel\n");
3311 cupsFilePuts(fp
, "*ColorModel FastGray/Fast Grayscale: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3314 default_color
= "FastGray";
3316 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3319 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3320 "*OrderDependency: 10 AnySetup *ColorModel\n");
3322 cupsFilePuts(fp
, "*ColorModel Gray/Grayscale: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3324 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3325 default_color
= "Gray";
3327 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "color"))
3330 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3331 "*OrderDependency: 10 AnySetup *ColorModel\n");
3333 cupsFilePuts(fp
, "*ColorModel RGB/Color: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3335 default_color
= "RGB";
3341 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3342 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3350 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3352 cupsFilePuts(fp
, "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
3353 "*OrderDependency: 10 AnySetup *Duplex\n"
3354 "*DefaultDuplex: None\n"
3355 "*Duplex None/Off (1-Sided): \"<</Duplex false>>setpagedevice\"\n"
3356 "*Duplex DuplexNoTumble/Long-Edge (Portrait): \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3357 "*Duplex DuplexTumble/Short-Edge (Landscape): \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3358 "*CloseUI: *Duplex\n");
3360 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3362 const char *keyword
= ippGetString(attr
, 0, NULL
);
3365 if (!strcmp(keyword
, "flipped"))
3366 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3367 else if (!strcmp(keyword
, "manual-tumble"))
3368 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3369 else if (!strcmp(keyword
, "normal"))
3370 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3372 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3374 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3376 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3378 const char *dm
= ippGetString(attr
, i
, NULL
);
3381 if (!_cups_strcasecmp(dm
, "DM1"))
3383 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3386 else if (!_cups_strcasecmp(dm
, "DM2"))
3388 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3391 else if (!_cups_strcasecmp(dm
, "DM3"))
3393 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3396 else if (!_cups_strcasecmp(dm
, "DM4"))
3398 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3406 * cupsPrintQuality and DefaultResolution...
3409 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3411 count
= ippGetCount(attr
);
3413 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3414 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3416 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3417 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3418 "*DefaultcupsPrintQuality: Normal\n");
3421 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3422 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3424 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3425 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3428 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3429 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3432 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3434 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3436 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3438 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3440 const char *rs
= ippGetString(attr
, i
, NULL
);
3443 if (_cups_strncasecmp(rs
, "RS", 2))
3446 lowdpi
= atoi(rs
+ 2);
3447 if ((rs
= strrchr(rs
, '-')) != NULL
)
3448 hidpi
= atoi(rs
+ 1);
3457 * Invalid "urf-supported" value...
3460 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3465 * Generate print qualities based on low and high DPIs...
3468 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
3470 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3471 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3472 "*DefaultcupsPrintQuality: Normal\n");
3473 if ((lowdpi
& 1) == 0)
3474 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
/ 2);
3475 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
);
3477 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", hidpi
, hidpi
);
3478 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3481 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
3483 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3484 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3487 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3490 * Close up and return...
3500 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
3504 const char * /* O - InputSlot name */
3505 _pwgInputSlotForSource(
3506 const char *media_source
, /* I - PWG media-source */
3507 char *name
, /* I - Name buffer */
3508 size_t namesize
) /* I - Size of name buffer */
3511 * Range check input...
3514 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
3517 if (_cups_strcasecmp(media_source
, "main"))
3518 strlcpy(name
, "Cassette", namesize
);
3519 else if (_cups_strcasecmp(media_source
, "alternate"))
3520 strlcpy(name
, "Multipurpose", namesize
);
3521 else if (_cups_strcasecmp(media_source
, "large-capacity"))
3522 strlcpy(name
, "LargeCapacity", namesize
);
3523 else if (_cups_strcasecmp(media_source
, "bottom"))
3524 strlcpy(name
, "Lower", namesize
);
3525 else if (_cups_strcasecmp(media_source
, "middle"))
3526 strlcpy(name
, "Middle", namesize
);
3527 else if (_cups_strcasecmp(media_source
, "top"))
3528 strlcpy(name
, "Upper", namesize
);
3529 else if (_cups_strcasecmp(media_source
, "rear"))
3530 strlcpy(name
, "Rear", namesize
);
3531 else if (_cups_strcasecmp(media_source
, "side"))
3532 strlcpy(name
, "Side", namesize
);
3533 else if (_cups_strcasecmp(media_source
, "envelope"))
3534 strlcpy(name
, "Envelope", namesize
);
3535 else if (_cups_strcasecmp(media_source
, "main-roll"))
3536 strlcpy(name
, "Roll", namesize
);
3537 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
3538 strlcpy(name
, "Roll2", namesize
);
3540 pwg_ppdize_name(media_source
, name
, namesize
);
3547 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
3551 const char * /* O - MediaType name */
3552 _pwgMediaTypeForType(
3553 const char *media_type
, /* I - PWG media-type */
3554 char *name
, /* I - Name buffer */
3555 size_t namesize
) /* I - Size of name buffer */
3558 * Range check input...
3561 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
3564 if (_cups_strcasecmp(media_type
, "auto"))
3565 strlcpy(name
, "Auto", namesize
);
3566 else if (_cups_strcasecmp(media_type
, "cardstock"))
3567 strlcpy(name
, "Cardstock", namesize
);
3568 else if (_cups_strcasecmp(media_type
, "envelope"))
3569 strlcpy(name
, "Envelope", namesize
);
3570 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
3571 strlcpy(name
, "Glossy", namesize
);
3572 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
3573 strlcpy(name
, "HighGloss", namesize
);
3574 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
3575 strlcpy(name
, "Matte", namesize
);
3576 else if (_cups_strcasecmp(media_type
, "stationery"))
3577 strlcpy(name
, "Plain", namesize
);
3578 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
3579 strlcpy(name
, "Coated", namesize
);
3580 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
3581 strlcpy(name
, "Inkjet", namesize
);
3582 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
3583 strlcpy(name
, "Letterhead", namesize
);
3584 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
3585 strlcpy(name
, "Preprinted", namesize
);
3586 else if (_cups_strcasecmp(media_type
, "transparency"))
3587 strlcpy(name
, "Transparency", namesize
);
3589 pwg_ppdize_name(media_type
, name
, namesize
);
3596 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
3599 const char * /* O - PageSize name */
3600 _pwgPageSizeForMedia(
3601 pwg_media_t
*media
, /* I - Media */
3602 char *name
, /* I - PageSize name buffer */
3603 size_t namesize
) /* I - Size of name buffer */
3605 const char *sizeptr
, /* Pointer to size in PWG name */
3606 *dimptr
; /* Pointer to dimensions in PWG name */
3610 * Range check input...
3613 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
3617 * Copy or generate a PageSize name...
3623 * Use a standard Adobe name...
3626 strlcpy(name
, media
->ppd
, namesize
);
3628 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
3629 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
3630 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
3631 (size_t)(dimptr
- sizeptr
) > namesize
)
3634 * Use a name of the form "wNNNhNNN"...
3637 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
3638 (int)PWG_TO_POINTS(media
->length
));
3643 * Copy the size name from class_sizename_dimensions...
3646 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
3647 name
[dimptr
- sizeptr
- 1] = '\0';
3655 * 'pwg_compare_finishings()' - Compare two finishings values.
3658 static int /* O- Result of comparison */
3659 pwg_compare_finishings(
3660 _pwg_finishings_t
*a
, /* I - First finishings value */
3661 _pwg_finishings_t
*b
) /* I - Second finishings value */
3663 return ((int)b
->value
- (int)a
->value
);
3668 * 'pwg_free_finishings()' - Free a finishings value.
3672 pwg_free_finishings(
3673 _pwg_finishings_t
*f
) /* I - Finishings value */
3675 cupsFreeOptions(f
->num_options
, f
->options
);
3681 * 'pwg_free_material()' - Free a material value.
3685 pwg_free_material(_pwg_material_t
*m
) /* I - Material value */
3687 _cupsStrFree(m
->key
);
3688 _cupsStrFree(m
->name
);
3690 cupsFreeOptions(m
->num_props
, m
->props
);
3697 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
3701 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
3702 char *name
, /* I - Name buffer */
3703 size_t namesize
) /* I - Size of name buffer */
3705 char *ptr
, /* Pointer into name buffer */
3706 *end
; /* End of name buffer */
3709 *name
= (char)toupper(*ipp
++);
3711 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
3713 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
3716 *ptr
++ = (char)toupper(*ipp
++ & 255);
3727 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
3731 pwg_ppdize_resolution(
3732 ipp_attribute_t
*attr
, /* I - Attribute to convert */
3733 int element
, /* I - Element to convert */
3734 int *xres
, /* O - X resolution in DPI */
3735 int *yres
, /* O - Y resolution in DPI */
3736 char *name
, /* I - Name buffer */
3737 size_t namesize
) /* I - Size of name buffer */
3739 ipp_res_t units
; /* Units for resolution */
3742 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
3744 if (units
== IPP_RES_PER_CM
)
3746 *xres
= (int)(*xres
* 2.54);
3747 *yres
= (int)(*yres
* 2.54);
3750 if (name
&& namesize
> 4)
3753 snprintf(name
, namesize
, "%ddpi", *xres
);
3755 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
3761 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
3765 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
3766 char *name
, /* I - Name buffer */
3767 size_t namesize
, /* I - Size of name buffer */
3768 const char *dashchars
)/* I - Characters to be replaced by dashes */
3770 char *ptr
, /* Pointer into name buffer */
3771 *end
; /* End of name buffer */
3774 if (_cups_islower(*ppd
))
3777 * Already lowercase name, use as-is?
3780 const char *ppdptr
; /* Pointer into PPD keyword */
3782 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
3783 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
3788 strlcpy(name
, ppd
, namesize
);
3793 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
3795 if (_cups_isalnum(*ppd
) || *ppd
== '-')
3796 *ptr
++ = (char)tolower(*ppd
& 255);
3797 else if (strchr(dashchars
, *ppd
))
3802 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
3803 _cups_isupper(ppd
[1]) && ptr
< end
)
3805 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))