2 * PPD cache implementation for CUPS.
4 * Copyright 2010-2017 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * Include necessary headers...
13 #include "cups-private.h"
14 #include "ppd-private.h"
19 * Macro to test for two almost-equal PWG measurements.
22 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
29 static int cups_get_url(http_t
**http
, const char *url
, char *name
, size_t namesize
);
30 static void pwg_add_finishing(cups_array_t
*finishings
, ipp_finishings_t
template, const char *name
, const char *value
);
31 static void pwg_add_message(cups_array_t
*a
, const char *msg
, const char *str
);
32 static int pwg_compare_finishings(_pwg_finishings_t
*a
, _pwg_finishings_t
*b
);
33 static int pwg_compare_sizes(cups_size_t
*a
, cups_size_t
*b
);
34 static cups_size_t
*pwg_copy_size(cups_size_t
*size
);
35 static void pwg_free_finishings(_pwg_finishings_t
*f
);
36 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
37 static void pwg_ppdize_resolution(ipp_attribute_t
*attr
, int element
, int *xres
, int *yres
, char *name
, size_t namesize
);
38 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
,
39 const char *dashchars
);
43 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
45 * This functions converts PPD and CUPS-specific options to their standard IPP
46 * attributes and values and adds them to the specified IPP request.
49 int /* O - New number of copies */
51 ipp_t
*request
, /* I - IPP request */
52 ppd_file_t
*ppd
, /* I - PPD file */
53 _ppd_cache_t
*pc
, /* I - PPD cache info */
54 ipp_attribute_t
*media_col_sup
, /* I - media-col-supported values */
55 ipp_attribute_t
*doc_handling_sup
, /* I - multiple-document-handling-supported values */
56 ipp_attribute_t
*print_color_mode_sup
,
57 /* I - Printer supports print-color-mode */
58 const char *user
, /* I - User info */
59 const char *format
, /* I - document-format value */
60 int copies
, /* I - Number of copies */
61 int num_options
, /* I - Number of options */
62 cups_option_t
*options
) /* I - Options */
64 int i
; /* Looping var */
65 const char *keyword
, /* PWG keyword */
66 *password
; /* Password string */
67 pwg_size_t
*size
; /* PWG media size */
68 ipp_t
*media_col
, /* media-col value */
69 *media_size
; /* media-size value */
70 const char *media_source
, /* media-source value */
71 *media_type
, /* media-type value */
72 *collate_str
, /* multiple-document-handling value */
73 *color_attr_name
, /* Supported color attribute */
74 *mandatory
, /* Mandatory attributes */
75 *finishing_template
; /* Finishing template */
76 int num_finishings
= 0, /* Number of finishing values */
77 finishings
[10]; /* Finishing enum values */
78 ppd_choice_t
*choice
; /* Marked choice */
79 int finishings_copies
= copies
;
80 /* Number of copies for finishings */
84 * Send standard IPP attributes...
87 if (pc
->password
&& (password
= cupsGetOption("job-password", num_options
, options
)) != NULL
&& ippGetOperation(request
) != IPP_OP_VALIDATE_JOB
)
89 ipp_attribute_t
*attr
= NULL
; /* job-password attribute */
91 if ((keyword
= cupsGetOption("job-password-encryption", num_options
, options
)) == NULL
)
94 if (!strcmp(keyword
, "none"))
97 * Add plain-text job-password...
100 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", password
, (int)strlen(password
));
105 * Add hashed job-password...
108 unsigned char hash
[64]; /* Hash of password */
109 ssize_t hashlen
; /* Length of hash */
111 if ((hashlen
= cupsHashData(keyword
, password
, strlen(password
), hash
, sizeof(hash
))) > 0)
112 attr
= ippAddOctetString(request
, IPP_TAG_OPERATION
, "job-password", hash
, (int)hashlen
);
116 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "job-password-encryption", NULL
, keyword
);
121 if ((keyword
= cupsGetOption("job-account-id", num_options
, options
)) == NULL
)
122 keyword
= cupsGetOption("job-billing", num_options
, options
);
125 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-account-id", NULL
, keyword
);
128 if (pc
->accounting_user_id
)
130 if ((keyword
= cupsGetOption("job-accounting-user-id", num_options
, options
)) == NULL
)
134 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-accounting-user-id", NULL
, keyword
);
137 for (mandatory
= (const char *)cupsArrayFirst(pc
->mandatory
); mandatory
; mandatory
= (const char *)cupsArrayNext(pc
->mandatory
))
139 if (strcmp(mandatory
, "copies") &&
140 strcmp(mandatory
, "destination-uris") &&
141 strcmp(mandatory
, "finishings") &&
142 strcmp(mandatory
, "finishings-col") &&
143 strcmp(mandatory
, "finishing-template") &&
144 strcmp(mandatory
, "job-account-id") &&
145 strcmp(mandatory
, "job-accounting-user-id") &&
146 strcmp(mandatory
, "job-password") &&
147 strcmp(mandatory
, "job-password-encryption") &&
148 strcmp(mandatory
, "media") &&
149 strncmp(mandatory
, "media-col", 9) &&
150 strcmp(mandatory
, "multiple-document-handling") &&
151 strcmp(mandatory
, "output-bin") &&
152 strcmp(mandatory
, "print-color-mode") &&
153 strcmp(mandatory
, "print-quality") &&
154 strcmp(mandatory
, "sides") &&
155 (keyword
= cupsGetOption(mandatory
, num_options
, options
)) != NULL
)
157 _ipp_option_t
*opt
= _ippFindOption(mandatory
);
159 ipp_tag_t value_tag
= opt
? opt
->value_tag
: IPP_TAG_NAME
;
164 case IPP_TAG_INTEGER
:
166 ippAddInteger(request
, IPP_TAG_JOB
, value_tag
, mandatory
, atoi(keyword
));
168 case IPP_TAG_BOOLEAN
:
169 ippAddBoolean(request
, IPP_TAG_JOB
, mandatory
, !_cups_strcasecmp(keyword
, "true"));
173 int lower
, upper
; /* Range */
175 if (sscanf(keyword
, "%d-%d", &lower
, &upper
) != 2)
176 lower
= upper
= atoi(keyword
);
178 ippAddRange(request
, IPP_TAG_JOB
, mandatory
, lower
, upper
);
181 case IPP_TAG_STRING
:
182 ippAddOctetString(request
, IPP_TAG_JOB
, mandatory
, keyword
, (int)strlen(keyword
));
185 if (!strcmp(mandatory
, "print-color-mode") && !strcmp(keyword
, "monochrome"))
187 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
188 keyword
= "auto-monochrome";
189 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
190 keyword
= "process-monochrome";
193 ippAddString(request
, IPP_TAG_JOB
, value_tag
, mandatory
, NULL
, keyword
);
199 if ((keyword
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
200 keyword
= cupsGetOption("media", num_options
, options
);
202 media_source
= _ppdCacheGetSource(pc
, cupsGetOption("InputSlot", num_options
, options
));
203 media_type
= _ppdCacheGetType(pc
, cupsGetOption("MediaType", num_options
, options
));
204 size
= _ppdCacheGetSize(pc
, keyword
);
206 if (size
|| media_source
|| media_type
)
209 * Add a media-col value...
212 media_col
= ippNew();
216 media_size
= ippNew();
217 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
218 "x-dimension", size
->width
);
219 ippAddInteger(media_size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
220 "y-dimension", size
->length
);
222 ippAddCollection(media_col
, IPP_TAG_ZERO
, "media-size", media_size
);
225 for (i
= 0; i
< media_col_sup
->num_values
; i
++)
227 if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-left-margin"))
228 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
229 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-bottom-margin"))
230 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
231 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-right-margin"))
232 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
233 else if (size
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-top-margin"))
234 ippAddInteger(media_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
235 else if (media_source
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-source"))
236 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-source", NULL
, media_source
);
237 else if (media_type
&& !strcmp(media_col_sup
->values
[i
].string
.text
, "media-type"))
238 ippAddString(media_col
, IPP_TAG_ZERO
, IPP_TAG_KEYWORD
, "media-type", NULL
, media_type
);
241 ippAddCollection(request
, IPP_TAG_JOB
, "media-col", media_col
);
244 if ((keyword
= cupsGetOption("output-bin", num_options
, options
)) == NULL
)
246 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
)
247 keyword
= _ppdCacheGetBin(pc
, choice
->choice
);
251 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "output-bin", NULL
, keyword
);
253 color_attr_name
= print_color_mode_sup
? "print-color-mode" : "output-mode";
255 if ((keyword
= cupsGetOption("print-color-mode", num_options
, options
)) == NULL
)
257 if ((choice
= ppdFindMarkedChoice(ppd
, "ColorModel")) != NULL
)
259 if (!_cups_strcasecmp(choice
->choice
, "Gray"))
260 keyword
= "monochrome";
266 if (keyword
&& !strcmp(keyword
, "monochrome"))
268 if (ippContainsString(print_color_mode_sup
, "auto-monochrome"))
269 keyword
= "auto-monochrome";
270 else if (ippContainsString(print_color_mode_sup
, "process-monochrome") && !ippContainsString(print_color_mode_sup
, "monochrome"))
271 keyword
= "process-monochrome";
275 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, color_attr_name
, NULL
, keyword
);
277 if ((keyword
= cupsGetOption("print-quality", num_options
, options
)) != NULL
)
278 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", atoi(keyword
));
279 else if ((choice
= ppdFindMarkedChoice(ppd
, "cupsPrintQuality")) != NULL
)
281 if (!_cups_strcasecmp(choice
->choice
, "draft"))
282 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_DRAFT
);
283 else if (!_cups_strcasecmp(choice
->choice
, "normal"))
284 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_NORMAL
);
285 else if (!_cups_strcasecmp(choice
->choice
, "high"))
286 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "print-quality", IPP_QUALITY_HIGH
);
289 if ((keyword
= cupsGetOption("sides", num_options
, options
)) != NULL
)
290 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, keyword
);
291 else if (pc
->sides_option
&& (choice
= ppdFindMarkedChoice(ppd
, pc
->sides_option
)) != NULL
)
293 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_1sided
))
294 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "one-sided");
295 else if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_long
))
296 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-long-edge");
297 if (!_cups_strcasecmp(choice
->choice
, pc
->sides_2sided_short
))
298 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "sides", NULL
, "two-sided-short-edge");
305 if ((keyword
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
307 if (strstr(keyword
, "uncollated"))
312 else if ((keyword
= cupsGetOption("collate", num_options
, options
)) == NULL
)
317 if (!_cups_strcasecmp(format
, "image/gif") ||
318 !_cups_strcasecmp(format
, "image/jp2") ||
319 !_cups_strcasecmp(format
, "image/jpeg") ||
320 !_cups_strcasecmp(format
, "image/png") ||
321 !_cups_strcasecmp(format
, "image/tiff") ||
322 !_cups_strncasecmp(format
, "image/x-", 8))
325 * Collation makes no sense for single page image formats...
330 else if (!_cups_strncasecmp(format
, "image/", 6) ||
331 !_cups_strcasecmp(format
, "application/vnd.cups-raster"))
334 * Multi-page image formats will have copies applied by the upstream
342 if (doc_handling_sup
)
344 if (!_cups_strcasecmp(keyword
, "true"))
345 collate_str
= "separate-documents-collated-copies";
347 collate_str
= "separate-documents-uncollated-copies";
349 for (i
= 0; i
< doc_handling_sup
->num_values
; i
++)
351 if (!strcmp(doc_handling_sup
->values
[i
].string
.text
, collate_str
))
353 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "multiple-document-handling", NULL
, collate_str
);
358 if (i
>= doc_handling_sup
->num_values
)
363 * Map finishing options...
366 if ((finishing_template
= cupsGetOption("cupsFinishingTemplate", num_options
, options
)) == NULL
)
367 finishing_template
= cupsGetOption("finishing-template", num_options
, options
);
369 if (finishing_template
)
371 ipp_t
*fin_col
= ippNew(); /* finishings-col value */
373 ippAddString(fin_col
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, finishing_template
);
374 ippAddCollection(request
, IPP_TAG_JOB
, "finishings-col", fin_col
);
377 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
380 * Send job-pages-per-set attribute to apply finishings correctly...
383 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
388 num_finishings
= _ppdCacheGetFinishingValues(ppd
, pc
, (int)(sizeof(finishings
) / sizeof(finishings
[0])), finishings
);
389 if (num_finishings
> 0)
391 ippAddIntegers(request
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "finishings", num_finishings
, finishings
);
393 if (copies
!= finishings_copies
&& (keyword
= cupsGetOption("job-impressions", num_options
, options
)) != NULL
)
396 * Send job-pages-per-set attribute to apply finishings correctly...
399 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-pages-per-set", atoi(keyword
) / finishings_copies
);
409 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
412 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
416 _ppd_cache_t
* /* O - PPD cache and mapping data */
417 _ppdCacheCreateWithFile(
418 const char *filename
, /* I - File to read */
419 ipp_t
**attrs
) /* IO - IPP attributes, if any */
421 cups_file_t
*fp
; /* File */
422 _ppd_cache_t
*pc
; /* PWG mapping data */
423 pwg_size_t
*size
; /* Current size */
424 pwg_map_t
*map
; /* Current map */
425 _pwg_finishings_t
*finishings
; /* Current finishings option */
426 int linenum
, /* Current line number */
427 num_bins
, /* Number of bins in file */
428 num_sizes
, /* Number of sizes in file */
429 num_sources
, /* Number of sources in file */
430 num_types
; /* Number of types in file */
431 char line
[2048], /* Current line */
432 *value
, /* Pointer to value in line */
433 *valueptr
, /* Pointer into value */
434 pwg_keyword
[128], /* PWG keyword */
435 ppd_keyword
[PPD_MAX_NAME
];
437 _pwg_print_color_mode_t print_color_mode
;
438 /* Print color mode for preset */
439 _pwg_print_quality_t print_quality
; /* Print quality for preset */
442 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
445 * Range check input...
453 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
461 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
463 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
468 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
471 if (!cupsFileGets(fp
, line
, sizeof(line
)))
473 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
474 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
479 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
481 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
482 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
487 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
489 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of date PPD cache file."), 1);
490 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
491 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
497 * Allocate the mapping data structure...
500 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
502 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
503 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
507 pc
->max_copies
= 9999;
519 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
521 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
522 "linenum=%d", line
, value
, linenum
));
526 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
528 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
531 else if (!_cups_strcasecmp(line
, "Filter"))
534 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
535 (cups_acopy_func_t
)_cupsStrAlloc
,
536 (cups_afree_func_t
)_cupsStrFree
);
538 cupsArrayAdd(pc
->filters
, value
);
540 else if (!_cups_strcasecmp(line
, "PreFilter"))
543 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
544 (cups_acopy_func_t
)_cupsStrAlloc
,
545 (cups_afree_func_t
)_cupsStrFree
);
547 cupsArrayAdd(pc
->prefilters
, value
);
549 else if (!_cups_strcasecmp(line
, "Product"))
551 pc
->product
= _cupsStrAlloc(value
);
553 else if (!_cups_strcasecmp(line
, "SingleFile"))
555 pc
->single_file
= !_cups_strcasecmp(value
, "true");
557 else if (!_cups_strcasecmp(line
, "IPP"))
559 off_t pos
= cupsFileTell(fp
), /* Position in file */
560 length
= strtol(value
, NULL
, 10);
561 /* Length of IPP attributes */
565 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
566 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
569 else if (length
<= 0)
571 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
572 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
579 * Read IPP attributes into the provided variable...
584 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
585 *attrs
) != IPP_STATE_DATA
)
587 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
588 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
595 * Skip the IPP data entirely...
598 cupsFileSeek(fp
, pos
+ length
);
601 if (cupsFileTell(fp
) != (pos
+ length
))
603 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
604 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
608 else if (!_cups_strcasecmp(line
, "NumBins"))
612 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
613 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
617 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
619 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
620 "%d.", num_sizes
, linenum
));
621 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
625 if ((pc
->bins
= calloc((size_t)num_bins
, sizeof(pwg_map_t
))) == NULL
)
627 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
629 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
633 else if (!_cups_strcasecmp(line
, "Bin"))
635 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
637 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
638 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
642 if (pc
->num_bins
>= num_bins
)
644 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
646 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
650 map
= pc
->bins
+ pc
->num_bins
;
651 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
652 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
656 else if (!_cups_strcasecmp(line
, "NumSizes"))
660 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
665 if ((num_sizes
= atoi(value
)) < 0 || num_sizes
> 65536)
667 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
668 "%d.", num_sizes
, linenum
));
669 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
675 if ((pc
->sizes
= calloc((size_t)num_sizes
, sizeof(pwg_size_t
))) == NULL
)
677 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
679 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
684 else if (!_cups_strcasecmp(line
, "Size"))
686 if (pc
->num_sizes
>= num_sizes
)
688 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
690 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
694 size
= pc
->sizes
+ pc
->num_sizes
;
696 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
697 &(size
->width
), &(size
->length
), &(size
->left
),
698 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
700 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
702 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
706 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
707 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
711 else if (!_cups_strcasecmp(line
, "CustomSize"))
713 if (pc
->custom_max_width
> 0)
715 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
717 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
721 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
722 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
723 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
724 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
725 &(pc
->custom_size
.top
)) != 8)
727 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
729 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
733 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
734 pc
->custom_max_width
, pc
->custom_max_length
, NULL
);
735 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
737 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
738 pc
->custom_min_width
, pc
->custom_min_length
, NULL
);
739 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
741 else if (!_cups_strcasecmp(line
, "SourceOption"))
743 pc
->source_option
= _cupsStrAlloc(value
);
745 else if (!_cups_strcasecmp(line
, "NumSources"))
749 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
751 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
755 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
757 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
758 "line %d.", num_sources
, linenum
));
759 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
763 if ((pc
->sources
= calloc((size_t)num_sources
, sizeof(pwg_map_t
))) == NULL
)
765 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
767 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
771 else if (!_cups_strcasecmp(line
, "Source"))
773 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
775 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
777 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
781 if (pc
->num_sources
>= num_sources
)
783 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
785 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
789 map
= pc
->sources
+ pc
->num_sources
;
790 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
791 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
795 else if (!_cups_strcasecmp(line
, "NumTypes"))
799 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
800 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
804 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
806 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
807 "line %d.", num_types
, linenum
));
808 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
812 if ((pc
->types
= calloc((size_t)num_types
, sizeof(pwg_map_t
))) == NULL
)
814 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
816 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
820 else if (!_cups_strcasecmp(line
, "Type"))
822 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
824 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
826 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
830 if (pc
->num_types
>= num_types
)
832 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
834 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
838 map
= pc
->types
+ pc
->num_types
;
839 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
840 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
844 else if (!_cups_strcasecmp(line
, "Preset"))
847 * Preset output-mode print-quality name=value ...
850 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
851 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
853 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
854 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
855 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
856 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
857 valueptr
== value
|| !*valueptr
)
859 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
861 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
865 pc
->num_presets
[print_color_mode
][print_quality
] =
866 cupsParseOptions(valueptr
, 0,
867 pc
->presets
[print_color_mode
] + print_quality
);
869 else if (!_cups_strcasecmp(line
, "SidesOption"))
870 pc
->sides_option
= _cupsStrAlloc(value
);
871 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
872 pc
->sides_1sided
= _cupsStrAlloc(value
);
873 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
874 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
875 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
876 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
877 else if (!_cups_strcasecmp(line
, "Finishings"))
881 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
883 (cups_afree_func_t
)pwg_free_finishings
);
885 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
888 finishings
->value
= (ipp_finishings_t
)strtol(value
, &valueptr
, 10);
889 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
890 &(finishings
->options
));
892 cupsArrayAdd(pc
->finishings
, finishings
);
894 else if (!_cups_strcasecmp(line
, "FinishingTemplate"))
897 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
899 cupsArrayAdd(pc
->templates
, value
);
901 else if (!_cups_strcasecmp(line
, "MaxCopies"))
902 pc
->max_copies
= atoi(value
);
903 else if (!_cups_strcasecmp(line
, "ChargeInfoURI"))
904 pc
->charge_info_uri
= _cupsStrAlloc(value
);
905 else if (!_cups_strcasecmp(line
, "JobAccountId"))
906 pc
->account_id
= !_cups_strcasecmp(value
, "true");
907 else if (!_cups_strcasecmp(line
, "JobAccountingUserId"))
908 pc
->accounting_user_id
= !_cups_strcasecmp(value
, "true");
909 else if (!_cups_strcasecmp(line
, "JobPassword"))
910 pc
->password
= _cupsStrAlloc(value
);
911 else if (!_cups_strcasecmp(line
, "Mandatory"))
914 _cupsArrayAddStrings(pc
->mandatory
, value
, ' ');
916 pc
->mandatory
= _cupsArrayNewStrings(value
, ' ');
918 else if (!_cups_strcasecmp(line
, "SupportFile"))
920 if (!pc
->support_files
)
921 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
922 (cups_acopy_func_t
)_cupsStrAlloc
,
923 (cups_afree_func_t
)_cupsStrFree
);
925 cupsArrayAdd(pc
->support_files
, value
);
929 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
934 if (pc
->num_sizes
< num_sizes
)
936 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
937 pc
->num_sizes
, num_sizes
));
938 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
942 if (pc
->num_sources
< num_sources
)
944 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
945 pc
->num_sources
, num_sources
));
946 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
950 if (pc
->num_types
< num_types
)
952 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
953 pc
->num_types
, num_types
));
954 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Bad PPD cache file."), 1);
963 * If we get here the file was bad - free any data and return...
969 _ppdCacheDestroy(pc
);
982 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
985 _ppd_cache_t
* /* O - PPD cache and mapping data */
986 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
988 int i
, j
, k
; /* Looping vars */
989 _ppd_cache_t
*pc
; /* PWG mapping data */
990 ppd_option_t
*input_slot
, /* InputSlot option */
991 *media_type
, /* MediaType option */
992 *output_bin
, /* OutputBin option */
993 *color_model
, /* ColorModel option */
994 *duplex
, /* Duplex option */
995 *ppd_option
; /* Other PPD option */
996 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
997 pwg_map_t
*map
; /* Current source/type map */
998 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
999 int num_options
; /* Number of preset options and props */
1000 cups_option_t
*options
; /* Preset options and properties */
1001 ppd_size_t
*ppd_size
; /* Current PPD size */
1002 pwg_size_t
*pwg_size
; /* Current PWG size */
1003 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
1004 /* PWG keyword string */
1005 ppd_name
[PPD_MAX_NAME
];
1006 /* Normalized PPD name */
1007 const char *pwg_name
; /* Standard PWG media name */
1008 pwg_media_t
*pwg_media
; /* PWG media data */
1009 _pwg_print_color_mode_t pwg_print_color_mode
;
1010 /* print-color-mode index */
1011 _pwg_print_quality_t pwg_print_quality
;
1012 /* print-quality index */
1013 int similar
; /* Are the old and new size similar? */
1014 pwg_size_t
*old_size
; /* Current old size */
1015 int old_imageable
, /* Old imageable length in 2540ths */
1016 old_borderless
, /* Old borderless state */
1017 old_known_pwg
; /* Old PWG name is well-known */
1018 int new_width
, /* New width in 2540ths */
1019 new_length
, /* New length in 2540ths */
1020 new_left
, /* New left margin in 2540ths */
1021 new_bottom
, /* New bottom margin in 2540ths */
1022 new_right
, /* New right margin in 2540ths */
1023 new_top
, /* New top margin in 2540ths */
1024 new_imageable
, /* New imageable length in 2540ths */
1025 new_borderless
, /* New borderless state */
1026 new_known_pwg
; /* New PWG name is well-known */
1027 pwg_size_t
*new_size
; /* New size to add, if any */
1028 const char *filter
; /* Current filter */
1029 _pwg_finishings_t
*finishings
; /* Current finishings value */
1030 char msg_id
[256]; /* Message identifier */
1033 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
1036 * Range check input...
1043 * Allocate memory...
1046 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
1048 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
1052 pc
->strings
= _cupsMessageNew(NULL
);
1055 * Copy and convert size data...
1058 if (ppd
->num_sizes
> 0)
1060 if ((pc
->sizes
= calloc((size_t)ppd
->num_sizes
, sizeof(pwg_size_t
))) == NULL
)
1062 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1063 "pwg_size_t's.", ppd
->num_sizes
));
1067 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
1072 * Don't copy over custom size...
1075 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
1079 * Convert the PPD size name to the corresponding PWG keyword name.
1082 if ((pwg_media
= pwgMediaForPPD(ppd_size
->name
)) != NULL
)
1085 * Standard name, do we have conflicts?
1088 for (j
= 0; j
< pc
->num_sizes
; j
++)
1089 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
1099 * Standard name and no conflicts, use it!
1102 pwg_name
= pwg_media
->pwg
;
1108 * Not a standard name; convert it to a PWG vendor name of the form:
1110 * pp_lowerppd_WIDTHxHEIGHTuu
1113 pwg_name
= pwg_keyword
;
1116 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
), "_.");
1117 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
1118 PWG_FROM_POINTS(ppd_size
->width
),
1119 PWG_FROM_POINTS(ppd_size
->length
), NULL
);
1123 * If we have a similar paper with non-zero margins then we only want to
1124 * keep it if it has a larger imageable area length. The NULL check is for
1125 * dimensions that are <= 0...
1128 if ((pwg_media
= _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size
->width
),
1129 PWG_FROM_POINTS(ppd_size
->length
),
1133 new_width
= pwg_media
->width
;
1134 new_length
= pwg_media
->length
;
1135 new_left
= PWG_FROM_POINTS(ppd_size
->left
);
1136 new_bottom
= PWG_FROM_POINTS(ppd_size
->bottom
);
1137 new_right
= PWG_FROM_POINTS(ppd_size
->width
- ppd_size
->right
);
1138 new_top
= PWG_FROM_POINTS(ppd_size
->length
- ppd_size
->top
);
1139 new_imageable
= new_length
- new_top
- new_bottom
;
1140 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
1141 new_left
== 0 && new_right
== 0;
1143 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
1147 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
1148 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
1149 old_size
->right
== 0 && old_size
->top
== 0;
1150 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
1151 strncmp(old_size
->map
.pwg
, "om_", 3);
1153 similar
= old_borderless
== new_borderless
&&
1154 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
1155 _PWG_EQUIVALENT(old_size
->length
, new_length
);
1158 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
1161 * The new paper has a larger imageable area so it could replace
1162 * the older paper. Regardless of the imageable area, we always
1163 * prefer the size with a well-known PWG name.
1166 new_size
= old_size
;
1167 _cupsStrFree(old_size
->map
.ppd
);
1168 _cupsStrFree(old_size
->map
.pwg
);
1175 * The paper was unique enough to deserve its own entry so add it to the
1179 new_size
= pwg_size
++;
1189 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
1190 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
1191 new_size
->width
= new_width
;
1192 new_size
->length
= new_length
;
1193 new_size
->left
= new_left
;
1194 new_size
->bottom
= new_bottom
;
1195 new_size
->right
= new_right
;
1196 new_size
->top
= new_top
;
1201 if (ppd
->variable_sizes
)
1204 * Generate custom size data...
1207 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
1208 PWG_FROM_POINTS(ppd
->custom_max
[0]),
1209 PWG_FROM_POINTS(ppd
->custom_max
[1]), NULL
);
1210 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
1211 pc
->custom_max_width
= PWG_FROM_POINTS(ppd
->custom_max
[0]);
1212 pc
->custom_max_length
= PWG_FROM_POINTS(ppd
->custom_max
[1]);
1214 pwgFormatSizeName(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
1215 PWG_FROM_POINTS(ppd
->custom_min
[0]),
1216 PWG_FROM_POINTS(ppd
->custom_min
[1]), NULL
);
1217 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
1218 pc
->custom_min_width
= PWG_FROM_POINTS(ppd
->custom_min
[0]);
1219 pc
->custom_min_length
= PWG_FROM_POINTS(ppd
->custom_min
[1]);
1221 pc
->custom_size
.left
= PWG_FROM_POINTS(ppd
->custom_margins
[0]);
1222 pc
->custom_size
.bottom
= PWG_FROM_POINTS(ppd
->custom_margins
[1]);
1223 pc
->custom_size
.right
= PWG_FROM_POINTS(ppd
->custom_margins
[2]);
1224 pc
->custom_size
.top
= PWG_FROM_POINTS(ppd
->custom_margins
[3]);
1228 * Copy and convert InputSlot data...
1231 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
1232 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
1236 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
1238 if ((pc
->sources
= calloc((size_t)input_slot
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1240 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1241 "pwg_map_t's for InputSlot.", input_slot
->num_choices
));
1245 pc
->num_sources
= input_slot
->num_choices
;
1247 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
1250 i
--, choice
++, map
++)
1252 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1253 !_cups_strcasecmp(choice
->choice
, "Default"))
1255 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
1257 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
1259 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
1261 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
1262 !_cups_strcasecmp(choice
->choice
, "MP") ||
1263 !_cups_strcasecmp(choice
->choice
, "MPTray"))
1264 pwg_name
= "by-pass-tray";
1265 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
1266 pwg_name
= "large-capacity";
1267 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
1268 pwg_name
= "bottom";
1269 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
1270 pwg_name
= "middle";
1271 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
1273 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
1275 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
1276 pwg_name
= "main-roll";
1280 * Convert PPD name to lowercase...
1283 pwg_name
= pwg_keyword
;
1284 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1288 map
->pwg
= _cupsStrAlloc(pwg_name
);
1289 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1292 * Add localized text for PWG keyword to message catalog...
1295 snprintf(msg_id
, sizeof(msg_id
), "media-source.%s", pwg_name
);
1296 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1301 * Copy and convert MediaType data...
1304 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1306 if ((pc
->types
= calloc((size_t)media_type
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1308 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1309 "pwg_map_t's for MediaType.", media_type
->num_choices
));
1313 pc
->num_types
= media_type
->num_choices
;
1315 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
1318 i
--, choice
++, map
++)
1320 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
1321 !_cups_strcasecmp(choice
->choice
, "Any") ||
1322 !_cups_strcasecmp(choice
->choice
, "Default"))
1324 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
1325 pwg_name
= "cardstock";
1326 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
1327 pwg_name
= "envelope";
1328 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
1329 pwg_name
= "photographic-glossy";
1330 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
1331 pwg_name
= "photographic-high-gloss";
1332 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
1333 pwg_name
= "photographic-matte";
1334 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
1335 pwg_name
= "stationery";
1336 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
1337 pwg_name
= "stationery-coated";
1338 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
1339 pwg_name
= "stationery-inkjet";
1340 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
1341 pwg_name
= "stationery-letterhead";
1342 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
1343 pwg_name
= "stationery-preprinted";
1344 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
1345 pwg_name
= "stationery-recycled";
1346 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
1347 pwg_name
= "transparency";
1351 * Convert PPD name to lowercase...
1354 pwg_name
= pwg_keyword
;
1355 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
),
1359 map
->pwg
= _cupsStrAlloc(pwg_name
);
1360 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1363 * Add localized text for PWG keyword to message catalog...
1366 snprintf(msg_id
, sizeof(msg_id
), "media-type.%s", pwg_name
);
1367 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1372 * Copy and convert OutputBin data...
1375 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1377 if ((pc
->bins
= calloc((size_t)output_bin
->num_choices
, sizeof(pwg_map_t
))) == NULL
)
1379 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
1380 "pwg_map_t's for OutputBin.", output_bin
->num_choices
));
1384 pc
->num_bins
= output_bin
->num_choices
;
1386 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1389 i
--, choice
++, map
++)
1391 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
), "_");
1393 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1394 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1397 * Add localized text for PWG keyword to message catalog...
1400 snprintf(msg_id
, sizeof(msg_id
), "output-bin.%s", pwg_name
);
1401 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1405 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1408 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1411 const char *quality
, /* com.apple.print.preset.quality value */
1412 *output_mode
, /* com.apple.print.preset.output-mode value */
1413 *color_model_val
, /* ColorModel choice */
1414 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1415 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1420 * Add localized text for PWG keyword to message catalog...
1423 snprintf(msg_id
, sizeof(msg_id
), "preset-name.%s", ppd_attr
->spec
);
1424 pwg_add_message(pc
->strings
, msg_id
, ppd_attr
->text
);
1427 * Get the options for this preset...
1430 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1433 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1434 num_options
, options
)) != NULL
)
1437 * Get the print-quality for this preset...
1440 if (!strcmp(quality
, "low"))
1441 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1442 else if (!strcmp(quality
, "high"))
1443 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1445 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1448 * Ignore graphicsType "Photo" presets that are not high quality.
1451 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1452 num_options
, options
);
1454 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1455 !strcmp(graphicsType
, "Photo"))
1459 * Ignore presets for normal and draft quality where the coating
1460 * isn't "none" or "autodetect".
1463 media_front_coating
= cupsGetOption(
1464 "com.apple.print.preset.media-front-coating",
1465 num_options
, options
);
1467 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1468 media_front_coating
&&
1469 strcmp(media_front_coating
, "none") &&
1470 strcmp(media_front_coating
, "autodetect"))
1474 * Get the output mode for this preset...
1477 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1478 num_options
, options
);
1479 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1483 if (!strcmp(output_mode
, "monochrome"))
1484 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1486 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1488 else if (color_model_val
)
1490 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1491 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1493 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1496 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1499 * Save the options for this combination as needed...
1502 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1503 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1504 _ppdParseOptions(ppd_attr
->value
, 0,
1505 pc
->presets
[pwg_print_color_mode
] +
1506 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1509 cupsFreeOptions(num_options
, options
);
1511 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1514 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1515 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1516 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1519 * Try adding some common color options to create grayscale presets. These
1520 * are listed in order of popularity...
1523 const char *color_option
= NULL
, /* Color control option */
1524 *gray_choice
= NULL
; /* Choice to select grayscale */
1526 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1527 ppdFindChoice(color_model
, "Gray"))
1529 color_option
= "ColorModel";
1530 gray_choice
= "Gray";
1532 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1533 ppdFindChoice(color_model
, "grayscale"))
1535 color_option
= "HPColorMode";
1536 gray_choice
= "grayscale";
1538 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1539 ppdFindChoice(color_model
, "Mono"))
1541 color_option
= "BRMonoColor";
1542 gray_choice
= "Mono";
1544 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1545 ppdFindChoice(color_model
, "1"))
1547 color_option
= "CNIJSGrayScale";
1550 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1551 ppdFindChoice(color_model
, "True"))
1553 color_option
= "HPColorAsGray";
1554 gray_choice
= "True";
1557 if (color_option
&& gray_choice
)
1560 * Copy and convert ColorModel (output-mode) data...
1563 cups_option_t
*coption
, /* Color option */
1564 *moption
; /* Monochrome option */
1566 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1567 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1568 pwg_print_quality
++)
1570 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1573 * Copy the color options...
1576 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1577 [pwg_print_quality
];
1578 options
= calloc(sizeof(cups_option_t
), (size_t)num_options
);
1582 for (i
= num_options
, moption
= options
,
1583 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1584 [pwg_print_quality
];
1586 i
--, moption
++, coption
++)
1588 moption
->name
= _cupsStrRetain(coption
->name
);
1589 moption
->value
= _cupsStrRetain(coption
->value
);
1592 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1594 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1598 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1602 * Add the grayscale option to the preset...
1605 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1606 cupsAddOption(color_option
, gray_choice
,
1607 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1608 [pwg_print_quality
],
1609 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1616 * Copy and convert Duplex (sides) data...
1619 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1620 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1621 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1622 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1623 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1627 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1629 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1633 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1634 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1635 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1636 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1637 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1638 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1639 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1640 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1641 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1642 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1643 !pc
->sides_2sided_short
)
1644 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1649 * Copy filters and pre-filters...
1652 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1653 (cups_acopy_func_t
)_cupsStrAlloc
,
1654 (cups_afree_func_t
)_cupsStrFree
);
1656 cupsArrayAdd(pc
->filters
,
1657 "application/vnd.cups-raw application/octet-stream 0 -");
1659 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1663 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1665 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1667 else if (ppd
->num_filters
> 0)
1669 for (i
= 0; i
< ppd
->num_filters
; i
++)
1670 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1673 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1676 * See if we have a command filter...
1679 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1681 filter
= (const char *)cupsArrayNext(pc
->filters
))
1682 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1683 _cups_isspace(filter
[28]))
1687 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1688 _cups_strcasecmp(ppd_attr
->value
, "none")))
1691 * No command filter and no cupsCommands keyword telling us not to use one.
1692 * See if this is a PostScript printer, and if so add a PostScript command
1696 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1698 filter
= (const char *)cupsArrayNext(pc
->filters
))
1699 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1700 _cups_isspace(filter
[31]))
1704 cupsArrayAdd(pc
->filters
,
1705 "application/vnd.cups-command application/postscript 100 "
1709 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1711 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1712 (cups_acopy_func_t
)_cupsStrAlloc
,
1713 (cups_afree_func_t
)_cupsStrFree
);
1717 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1719 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1722 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1723 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1726 * Copy the product string, if any...
1730 pc
->product
= _cupsStrAlloc(ppd
->product
);
1733 * Copy finishings mapping data...
1736 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1739 * Have proper vendor mapping of IPP finishings values to PPD options...
1742 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1743 NULL
, NULL
, 0, NULL
,
1744 (cups_afree_func_t
)pwg_free_finishings
);
1748 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1751 finishings
->value
= (ipp_finishings_t
)atoi(ppd_attr
->spec
);
1752 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1753 &(finishings
->options
),
1754 _PPD_PARSE_OPTIONS
);
1756 cupsArrayAdd(pc
->finishings
, finishings
);
1758 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1764 * No IPP mapping data, try to map common/standard PPD keywords...
1767 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
, NULL
, NULL
, 0, NULL
, (cups_afree_func_t
)pwg_free_finishings
);
1769 if ((ppd_option
= ppdFindOption(ppd
, "StapleLocation")) != NULL
)
1772 * Add staple finishings...
1775 if (ppdFindChoice(ppd_option
, "SinglePortrait"))
1776 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "SinglePortrait");
1777 if (ppdFindChoice(ppd_option
, "UpperLeft")) /* Ricoh extension */
1778 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_LEFT
, "StapleLocation", "UpperLeft");
1779 if (ppdFindChoice(ppd_option
, "UpperRight")) /* Ricoh extension */
1780 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_TOP_RIGHT
, "StapleLocation", "UpperRight");
1781 if (ppdFindChoice(ppd_option
, "SingleLandscape"))
1782 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
, "StapleLocation", "SingleLandscape");
1783 if (ppdFindChoice(ppd_option
, "DualLandscape"))
1784 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_STAPLE_DUAL_LEFT
, "StapleLocation", "DualLandscape");
1787 if ((ppd_option
= ppdFindOption(ppd
, "RIPunch")) != NULL
)
1790 * Add (Ricoh) punch finishings...
1793 if (ppdFindChoice(ppd_option
, "Left2"))
1794 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_LEFT
, "RIPunch", "Left2");
1795 if (ppdFindChoice(ppd_option
, "Left3"))
1796 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
, "RIPunch", "Left3");
1797 if (ppdFindChoice(ppd_option
, "Left4"))
1798 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_LEFT
, "RIPunch", "Left4");
1799 if (ppdFindChoice(ppd_option
, "Right2"))
1800 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_RIGHT
, "RIPunch", "Right2");
1801 if (ppdFindChoice(ppd_option
, "Right3"))
1802 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
, "RIPunch", "Right3");
1803 if (ppdFindChoice(ppd_option
, "Right4"))
1804 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_RIGHT
, "RIPunch", "Right4");
1805 if (ppdFindChoice(ppd_option
, "Upper2"))
1806 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_DUAL_TOP
, "RIPunch", "Upper2");
1807 if (ppdFindChoice(ppd_option
, "Upper3"))
1808 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_TRIPLE_TOP
, "RIPunch", "Upper3");
1809 if (ppdFindChoice(ppd_option
, "Upper4"))
1810 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_PUNCH_QUAD_TOP
, "RIPunch", "Upper4");
1813 if ((ppd_option
= ppdFindOption(ppd
, "BindEdge")) != NULL
)
1816 * Add bind finishings...
1819 if (ppdFindChoice(ppd_option
, "Left"))
1820 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_LEFT
, "BindEdge", "Left");
1821 if (ppdFindChoice(ppd_option
, "Right"))
1822 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_RIGHT
, "BindEdge", "Right");
1823 if (ppdFindChoice(ppd_option
, "Top"))
1824 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_TOP
, "BindEdge", "Top");
1825 if (ppdFindChoice(ppd_option
, "Bottom"))
1826 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_BIND_BOTTOM
, "BindEdge", "Bottom");
1829 if ((ppd_option
= ppdFindOption(ppd
, "FoldType")) != NULL
)
1832 * Add (Adobe) fold finishings...
1835 if (ppdFindChoice(ppd_option
, "ZFold"))
1836 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_Z
, "FoldType", "ZFold");
1837 if (ppdFindChoice(ppd_option
, "Saddle"))
1838 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_HALF
, "FoldType", "Saddle");
1839 if (ppdFindChoice(ppd_option
, "DoubleGate"))
1840 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_DOUBLE_GATE
, "FoldType", "DoubleGate");
1841 if (ppdFindChoice(ppd_option
, "LeftGate"))
1842 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LEFT_GATE
, "FoldType", "LeftGate");
1843 if (ppdFindChoice(ppd_option
, "RightGate"))
1844 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_RIGHT_GATE
, "FoldType", "RightGate");
1845 if (ppdFindChoice(ppd_option
, "Letter"))
1846 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "FoldType", "Letter");
1847 if (ppdFindChoice(ppd_option
, "XFold"))
1848 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_POSTER
, "FoldType", "XFold");
1851 if ((ppd_option
= ppdFindOption(ppd
, "RIFoldType")) != NULL
)
1854 * Add (Ricoh) fold finishings...
1857 if (ppdFindChoice(ppd_option
, "OutsideTwoFold"))
1858 pwg_add_finishing(pc
->finishings
, IPP_FINISHINGS_FOLD_LETTER
, "RIFoldType", "OutsideTwoFold");
1861 if (cupsArrayCount(pc
->finishings
) == 0)
1863 cupsArrayDelete(pc
->finishings
);
1864 pc
->finishings
= NULL
;
1868 if ((ppd_option
= ppdFindOption(ppd
, "cupsFinishingTemplate")) != NULL
)
1870 pc
->templates
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)_cupsStrAlloc
, (cups_afree_func_t
)_cupsStrFree
);
1872 for (choice
= ppd_option
->choices
, i
= ppd_option
->num_choices
; i
> 0; choice
++, i
--)
1874 cupsArrayAdd(pc
->templates
, (void *)choice
->choice
);
1877 * Add localized text for PWG keyword to message catalog...
1880 snprintf(msg_id
, sizeof(msg_id
), "finishing-template.%s", choice
->choice
);
1881 pwg_add_message(pc
->strings
, msg_id
, choice
->text
);
1889 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMaxCopies", NULL
)) != NULL
)
1890 pc
->max_copies
= atoi(ppd_attr
->value
);
1891 else if (ppd
->manual_copies
)
1894 pc
->max_copies
= 9999;
1897 * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId,
1898 * cupsJobPassword, and cupsMandatory.
1901 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsChargeInfoURI", NULL
)) != NULL
)
1902 pc
->charge_info_uri
= _cupsStrAlloc(ppd_attr
->value
);
1904 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountId", NULL
)) != NULL
)
1905 pc
->account_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1907 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobAccountingUserId", NULL
)) != NULL
)
1908 pc
->accounting_user_id
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1910 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsJobPassword", NULL
)) != NULL
)
1911 pc
->password
= _cupsStrAlloc(ppd_attr
->value
);
1913 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsMandatory", NULL
)) != NULL
)
1914 pc
->mandatory
= _cupsArrayNewStrings(ppd_attr
->value
, ' ');
1920 pc
->support_files
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1921 (cups_acopy_func_t
)_cupsStrAlloc
,
1922 (cups_afree_func_t
)_cupsStrFree
);
1924 for (ppd_attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
1926 ppd_attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
1927 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1929 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
1930 cupsArrayAdd(pc
->support_files
, ppd_attr
->value
);
1933 * Return the cache data...
1939 * If we get here we need to destroy the PWG mapping data and return NULL...
1944 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Out of memory."), 1);
1945 _ppdCacheDestroy(pc
);
1952 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1956 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1958 int i
; /* Looping var */
1959 pwg_map_t
*map
; /* Current map */
1960 pwg_size_t
*size
; /* Current size */
1964 * Range check input...
1971 * Free memory as needed...
1976 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1978 _cupsStrFree(map
->pwg
);
1979 _cupsStrFree(map
->ppd
);
1987 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1989 _cupsStrFree(size
->map
.pwg
);
1990 _cupsStrFree(size
->map
.ppd
);
1996 if (pc
->source_option
)
1997 _cupsStrFree(pc
->source_option
);
2001 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2003 _cupsStrFree(map
->pwg
);
2004 _cupsStrFree(map
->ppd
);
2012 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2014 _cupsStrFree(map
->pwg
);
2015 _cupsStrFree(map
->ppd
);
2021 if (pc
->custom_max_keyword
)
2022 _cupsStrFree(pc
->custom_max_keyword
);
2024 if (pc
->custom_min_keyword
)
2025 _cupsStrFree(pc
->custom_min_keyword
);
2027 _cupsStrFree(pc
->product
);
2028 cupsArrayDelete(pc
->filters
);
2029 cupsArrayDelete(pc
->prefilters
);
2030 cupsArrayDelete(pc
->finishings
);
2032 _cupsStrFree(pc
->charge_info_uri
);
2033 _cupsStrFree(pc
->password
);
2035 cupsArrayDelete(pc
->mandatory
);
2037 cupsArrayDelete(pc
->support_files
);
2039 cupsArrayDelete(pc
->strings
);
2046 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
2050 const char * /* O - output-bin or NULL */
2052 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2053 const char *output_bin
) /* I - PPD OutputBin string */
2055 int i
; /* Looping var */
2059 * Range check input...
2062 if (!pc
|| !output_bin
)
2066 * Look up the OutputBin string...
2070 for (i
= 0; i
< pc
->num_bins
; i
++)
2071 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
2072 return (pc
->bins
[i
].pwg
);
2079 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
2080 * IPP finishings value(s).
2083 int /* O - New number of options */
2084 _ppdCacheGetFinishingOptions(
2085 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2086 ipp_t
*job
, /* I - Job attributes or NULL */
2087 ipp_finishings_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
2088 int num_options
, /* I - Number of options */
2089 cups_option_t
**options
) /* IO - Options */
2091 int i
; /* Looping var */
2092 _pwg_finishings_t
*f
, /* PWG finishings options */
2093 key
; /* Search key */
2094 ipp_attribute_t
*attr
; /* Finishings attribute */
2095 cups_option_t
*option
; /* Current finishings option */
2099 * Range check input...
2102 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
2103 (!job
&& value
== IPP_FINISHINGS_NONE
))
2104 return (num_options
);
2107 * Apply finishing options...
2110 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
2112 int num_values
= ippGetCount(attr
); /* Number of values */
2114 for (i
= 0; i
< num_values
; i
++)
2116 key
.value
= (ipp_finishings_t
)ippGetInteger(attr
, i
);
2118 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2120 int j
; /* Another looping var */
2122 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2123 num_options
= cupsAddOption(option
->name
, option
->value
,
2124 num_options
, options
);
2128 else if (value
!= IPP_FINISHINGS_NONE
)
2132 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
2134 int j
; /* Another looping var */
2136 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
2137 num_options
= cupsAddOption(option
->name
, option
->value
,
2138 num_options
, options
);
2142 return (num_options
);
2147 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
2151 int /* O - Number of finishings values */
2152 _ppdCacheGetFinishingValues(
2153 ppd_file_t
*ppd
, /* I - Marked PPD file */
2154 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2155 int max_values
, /* I - Maximum number of finishings values */
2156 int *values
) /* O - Finishings values */
2158 int i
, /* Looping var */
2159 num_values
= 0; /* Number of values */
2160 _pwg_finishings_t
*f
; /* Current finishings option */
2161 cups_option_t
*option
; /* Current option */
2162 ppd_choice_t
*choice
; /* Marked PPD choice */
2166 * Range check input...
2169 DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd
, pc
, max_values
, values
));
2171 if (!ppd
|| !pc
|| max_values
< 1 || !values
)
2173 DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0.");
2176 else if (!pc
->finishings
)
2178 DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0.");
2183 * Go through the finishings options and see what is set...
2186 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2188 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2190 DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2192 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2194 DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option
->name
, option
->value
));
2196 if ((choice
= ppdFindMarkedChoice(ppd
, option
->name
)) == NULL
|| _cups_strcasecmp(option
->value
, choice
->choice
))
2198 DEBUG_puts("_ppdCacheGetFinishingValues: NO");
2205 DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f
->value
, ippEnumString("finishings", f
->value
)));
2207 values
[num_values
++] = f
->value
;
2209 if (num_values
>= max_values
)
2214 if (num_values
== 0)
2217 * Always have at least "finishings" = 'none'...
2220 DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none).");
2221 values
[0] = IPP_FINISHINGS_NONE
;
2225 DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values
));
2227 return (num_values
);
2232 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
2233 * attributes or a keyword string.
2236 const char * /* O - PPD InputSlot or NULL */
2237 _ppdCacheGetInputSlot(
2238 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2239 ipp_t
*job
, /* I - Job attributes or NULL */
2240 const char *keyword
) /* I - Keyword string or NULL */
2243 * Range check input...
2246 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
2249 if (job
&& !keyword
)
2252 * Lookup the media-col attribute and any media-source found there...
2255 ipp_attribute_t
*media_col
, /* media-col attribute */
2256 *media_source
; /* media-source attribute */
2257 pwg_size_t size
; /* Dimensional size */
2258 int margins_set
; /* Were the margins set? */
2260 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2262 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
2264 IPP_TAG_KEYWORD
)) != NULL
)
2267 * Use the media-source value from media-col...
2270 keyword
= ippGetString(media_source
, 0, NULL
);
2272 else if (pwgInitSize(&size
, job
, &margins_set
))
2275 * For media <= 5x7, look for a photo tray...
2278 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
2285 int i
; /* Looping var */
2287 for (i
= 0; i
< pc
->num_sources
; i
++)
2288 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
2289 return (pc
->sources
[i
].ppd
);
2297 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
2298 * attributes or a keyword string.
2301 const char * /* O - PPD MediaType or NULL */
2302 _ppdCacheGetMediaType(
2303 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2304 ipp_t
*job
, /* I - Job attributes or NULL */
2305 const char *keyword
) /* I - Keyword string or NULL */
2308 * Range check input...
2311 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
2314 if (job
&& !keyword
)
2317 * Lookup the media-col attribute and any media-source found there...
2320 ipp_attribute_t
*media_col
, /* media-col attribute */
2321 *media_type
; /* media-type attribute */
2323 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
2326 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2328 IPP_TAG_KEYWORD
)) == NULL
)
2329 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
2330 "media-type", IPP_TAG_NAME
);
2333 keyword
= media_type
->values
[0].string
.text
;
2339 int i
; /* Looping var */
2341 for (i
= 0; i
< pc
->num_types
; i
++)
2342 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
2343 return (pc
->types
[i
].ppd
);
2351 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
2355 const char * /* O - PPD OutputBin or NULL */
2356 _ppdCacheGetOutputBin(
2357 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2358 const char *output_bin
) /* I - Keyword string */
2360 int i
; /* Looping var */
2364 * Range check input...
2367 if (!pc
|| !output_bin
)
2371 * Look up the OutputBin string...
2375 for (i
= 0; i
< pc
->num_bins
; i
++)
2376 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
2377 return (pc
->bins
[i
].ppd
);
2384 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
2385 * attributes or a keyword string.
2388 const char * /* O - PPD PageSize or NULL */
2389 _ppdCacheGetPageSize(
2390 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2391 ipp_t
*job
, /* I - Job attributes or NULL */
2392 const char *keyword
, /* I - Keyword string or NULL */
2393 int *exact
) /* O - 1 if exact match, 0 otherwise */
2395 int i
; /* Looping var */
2396 pwg_size_t
*size
, /* Current size */
2397 *closest
, /* Closest size */
2398 jobsize
; /* Size data from job */
2399 int margins_set
, /* Were the margins set? */
2400 dwidth
, /* Difference in width */
2401 dlength
, /* Difference in length */
2402 dleft
, /* Difference in left margins */
2403 dright
, /* Difference in right margins */
2404 dbottom
, /* Difference in bottom margins */
2405 dtop
, /* Difference in top margins */
2406 dmin
, /* Minimum difference */
2407 dclosest
; /* Closest difference */
2408 const char *ppd_name
; /* PPD media name */
2411 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
2412 pc
, job
, keyword
, exact
));
2415 * Range check input...
2418 if (!pc
|| (!job
&& !keyword
))
2429 * Try getting the PPD media name from the job attributes...
2432 ipp_attribute_t
*attr
; /* Job attribute */
2434 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
2435 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
2436 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
2440 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
2441 attr
->name
, ippTagString(attr
->value_tag
)));
2443 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
2446 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
2447 attr
->value_tag
== IPP_TAG_KEYWORD
))
2448 ppd_name
= attr
->values
[0].string
.text
;
2451 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
2456 * Try looking up the named PPD size first...
2459 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2461 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
2462 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
2464 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
2465 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
2470 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
2472 return (size
->map
.ppd
);
2477 if (job
&& !keyword
)
2480 * Get the size using media-col or media, with the preference being
2484 if (!pwgInitSize(&jobsize
, job
, &margins_set
))
2490 * Get the size using a media keyword...
2493 pwg_media_t
*media
; /* Media definition */
2496 if ((media
= pwgMediaForPWG(keyword
)) == NULL
)
2497 if ((media
= pwgMediaForLegacy(keyword
)) == NULL
)
2498 if ((media
= pwgMediaForPPD(keyword
)) == NULL
)
2501 jobsize
.width
= media
->width
;
2502 jobsize
.length
= media
->length
;
2507 * Now that we have the dimensions and possibly the margins, look at the
2508 * available sizes and find the match...
2512 dclosest
= 999999999;
2514 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
2515 _cups_strncasecmp(ppd_name
, "custom_", 7))
2517 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2520 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
2521 * is just about 176/2540ths...
2524 dwidth
= size
->width
- jobsize
.width
;
2525 dlength
= size
->length
- jobsize
.length
;
2527 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
2533 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
2536 dleft
= size
->left
- jobsize
.left
;
2537 dright
= size
->right
- jobsize
.right
;
2538 dtop
= size
->top
- jobsize
.top
;
2539 dbottom
= size
->bottom
- jobsize
.bottom
;
2541 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
2542 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
2544 dleft
= dleft
< 0 ? -dleft
: dleft
;
2545 dright
= dright
< 0 ? -dright
: dright
;
2546 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
2547 dtop
= dtop
< 0 ? -dtop
: dtop
;
2548 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
2550 if (dmin
< dclosest
)
2563 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
2565 return (size
->map
.ppd
);
2571 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
2574 return (closest
->map
.ppd
);
2578 * If we get here we need to check for custom page size support...
2581 if (jobsize
.width
>= pc
->custom_min_width
&&
2582 jobsize
.width
<= pc
->custom_max_width
&&
2583 jobsize
.length
>= pc
->custom_min_length
&&
2584 jobsize
.length
<= pc
->custom_max_length
)
2587 * In range, format as Custom.WWWWxLLLL (points).
2590 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
2591 (int)PWG_TO_POINTS(jobsize
.width
), (int)PWG_TO_POINTS(jobsize
.length
));
2593 if (margins_set
&& exact
)
2595 dleft
= pc
->custom_size
.left
- jobsize
.left
;
2596 dright
= pc
->custom_size
.right
- jobsize
.right
;
2597 dtop
= pc
->custom_size
.top
- jobsize
.top
;
2598 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
2600 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
2601 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
2607 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
2608 pc
->custom_ppd_size
));
2610 return (pc
->custom_ppd_size
);
2614 * No custom page size support or the size is out of range - return NULL.
2617 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2624 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2627 pwg_size_t
* /* O - PWG size or NULL */
2629 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2630 const char *page_size
) /* I - PPD PageSize */
2632 int i
; /* Looping var */
2633 pwg_media_t
*media
; /* Media */
2634 pwg_size_t
*size
; /* Current size */
2638 * Range check input...
2641 if (!pc
|| !page_size
)
2644 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2647 * Custom size; size name can be one of the following:
2649 * Custom.WIDTHxLENGTHin - Size in inches
2650 * Custom.WIDTHxLENGTHft - Size in feet
2651 * Custom.WIDTHxLENGTHcm - Size in centimeters
2652 * Custom.WIDTHxLENGTHmm - Size in millimeters
2653 * Custom.WIDTHxLENGTHm - Size in meters
2654 * Custom.WIDTHxLENGTH[pt] - Size in points
2657 double w
, l
; /* Width and length of page */
2658 char *ptr
; /* Pointer into PageSize */
2659 struct lconv
*loc
; /* Locale data */
2662 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2663 if (!ptr
|| *ptr
!= 'x')
2666 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2670 if (!_cups_strcasecmp(ptr
, "in"))
2675 else if (!_cups_strcasecmp(ptr
, "ft"))
2680 else if (!_cups_strcasecmp(ptr
, "mm"))
2685 else if (!_cups_strcasecmp(ptr
, "cm"))
2690 else if (!_cups_strcasecmp(ptr
, "m"))
2701 pc
->custom_size
.width
= (int)w
;
2702 pc
->custom_size
.length
= (int)l
;
2704 return (&(pc
->custom_size
));
2708 * Not a custom size - look it up...
2711 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2712 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2713 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2717 * Look up standard sizes...
2720 if ((media
= pwgMediaForPPD(page_size
)) == NULL
)
2721 if ((media
= pwgMediaForLegacy(page_size
)) == NULL
)
2722 media
= pwgMediaForPWG(page_size
);
2726 pc
->custom_size
.width
= media
->width
;
2727 pc
->custom_size
.length
= media
->length
;
2729 return (&(pc
->custom_size
));
2737 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2741 const char * /* O - PWG media-source keyword */
2743 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2744 const char *input_slot
) /* I - PPD InputSlot */
2746 int i
; /* Looping var */
2747 pwg_map_t
*source
; /* Current source */
2751 * Range check input...
2754 if (!pc
|| !input_slot
)
2757 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2758 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2759 return (source
->pwg
);
2766 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2770 const char * /* O - PWG media-type keyword */
2772 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2773 const char *media_type
) /* I - PPD MediaType */
2775 int i
; /* Looping var */
2776 pwg_map_t
*type
; /* Current type */
2780 * Range check input...
2783 if (!pc
|| !media_type
)
2786 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2787 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2795 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2798 int /* O - 1 on success, 0 on failure */
2800 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2801 const char *filename
, /* I - File to write */
2802 ipp_t
*attrs
) /* I - Attributes to write, if any */
2804 int i
, j
, k
; /* Looping vars */
2805 cups_file_t
*fp
; /* Output file */
2806 pwg_size_t
*size
; /* Current size */
2807 pwg_map_t
*map
; /* Current map */
2808 _pwg_finishings_t
*f
; /* Current finishing option */
2809 cups_option_t
*option
; /* Current option */
2810 const char *value
; /* String value */
2811 char newfile
[1024]; /* New filename */
2815 * Range check input...
2818 if (!pc
|| !filename
)
2820 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
2825 * Open the file and write with compression...
2828 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2829 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2831 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
2836 * Standard header...
2839 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2845 if (pc
->num_bins
> 0)
2847 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2848 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2849 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2856 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2857 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2858 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2859 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2860 size
->bottom
, size
->right
, size
->top
);
2861 if (pc
->custom_max_width
> 0)
2862 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2863 pc
->custom_max_width
, pc
->custom_max_length
,
2864 pc
->custom_min_width
, pc
->custom_min_length
,
2865 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2866 pc
->custom_size
.right
, pc
->custom_size
.top
);
2872 if (pc
->source_option
)
2873 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2875 if (pc
->num_sources
> 0)
2877 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2878 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2879 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2886 if (pc
->num_types
> 0)
2888 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2889 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2890 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2897 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2898 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2899 if (pc
->num_presets
[i
][j
])
2901 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2902 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2905 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2906 cupsFilePutChar(fp
, '\n');
2913 if (pc
->sides_option
)
2914 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2916 if (pc
->sides_1sided
)
2917 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2919 if (pc
->sides_2sided_long
)
2920 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2922 if (pc
->sides_2sided_short
)
2923 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2926 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2930 cupsFilePutConf(fp
, "Product", pc
->product
);
2932 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2934 value
= (const char *)cupsArrayNext(pc
->filters
))
2935 cupsFilePutConf(fp
, "Filter", value
);
2937 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2939 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2940 cupsFilePutConf(fp
, "PreFilter", value
);
2942 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2945 * Finishing options...
2948 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2950 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2952 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2953 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2954 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2955 cupsFilePutChar(fp
, '\n');
2958 for (value
= (const char *)cupsArrayFirst(pc
->templates
); value
; value
= (const char *)cupsArrayNext(pc
->templates
))
2959 cupsFilePutConf(fp
, "FinishingTemplate", value
);
2965 cupsFilePrintf(fp
, "MaxCopies %d\n", pc
->max_copies
);
2968 * Accounting/quota/PIN/managed printing values...
2971 if (pc
->charge_info_uri
)
2972 cupsFilePutConf(fp
, "ChargeInfoURI", pc
->charge_info_uri
);
2974 cupsFilePrintf(fp
, "AccountId %s\n", pc
->account_id
? "true" : "false");
2975 cupsFilePrintf(fp
, "AccountingUserId %s\n",
2976 pc
->accounting_user_id
? "true" : "false");
2979 cupsFilePutConf(fp
, "Password", pc
->password
);
2981 for (value
= (char *)cupsArrayFirst(pc
->mandatory
);
2983 value
= (char *)cupsArrayNext(pc
->mandatory
))
2984 cupsFilePutConf(fp
, "Mandatory", value
);
2990 for (value
= (char *)cupsArrayFirst(pc
->support_files
);
2992 value
= (char *)cupsArrayNext(pc
->support_files
))
2993 cupsFilePutConf(fp
, "SupportFile", value
);
2996 * IPP attributes, if any...
3001 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
3003 attrs
->state
= IPP_STATE_IDLE
;
3004 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
3008 * Close and return...
3011 if (cupsFileClose(fp
))
3018 return (!rename(newfile
, filename
));
3023 * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities
3024 * of an IPP printer.
3027 char * /* O - PPD filename or @code NULL@ on error */
3028 _ppdCreateFromIPP(char *buffer
, /* I - Filename buffer */
3029 size_t bufsize
, /* I - Size of filename buffer */
3030 ipp_t
*response
) /* I - Get-Printer-Attributes response */
3032 cups_file_t
*fp
; /* PPD file */
3033 cups_array_t
*sizes
; /* Media sizes supported by printer */
3034 cups_size_t
*size
; /* Current media size */
3035 ipp_attribute_t
*attr
, /* xxx-supported */
3036 *defattr
, /* xxx-default */
3037 *quality
, /* print-quality-supported */
3038 *x_dim
, *y_dim
; /* Media dimensions */
3039 ipp_t
*media_col
, /* Media collection */
3040 *media_size
; /* Media size collection */
3041 char make
[256], /* Make and model */
3042 *model
, /* Model name */
3043 ppdname
[PPD_MAX_NAME
];
3045 int i
, j
, /* Looping vars */
3046 count
, /* Number of values */
3047 bottom
, /* Largest bottom margin */
3048 left
, /* Largest left margin */
3049 right
, /* Largest right margin */
3050 top
, /* Largest top margin */
3051 max_length
= 0, /* Maximum custom size */
3053 min_length
= INT_MAX
,
3054 /* Minimum custom size */
3055 min_width
= INT_MAX
,
3056 is_apple
= 0, /* Does the printer support Apple raster? */
3057 is_pdf
= 0, /* Does the printer support PDF? */
3058 is_pwg
= 0; /* Does the printer support PWG Raster? */
3059 pwg_media_t
*pwg
; /* PWG media size */
3060 int xres
, yres
; /* Resolution values */
3061 int resolutions
[1000];
3062 /* Array of resolution indices */
3063 char msgid
[256]; /* Message identifier (attr.value) */
3064 const char *keyword
, /* Keyword value */
3065 *msgstr
; /* Localized string */
3066 cups_lang_t
*lang
= cupsLangDefault();
3067 /* Localization info */
3068 cups_array_t
*strings
= NULL
;/* Printer strings file */
3069 struct lconv
*loc
= localeconv();
3071 cups_array_t
*fin_options
= NULL
;
3072 /* Finishing options */
3076 * Range check input...
3082 if (!buffer
|| bufsize
< 1)
3084 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
3090 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("No IPP attributes."), 1);
3095 * Open a temporary file for the PPD...
3098 if ((fp
= cupsTempFile2(buffer
, (int)bufsize
)) == NULL
)
3100 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(errno
), 0);
3105 * Standard stuff for PPD file...
3108 cupsFilePuts(fp
, "*PPD-Adobe: \"4.3\"\n");
3109 cupsFilePuts(fp
, "*FormatVersion: \"4.3\"\n");
3110 cupsFilePrintf(fp
, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3111 cupsFilePuts(fp
, "*LanguageVersion: English\n");
3112 cupsFilePuts(fp
, "*LanguageEncoding: ISOLatin1\n");
3113 cupsFilePuts(fp
, "*PSVersion: \"(3010.000) 0\"\n");
3114 cupsFilePuts(fp
, "*LanguageLevel: \"3\"\n");
3115 cupsFilePuts(fp
, "*FileSystem: False\n");
3116 cupsFilePuts(fp
, "*PCFileName: \"ippeve.ppd\"\n");
3118 if ((attr
= ippFindAttribute(response
, "printer-make-and-model", IPP_TAG_TEXT
)) != NULL
)
3119 strlcpy(make
, ippGetString(attr
, 0, NULL
), sizeof(make
));
3121 strlcpy(make
, "Unknown Printer", sizeof(make
));
3123 if (!_cups_strncasecmp(make
, "Hewlett Packard ", 16) ||
3124 !_cups_strncasecmp(make
, "Hewlett-Packard ", 16))
3127 strlcpy(make
, "HP", sizeof(make
));
3129 else if ((model
= strchr(make
, ' ')) != NULL
)
3134 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"\n", make
);
3135 cupsFilePrintf(fp
, "*ModelName: \"%s\"\n", model
);
3136 cupsFilePrintf(fp
, "*Product: \"(%s)\"\n", model
);
3137 cupsFilePrintf(fp
, "*NickName: \"%s\"\n", model
);
3138 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"\n", model
);
3140 if ((attr
= ippFindAttribute(response
, "color-supported", IPP_TAG_BOOLEAN
)) != NULL
&& ippGetBoolean(attr
, 0))
3141 cupsFilePuts(fp
, "*ColorDevice: True\n");
3143 cupsFilePuts(fp
, "*ColorDevice: False\n");
3145 cupsFilePrintf(fp
, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR
, CUPS_VERSION_MINOR
);
3146 cupsFilePuts(fp
, "*cupsSNMPSupplies: False\n");
3147 cupsFilePrintf(fp
, "*cupsLanguages: \"%s\"\n", lang
->language
);
3149 if ((attr
= ippFindAttribute(response
, "printer-more-info", IPP_TAG_URI
)) != NULL
)
3150 cupsFilePrintf(fp
, "*APSupplies: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3152 if ((attr
= ippFindAttribute(response
, "printer-charge-info-uri", IPP_TAG_URI
)) != NULL
)
3153 cupsFilePrintf(fp
, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3155 if ((attr
= ippFindAttribute(response
, "printer-strings-uri", IPP_TAG_URI
)) != NULL
)
3157 http_t
*http
= NULL
; /* Connection to printer */
3158 char stringsfile
[1024]; /* Temporary strings file */
3160 if (cups_get_url(&http
, ippGetString(attr
, 0, NULL
), stringsfile
, sizeof(stringsfile
)))
3162 cupsFilePrintf(fp
, "*cupsStringsURI: \"%s\"\n", ippGetString(attr
, 0, NULL
));
3164 strings
= _cupsMessageLoad(stringsfile
, _CUPS_MESSAGE_STRINGS
| _CUPS_MESSAGE_UNQUOTE
);
3166 unlink(stringsfile
);
3177 if ((attr
= ippFindAttribute(response
, "document-format-supported", IPP_TAG_MIMETYPE
)) != NULL
)
3179 is_apple
= ippContainsString(attr
, "image/urf");
3180 is_pdf
= ippContainsString(attr
, "application/pdf");
3181 is_pwg
= ippContainsString(attr
, "image/pwg-raster");
3183 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3185 const char *format
= ippGetString(attr
, i
, NULL
);
3189 * Write cupsFilter2 lines for supported formats...
3192 if (!_cups_strcasecmp(format
, "application/pdf"))
3193 cupsFilePuts(fp
, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n");
3194 else if (!_cups_strcasecmp(format
, "image/jpeg") || !_cups_strcasecmp(format
, "image/png"))
3195 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 0 -\"\n", format
, format
);
3196 else if (!_cups_strcasecmp(format
, "image/pwg-raster") || !_cups_strcasecmp(format
, "image/urf"))
3197 cupsFilePrintf(fp
, "*cupsFilter2: \"%s %s 100 -\"\n", format
, format
);
3201 if (!is_apple
&& !is_pdf
&& !is_pwg
)
3205 * PageSize/PageRegion/ImageableArea/PaperDimension
3208 if ((attr
= ippFindAttribute(response
, "media-bottom-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3210 for (i
= 1, bottom
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3211 if (ippGetInteger(attr
, i
) > bottom
)
3212 bottom
= ippGetInteger(attr
, i
);
3217 if ((attr
= ippFindAttribute(response
, "media-left-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3219 for (i
= 1, left
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3220 if (ippGetInteger(attr
, i
) > left
)
3221 left
= ippGetInteger(attr
, i
);
3226 if ((attr
= ippFindAttribute(response
, "media-right-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3228 for (i
= 1, right
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3229 if (ippGetInteger(attr
, i
) > right
)
3230 right
= ippGetInteger(attr
, i
);
3235 if ((attr
= ippFindAttribute(response
, "media-top-margin-supported", IPP_TAG_INTEGER
)) != NULL
)
3237 for (i
= 1, top
= ippGetInteger(attr
, 0), count
= ippGetCount(attr
); i
< count
; i
++)
3238 if (ippGetInteger(attr
, i
) > top
)
3239 top
= ippGetInteger(attr
, i
);
3244 if ((defattr
= ippFindAttribute(response
, "media-col-default", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3246 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-size", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3248 media_size
= ippGetCollection(attr
, 0);
3249 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
3250 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
3252 if (x_dim
&& y_dim
&& (pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
)
3253 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3255 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3258 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3260 else if ((pwg
= pwgMediaForPWG(ippGetString(ippFindAttribute(response
, "media-default", IPP_TAG_ZERO
), 0, NULL
))) != NULL
)
3261 strlcpy(ppdname
, pwg
->ppd
, sizeof(ppdname
));
3263 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3265 sizes
= cupsArrayNew3((cups_array_func_t
)pwg_compare_sizes
, NULL
, NULL
, 0, (cups_acopy_func_t
)pwg_copy_size
, (cups_afree_func_t
)free
);
3267 if ((attr
= ippFindAttribute(response
, "media-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3269 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3271 cups_size_t temp
; /* Current size */
3272 ipp_attribute_t
*margin
; /* media-xxx-margin attribute */
3274 media_col
= ippGetCollection(attr
, i
);
3275 media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0);
3276 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3277 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3278 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3282 temp
.width
= pwg
->width
;
3283 temp
.length
= pwg
->length
;
3285 if ((margin
= ippFindAttribute(media_col
, "media-bottom-margin", IPP_TAG_INTEGER
)) != NULL
)
3286 temp
.bottom
= ippGetInteger(margin
, 0);
3288 temp
.bottom
= bottom
;
3290 if ((margin
= ippFindAttribute(media_col
, "media-left-margin", IPP_TAG_INTEGER
)) != NULL
)
3291 temp
.left
= ippGetInteger(margin
, 0);
3295 if ((margin
= ippFindAttribute(media_col
, "media-right-margin", IPP_TAG_INTEGER
)) != NULL
)
3296 temp
.right
= ippGetInteger(margin
, 0);
3300 if ((margin
= ippFindAttribute(media_col
, "media-top-margin", IPP_TAG_INTEGER
)) != NULL
)
3301 temp
.top
= ippGetInteger(margin
, 0);
3305 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3306 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3308 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3310 if (!cupsArrayFind(sizes
, &temp
))
3311 cupsArrayAdd(sizes
, &temp
);
3313 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3316 * Custom size - record the min/max values...
3319 int lower
, upper
; /* Range values */
3321 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3322 lower
= ippGetRange(x_dim
, 0, &upper
);
3324 lower
= upper
= ippGetInteger(x_dim
, 0);
3326 if (lower
< min_width
)
3328 if (upper
> max_width
)
3331 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3332 lower
= ippGetRange(y_dim
, 0, &upper
);
3334 lower
= upper
= ippGetInteger(y_dim
, 0);
3336 if (lower
< min_length
)
3338 if (upper
> max_length
)
3343 if ((max_width
== 0 || max_length
== 0) && (attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3346 * Some printers don't list custom size support in media-col-database...
3349 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3351 media_size
= ippGetCollection(attr
, i
);
3352 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3353 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3355 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3358 * Custom size - record the min/max values...
3361 int lower
, upper
; /* Range values */
3363 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3364 lower
= ippGetRange(x_dim
, 0, &upper
);
3366 lower
= upper
= ippGetInteger(x_dim
, 0);
3368 if (lower
< min_width
)
3370 if (upper
> max_width
)
3373 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3374 lower
= ippGetRange(y_dim
, 0, &upper
);
3376 lower
= upper
= ippGetInteger(y_dim
, 0);
3378 if (lower
< min_length
)
3380 if (upper
> max_length
)
3386 else if ((attr
= ippFindAttribute(response
, "media-size-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
3388 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3390 cups_size_t temp
; /* Current size */
3392 media_size
= ippGetCollection(attr
, i
);
3393 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_ZERO
);
3394 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_ZERO
);
3395 pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0));
3399 temp
.width
= pwg
->width
;
3400 temp
.length
= pwg
->length
;
3401 temp
.bottom
= bottom
;
3406 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3407 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3409 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3411 if (!cupsArrayFind(sizes
, &temp
))
3412 cupsArrayAdd(sizes
, &temp
);
3414 else if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
|| ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3417 * Custom size - record the min/max values...
3420 int lower
, upper
; /* Range values */
3422 if (ippGetValueTag(x_dim
) == IPP_TAG_RANGE
)
3423 lower
= ippGetRange(x_dim
, 0, &upper
);
3425 lower
= upper
= ippGetInteger(x_dim
, 0);
3427 if (lower
< min_width
)
3429 if (upper
> max_width
)
3432 if (ippGetValueTag(y_dim
) == IPP_TAG_RANGE
)
3433 lower
= ippGetRange(y_dim
, 0, &upper
);
3435 lower
= upper
= ippGetInteger(y_dim
, 0);
3437 if (lower
< min_length
)
3439 if (upper
> max_length
)
3444 else if ((attr
= ippFindAttribute(response
, "media-supported", IPP_TAG_ZERO
)) != NULL
)
3446 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3448 const char *pwg_size
= ippGetString(attr
, i
, NULL
);
3450 cups_size_t temp
; /* Current size */
3452 if ((pwg
= pwgMediaForPWG(pwg_size
)) != NULL
)
3454 if (strstr(pwg_size
, "_max_") || strstr(pwg_size
, "_max."))
3456 if (pwg
->width
> max_width
)
3457 max_width
= pwg
->width
;
3458 if (pwg
->length
> max_length
)
3459 max_length
= pwg
->length
;
3461 else if (strstr(pwg_size
, "_min_") || strstr(pwg_size
, "_min."))
3463 if (pwg
->width
< min_width
)
3464 min_width
= pwg
->width
;
3465 if (pwg
->length
< min_length
)
3466 min_length
= pwg
->length
;
3470 temp
.width
= pwg
->width
;
3471 temp
.length
= pwg
->length
;
3472 temp
.bottom
= bottom
;
3477 if (temp
.bottom
== 0 && temp
.left
== 0 && temp
.right
== 0 && temp
.top
== 0)
3478 snprintf(temp
.media
, sizeof(temp
.media
), "%s.Borderless", pwg
->ppd
);
3480 strlcpy(temp
.media
, pwg
->ppd
, sizeof(temp
.media
));
3482 if (!cupsArrayFind(sizes
, &temp
))
3483 cupsArrayAdd(sizes
, &temp
);
3489 if (cupsArrayCount(sizes
) > 0)
3492 * List all of the standard sizes...
3495 char tleft
[256], /* Left string */
3496 tbottom
[256], /* Bottom string */
3497 tright
[256], /* Right string */
3498 ttop
[256], /* Top string */
3499 twidth
[256], /* Width string */
3500 tlength
[256]; /* Length string */
3502 cupsFilePrintf(fp
, "*OpenUI *PageSize: PickOne\n"
3503 "*OrderDependency: 10 AnySetup *PageSize\n"
3504 "*DefaultPageSize: %s\n", ppdname
);
3505 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3507 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3508 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3510 cupsFilePrintf(fp
, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3512 cupsFilePuts(fp
, "*CloseUI: *PageSize\n");
3514 cupsFilePrintf(fp
, "*OpenUI *PageRegion: PickOne\n"
3515 "*OrderDependency: 10 AnySetup *PageRegion\n"
3516 "*DefaultPageRegion: %s\n", ppdname
);
3517 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3519 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3520 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3522 cupsFilePrintf(fp
, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size
->media
, twidth
, tlength
);
3524 cupsFilePuts(fp
, "*CloseUI: *PageRegion\n");
3526 cupsFilePrintf(fp
, "*DefaultImageableArea: %s\n"
3527 "*DefaultPaperDimension: %s\n", ppdname
, ppdname
);
3529 for (size
= (cups_size_t
*)cupsArrayFirst(sizes
); size
; size
= (cups_size_t
*)cupsArrayNext(sizes
))
3531 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), size
->left
* 72.0 / 2540.0, loc
);
3532 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), size
->bottom
* 72.0 / 2540.0, loc
);
3533 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), (size
->width
- size
->right
) * 72.0 / 2540.0, loc
);
3534 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), (size
->length
- size
->top
) * 72.0 / 2540.0, loc
);
3535 _cupsStrFormatd(twidth
, twidth
+ sizeof(twidth
), size
->width
* 72.0 / 2540.0, loc
);
3536 _cupsStrFormatd(tlength
, tlength
+ sizeof(tlength
), size
->length
* 72.0 / 2540.0, loc
);
3538 cupsFilePrintf(fp
, "*ImageableArea %s: \"%s %s %s %s\"\n", size
->media
, tleft
, tbottom
, tright
, ttop
);
3539 cupsFilePrintf(fp
, "*PaperDimension %s: \"%s %s\"\n", size
->media
, twidth
, tlength
);
3542 cupsArrayDelete(sizes
);
3545 * Custom size support...
3548 if (max_width
> 0 && min_width
< INT_MAX
&& max_length
> 0 && min_length
< INT_MAX
)
3550 char tmax
[256], tmin
[256]; /* Min/max values */
3552 _cupsStrFormatd(tleft
, tleft
+ sizeof(tleft
), left
* 72.0 / 2540.0, loc
);
3553 _cupsStrFormatd(tbottom
, tbottom
+ sizeof(tbottom
), bottom
* 72.0 / 2540.0, loc
);
3554 _cupsStrFormatd(tright
, tright
+ sizeof(tright
), right
* 72.0 / 2540.0, loc
);
3555 _cupsStrFormatd(ttop
, ttop
+ sizeof(ttop
), top
* 72.0 / 2540.0, loc
);
3557 cupsFilePrintf(fp
, "*HWMargins: \"%s %s %s %s\"\n", tleft
, tbottom
, tright
, ttop
);
3559 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_width
* 72.0 / 2540.0, loc
);
3560 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_width
* 72.0 / 2540.0, loc
);
3561 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin
, tmax
);
3563 _cupsStrFormatd(tmax
, tmax
+ sizeof(tmax
), max_length
* 72.0 / 2540.0, loc
);
3564 _cupsStrFormatd(tmin
, tmin
+ sizeof(tmin
), min_length
* 72.0 / 2540.0, loc
);
3565 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin
, tmax
);
3567 cupsFilePuts(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
3568 cupsFilePuts(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
3569 cupsFilePuts(fp
, "*ParamCustomPageSize Orientation: 5 int 0 3\n");
3570 cupsFilePuts(fp
, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
3575 cupsArrayDelete(sizes
);
3583 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-source", IPP_TAG_ZERO
)) != NULL
)
3584 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3586 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3588 if ((attr
= ippFindAttribute(response
, "media-source-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3590 static const char * const sources
[] =
3591 { /* Standard "media-source" strings */
3644 cupsFilePrintf(fp
, "*OpenUI *InputSlot: PickOne\n"
3645 "*OrderDependency: 10 AnySetup *InputSlot\n"
3646 "*DefaultInputSlot: %s\n", ppdname
);
3647 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3649 keyword
= ippGetString(attr
, i
, NULL
);
3651 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3653 for (j
= 0; j
< (int)(sizeof(sources
) / sizeof(sources
[0])); j
++)
3654 if (!strcmp(sources
[j
], keyword
))
3656 snprintf(msgid
, sizeof(msgid
), "media-source.%s", keyword
);
3657 cupsFilePrintf(fp
, "*InputSlot %s/%s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname
, _cupsLangString(lang
, msgid
), j
);
3661 cupsFilePuts(fp
, "*CloseUI: *InputSlot\n");
3668 if ((attr
= ippFindAttribute(ippGetCollection(defattr
, 0), "media-type", IPP_TAG_ZERO
)) != NULL
)
3669 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3671 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3673 if ((attr
= ippFindAttribute(response
, "media-type-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3675 cupsFilePrintf(fp
, "*OpenUI *MediaType: PickOne\n"
3676 "*OrderDependency: 10 AnySetup *MediaType\n"
3677 "*DefaultMediaType: %s\n", ppdname
);
3678 for (i
= 0; i
< count
; i
++)
3680 keyword
= ippGetString(attr
, i
, NULL
);
3682 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3684 snprintf(msgid
, sizeof(msgid
), "media-type.%s", keyword
);
3685 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3686 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3689 cupsFilePrintf(fp
, "*MediaType %s/%s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname
, msgstr
, ppdname
);
3691 cupsFilePuts(fp
, "*CloseUI: *MediaType\n");
3698 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) == NULL
)
3699 if ((attr
= ippFindAttribute(response
, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD
)) == NULL
)
3700 if ((attr
= ippFindAttribute(response
, "print-color-mode-supported", IPP_TAG_KEYWORD
)) == NULL
)
3701 attr
= ippFindAttribute(response
, "output-mode-supported", IPP_TAG_KEYWORD
);
3705 const char *default_color
= NULL
; /* Default */
3707 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3709 keyword
= ippGetString(attr
, i
, NULL
);
3711 if (!strcasecmp(keyword
, "black_1") || !strcmp(keyword
, "bi-level") || !strcmp(keyword
, "process-bi-level"))
3714 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3715 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3717 cupsFilePrintf(fp
, "*ColorModel FastGray/%s: \"<</cupsColorSpace 3/cupsBitsPerColor 1/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Fast Grayscale")));
3720 default_color
= "FastGray";
3722 else if (!strcasecmp(keyword
, "sgray_8") || !strcmp(keyword
, "W8") || !strcmp(keyword
, "monochrome") || !strcmp(keyword
, "process-monochrome"))
3725 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3726 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3728 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3730 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3731 default_color
= "Gray";
3733 else if (!strcasecmp(keyword
, "sgray_16") || !strcmp(keyword
, "W8-16"))
3736 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3737 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3739 if (!strcmp(keyword
, "W8-16"))
3741 cupsFilePrintf(fp
, "*ColorModel Gray/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Grayscale")));
3743 if (!default_color
|| !strcmp(default_color
, "FastGray"))
3744 default_color
= "Gray";
3747 cupsFilePrintf(fp
, "*ColorModel Gray16/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Gray")));
3749 else if (!strcasecmp(keyword
, "srgb_8") || !strncmp(keyword
, "SRGB24", 7) || !strcmp(keyword
, "color"))
3752 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3753 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3755 cupsFilePrintf(fp
, "*ColorModel RGB/%s: \"<</cupsColorSpace 19/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Color")));
3757 default_color
= "RGB";
3759 else if (!strcasecmp(keyword
, "adobe-rgb_16") || !strcmp(keyword
, "ADOBERGB48") || !strcmp(keyword
, "ADOBERGB24-48"))
3762 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3763 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3765 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3768 default_color
= "AdobeRGB";
3770 else if ((!strcasecmp(keyword
, "adobe-rgb_8") && !ippContainsString(attr
, "adobe-rgb_16")) || !strcmp(keyword
, "ADOBERGB24"))
3773 cupsFilePrintf(fp
, "*OpenUI *ColorModel/%s: PickOne\n"
3774 "*OrderDependency: 10 AnySetup *ColorModel\n", _cupsLangString(lang
, _("Color Mode")));
3776 cupsFilePrintf(fp
, "*ColorModel AdobeRGB/%s: \"<</cupsColorSpace 20/cupsBitsPerColor 8/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", _cupsLangString(lang
, _("Deep Color")));
3779 default_color
= "AdobeRGB";
3785 cupsFilePrintf(fp
, "*DefaultColorModel: %s\n", default_color
);
3786 cupsFilePuts(fp
, "*CloseUI: *ColorModel\n");
3794 if ((attr
= ippFindAttribute(response
, "sides-supported", IPP_TAG_KEYWORD
)) != NULL
&& ippContainsString(attr
, "two-sided-long-edge"))
3796 cupsFilePrintf(fp
, "*OpenUI *Duplex/%s: PickOne\n"
3797 "*OrderDependency: 10 AnySetup *Duplex\n"
3798 "*DefaultDuplex: None\n"
3799 "*Duplex None/%s: \"<</Duplex false>>setpagedevice\"\n"
3800 "*Duplex DuplexNoTumble/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n"
3801 "*Duplex DuplexTumble/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n"
3802 "*CloseUI: *Duplex\n", _cupsLangString(lang
, _("2-Sided Printing")), _cupsLangString(lang
, _("Off (1-Sided)")), _cupsLangString(lang
, _("Long-Edge (Portrait)")), _cupsLangString(lang
, _("Short-Edge (Landscape)")));
3804 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
3806 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
3808 const char *dm
= ippGetString(attr
, i
, NULL
);
3811 if (!_cups_strcasecmp(dm
, "DM1"))
3813 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3816 else if (!_cups_strcasecmp(dm
, "DM2"))
3818 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3821 else if (!_cups_strcasecmp(dm
, "DM3"))
3823 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3826 else if (!_cups_strcasecmp(dm
, "DM4"))
3828 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3833 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD
)) != NULL
)
3835 keyword
= ippGetString(attr
, 0, NULL
);
3837 if (!strcmp(keyword
, "flipped"))
3838 cupsFilePuts(fp
, "*cupsBackSide: Flipped\n");
3839 else if (!strcmp(keyword
, "manual-tumble"))
3840 cupsFilePuts(fp
, "*cupsBackSide: ManualTumble\n");
3841 else if (!strcmp(keyword
, "normal"))
3842 cupsFilePuts(fp
, "*cupsBackSide: Normal\n");
3844 cupsFilePuts(fp
, "*cupsBackSide: Rotated\n");
3852 if ((attr
= ippFindAttribute(response
, "output-bin-default", IPP_TAG_ZERO
)) != NULL
)
3853 pwg_ppdize_name(ippGetString(attr
, 0, NULL
), ppdname
, sizeof(ppdname
));
3855 strlcpy(ppdname
, "Unknown", sizeof(ppdname
));
3857 if ((attr
= ippFindAttribute(response
, "output-bin-supported", IPP_TAG_ZERO
)) != NULL
&& (count
= ippGetCount(attr
)) > 1)
3859 cupsFilePrintf(fp
, "*OpenUI *OutputBin: PickOne\n"
3860 "*OrderDependency: 10 AnySetup *OutputBin\n"
3861 "*DefaultOutputBin: %s\n", ppdname
);
3862 for (i
= 0; i
< count
; i
++)
3864 keyword
= ippGetString(attr
, i
, NULL
);
3866 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
3868 snprintf(msgid
, sizeof(msgid
), "output-bin.%s", keyword
);
3869 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3870 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3873 cupsFilePrintf(fp
, "*OutputBin %s/%s: \"\"\n", ppdname
, msgstr
);
3875 cupsFilePuts(fp
, "*CloseUI: *OutputBin\n");
3879 * Finishing options...
3882 if ((attr
= ippFindAttribute(response
, "finishings-supported", IPP_TAG_ENUM
)) != NULL
)
3884 int value
; /* Enum value */
3885 cups_array_t
*names
; /* Names we've added */
3887 count
= ippGetCount(attr
);
3888 names
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
, (cups_afree_func_t
)free
);
3889 fin_options
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3892 * Staple/Bind/Stitch
3895 for (i
= 0; i
< count
; i
++)
3897 value
= ippGetInteger(attr
, i
);
3898 keyword
= ippEnumString("finishings", value
);
3900 if (!strncmp(keyword
, "staple-", 7) || !strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch"))
3906 cupsArrayAdd(fin_options
, "*StapleLocation");
3908 cupsFilePrintf(fp
, "*OpenUI *StapleLocation/%s: PickOne\n", _cupsLangString(lang
, _("Staple")));
3909 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *StapleLocation\n");
3910 cupsFilePuts(fp
, "*DefaultStapleLocation: None\n");
3911 cupsFilePrintf(fp
, "*StapleLocation None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3913 for (; i
< count
; i
++)
3915 value
= ippGetInteger(attr
, i
);
3916 keyword
= ippEnumString("finishings", value
);
3918 if (strncmp(keyword
, "staple-", 7) && strncmp(keyword
, "bind-", 5) && strncmp(keyword
, "edge-stitch-", 12) && strcmp(keyword
, "saddle-stitch"))
3921 if (cupsArrayFind(names
, (char *)keyword
))
3922 continue; /* Already did this finishing template */
3924 cupsArrayAdd(names
, (char *)keyword
);
3926 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
3927 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3928 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3931 cupsFilePrintf(fp
, "*StapleLocation %s/%s: \"\"\n", keyword
, msgstr
);
3932 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value
, keyword
, keyword
);
3935 cupsFilePuts(fp
, "*CloseUI: *StapleLocation\n");
3942 for (i
= 0; i
< count
; i
++)
3944 value
= ippGetInteger(attr
, i
);
3945 keyword
= ippEnumString("finishings", value
);
3947 if (!strncmp(keyword
, "fold-", 5))
3953 cupsArrayAdd(fin_options
, "*FoldType");
3955 cupsFilePrintf(fp
, "*OpenUI *FoldType/%s: PickOne\n", _cupsLangString(lang
, _("Fold")));
3956 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *FoldType\n");
3957 cupsFilePuts(fp
, "*DefaultFoldType: None\n");
3958 cupsFilePrintf(fp
, "*FoldType None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
3960 for (; i
< count
; i
++)
3962 value
= ippGetInteger(attr
, i
);
3963 keyword
= ippEnumString("finishings", value
);
3965 if (strncmp(keyword
, "fold-", 5))
3968 if (cupsArrayFind(names
, (char *)keyword
))
3969 continue; /* Already did this finishing template */
3971 cupsArrayAdd(names
, (char *)keyword
);
3973 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
3974 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
3975 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
3978 cupsFilePrintf(fp
, "*FoldType %s/%s: \"\"\n", keyword
, msgstr
);
3979 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value
, keyword
, keyword
);
3982 cupsFilePuts(fp
, "*CloseUI: *FoldType\n");
3989 for (i
= 0; i
< count
; i
++)
3991 value
= ippGetInteger(attr
, i
);
3992 keyword
= ippEnumString("finishings", value
);
3994 if (!strncmp(keyword
, "punch-", 6))
4000 cupsArrayAdd(fin_options
, "*PunchMedia");
4002 cupsFilePrintf(fp
, "*OpenUI *PunchMedia/%s: PickOne\n", _cupsLangString(lang
, _("Punch")));
4003 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *PunchMedia\n");
4004 cupsFilePuts(fp
, "*DefaultPunchMedia: None\n");
4005 cupsFilePrintf(fp
, "*PunchMedia None/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4007 for (i
= 0; i
< count
; i
++)
4009 value
= ippGetInteger(attr
, i
);
4010 keyword
= ippEnumString("finishings", value
);
4012 if (strncmp(keyword
, "punch-", 6))
4015 if (cupsArrayFind(names
, (char *)keyword
))
4016 continue; /* Already did this finishing template */
4018 cupsArrayAdd(names
, (char *)keyword
);
4020 snprintf(msgid
, sizeof(msgid
), "finishings.%d", value
);
4021 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4022 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4025 cupsFilePrintf(fp
, "*PunchMedia %s/%s: \"\"\n", keyword
, msgstr
);
4026 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value
, keyword
, keyword
);
4029 cupsFilePuts(fp
, "*CloseUI: *PunchMedia\n");
4036 if (ippContainsInteger(attr
, IPP_FINISHINGS_BOOKLET_MAKER
))
4038 cupsArrayAdd(fin_options
, "*Booklet");
4040 cupsFilePrintf(fp
, "*OpenUI *Booklet/%s: Boolean\n", _cupsLangString(lang
, _("Booklet")));
4041 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *Booklet\n");
4042 cupsFilePuts(fp
, "*DefaultBooklet: False\n");
4043 cupsFilePuts(fp
, "*Booklet False: \"\"\n");
4044 cupsFilePuts(fp
, "*Booklet True: \"\"\n");
4045 cupsFilePrintf(fp
, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER
);
4046 cupsFilePuts(fp
, "*CloseUI: *Booklet\n");
4049 cupsArrayDelete(names
);
4052 if ((attr
= ippFindAttribute(response
, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4054 ipp_t
*finishing_col
; /* Current finishing collection */
4055 ipp_attribute_t
*finishing_attr
; /* Current finishing member attribute */
4056 cups_array_t
*templates
; /* Finishing templates */
4058 cupsFilePrintf(fp
, "*OpenUI *cupsFinishingTemplate/%s: PickOne\n", _cupsLangString(lang
, _("Finishing Preset")));
4059 cupsFilePuts(fp
, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n");
4060 cupsFilePuts(fp
, "*DefaultcupsFinishingTemplate: none\n");
4061 cupsFilePrintf(fp
, "*cupsFinishingTemplate none/%s: \"\"\n", _cupsLangString(lang
, _("None")));
4063 templates
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4064 count
= ippGetCount(attr
);
4066 for (i
= 0; i
< count
; i
++)
4068 finishing_col
= ippGetCollection(attr
, i
);
4069 keyword
= ippGetString(ippFindAttribute(finishing_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
);
4071 if (!keyword
|| cupsArrayFind(templates
, (void *)keyword
))
4074 if (strncmp(keyword
, "fold-", 5) && (strstr(keyword
, "-bottom") || strstr(keyword
, "-left") || strstr(keyword
, "-right") || strstr(keyword
, "-top")))
4077 cupsArrayAdd(templates
, (void *)keyword
);
4079 snprintf(msgid
, sizeof(msgid
), "finishing-template.%s", keyword
);
4080 if ((msgstr
= _cupsLangString(lang
, msgid
)) == msgid
|| !strcmp(msgid
, msgstr
))
4081 if ((msgstr
= _cupsMessageLookup(strings
, msgid
)) == msgid
)
4084 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s/%s: \"\n", keyword
, msgstr
);
4085 for (finishing_attr
= ippFirstAttribute(finishing_col
); finishing_attr
; finishing_attr
= ippNextAttribute(finishing_col
))
4087 if (ippGetValueTag(finishing_attr
) == IPP_TAG_BEGIN_COLLECTION
)
4089 const char *name
= ippGetName(finishing_attr
);
4090 /* Member attribute name */
4092 if (strcmp(name
, "media-size"))
4093 cupsFilePrintf(fp
, "%s\n", name
);
4096 cupsFilePuts(fp
, "\"\n");
4097 cupsFilePuts(fp
, "*End\n");
4100 cupsFilePuts(fp
, "*CloseUI: *cupsFinishingTemplate\n");
4102 if (cupsArrayCount(fin_options
))
4104 const char *fin_option
; /* Current finishing option */
4106 cupsFilePuts(fp
, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate");
4107 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4108 cupsFilePrintf(fp
, " %s", fin_option
);
4109 cupsFilePuts(fp
, "\"\n");
4111 cupsFilePuts(fp
, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None");
4112 for (fin_option
= (const char *)cupsArrayFirst(fin_options
); fin_option
; fin_option
= (const char *)cupsArrayNext(fin_options
))
4113 cupsFilePrintf(fp
, " %s None", fin_option
);
4114 cupsFilePuts(fp
, "\"\n");
4117 cupsArrayDelete(templates
);
4120 cupsArrayDelete(fin_options
);
4123 * cupsPrintQuality and DefaultResolution...
4126 quality
= ippFindAttribute(response
, "print-quality-supported", IPP_TAG_ENUM
);
4128 if ((attr
= ippFindAttribute(response
, "urf-supported", IPP_TAG_KEYWORD
)) != NULL
)
4130 int lowdpi
= 0, hidpi
= 0; /* Lower and higher resolution */
4132 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4134 const char *rs
= ippGetString(attr
, i
, NULL
);
4137 if (_cups_strncasecmp(rs
, "RS", 2))
4140 lowdpi
= atoi(rs
+ 2);
4141 if ((rs
= strrchr(rs
, '-')) != NULL
)
4142 hidpi
= atoi(rs
+ 1);
4151 * Invalid "urf-supported" value...
4159 * Generate print qualities based on low and high DPIs...
4162 cupsFilePrintf(fp
, "*DefaultResolution: %ddpi\n", lowdpi
);
4164 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4165 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4166 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4167 if ((lowdpi
& 1) == 0)
4168 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
/ 2);
4169 else if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4170 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), lowdpi
, lowdpi
);
4171 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), lowdpi
, lowdpi
);
4172 if (hidpi
> lowdpi
|| ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4173 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), hidpi
, hidpi
);
4174 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4177 else if ((attr
= ippFindAttribute(response
, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION
)) != NULL
)
4180 * Make a sorted list of resolutions.
4183 count
= ippGetCount(attr
);
4184 if (count
> (int)(sizeof(resolutions
) / sizeof(resolutions
[0])))
4185 count
= (int)(sizeof(resolutions
) / sizeof(resolutions
[0]));
4187 resolutions
[0] = 0; /* Not in loop to silence Clang static analyzer... */
4188 for (i
= 1; i
< count
; i
++)
4191 for (i
= 0; i
< (count
- 1); i
++)
4193 for (j
= i
+ 1; j
< count
; j
++)
4195 int ix
, iy
, /* First X and Y resolution */
4196 jx
, jy
, /* Second X and Y resolution */
4197 temp
; /* Swap variable */
4198 ipp_res_t units
; /* Resolution units */
4200 ix
= ippGetResolution(attr
, resolutions
[i
], &iy
, &units
);
4201 jx
= ippGetResolution(attr
, resolutions
[j
], &jy
, &units
);
4203 if (ix
> jx
|| (ix
== jx
&& iy
> jy
))
4206 * Swap these two resolutions...
4209 temp
= resolutions
[i
];
4210 resolutions
[i
] = resolutions
[j
];
4211 resolutions
[j
] = temp
;
4217 * Generate print quality options...
4220 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, ppdname
, sizeof(ppdname
));
4221 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4223 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4224 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4225 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4226 if (count
> 2 || ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4228 pwg_ppdize_resolution(attr
, resolutions
[0], &xres
, &yres
, NULL
, 0);
4229 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4231 pwg_ppdize_resolution(attr
, resolutions
[count
/ 2], &xres
, &yres
, NULL
, 0);
4232 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4233 if (count
> 1 || ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4235 pwg_ppdize_resolution(attr
, resolutions
[count
- 1], &xres
, &yres
, NULL
, 0);
4236 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4239 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4241 else if (is_apple
|| is_pwg
)
4245 if ((attr
= ippFindAttribute(response
, "printer-resolution-default", IPP_TAG_RESOLUTION
)) != NULL
)
4247 pwg_ppdize_resolution(attr
, 0, &xres
, &yres
, ppdname
, sizeof(ppdname
));
4252 strlcpy(ppdname
, "300dpi", sizeof(ppdname
));
4255 cupsFilePrintf(fp
, "*DefaultResolution: %s\n", ppdname
);
4257 cupsFilePrintf(fp
, "*OpenUI *cupsPrintQuality/%s: PickOne\n"
4258 "*OrderDependency: 10 AnySetup *cupsPrintQuality\n"
4259 "*DefaultcupsPrintQuality: Normal\n", _cupsLangString(lang
, _("Print Quality")));
4260 if (ippContainsInteger(quality
, IPP_QUALITY_DRAFT
))
4261 cupsFilePrintf(fp
, "*cupsPrintQuality Draft/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Draft")), xres
, yres
);
4262 cupsFilePrintf(fp
, "*cupsPrintQuality Normal/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("Normal")), xres
, yres
);
4263 if (ippContainsInteger(quality
, IPP_QUALITY_HIGH
))
4264 cupsFilePrintf(fp
, "*cupsPrintQuality High/%s: \"<</HWResolution[%d %d]>>setpagedevice\"\n", _cupsLangString(lang
, _("High")), xres
, yres
);
4265 cupsFilePuts(fp
, "*CloseUI: *cupsPrintQuality\n");
4272 if ((attr
= ippFindAttribute(response
, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
4274 for (i
= 0, count
= ippGetCount(attr
); i
< count
; i
++)
4276 ipp_t
*preset
= ippGetCollection(attr
, i
);
4277 /* Preset collection */
4278 const char *preset_name
= ippGetString(ippFindAttribute(preset
, "preset-name", IPP_TAG_ZERO
), 0, NULL
),
4280 *localized_name
; /* Localized preset name */
4281 ipp_attribute_t
*member
; /* Member attribute in preset */
4282 const char *member_name
; /* Member attribute name */
4283 char member_value
[256]; /* Member attribute value */
4285 if (!preset
|| !preset_name
)
4288 if ((localized_name
= _cupsMessageLookup(strings
, preset_name
)) == preset_name
)
4289 cupsFilePrintf(fp
, "*APPrinterPreset %s: \"\n", preset_name
);
4291 cupsFilePrintf(fp
, "*APPrinterPreset %s/%s: \"\n", preset_name
, localized_name
);
4293 for (member
= ippFirstAttribute(preset
); member
; member
= ippNextAttribute(preset
))
4295 member_name
= ippGetName(member
);
4297 if (!member_name
|| !strcmp(member_name
, "preset-name"))
4300 if (!strcmp(member_name
, "finishings"))
4302 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4304 const char *option
= NULL
; /* PPD option name */
4306 keyword
= ippEnumString("finishings", ippGetInteger(member
, i
));
4308 if (!strcmp(keyword
, "booklet-maker"))
4313 else if (!strncmp(keyword
, "fold-", 5))
4314 option
= "FoldType";
4315 else if (!strncmp(keyword
, "punch-", 6))
4316 option
= "PunchMedia";
4317 else if (!strncmp(keyword
, "bind-", 5) || !strncmp(keyword
, "edge-stitch-", 12) || !strcmp(keyword
, "saddle-stitch") || !strncmp(keyword
, "staple-", 7))
4318 option
= "StapleLocation";
4320 if (option
&& keyword
)
4321 cupsFilePrintf(fp
, "*%s %s\n", option
, keyword
);
4324 else if (!strcmp(member_name
, "finishings-col"))
4326 ipp_t
*fin_col
; /* finishings-col value */
4328 for (i
= 0, count
= ippGetCount(member
); i
< count
; i
++)
4330 fin_col
= ippGetCollection(member
, i
);
4332 if ((keyword
= ippGetString(ippFindAttribute(fin_col
, "finishing-template", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4333 cupsFilePrintf(fp
, "*cupsFinishingTemplate %s\n", keyword
);
4336 else if (!strcmp(member_name
, "media"))
4339 * Map media to PageSize...
4342 if ((pwg
= pwgMediaForPWG(ippGetString(member
, 0, NULL
))) != NULL
&& pwg
->ppd
)
4343 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4345 else if (!strcmp(member_name
, "media-col"))
4347 media_col
= ippGetCollection(member
, 0);
4349 if ((media_size
= ippGetCollection(ippFindAttribute(media_col
, "media-size", IPP_TAG_BEGIN_COLLECTION
), 0)) != NULL
)
4351 x_dim
= ippFindAttribute(media_size
, "x-dimension", IPP_TAG_INTEGER
);
4352 y_dim
= ippFindAttribute(media_size
, "y-dimension", IPP_TAG_INTEGER
);
4353 if ((pwg
= pwgMediaForSize(ippGetInteger(x_dim
, 0), ippGetInteger(y_dim
, 0))) != NULL
&& pwg
->ppd
)
4354 cupsFilePrintf(fp
, "*PageSize %s\n", pwg
->ppd
);
4357 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-source", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4359 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4360 cupsFilePrintf(fp
, "*InputSlot %s\n", keyword
);
4363 if ((keyword
= ippGetString(ippFindAttribute(media_col
, "media-type", IPP_TAG_ZERO
), 0, NULL
)) != NULL
)
4365 pwg_ppdize_name(keyword
, ppdname
, sizeof(ppdname
));
4366 cupsFilePrintf(fp
, "*MediaType %s\n", keyword
);
4369 else if (!strcmp(member_name
, "print-quality"))
4372 * Map print-quality to cupsPrintQuality...
4375 int qval
= ippGetInteger(member
, 0);
4376 /* print-quality value */
4377 static const char * const qualities
[] = { "Draft", "Normal", "High" };
4378 /* cupsPrintQuality values */
4380 if (qval
>= IPP_QUALITY_DRAFT
&& qval
<= IPP_QUALITY_HIGH
)
4381 cupsFilePrintf(fp
, "*cupsPrintQuality %s\n", qualities
[qval
- IPP_QUALITY_DRAFT
]);
4383 else if (!strcmp(member_name
, "output-bin"))
4385 pwg_ppdize_name(ippGetString(member
, 0, NULL
), ppdname
, sizeof(ppdname
));
4386 cupsFilePrintf(fp
, "*OutputBin %s\n", ppdname
);
4388 else if (!strcmp(member_name
, "sides"))
4390 keyword
= ippGetString(member
, 0, NULL
);
4391 if (keyword
&& !strcmp(keyword
, "one-sided"))
4392 cupsFilePuts(fp
, "*Duplex None\n");
4393 else if (keyword
&& !strcmp(keyword
, "two-sided-long-edge"))
4394 cupsFilePuts(fp
, "*Duplex DuplexNoTumble\n");
4395 else if (keyword
&& !strcmp(keyword
, "two-sided-short-edge"))
4396 cupsFilePuts(fp
, "*Duplex DuplexTumble\n");
4401 * Add attribute name and value as-is...
4404 ippAttributeString(member
, member_value
, sizeof(member_value
));
4405 cupsFilePrintf(fp
, "*%s %s\n", member_name
, member_value
);
4409 cupsFilePuts(fp
, "\"\n*End\n");
4414 * Close up and return...
4422 * If we get here then there was a problem creating the PPD...
4431 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Printer does not support required IPP attributes or document formats."), 1);
4438 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
4442 const char * /* O - InputSlot name */
4443 _pwgInputSlotForSource(
4444 const char *media_source
, /* I - PWG media-source */
4445 char *name
, /* I - Name buffer */
4446 size_t namesize
) /* I - Size of name buffer */
4449 * Range check input...
4452 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
4455 if (_cups_strcasecmp(media_source
, "main"))
4456 strlcpy(name
, "Cassette", namesize
);
4457 else if (_cups_strcasecmp(media_source
, "alternate"))
4458 strlcpy(name
, "Multipurpose", namesize
);
4459 else if (_cups_strcasecmp(media_source
, "large-capacity"))
4460 strlcpy(name
, "LargeCapacity", namesize
);
4461 else if (_cups_strcasecmp(media_source
, "bottom"))
4462 strlcpy(name
, "Lower", namesize
);
4463 else if (_cups_strcasecmp(media_source
, "middle"))
4464 strlcpy(name
, "Middle", namesize
);
4465 else if (_cups_strcasecmp(media_source
, "top"))
4466 strlcpy(name
, "Upper", namesize
);
4467 else if (_cups_strcasecmp(media_source
, "rear"))
4468 strlcpy(name
, "Rear", namesize
);
4469 else if (_cups_strcasecmp(media_source
, "side"))
4470 strlcpy(name
, "Side", namesize
);
4471 else if (_cups_strcasecmp(media_source
, "envelope"))
4472 strlcpy(name
, "Envelope", namesize
);
4473 else if (_cups_strcasecmp(media_source
, "main-roll"))
4474 strlcpy(name
, "Roll", namesize
);
4475 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
4476 strlcpy(name
, "Roll2", namesize
);
4478 pwg_ppdize_name(media_source
, name
, namesize
);
4485 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
4489 const char * /* O - MediaType name */
4490 _pwgMediaTypeForType(
4491 const char *media_type
, /* I - PWG media-type */
4492 char *name
, /* I - Name buffer */
4493 size_t namesize
) /* I - Size of name buffer */
4496 * Range check input...
4499 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
4502 if (_cups_strcasecmp(media_type
, "auto"))
4503 strlcpy(name
, "Auto", namesize
);
4504 else if (_cups_strcasecmp(media_type
, "cardstock"))
4505 strlcpy(name
, "Cardstock", namesize
);
4506 else if (_cups_strcasecmp(media_type
, "envelope"))
4507 strlcpy(name
, "Envelope", namesize
);
4508 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
4509 strlcpy(name
, "Glossy", namesize
);
4510 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
4511 strlcpy(name
, "HighGloss", namesize
);
4512 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
4513 strlcpy(name
, "Matte", namesize
);
4514 else if (_cups_strcasecmp(media_type
, "stationery"))
4515 strlcpy(name
, "Plain", namesize
);
4516 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
4517 strlcpy(name
, "Coated", namesize
);
4518 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
4519 strlcpy(name
, "Inkjet", namesize
);
4520 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
4521 strlcpy(name
, "Letterhead", namesize
);
4522 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
4523 strlcpy(name
, "Preprinted", namesize
);
4524 else if (_cups_strcasecmp(media_type
, "transparency"))
4525 strlcpy(name
, "Transparency", namesize
);
4527 pwg_ppdize_name(media_type
, name
, namesize
);
4534 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
4537 const char * /* O - PageSize name */
4538 _pwgPageSizeForMedia(
4539 pwg_media_t
*media
, /* I - Media */
4540 char *name
, /* I - PageSize name buffer */
4541 size_t namesize
) /* I - Size of name buffer */
4543 const char *sizeptr
, /* Pointer to size in PWG name */
4544 *dimptr
; /* Pointer to dimensions in PWG name */
4548 * Range check input...
4551 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
4555 * Copy or generate a PageSize name...
4561 * Use a standard Adobe name...
4564 strlcpy(name
, media
->ppd
, namesize
);
4566 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
4567 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
4568 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
4569 (size_t)(dimptr
- sizeptr
) > namesize
)
4572 * Use a name of the form "wNNNhNNN"...
4575 snprintf(name
, namesize
, "w%dh%d", (int)PWG_TO_POINTS(media
->width
),
4576 (int)PWG_TO_POINTS(media
->length
));
4581 * Copy the size name from class_sizename_dimensions...
4584 memcpy(name
, sizeptr
+ 1, (size_t)(dimptr
- sizeptr
- 1));
4585 name
[dimptr
- sizeptr
- 1] = '\0';
4593 * 'cups_get_url()' - Get a copy of the file at the given URL.
4596 static int /* O - 1 on success, 0 on failure */
4597 cups_get_url(http_t
**http
, /* IO - Current HTTP connection */
4598 const char *url
, /* I - URL to get */
4599 char *name
, /* I - Temporary filename */
4600 size_t namesize
) /* I - Size of temporary filename buffer */
4602 char scheme
[32], /* URL scheme */
4603 userpass
[256], /* URL username:password */
4604 host
[256], /* URL host */
4605 curhost
[256], /* Current host */
4606 resource
[256]; /* URL resource */
4607 int port
; /* URL port */
4608 http_encryption_t encryption
; /* Type of encryption to use */
4609 http_status_t status
; /* Status of GET request */
4610 int fd
; /* Temporary file */
4613 if (httpSeparateURI(HTTP_URI_CODING_ALL
, url
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4616 if (port
== 443 || !strcmp(scheme
, "https"))
4617 encryption
= HTTP_ENCRYPTION_ALWAYS
;
4619 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
4621 if (!*http
|| strcasecmp(host
, httpGetHostname(*http
, curhost
, sizeof(curhost
))) || httpAddrPort(httpGetAddress(*http
)) != port
)
4624 *http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 5000, NULL
);
4630 if ((fd
= cupsTempFd(name
, (int)namesize
)) < 0)
4633 status
= cupsGetFd(*http
, resource
, fd
);
4637 if (status
!= HTTP_STATUS_OK
)
4649 * 'pwg_add_finishing()' - Add a finishings value.
4654 cups_array_t
*finishings
, /* I - Finishings array */
4655 ipp_finishings_t
template, /* I - Finishing template */
4656 const char *name
, /* I - PPD option */
4657 const char *value
) /* I - PPD choice */
4659 _pwg_finishings_t
*f
; /* New finishings value */
4662 if ((f
= (_pwg_finishings_t
*)calloc(1, sizeof(_pwg_finishings_t
))) != NULL
)
4664 f
->value
= template;
4665 f
->num_options
= cupsAddOption(name
, value
, 0, &f
->options
);
4667 cupsArrayAdd(finishings
, f
);
4673 * 'pwg_add_message()' - Add a message to the PPD cached strings.
4677 pwg_add_message(cups_array_t
*a
, /* I - Message catalog */
4678 const char *msg
, /* I - Message identifier */
4679 const char *str
) /* I - Localized string */
4681 _cups_message_t
*m
; /* New message */
4684 if ((m
= calloc(1, sizeof(_cups_message_t
))) != NULL
)
4686 m
->msg
= strdup(msg
);
4687 m
->str
= strdup(str
);
4694 * 'pwg_compare_finishings()' - Compare two finishings values.
4697 static int /* O - Result of comparison */
4698 pwg_compare_finishings(
4699 _pwg_finishings_t
*a
, /* I - First finishings value */
4700 _pwg_finishings_t
*b
) /* I - Second finishings value */
4702 return ((int)b
->value
- (int)a
->value
);
4707 * 'pwg_compare_sizes()' - Compare two media sizes...
4710 static int /* O - Result of comparison */
4711 pwg_compare_sizes(cups_size_t
*a
, /* I - First media size */
4712 cups_size_t
*b
) /* I - Second media size */
4714 return (strcmp(a
->media
, b
->media
));
4719 * 'pwg_copy_size()' - Copy a media size.
4722 static cups_size_t
* /* O - New media size */
4723 pwg_copy_size(cups_size_t
*size
) /* I - Media size to copy */
4725 cups_size_t
*newsize
= (cups_size_t
*)calloc(1, sizeof(cups_size_t
));
4726 /* New media size */
4729 memcpy(newsize
, size
, sizeof(cups_size_t
));
4736 * 'pwg_free_finishings()' - Free a finishings value.
4740 pwg_free_finishings(
4741 _pwg_finishings_t
*f
) /* I - Finishings value */
4743 cupsFreeOptions(f
->num_options
, f
->options
);
4749 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
4753 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
4754 char *name
, /* I - Name buffer */
4755 size_t namesize
) /* I - Size of name buffer */
4757 char *ptr
, /* Pointer into name buffer */
4758 *end
; /* End of name buffer */
4767 *name
= (char)toupper(*ipp
++);
4769 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
4771 if (*ipp
== '-' && _cups_isalnum(ipp
[1]))
4774 *ptr
++ = (char)toupper(*ipp
++ & 255);
4785 * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values.
4789 pwg_ppdize_resolution(
4790 ipp_attribute_t
*attr
, /* I - Attribute to convert */
4791 int element
, /* I - Element to convert */
4792 int *xres
, /* O - X resolution in DPI */
4793 int *yres
, /* O - Y resolution in DPI */
4794 char *name
, /* I - Name buffer */
4795 size_t namesize
) /* I - Size of name buffer */
4797 ipp_res_t units
; /* Units for resolution */
4800 *xres
= ippGetResolution(attr
, element
, yres
, &units
);
4802 if (units
== IPP_RES_PER_CM
)
4804 *xres
= (int)(*xres
* 2.54);
4805 *yres
= (int)(*yres
* 2.54);
4808 if (name
&& namesize
> 4)
4811 snprintf(name
, namesize
, "%ddpi", *xres
);
4813 snprintf(name
, namesize
, "%dx%ddpi", *xres
, *yres
);
4819 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
4823 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
4824 char *name
, /* I - Name buffer */
4825 size_t namesize
, /* I - Size of name buffer */
4826 const char *dashchars
)/* I - Characters to be replaced by dashes */
4828 char *ptr
, /* Pointer into name buffer */
4829 *end
; /* End of name buffer */
4832 if (_cups_islower(*ppd
))
4835 * Already lowercase name, use as-is?
4838 const char *ppdptr
; /* Pointer into PPD keyword */
4840 for (ppdptr
= ppd
+ 1; *ppdptr
; ppdptr
++)
4841 if (_cups_isupper(*ppdptr
) || strchr(dashchars
, *ppdptr
))
4846 strlcpy(name
, ppd
, namesize
);
4851 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
4853 if (_cups_isalnum(*ppd
) || *ppd
== '-')
4854 *ptr
++ = (char)tolower(*ppd
& 255);
4855 else if (strchr(dashchars
, *ppd
))
4860 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
4861 _cups_isupper(ppd
[1]) && ptr
< end
)
4863 else if (!isdigit(*ppd
& 255) && isdigit(ppd
[1] & 255))