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_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
40 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
41 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
42 const char *dashchars
);
46 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
48 * This functions converts PPD and CUPS-specific options to their standard IPP
49 * attributes and values and adds them to the specified IPP request.
52 int /* O - New number of copies */
53 _cupsConvertOptions(ipp_t
*request
, /* I - IPP request */
54 ppd_file_t
*ppd
, /* I - PPD file */
55 _ppd_cache_t
*pc
, /* I - PPD cache info */
56 ipp_attribute_t
*media_col_sup
,
57 /* I - media-col-supported values */
58 ipp_attribute_t
*doc_handling_sup
,
59 /* I - multiple-document-handling-supported values */
60 ipp_attribute_t
*print_color_mode_sup
,
61 /* I - Printer supports print-color-mode */
62 const char *user
, /* I - User info */
63 const char *format
, /* I - document-format value */
64 int copies
, /* I - Number of copies */
65 int num_options
, /* I - Number of options */
66 cups_option_t
*options
) /* I - Options */
68 int i
; /* Looping var */
69 const char *keyword
; /* PWG keyword */
70 pwg_size_t
*size
; /* PWG media size */
71 ipp_t
*media_col
, /* media-col value */
72 *media_size
; /* media-size value */
73 const char *media_source
, /* media-source value */
74 *media_type
, /* media-type value */
75 *collate_str
, /* multiple-document-handling value */
76 *color_attr_name
, /* Supported color attribute */
77 *mandatory
; /* Mandatory attributes */
78 int num_finishings
= 0, /* Number of finishing values */
79 finishings
[10]; /* Finishing enum values */
80 ppd_choice_t
*choice
; /* Marked choice */
84 * Send standard IPP attributes...
87 if (pc
->password
&& (keyword
= cupsGetOption("job-password", num_options
, options
)) != NULL
)
89 ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", keyword
, (int)strlen(keyword
));
91 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
94 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
99 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
100 keyword
= cupsGetOption("job-billing", num_options
, options
);
103 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
106 if (pc
->accounting_user_id
)
108 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
112 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
115 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
117 if (strcmp(mandatory
, "copies") &&
118 strcmp(mandatory
, "destination-uris") &&
119 strcmp(mandatory
, "finishings") &&
120 strcmp(mandatory
, "job-account-id") &&
121 strcmp(mandatory
, "job-accounting-user-id") &&
122 strcmp(mandatory
, "job-password") &&
123 strcmp(mandatory
, "job-password-encryption") &&
124 strcmp(mandatory
, "media") &&
125 strncmp(mandatory
, "media-col", 9) &&
126 strcmp(mandatory
, "multiple-document-handling") &&
127 strcmp(mandatory
, "output-bin") &&
128 strcmp(mandatory
, "print-color-mode") &&
129 strcmp(mandatory
, "print-quality") &&
130 strcmp(mandatory
, "sides") &&
131 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
133 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
135 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
140 case IPP_TAG_INTEGER
:
142 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
144 case IPP_TAG_BOOLEAN
:
145 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
149 int lower
, upper
; /* Range */
151 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
152 lower
= upper
= atoi(keyword
);
154 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
157 case IPP_TAG_STRING
:
158 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
161 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
163 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
164 keyword
= "auto-monochrome";
165 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
166 keyword
= "process-monochrome";
169 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
175 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
176 keyword
= cupsGetOption("media", num_options
, options
);
178 if ((size
= _ppdCacheGetSize(pc
, keyword
)) != NULL
)
181 * Add a media-col value...
184 media_size
= ippNew();
185 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
186 "x-dimension", size
->width
);
187 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
188 "y-dimension", size
->length
);
190 media_col
= ippNew();
191 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
193 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot",
196 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType",
200 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
202 if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
203 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
204 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
205 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
206 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
207 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
208 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
209 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
210 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-source") && media_source
)
211 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
212 else if (!strcmp(media_col_sup
->values
[i
].string
.text
, "media-type") && media_type
)
213 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
216 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
219 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
221 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
222 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
226 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
228 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
230 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
232 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
234 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
235 keyword
= "monochrome";
241 if (keyword
&& !strcmp(keyword
, "monochrome"))
243 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
244 keyword
= "auto-monochrome";
245 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
246 keyword
= "process-monochrome";
250 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
252 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
253 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
254 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
256 if (!_cups_strcasecmp(choice
->choice
, "draft"))
257 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
258 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
259 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
260 else if (!_cups_strcasecmp(choice
->choice
, "high"))
261 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
264 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
265 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
266 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
268 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
269 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
270 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
271 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
272 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
273 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
280 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
282 if (strstr(keyword
, "uncollated"))
287 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
292 if (!_cups_strcasecmp(format
, "image/gif") ||
293 !_cups_strcasecmp(format
, "image/jp2") ||
294 !_cups_strcasecmp(format
, "image/jpeg") ||
295 !_cups_strcasecmp(format
, "image/png") ||
296 !_cups_strcasecmp(format
, "image/tiff") ||
297 !_cups_strncasecmp(format
, "image/x-", 8))
300 * Collation makes no sense for single page image formats...
305 else if (!_cups_strncasecmp(format
, "image/", 6) ||
306 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
309 * Multi-page image formats will have copies applied by the upstream
317 if (doc_handling_sup
)
319 if (!_cups_strcasecmp(keyword
, "true"))
320 collate_str
= "separate-documents-collated-copies";
322 collate_str
= "separate-documents-uncollated-copies";
324 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
326 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
328 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
333 if (i
>= doc_handling_sup
->num_values
)
338 * Map finishing options...
341 num_finishings
= _ppdCacheGetFinishingValues(pc
, num_options
, options
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
342 if (num_finishings
> 0)
344 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
346 if (copies
> 1 && (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
349 * Send job-pages-per-set attribute to apply finishings correctly...
352 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / copies
);
361 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
364 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
368 _ppd_cache_t
* /* O - PPD cache and mapping data */
369 _ppdCacheCreateWithFile(
370 const char *filename
, /* I - File to read */
371 ipp_t
**attrs
) /* IO - IPP attributes, if any */
373 cups_file_t
*fp
; /* File */
374 _ppd_cache_t
*pc
; /* PWG mapping data */
375 pwg_size_t
*size
; /* Current size */
376 pwg_map_t
*map
; /* Current map */
377 _pwg_finishings_t
*finishings
; /* Current finishings option */
378 int linenum
, /* Current line number */
379 num_bins
, /* Number of bins in file */
380 num_sizes
, /* Number of sizes in file */
381 num_sources
, /* Number of sources in file */
382 num_types
; /* Number of types in file */
383 char line
[2048], /* Current line */
384 *value
, /* Pointer to value in line */
385 *valueptr
, /* Pointer into value */
386 pwg_keyword
[128], /* PWG keyword */
387 ppd_keyword
[PPD_MAX_NAME
];
389 _pwg_print_color_mode_t print_color_mode
;
390 /* Print color mode for preset */
391 _pwg_print_quality_t print_quality
; /* Print quality for preset */
394 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
397 * Range check input...
405 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
413 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
415 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
420 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
423 if (!cupsFileGets(fp
, line
, sizeof(line
)))
425 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
426 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
431 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
433 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
434 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
439 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
441 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
442 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
443 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
449 * Allocate the mapping data structure...
452 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
454 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
455 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
459 pc
->max_copies
= 9999;
471 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
473 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
474 "linenum=%d", line
, value
, linenum
));
478 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
480 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
483 else if (!_cups_strcasecmp(line
, "Filter"))
486 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
487 (cups_acopy_func_t
)_cupsStrAlloc
,
488 (cups_afree_func_t
)_cupsStrFree
);
490 cupsArrayAdd(pc
->filters
, value
);
492 else if (!_cups_strcasecmp(line
, "PreFilter"))
495 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
496 (cups_acopy_func_t
)_cupsStrAlloc
,
497 (cups_afree_func_t
)_cupsStrFree
);
499 cupsArrayAdd(pc
->prefilters
, value
);
501 else if (!_cups_strcasecmp(line
, "Product"))
503 pc
->product
= _cupsStrAlloc(value
);
505 else if (!_cups_strcasecmp(line
, "SingleFile"))
507 pc
->single_file
= !_cups_strcasecmp(value
, "true");
509 else if (!_cups_strcasecmp(line
, "IPP"))
511 off_t pos
= cupsFileTell(fp
), /* Position in file */
512 length
= strtol(value
, NULL
, 10);
513 /* Length of IPP attributes */
517 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
518 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
521 else if (length
<= 0)
523 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
524 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
531 * Read IPP attributes into the provided variable...
536 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
537 *attrs
) != IPP_STATE_DATA
)
539 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
540 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
547 * Skip the IPP data entirely...
550 cupsFileSeek(fp
, pos
+ length
);
553 if (cupsFileTell(fp
) != (pos
+ length
))
555 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
556 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
560 else if (!_cups_strcasecmp(line
, "NumBins"))
564 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
565 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
569 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
571 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
572 "%d.", num_sizes
, linenum
));
573 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
577 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
579 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
581 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
585 else if (!_cups_strcasecmp(line
, "Bin"))
587 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
589 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
590 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
594 if (pc
->num_bins
>= num_bins
)
596 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
598 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
602 map
= pc
->bins
+ pc
->num_bins
;
603 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
604 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
608 else if (!_cups_strcasecmp(line
, "NumSizes"))
612 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
613 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
617 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
619 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
620 "%d.", num_sizes
, linenum
));
621 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
627 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
629 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
631 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
636 else if (!_cups_strcasecmp(line
, "Size"))
638 if (pc
->num_sizes
>= num_sizes
)
640 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
642 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
646 size
= pc
->sizes
+ pc
->num_sizes
;
648 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
649 &(size
->width
), &(size
->length
), &(size
->left
),
650 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
652 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
654 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
658 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
659 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
663 else if (!_cups_strcasecmp(line
, "CustomSize"))
665 if (pc
->custom_max_width
> 0)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
673 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
674 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
675 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
676 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
677 &(pc
->custom_size
.top
)) != 8)
679 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
681 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
685 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
686 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
687 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
689 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
690 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
691 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
693 else if (!_cups_strcasecmp(line
, "SourceOption"))
695 pc
->source_option
= _cupsStrAlloc(value
);
697 else if (!_cups_strcasecmp(line
, "NumSources"))
701 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
703 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
707 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
709 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
710 "line %d.", num_sources
, linenum
));
711 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
715 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
717 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
719 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
723 else if (!_cups_strcasecmp(line
, "Source"))
725 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
727 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
729 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
733 if (pc
->num_sources
>= num_sources
)
735 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
737 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
741 map
= pc
->sources
+ pc
->num_sources
;
742 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
743 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
747 else if (!_cups_strcasecmp(line
, "NumTypes"))
751 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
752 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
756 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
758 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
759 "line %d.", num_types
, linenum
));
760 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
764 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
766 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
768 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
772 else if (!_cups_strcasecmp(line
, "Type"))
774 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
776 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
778 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
782 if (pc
->num_types
>= num_types
)
784 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
786 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
790 map
= pc
->types
+ pc
->num_types
;
791 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
792 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
796 else if (!_cups_strcasecmp(line
, "Preset"))
799 * Preset output-mode print-quality name=value ...
802 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
803 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
805 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
806 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
807 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
808 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
809 valueptr
== value
|| !*valueptr
)
811 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
813 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
817 pc
->num_presets
[print_color_mode
][print_quality
] =
818 cupsParseOptions(valueptr
, 0,
819 pc
->presets
[print_color_mode
] + print_quality
);
821 else if (!_cups_strcasecmp(line
, "SidesOption"))
822 pc
->sides_option
= _cupsStrAlloc(value
);
823 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
824 pc
->sides_1sided
= _cupsStrAlloc(value
);
825 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
826 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
827 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
828 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
829 else if (!_cups_strcasecmp(line
, "Finishings"))
833 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
835 (cups_afree_func_t
)pwg_free_finishings
);
837 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
840 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
841 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
842 &(finishings
->options
));
844 cupsArrayAdd(pc
->finishings
, finishings
);
846 else if (!_cups_strcasecmp(line
, "MaxCopies"))
847 pc
->max_copies
= atoi(value
);
848 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
849 pc
->charge_info_uri
= _cupsStrAlloc(value
);
850 else if (!_cups_strcasecmp(line
, "JobAccountId"))
851 pc
->account_id
= !_cups_strcasecmp(value
, "true");
852 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
853 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
854 else if (!_cups_strcasecmp(line
, "JobPassword"))
855 pc
->password
= _cupsStrAlloc(value
);
856 else if (!_cups_strcasecmp(line
, "Mandatory"))
859 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
861 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
863 else if (!_cups_strcasecmp(line
, "SupportFile"))
865 if (!pc
->support_files
)
866 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
867 (cups_acopy_func_t
)_cupsStrAlloc
,
868 (cups_afree_func_t
)_cupsStrFree
);
870 cupsArrayAdd(pc
->support_files
, value
);
874 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
879 if (pc
->num_sizes
< num_sizes
)
881 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
882 pc
->num_sizes
, num_sizes
));
883 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
887 if (pc
->num_sources
< num_sources
)
889 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
890 pc
->num_sources
, num_sources
));
891 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
895 if (pc
->num_types
< num_types
)
897 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
898 pc
->num_types
, num_types
));
899 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
908 * If we get here the file was bad - free any data and return...
914 _ppdCacheDestroy(pc
);
927 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
930 _ppd_cache_t
* /* O - PPD cache and mapping data */
931 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
933 int i
, j
, k
; /* Looping vars */
934 _ppd_cache_t
*pc
; /* PWG mapping data */
935 ppd_option_t
*input_slot
, /* InputSlot option */
936 *media_type
, /* MediaType option */
937 *output_bin
, /* OutputBin option */
938 *color_model
, /* ColorModel option */
939 *duplex
; /* Duplex option */
940 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
941 pwg_map_t
*map
; /* Current source/type map */
942 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
943 int num_options
; /* Number of preset options and props */
944 cups_option_t
*options
; /* Preset options and properties */
945 ppd_size_t
*ppd_size
; /* Current PPD size */
946 pwg_size_t
*pwg_size
; /* Current PWG size */
947 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
948 /* PWG keyword string */
949 ppd_name
[PPD_MAX_NAME
];
950 /* Normalized PPD name */
951 const char *pwg_name
; /* Standard PWG media name */
952 pwg_media_t
*pwg_media
; /* PWG media data */
953 _pwg_print_color_mode_t pwg_print_color_mode
;
954 /* print-color-mode index */
955 _pwg_print_quality_t pwg_print_quality
;
956 /* print-quality index */
957 int similar
; /* Are the old and new size similar? */
958 pwg_size_t
*old_size
; /* Current old size */
959 int old_imageable
, /* Old imageable length in 2540ths */
960 old_borderless
, /* Old borderless state */
961 old_known_pwg
; /* Old PWG name is well-known */
962 int new_width
, /* New width in 2540ths */
963 new_length
, /* New length in 2540ths */
964 new_left
, /* New left margin in 2540ths */
965 new_bottom
, /* New bottom margin in 2540ths */
966 new_right
, /* New right margin in 2540ths */
967 new_top
, /* New top margin in 2540ths */
968 new_imageable
, /* New imageable length in 2540ths */
969 new_borderless
, /* New borderless state */
970 new_known_pwg
; /* New PWG name is well-known */
971 pwg_size_t
*new_size
; /* New size to add, if any */
972 const char *filter
; /* Current filter */
973 _pwg_finishings_t
*finishings
; /* Current finishings value */
976 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
979 * Range check input...
989 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
991 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
996 * Copy and convert size data...
999 if (ppd
->num_sizes
> 0)
1001 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1003 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1004 "pwg_size_t's.", ppd
->num_sizes
));
1008 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1013 * Don't copy over custom size...
1016 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1020 * Convert the PPD size name to the corresponding PWG keyword name.
1023 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1026 * Standard name, do we have conflicts?
1029 for (j
= 0; j
< pc
->num_sizes
; j
++)
1030 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1040 * Standard name and no conflicts, use it!
1043 pwg_name
= pwg_media
->pwg
;
1049 * Not a standard name; convert it to a PWG vendor name of the form:
1051 * pp_lowerppd_WIDTHxHEIGHTuu
1054 pwg_name
= pwg_keyword
;
1057 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1058 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1059 PWG_FROM_POINTS(ppd_size
->width
),
1060 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1064 * If we have a similar paper with non-zero margins then we only want to
1065 * keep it if it has a larger imageable area length. The NULL check is for
1066 * dimensions that are <= 0...
1069 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1070 PWG_FROM_POINTS(ppd_size
->length
),
1074 new_width
= pwg_media
->width
;
1075 new_length
= pwg_media
->length
;
1076 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1077 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1078 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1079 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1080 new_imageable
= new_length
- new_top
- new_bottom
;
1081 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1082 new_left
== 0 && new_right
== 0;
1084 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1088 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1089 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1090 old_size
->right
== 0 && old_size
->top
== 0;
1091 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1092 strncmp(old_size
->map
.pwg
, "om_", 3);
1094 similar
= old_borderless
== new_borderless
&&
1095 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1096 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1099 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1102 * The new paper has a larger imageable area so it could replace
1103 * the older paper. Regardless of the imageable area, we always
1104 * prefer the size with a well-known PWG name.
1107 new_size
= old_size
;
1108 _cupsStrFree(old_size
->map
.ppd
);
1109 _cupsStrFree(old_size
->map
.pwg
);
1116 * The paper was unique enough to deserve its own entry so add it to the
1120 new_size
= pwg_size
++;
1130 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1131 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1132 new_size
->width
= new_width
;
1133 new_size
->length
= new_length
;
1134 new_size
->left
= new_left
;
1135 new_size
->bottom
= new_bottom
;
1136 new_size
->right
= new_right
;
1137 new_size
->top
= new_top
;
1142 if (ppd
->variable_sizes
)
1145 * Generate custom size data...
1148 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1149 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1150 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1151 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1152 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1153 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1155 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1156 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1157 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1158 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1159 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1160 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1162 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1163 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1164 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1165 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1169 * Copy and convert InputSlot data...
1172 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1173 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1177 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1179 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1181 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1182 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1186 pc
->num_sources
= input_slot
->num_choices
;
1188 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1191 i
--, choice
++, map
++)
1193 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1194 !_cups_strcasecmp(choice
->choice
, "Default"))
1196 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1198 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1200 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1202 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1203 !_cups_strcasecmp(choice
->choice
, "MP") ||
1204 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1205 pwg_name
= "by-pass-tray";
1206 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1207 pwg_name
= "large-capacity";
1208 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1209 pwg_name
= "bottom";
1210 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1211 pwg_name
= "middle";
1212 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1214 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1216 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1217 pwg_name
= "main-roll";
1221 * Convert PPD name to lowercase...
1224 pwg_name
= pwg_keyword
;
1225 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1229 map
->pwg
= _cupsStrAlloc(pwg_name
);
1230 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1235 * Copy and convert MediaType data...
1238 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1240 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1242 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1243 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1247 pc
->num_types
= media_type
->num_choices
;
1249 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1252 i
--, choice
++, map
++)
1254 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1255 !_cups_strcasecmp(choice
->choice
, "Any") ||
1256 !_cups_strcasecmp(choice
->choice
, "Default"))
1258 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1259 pwg_name
= "cardstock";
1260 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1261 pwg_name
= "envelope";
1262 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1263 pwg_name
= "photographic-glossy";
1264 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1265 pwg_name
= "photographic-high-gloss";
1266 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1267 pwg_name
= "photographic-matte";
1268 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1269 pwg_name
= "stationery";
1270 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1271 pwg_name
= "stationery-coated";
1272 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1273 pwg_name
= "stationery-inkjet";
1274 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1275 pwg_name
= "stationery-letterhead";
1276 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1277 pwg_name
= "stationery-preprinted";
1278 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1279 pwg_name
= "stationery-recycled";
1280 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1281 pwg_name
= "transparency";
1285 * Convert PPD name to lowercase...
1288 pwg_name
= pwg_keyword
;
1289 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1293 map
->pwg
= _cupsStrAlloc(pwg_name
);
1294 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1299 * Copy and convert OutputBin data...
1302 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1304 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1306 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1307 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1311 pc
->num_bins
= output_bin
->num_choices
;
1313 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1316 i
--, choice
++, map
++)
1318 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1320 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1321 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1325 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1328 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1331 const char *quality
, /* com.apple.print.preset.quality value */
1332 *output_mode
, /* com.apple.print.preset.output-mode value */
1333 *color_model_val
, /* ColorModel choice */
1334 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1335 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1339 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1342 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1343 num_options
, options
)) != NULL
)
1346 * Get the print-quality for this preset...
1349 if (!strcmp(quality
, "low"))
1350 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1351 else if (!strcmp(quality
, "high"))
1352 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1354 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1357 * Ignore graphicsType "Photo" presets that are not high quality.
1360 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1361 num_options
, options
);
1363 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1364 !strcmp(graphicsType
, "Photo"))
1368 * Ignore presets for normal and draft quality where the coating
1369 * isn't "none" or "autodetect".
1372 media_front_coating
= cupsGetOption(
1373 "com.apple.print.preset.media-front-coating",
1374 num_options
, options
);
1376 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1377 media_front_coating
&&
1378 strcmp(media_front_coating
, "none") &&
1379 strcmp(media_front_coating
, "autodetect"))
1383 * Get the output mode for this preset...
1386 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1387 num_options
, options
);
1388 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1392 if (!strcmp(output_mode
, "monochrome"))
1393 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1395 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1397 else if (color_model_val
)
1399 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1400 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1402 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1405 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1408 * Save the options for this combination as needed...
1411 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1412 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1413 _ppdParseOptions(ppd_attr
->value
, 0,
1414 pc
->presets
[pwg_print_color_mode
] +
1415 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1418 cupsFreeOptions(num_options
, options
);
1420 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1423 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1424 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1425 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1428 * Try adding some common color options to create grayscale presets. These
1429 * are listed in order of popularity...
1432 const char *color_option
= NULL
, /* Color control option */
1433 *gray_choice
= NULL
; /* Choice to select grayscale */
1435 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1436 ppdFindChoice(color_model
, "Gray"))
1438 color_option
= "ColorModel";
1439 gray_choice
= "Gray";
1441 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1442 ppdFindChoice(color_model
, "grayscale"))
1444 color_option
= "HPColorMode";
1445 gray_choice
= "grayscale";
1447 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1448 ppdFindChoice(color_model
, "Mono"))
1450 color_option
= "BRMonoColor";
1451 gray_choice
= "Mono";
1453 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1454 ppdFindChoice(color_model
, "1"))
1456 color_option
= "CNIJSGrayScale";
1459 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1460 ppdFindChoice(color_model
, "True"))
1462 color_option
= "HPColorAsGray";
1463 gray_choice
= "True";
1466 if (color_option
&& gray_choice
)
1469 * Copy and convert ColorModel (output-mode) data...
1472 cups_option_t
*coption
, /* Color option */
1473 *moption
; /* Monochrome option */
1475 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1476 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1477 pwg_print_quality
++)
1479 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1482 * Copy the color options...
1485 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1486 [pwg_print_quality
];
1487 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1491 for (i
= num_options
, moption
= options
,
1492 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1493 [pwg_print_quality
];
1495 i
--, moption
++, coption
++)
1497 moption
->name
= _cupsStrRetain(coption
->name
);
1498 moption
->value
= _cupsStrRetain(coption
->value
);
1501 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1503 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1507 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1511 * Add the grayscale option to the preset...
1514 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1515 cupsAddOption(color_option
, gray_choice
,
1516 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1517 [pwg_print_quality
],
1518 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1525 * Copy and convert Duplex (sides) data...
1528 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1529 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1530 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1531 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1532 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1536 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1538 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1542 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1543 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1544 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1545 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1546 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1547 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1548 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1549 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1550 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1551 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1552 !pc
->sides_2sided_short
)
1553 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1558 * Copy filters and pre-filters...
1561 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1562 (cups_acopy_func_t
)_cupsStrAlloc
,
1563 (cups_afree_func_t
)_cupsStrFree
);
1565 cupsArrayAdd(pc
->filters
,
1566 "application/vnd.cups-raw application/octet-stream 0 -");
1568 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1572 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1574 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1576 else if (ppd
->num_filters
> 0)
1578 for (i
= 0; i
< ppd
->num_filters
; i
++)
1579 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1582 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1585 * See if we have a command filter...
1588 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1590 filter
= (const char *)cupsArrayNext(pc
->filters
))
1591 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1592 _cups_isspace(filter
[28]))
1596 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1597 _cups_strcasecmp(ppd_attr
->value
, "none")))
1600 * No command filter and no cupsCommands keyword telling us not to use one.
1601 * See if this is a PostScript printer, and if so add a PostScript command
1605 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1607 filter
= (const char *)cupsArrayNext(pc
->filters
))
1608 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1609 _cups_isspace(filter
[31]))
1613 cupsArrayAdd(pc
->filters
,
1614 "application/vnd.cups-command application/postscript 100 "
1618 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1620 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1621 (cups_acopy_func_t
)_cupsStrAlloc
,
1622 (cups_afree_func_t
)_cupsStrFree
);
1626 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1628 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1631 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1632 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1635 * Copy the product string, if any...
1639 pc
->product
= _cupsStrAlloc(ppd
->product
);
1642 * Copy finishings mapping data...
1645 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1647 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1648 NULL
, NULL
, 0, NULL
,
1649 (cups_afree_func_t
)pwg_free_finishings
);
1653 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1656 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1657 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1658 &(finishings
->options
),
1659 _PPD_PARSE_OPTIONS
);
1661 cupsArrayAdd(pc
->finishings
, finishings
);
1663 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1671 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1672 pc
->max_copies
= atoi(ppd_attr
->value
);
1673 else if (ppd
->manual_copies
)
1676 pc
->max_copies
= 9999;
1679 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1680 * cupsJobPassword, and cupsMandatory.
1683 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1684 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1686 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1687 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1689 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1690 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1692 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1693 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1695 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1696 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1702 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1703 (cups_acopy_func_t
)_cupsStrAlloc
,
1704 (cups_afree_func_t
)_cupsStrFree
);
1706 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1708 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1709 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1711 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1712 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1715 * Return the cache data...
1721 * If we get here we need to destroy the PWG mapping data and return NULL...
1726 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1727 _ppdCacheDestroy(pc
);
1734 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1738 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1740 int i
; /* Looping var */
1741 pwg_map_t
*map
; /* Current map */
1742 pwg_size_t
*size
; /* Current size */
1746 * Range check input...
1753 * Free memory as needed...
1758 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1760 _cupsStrFree(map
->pwg
);
1761 _cupsStrFree(map
->ppd
);
1769 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1771 _cupsStrFree(size
->map
.pwg
);
1772 _cupsStrFree(size
->map
.ppd
);
1778 if (pc
->source_option
)
1779 _cupsStrFree(pc
->source_option
);
1783 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1785 _cupsStrFree(map
->pwg
);
1786 _cupsStrFree(map
->ppd
);
1794 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1796 _cupsStrFree(map
->pwg
);
1797 _cupsStrFree(map
->ppd
);
1803 if (pc
->custom_max_keyword
)
1804 _cupsStrFree(pc
->custom_max_keyword
);
1806 if (pc
->custom_min_keyword
)
1807 _cupsStrFree(pc
->custom_min_keyword
);
1809 _cupsStrFree(pc
->product
);
1810 cupsArrayDelete(pc
->filters
);
1811 cupsArrayDelete(pc
->prefilters
);
1812 cupsArrayDelete(pc
->finishings
);
1814 _cupsStrFree(pc
->charge_info_uri
);
1815 _cupsStrFree(pc
->password
);
1817 cupsArrayDelete(pc
->mandatory
);
1819 cupsArrayDelete(pc
->support_files
);
1826 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1830 const char * /* O - output-bin or NULL */
1832 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1833 const char *output_bin
) /* I - PPD OutputBin string */
1835 int i
; /* Looping var */
1839 * Range check input...
1842 if (!pc
|| !output_bin
)
1846 * Look up the OutputBin string...
1850 for (i
= 0; i
< pc
->num_bins
; i
++)
1851 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1852 return (pc
->bins
[i
].pwg
);
1859 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1860 * IPP finishings value(s).
1863 int /* O - New number of options */
1864 _ppdCacheGetFinishingOptions(
1865 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1866 ipp_t
*job
, /* I - Job attributes or NULL */
1867 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1868 int num_options
, /* I - Number of options */
1869 cups_option_t
**options
) /* IO - Options */
1871 int i
; /* Looping var */
1872 _pwg_finishings_t
*f
, /* PWG finishings options */
1873 key
; /* Search key */
1874 ipp_attribute_t
*attr
; /* Finishings attribute */
1875 cups_option_t
*option
; /* Current finishings option */
1879 * Range check input...
1882 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1883 (!job
&& value
== IPP_FINISHINGS_NONE
))
1884 return (num_options
);
1887 * Apply finishing options...
1890 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
1892 int num_values
= ippGetCount(attr
); /* Number of values */
1894 for (i
= 0; i
< num_values
; i
++)
1896 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
1898 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
1900 int j
; /* Another looping var */
1902 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
1903 num_options
= cupsAddOption(option
->name
, option
->value
,
1904 num_options
, options
);
1908 else if (value
!= IPP_FINISHINGS_NONE
)
1912 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
1914 int j
; /* Another looping var */
1916 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
1917 num_options
= cupsAddOption(option
->name
, option
->value
,
1918 num_options
, options
);
1922 return (num_options
);
1927 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
1931 int /* O - Number of finishings values */
1932 _ppdCacheGetFinishingValues(
1933 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1934 int num_options
, /* I - Number of options */
1935 cups_option_t
*options
, /* I - Options */
1936 int max_values
, /* I - Maximum number of finishings values */
1937 int *values
) /* O - Finishings values */
1939 int i
, /* Looping var */
1940 num_values
= 0; /* Number of values */
1941 _pwg_finishings_t
*f
; /* Current finishings option */
1942 cups_option_t
*option
; /* Current option */
1943 const char *val
; /* Value for option */
1947 * Range check input...
1950 DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc
, num_options
, options
, max_values
, values
));
1952 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
1954 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
1959 * Go through the finishings options and see what is set...
1962 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
1964 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
1966 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
1968 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
1970 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
1972 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
1973 _cups_strcasecmp(option
->value
, val
))
1975 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
1982 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f
->value
));
1984 values
[num_values
++] = f
->value
;
1986 if (num_values
>= max_values
)
1991 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
1993 return (num_values
);
1998 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
1999 * attributes or a keyword string.
2002 const char * /* O - PPD InputSlot or NULL */
2003 _ppdCacheGetInputSlot(
2004 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2005 ipp_t
*job
, /* I - Job attributes or NULL */
2006 const char *keyword
) /* I - Keyword string or NULL */
2009 * Range check input...
2012 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2015 if (job
&& !keyword
)
2018 * Lookup the media-col attribute and any media-source found there...
2021 ipp_attribute_t
*media_col
, /* media-col attribute */
2022 *media_source
; /* media-source attribute */
2023 pwg_size_t size
; /* Dimensional size */
2024 int margins_set
; /* Were the margins set? */
2026 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2028 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2030 IPP_TAG_KEYWORD
)) != NULL
)
2033 * Use the media-source value from media-col...
2036 keyword
= ippGetString(media_source
, 0, NULL
);
2038 else if (pwgInitSize(&size
, job
, &margins_set
))
2041 * For media <= 5x7, look for a photo tray...
2044 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2051 int i
; /* Looping var */
2053 for (i
= 0; i
< pc
->num_sources
; i
++)
2054 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2055 return (pc
->sources
[i
].ppd
);
2063 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2064 * attributes or a keyword string.
2067 const char * /* O - PPD MediaType or NULL */
2068 _ppdCacheGetMediaType(
2069 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2070 ipp_t
*job
, /* I - Job attributes or NULL */
2071 const char *keyword
) /* I - Keyword string or NULL */
2074 * Range check input...
2077 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2080 if (job
&& !keyword
)
2083 * Lookup the media-col attribute and any media-source found there...
2086 ipp_attribute_t
*media_col
, /* media-col attribute */
2087 *media_type
; /* media-type attribute */
2089 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2092 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2094 IPP_TAG_KEYWORD
)) == NULL
)
2095 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2096 "media-type", IPP_TAG_NAME
);
2099 keyword
= media_type
->values
[0].string
.text
;
2105 int i
; /* Looping var */
2107 for (i
= 0; i
< pc
->num_types
; i
++)
2108 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2109 return (pc
->types
[i
].ppd
);
2117 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2121 const char * /* O - PPD OutputBin or NULL */
2122 _ppdCacheGetOutputBin(
2123 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2124 const char *output_bin
) /* I - Keyword string */
2126 int i
; /* Looping var */
2130 * Range check input...
2133 if (!pc
|| !output_bin
)
2137 * Look up the OutputBin string...
2141 for (i
= 0; i
< pc
->num_bins
; i
++)
2142 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2143 return (pc
->bins
[i
].ppd
);
2150 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2151 * attributes or a keyword string.
2154 const char * /* O - PPD PageSize or NULL */
2155 _ppdCacheGetPageSize(
2156 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2157 ipp_t
*job
, /* I - Job attributes or NULL */
2158 const char *keyword
, /* I - Keyword string or NULL */
2159 int *exact
) /* O - 1 if exact match, 0 otherwise */
2161 int i
; /* Looping var */
2162 pwg_size_t
*size
, /* Current size */
2163 *closest
, /* Closest size */
2164 jobsize
; /* Size data from job */
2165 int margins_set
, /* Were the margins set? */
2166 dwidth
, /* Difference in width */
2167 dlength
, /* Difference in length */
2168 dleft
, /* Difference in left margins */
2169 dright
, /* Difference in right margins */
2170 dbottom
, /* Difference in bottom margins */
2171 dtop
, /* Difference in top margins */
2172 dmin
, /* Minimum difference */
2173 dclosest
; /* Closest difference */
2174 const char *ppd_name
; /* PPD media name */
2177 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2178 pc
, job
, keyword
, exact
));
2181 * Range check input...
2184 if (!pc
|| (!job
&& !keyword
))
2195 * Try getting the PPD media name from the job attributes...
2198 ipp_attribute_t
*attr
; /* Job attribute */
2200 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2201 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2202 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2206 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2207 attr
->name
, ippTagString(attr
->value_tag
)));
2209 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2212 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2213 attr
->value_tag
== IPP_TAG_KEYWORD
))
2214 ppd_name
= attr
->values
[0].string
.text
;
2217 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2222 * Try looking up the named PPD size first...
2225 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2227 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2228 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2230 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2231 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2236 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2238 return (size
->map
.ppd
);
2243 if (job
&& !keyword
)
2246 * Get the size using media-col or media, with the preference being
2250 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2256 * Get the size using a media keyword...
2259 pwg_media_t
*media
; /* Media definition */
2262 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2263 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2264 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2267 jobsize
.width
= media
->width
;
2268 jobsize
.length
= media
->length
;
2273 * Now that we have the dimensions and possibly the margins, look at the
2274 * available sizes and find the match...
2278 dclosest
= 999999999;
2280 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2281 _cups_strncasecmp(ppd_name
, "custom_", 7))
2283 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2286 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2287 * is just about 176/2540ths...
2290 dwidth
= size
->width
- jobsize
.width
;
2291 dlength
= size
->length
- jobsize
.length
;
2293 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2299 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2302 dleft
= size
->left
- jobsize
.left
;
2303 dright
= size
->right
- jobsize
.right
;
2304 dtop
= size
->top
- jobsize
.top
;
2305 dbottom
= size
->bottom
- jobsize
.bottom
;
2307 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2308 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2310 dleft
= dleft
< 0 ? -dleft
: dleft
;
2311 dright
= dright
< 0 ? -dright
: dright
;
2312 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2313 dtop
= dtop
< 0 ? -dtop
: dtop
;
2314 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2316 if (dmin
< dclosest
)
2329 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2331 return (size
->map
.ppd
);
2337 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2340 return (closest
->map
.ppd
);
2344 * If we get here we need to check for custom page size support...
2347 if (jobsize
.width
>= pc
->custom_min_width
&&
2348 jobsize
.width
<= pc
->custom_max_width
&&
2349 jobsize
.length
>= pc
->custom_min_length
&&
2350 jobsize
.length
<= pc
->custom_max_length
)
2353 * In range, format as Custom.WWWWxLLLL (points).
2356 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2357 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2359 if (margins_set
&& exact
)
2361 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2362 dright
= pc
->custom_size
.right
- jobsize
.right
;
2363 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2364 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2366 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2367 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2373 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2374 pc
->custom_ppd_size
));
2376 return (pc
->custom_ppd_size
);
2380 * No custom page size support or the size is out of range - return NULL.
2383 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2390 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2393 pwg_size_t
* /* O - PWG size or NULL */
2395 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2396 const char *page_size
) /* I - PPD PageSize */
2398 int i
; /* Looping var */
2399 pwg_media_t
*media
; /* Media */
2400 pwg_size_t
*size
; /* Current size */
2404 * Range check input...
2407 if (!pc
|| !page_size
)
2410 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2413 * Custom size; size name can be one of the following:
2415 * Custom.WIDTHxLENGTHin - Size in inches
2416 * Custom.WIDTHxLENGTHft - Size in feet
2417 * Custom.WIDTHxLENGTHcm - Size in centimeters
2418 * Custom.WIDTHxLENGTHmm - Size in millimeters
2419 * Custom.WIDTHxLENGTHm - Size in meters
2420 * Custom.WIDTHxLENGTH[pt] - Size in points
2423 double w
, l
; /* Width and length of page */
2424 char *ptr
; /* Pointer into PageSize */
2425 struct lconv
*loc
; /* Locale data */
2428 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2429 if (!ptr
|| *ptr
!= 'x')
2432 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2436 if (!_cups_strcasecmp(ptr
, "in"))
2441 else if (!_cups_strcasecmp(ptr
, "ft"))
2446 else if (!_cups_strcasecmp(ptr
, "mm"))
2451 else if (!_cups_strcasecmp(ptr
, "cm"))
2456 else if (!_cups_strcasecmp(ptr
, "m"))
2467 pc
->custom_size
.width
= (int)w
;
2468 pc
->custom_size
.length
= (int)l
;
2470 return (&(pc
->custom_size
));
2474 * Not a custom size - look it up...
2477 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2478 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2479 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2483 * Look up standard sizes...
2486 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2487 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2488 media
= pwgMediaForPWG(page_size
);
2492 pc
->custom_size
.width
= media
->width
;
2493 pc
->custom_size
.length
= media
->length
;
2495 return (&(pc
->custom_size
));
2503 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2507 const char * /* O - PWG media-source keyword */
2509 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2510 const char *input_slot
) /* I - PPD InputSlot */
2512 int i
; /* Looping var */
2513 pwg_map_t
*source
; /* Current source */
2517 * Range check input...
2520 if (!pc
|| !input_slot
)
2523 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2524 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2525 return (source
->pwg
);
2532 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2536 const char * /* O - PWG media-type keyword */
2538 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2539 const char *media_type
) /* I - PPD MediaType */
2541 int i
; /* Looping var */
2542 pwg_map_t
*type
; /* Current type */
2546 * Range check input...
2549 if (!pc
|| !media_type
)
2552 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2553 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2561 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2564 int /* O - 1 on success, 0 on failure */
2566 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2567 const char *filename
, /* I - File to write */
2568 ipp_t
*attrs
) /* I - Attributes to write, if any */
2570 int i
, j
, k
; /* Looping vars */
2571 cups_file_t
*fp
; /* Output file */
2572 pwg_size_t
*size
; /* Current size */
2573 pwg_map_t
*map
; /* Current map */
2574 _pwg_finishings_t
*f
; /* Current finishing option */
2575 cups_option_t
*option
; /* Current option */
2576 const char *value
; /* Filter/pre-filter value */
2577 char newfile
[1024]; /* New filename */
2581 * Range check input...
2584 if (!pc
|| !filename
)
2586 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2591 * Open the file and write with compression...
2594 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2595 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2597 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2602 * Standard header...
2605 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2611 if (pc
->num_bins
> 0)
2613 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2614 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2615 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2622 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2623 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2624 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2625 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2626 size
->bottom
, size
->right
, size
->top
);
2627 if (pc
->custom_max_width
> 0)
2628 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2629 pc
->custom_max_width
, pc
->custom_max_length
,
2630 pc
->custom_min_width
, pc
->custom_min_length
,
2631 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2632 pc
->custom_size
.right
, pc
->custom_size
.top
);
2638 if (pc
->source_option
)
2639 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2641 if (pc
->num_sources
> 0)
2643 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2644 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2645 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2652 if (pc
->num_types
> 0)
2654 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2655 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2656 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2663 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2664 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2665 if (pc
->num_presets
[i
][j
])
2667 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2668 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2671 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2672 cupsFilePutChar(fp
, '\n');
2679 if (pc
->sides_option
)
2680 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2682 if (pc
->sides_1sided
)
2683 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2685 if (pc
->sides_2sided_long
)
2686 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2688 if (pc
->sides_2sided_short
)
2689 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2692 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2696 cupsFilePutConf(fp
, "Product", pc
->product
);
2698 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2700 value
= (const char *)cupsArrayNext(pc
->filters
))
2701 cupsFilePutConf(fp
, "Filter", value
);
2703 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2705 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2706 cupsFilePutConf(fp
, "PreFilter", value
);
2708 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2711 * Finishing options...
2714 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2716 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2718 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2719 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2720 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2721 cupsFilePutChar(fp
, '\n');
2728 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2731 * Accounting/quota/PIN/managed printing values...
2734 if (pc
->charge_info_uri
)
2735 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2737 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2738 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2739 pc
->accounting_user_id
? "true" : "false");
2742 cupsFilePutConf(fp
, "Password", pc
->password
);
2744 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2746 value
= (char *)cupsArrayNext(pc
->mandatory
))
2747 cupsFilePutConf(fp
, "Mandatory", value
);
2753 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2755 value
= (char *)cupsArrayNext(pc
->support_files
))
2756 cupsFilePutConf(fp
, "SupportFile", value
);
2759 * IPP attributes, if any...
2764 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2766 attrs
->state
= IPP_STATE_IDLE
;
2767 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2771 * Close and return...
2774 if (cupsFileClose(fp
))
2781 return (!rename(newfile
, filename
));
2786 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
2787 * of an IPP printer.
2790 char * /* O - PPD filename or NULL on error */
2791 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
2792 size_t bufsize
, /* I - Size of filename buffer */
2793 ipp_t
*response
) /* I - Get-Printer-Attributes response */
2795 cups_file_t
*fp
; /* PPD file */
2796 ipp_attribute_t
*attr
, /* xxx-supported */
2797 *defattr
, /* xxx-default */
2798 *x_dim
, *y_dim
; /* Media dimensions */
2799 ipp_t
*media_size
; /* Media size collection */
2800 char make
[256], /* Make and model */
2801 *model
, /* Model name */
2802 ppdname
[PPD_MAX_NAME
];
2804 int i
, j
, /* Looping vars */
2805 count
, /* Number of values */
2806 bottom
, /* Largest bottom margin */
2807 left
, /* Largest left margin */
2808 right
, /* Largest right margin */
2809 top
; /* Largest top margin */
2810 pwg_media_t
*pwg
; /* PWG media size */
2811 int xres
, yres
; /* Resolution values */
2812 struct lconv
*loc
= localeconv();
2817 * Range check input...
2823 if (!buffer
|| bufsize
< 1 || !response
)
2827 * Open a temporary file for the PPD...
2830 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
2834 * Standard stuff for PPD file...
2837 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
2838 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
2839 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2840 cupsFilePuts(fp
, "*LanguageVersion: English\n");
2841 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
2842 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
2843 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
2844 cupsFilePuts(fp
, "*FileSystem: False\n");
2845 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
2847 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
2848 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
2850 strlcpy(make
, "Unknown Printer", sizeof(make
));
2852 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
2853 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
2856 strlcpy(make
, "HP", sizeof(make
));
2858 else if ((model
= strchr(make
, ' ')) != NULL
)
2863 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
2864 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
2865 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
2866 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
2867 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
2869 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
2870 cupsFilePuts(fp
, "*ColorDevice: True\n");
2872 cupsFilePuts(fp
, "*ColorDevice: False\n");
2874 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
2875 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
2876 cupsFilePuts(fp
, "*cupsLanguages: \"en\"\n");
2882 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
2884 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
2886 const char *format
= ippGetString(attr
, i
, NULL
);
2889 if (!_cups_strcasecmp(format
, "application/pdf"))
2890 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
2891 else if (!_cups_strcasecmp(format
, "application/postscript"))
2892 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-postscript application/postscript 10 -\"\n");
2893 else if (_cups_strcasecmp(format
, "application/octet-stream") && _cups_strcasecmp(format
, "application/vnd.hp-pcl") && _cups_strcasecmp(format
, "text/plain"))
2894 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 10 -\"\n", format
, format
);
2899 * PageSize/PageRegion/ImageableArea/PaperDimension
2902 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
2904 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
2905 if (ippGetInteger(attr
, i
) > bottom
)
2906 bottom
= ippGetInteger(attr
, i
);
2911 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
2913 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
2914 if (ippGetInteger(attr
, i
) > left
)
2915 left
= ippGetInteger(attr
, i
);
2920 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
2922 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
2923 if (ippGetInteger(attr
, i
) > right
)
2924 right
= ippGetInteger(attr
, i
);
2929 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
2931 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
2932 if (ippGetInteger(attr
, i
) > top
)
2933 top
= ippGetInteger(attr
, i
);
2938 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
2940 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
2942 media_size
= ippGetCollection(attr
, 0);
2943 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
2944 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
2948 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
2949 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
2952 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
2955 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
2958 if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
2960 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
2961 "*OrderDependency: 10 AnySetup *PageSize\n"
2962 "*DefaultPageSize: %s\n", ppdname
);
2963 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
2965 media_size
= ippGetCollection(attr
, i
);
2966 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
2967 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
2971 char twidth
[256], /* Width string */
2972 tlength
[256]; /* Length string */
2974 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
2976 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
2977 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
2979 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", pwg
->ppd
, twidth
, tlength
);
2982 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
2984 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
2985 "*OrderDependency: 10 AnySetup *PageRegion\n"
2986 "*DefaultPageRegion: %s\n", ppdname
);
2987 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
2989 media_size
= ippGetCollection(attr
, i
);
2990 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
2991 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
2995 char twidth
[256], /* Width string */
2996 tlength
[256]; /* Length string */
2998 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3000 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3001 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3003 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%.1f %.1f]>>setpagedevice\"\n", pwg
->ppd
, pwg
->width
* 72.0 / 2540.0, pwg
->length
* 72.0 / 2540.0);
3006 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3008 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3009 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3010 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3012 media_size
= ippGetCollection(attr
, i
);
3013 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3014 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3018 char tleft
[256], /* Left string */
3019 tbottom
[256], /* Bottom string */
3020 tright
[256], /* Right string */
3021 ttop
[256], /* Top string */
3022 twidth
[256], /* Width string */
3023 tlength
[256]; /* Length string */
3025 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3027 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3028 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3029 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (pwg
->width
- right
) * 72.0 / 2540.0, loc
);
3030 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (pwg
->length
- top
) * 72.0 / 2540.0, loc
);
3031 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), pwg
->width
* 72.0 / 2540.0, loc
);
3032 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), pwg
->length
* 72.0 / 2540.0, loc
);
3034 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", pwg
->ppd
, tleft
, tbottom
, tright
, ttop
);
3035 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", pwg
->ppd
, twidth
, tlength
);
3044 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_KEYWORD
)) != NULL
)
3045 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3047 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3049 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3051 static const char * const sources
[][2] =
3053 { "Auto", "Automatic" },
3055 { "Alternate", "Alternate" },
3056 { "LargeCapacity", "Large Capacity" },
3057 { "Manual", "Manual" },
3058 { "Envelope", "Envelope" },
3060 { "Photo", "Photo" },
3061 { "Hagaki", "Hagaki" },
3062 { "MainRoll", "Main Roll" },
3063 { "AlternateRoll", "Alternate Roll" },
3065 { "Middle", "Middle" },
3066 { "Bottom", "Bottom" },
3069 { "Right", "Right" },
3070 { "Center", "Center" },
3072 { "ByPassTray", "Multipurpose" },
3073 { "Tray1", "Tray 1" },
3074 { "Tray2", "Tray 2" },
3075 { "Tray3", "Tray 3" },
3076 { "Tray4", "Tray 4" },
3077 { "Tray5", "Tray 5" },
3078 { "Tray6", "Tray 6" },
3079 { "Tray7", "Tray 7" },
3080 { "Tray8", "Tray 8" },
3081 { "Tray9", "Tray 9" },
3082 { "Tray10", "Tray 10" },
3083 { "Tray11", "Tray 11" },
3084 { "Tray12", "Tray 12" },
3085 { "Tray13", "Tray 13" },
3086 { "Tray14", "Tray 14" },
3087 { "Tray15", "Tray 15" },
3088 { "Tray16", "Tray 16" },
3089 { "Tray17", "Tray 17" },
3090 { "Tray18", "Tray 18" },
3091 { "Tray19", "Tray 19" },
3092 { "Tray20", "Tray 20" },
3093 { "Roll1", "Roll 1" },
3094 { "Roll2", "Roll 2" },
3095 { "Roll3", "Roll 3" },
3096 { "Roll4", "Roll 4" },
3097 { "Roll5", "Roll 5" },
3098 { "Roll6", "Roll 6" },
3099 { "Roll7", "Roll 7" },
3100 { "Roll8", "Roll 8" },
3101 { "Roll9", "Roll 9" },
3102 { "Roll10", "Roll 10" }
3105 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3106 "*OrderDependency: 10 AnySetup *InputSlot\n"
3107 "*DefaultInputSlot: %s\n", ppdname
);
3108 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3110 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3112 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3113 if (!strcmp(sources
[j
][0], ppdname
))
3115 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, sources
[j
][1], j
);
3119 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3126 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_KEYWORD
)) != NULL
)
3127 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3129 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3131 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_KEYWORD
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3133 static const char * const types
[][2] =
3134 { /* Media type strings (far from complete) */
3135 { "Auto", "Automatic" },
3136 { "Cardstock", "Cardstock" },
3137 { "Disc", "CD/DVD/Bluray" },
3138 { "Envelope", "Envelope" },
3139 { "Labels", "Label" },
3140 { "Other", "Other" },
3141 { "Photographic", "Photo" },
3142 { "PhotographicGlossy", "Glossy Photo" },
3143 { "PhotographicHighGloss", "High-Gloss Photo" },
3144 { "PhotographicMatte", "Matte Photo" },
3145 { "PhotographicSatin", "Satin Photo" },
3146 { "PhotographicSemiGloss", "Semi-Gloss Photo" },
3147 { "Stationery", "Plain Paper" },
3148 { "StationeryLetterhead", "Letterhead" },
3149 { "Transparency", "Transparency" }
3152 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3153 "*OrderDependency: 10 AnySetup *MediaType\n"
3154 "*DefaultMediaType: %s\n", ppdname
);
3155 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3157 pwg_ppdize_name(ippGetString(attr
, i
, NULL
), ppdname
, sizeof(ppdname
));
3159 for (j
= 0; j
< (int)(sizeof(types
) / sizeof(types
[0])); j
++)
3160 if (!strcmp(types
[j
][0], ppdname
))
3162 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, types
[j
][1], ppdname
);
3166 if (j
>= (int)(sizeof(types
) / sizeof(types
[0])))
3167 cupsFilePrintf(fp
, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, ppdname
);
3170 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3177 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3178 attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
);
3182 const char *default_color
= NULL
; /* Default */
3184 cupsFilePuts(fp
, "*OpenUI *ColorModel/Color Mode: PickOne\n"
3185 "*OrderDependency: 10 AnySetup *ColorModel\n");
3186 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3188 const char *keyword
= ippGetString(attr
, i
, NULL
);
3189 /* Keyword for color/bit depth */
3191 if (!strcmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3193 cupsFilePuts(fp
, "*ColorModel FastGray/Fast Grayscale: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3196 default_color
= "FastGray";
3198 else if (!strcmp(keyword
, "sgray_8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3200 cupsFilePuts(fp
, "*ColorModel Gray/Grayscale: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3202 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3203 default_color
= "Gray";
3205 else if (!strcmp(keyword
, "srgb_8") || !strcmp(keyword
, "color"))
3207 cupsFilePuts(fp
, "*ColorModel RGB/Color: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n");
3209 default_color
= "RGB";
3214 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3216 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3223 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3225 cupsFilePuts(fp
, "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
3226 "*OrderDependency: 10 AnySetup *Duplex\n"
3227 "*DefaultDuplex: None\n"
3228 "*Duplex None/Off (1-Sided): \"<</Duplex false>>setpagedevice\"\n"
3229 "*Duplex DuplexNoTumble/Long-Edge (Portrait): \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3230 "*Duplex DuplexTumble/Short-Edge (Landscape): \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3231 "*CloseUI: *Duplex\n");
3233 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3235 const char *keyword
= ippGetString(attr
, 0, NULL
);
3238 if (!strcmp(keyword
, "flipped"))
3239 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3240 else if (!strcmp(keyword
, "manual-tumble"))
3241 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3242 else if (!strcmp(keyword
, "normal"))
3243 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3245 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3247 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3249 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3251 const char *dm
= ippGetString(attr
, i
, NULL
);
3254 if (!_cups_strcasecmp(dm
, "DM1"))
3256 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3259 else if (!_cups_strcasecmp(dm
, "DM2"))
3261 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3264 else if (!_cups_strcasecmp(dm
, "DM3"))
3266 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3269 else if (!_cups_strcasecmp(dm
, "DM4"))
3271 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3279 * cupsPrintQuality and DefaultResolution...
3282 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
3284 count
= ippGetCount(attr
);
3286 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3287 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3289 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3290 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3291 "*DefaultcupsPrintQuality: Normal\n");
3294 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, NULL
, 0);
3295 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3297 pwg_ppdize_resolution(attr
, count
/ 2, &xres
, &yres
, NULL
, 0);
3298 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3301 pwg_ppdize_resolution(attr
, count
- 1, &xres
, &yres
, NULL
, 0);
3302 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres
, yres
);
3305 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3307 else if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3309 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
3311 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3313 const char *rs
= ippGetString(attr
, i
, NULL
);
3316 if (_cups_strncasecmp(rs
, "RS", 2))
3319 lowdpi
= atoi(rs
+ 2);
3320 if ((rs
= strrchr(rs
, '-')) != NULL
)
3321 hidpi
= atoi(rs
+ 1);
3330 * Invalid "urf-supported" value...
3333 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3338 * Generate print qualities based on low and high DPIs...
3341 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
3343 cupsFilePuts(fp
, "*OpenUI *cupsPrintQuality/Print Quality: PickOne\n"
3344 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
3345 "*DefaultcupsPrintQuality: Normal\n");
3346 if ((lowdpi
& 1) == 0)
3347 cupsFilePrintf(fp
, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
/ 2);
3348 cupsFilePrintf(fp
, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", lowdpi
, lowdpi
);
3350 cupsFilePrintf(fp
, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", hidpi
, hidpi
);
3351 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
3354 else if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
3356 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
3357 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
3360 cupsFilePuts(fp
, "*DefaultResolution: 300dpi\n");
3363 * Close up and return...
3373 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
3377 const char * /* O - InputSlot name */
3378 _pwgInputSlotForSource(
3379 const char *media_source
, /* I - PWG media-source */
3380 char *name
, /* I - Name buffer */
3381 size_t namesize
) /* I - Size of name buffer */
3384 * Range check input...
3387 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
3390 if (_cups_strcasecmp(media_source
, "main"))
3391 strlcpy(name
, "Cassette", namesize
);
3392 else if (_cups_strcasecmp(media_source
, "alternate"))
3393 strlcpy(name
, "Multipurpose", namesize
);
3394 else if (_cups_strcasecmp(media_source
, "large-capacity"))
3395 strlcpy(name
, "LargeCapacity", namesize
);
3396 else if (_cups_strcasecmp(media_source
, "bottom"))
3397 strlcpy(name
, "Lower", namesize
);
3398 else if (_cups_strcasecmp(media_source
, "middle"))
3399 strlcpy(name
, "Middle", namesize
);
3400 else if (_cups_strcasecmp(media_source
, "top"))
3401 strlcpy(name
, "Upper", namesize
);
3402 else if (_cups_strcasecmp(media_source
, "rear"))
3403 strlcpy(name
, "Rear", namesize
);
3404 else if (_cups_strcasecmp(media_source
, "side"))
3405 strlcpy(name
, "Side", namesize
);
3406 else if (_cups_strcasecmp(media_source
, "envelope"))
3407 strlcpy(name
, "Envelope", namesize
);
3408 else if (_cups_strcasecmp(media_source
, "main-roll"))
3409 strlcpy(name
, "Roll", namesize
);
3410 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
3411 strlcpy(name
, "Roll2", namesize
);
3413 pwg_ppdize_name(media_source
, name
, namesize
);
3420 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
3424 const char * /* O - MediaType name */
3425 _pwgMediaTypeForType(
3426 const char *media_type
, /* I - PWG media-type */
3427 char *name
, /* I - Name buffer */
3428 size_t namesize
) /* I - Size of name buffer */
3431 * Range check input...
3434 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
3437 if (_cups_strcasecmp(media_type
, "auto"))
3438 strlcpy(name
, "Auto", namesize
);
3439 else if (_cups_strcasecmp(media_type
, "cardstock"))
3440 strlcpy(name
, "Cardstock", namesize
);
3441 else if (_cups_strcasecmp(media_type
, "envelope"))
3442 strlcpy(name
, "Envelope", namesize
);
3443 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
3444 strlcpy(name
, "Glossy", namesize
);
3445 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
3446 strlcpy(name
, "HighGloss", namesize
);
3447 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
3448 strlcpy(name
, "Matte", namesize
);
3449 else if (_cups_strcasecmp(media_type
, "stationery"))
3450 strlcpy(name
, "Plain", namesize
);
3451 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
3452 strlcpy(name
, "Coated", namesize
);
3453 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
3454 strlcpy(name
, "Inkjet", namesize
);
3455 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
3456 strlcpy(name
, "Letterhead", namesize
);
3457 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
3458 strlcpy(name
, "Preprinted", namesize
);
3459 else if (_cups_strcasecmp(media_type
, "transparency"))
3460 strlcpy(name
, "Transparency", namesize
);
3462 pwg_ppdize_name(media_type
, name
, namesize
);
3469 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
3472 const char * /* O - PageSize name */
3473 _pwgPageSizeForMedia(
3474 pwg_media_t
*media
, /* I - Media */
3475 char *name
, /* I - PageSize name buffer */
3476 size_t namesize
) /* I - Size of name buffer */
3478 const char *sizeptr
, /* Pointer to size in PWG name */
3479 *dimptr
; /* Pointer to dimensions in PWG name */
3483 * Range check input...
3486 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
3490 * Copy or generate a PageSize name...
3496 * Use a standard Adobe name...
3499 strlcpy(name
, media
->ppd
, namesize
);
3501 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
3502 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
3503 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
3504 (size_t)(dimptr
- sizeptr
) > namesize
)
3507 * Use a name of the form "wNNNhNNN"...
3510 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
3511 (int)PWG_TO_POINTS(media
->length
));
3516 * Copy the size name from class_sizename_dimensions...
3519 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
3520 name
[dimptr
- sizeptr
- 1] = '\0';
3528 * 'pwg_compare_finishings()' - Compare two finishings values.
3531 static int /* O- Result of comparison */
3532 pwg_compare_finishings(
3533 _pwg_finishings_t
*a
, /* I - First finishings value */
3534 _pwg_finishings_t
*b
) /* I - Second finishings value */
3536 return ((int)b
->value
- (int)a
->value
);
3541 * 'pwg_free_finishings()' - Free a finishings value.
3545 pwg_free_finishings(
3546 _pwg_finishings_t
*f
) /* I - Finishings value */
3548 cupsFreeOptions(f
->num_options
, f
->options
);
3554 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
3558 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
3559 char *name
, /* I - Name buffer */
3560 size_t namesize
) /* I - Size of name buffer */
3562 char *ptr
, /* Pointer into name buffer */
3563 *end
; /* End of name buffer */
3566 *name
= (char)toupper(*ipp
++);
3568 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
3570 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
3573 *ptr
++ = (char)toupper(*ipp
++ & 255);
3585 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
3589 pwg_ppdize_resolution(
3590 ipp_attribute_t
*attr
, /* I - Attribute to convert */
3591 int element
, /* I - Element to convert */
3592 int *xres
, /* O - X resolution in DPI */
3593 int *yres
, /* O - Y resolution in DPI */
3594 char *name
, /* I - Name buffer */
3595 size_t namesize
) /* I - Size of name buffer */
3597 ipp_res_t units
; /* Units for resolution */
3600 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
3602 if (units
== IPP_RES_PER_CM
)
3604 *xres
= (int)(*xres
* 2.54);
3605 *yres
= (int)(*yres
* 2.54);
3608 if (name
&& namesize
> 4)
3611 snprintf(name
, namesize
, "%ddpi", *xres
);
3613 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
3619 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
3623 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
3624 char *name
, /* I - Name buffer */
3625 size_t namesize
, /* I - Size of name buffer */
3626 const char *dashchars
)/* I - Characters to be replaced by dashes */
3628 char *ptr
, /* Pointer into name buffer */
3629 *end
; /* End of name buffer */
3632 if (_cups_islower(*ppd
))
3635 * Already lowercase name, use as-is?
3638 const char *ppdptr
; /* Pointer into PPD keyword */
3640 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
3641 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
3646 strlcpy(name
, ppd
, namesize
);
3651 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
3653 if (_cups_isalnum(*ppd
) || *ppd
== '-')
3654 *ptr
++ = (char)tolower(*ppd
& 255);
3655 else if (strchr(dashchars
, *ppd
))
3660 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
3661 _cups_isupper(ppd
[1]) && ptr
< end
)
3663 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))