4 * PPD cache implementation for CUPS.
6 * Copyright 2010-2011 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * _ppdCacheCreateWithFile() - Create PPD cache and mapping data from a
20 * _ppdCacheCreateWithPPD() - Create PWG mapping data from a PPD file.
21 * _ppdCacheDestroy() - Free all memory used for PWG mapping data.
22 * _ppdCacheGetBin() - Get the PWG output-bin keyword associated with
24 * _ppdCacheGetInputSlot() - Get the PPD InputSlot associated with the job
25 * attributes or a keyword string.
26 * _ppdCacheGetMediaType() - Get the PPD MediaType associated with the job
27 * attributes or a keyword string.
28 * _ppdCacheGetOutputBin() - Get the PPD OutputBin associated with the
30 * _ppdCacheGetPageSize() - Get the PPD PageSize associated with the job
31 * attributes or a keyword string.
32 * _ppdCacheGetSize() - Get the PWG size associated with a PPD
34 * _ppdCacheGetSource() - Get the PWG media-source associated with a PPD
36 * _ppdCacheGetType() - Get the PWG media-type associated with a PPD
38 * _ppdCacheWriteFile() - Write PWG mapping data to a file.
39 * _pwgInputSlotForSource() - Get the InputSlot name for the given PWG
41 * _pwgMediaTypeForType() - Get the MediaType name for the given PWG
43 * _pwgPageSizeForMedia() - Get the PageSize name for the given media.
44 * pwg_ppdize_name() - Convert an IPP keyword to a PPD keyword.
45 * pwg_unppdize_name() - Convert a PPD keyword to a lowercase IPP
50 * Include necessary headers...
53 #include "cups-private.h"
58 * Macro to test for two almost-equal PWG measurements.
61 #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)
68 static int pwg_compare_finishings(_pwg_finishings_t
*a
,
69 _pwg_finishings_t
*b
);
70 static void pwg_free_finishings(_pwg_finishings_t
*f
);
71 static void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
72 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
);
76 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
79 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
83 _ppd_cache_t
* /* O - PPD cache and mapping data */
84 _ppdCacheCreateWithFile(
85 const char *filename
, /* I - File to read */
86 ipp_t
**attrs
) /* IO - IPP attributes, if any */
88 cups_file_t
*fp
; /* File */
89 _ppd_cache_t
*pc
; /* PWG mapping data */
90 _pwg_size_t
*size
; /* Current size */
91 _pwg_map_t
*map
; /* Current map */
92 _pwg_finishings_t
*finishings
; /* Current finishings option */
93 int linenum
, /* Current line number */
94 num_bins
, /* Number of bins in file */
95 num_sizes
, /* Number of sizes in file */
96 num_sources
, /* Number of sources in file */
97 num_types
; /* Number of types in file */
98 char line
[2048], /* Current line */
99 *value
, /* Pointer to value in line */
100 *valueptr
, /* Pointer into value */
101 pwg_keyword
[128], /* PWG keyword */
102 ppd_keyword
[PPD_MAX_NAME
];
104 _pwg_print_color_mode_t print_color_mode
;
105 /* Print color mode for preset */
106 _pwg_print_quality_t print_quality
; /* Print quality for preset */
109 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
112 * Range check input...
120 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
128 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
130 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
135 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
138 if (!cupsFileGets(fp
, line
, sizeof(line
)))
140 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
141 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
146 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16))
148 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
149 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
154 if (atoi(line
+ 16) != _PPD_CACHE_VERSION
)
156 _cupsSetError(IPP_INTERNAL_ERROR
, _("Out of date PPD cache file."), 1);
157 DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, "
158 "expected %d.", line
+ 16, _PPD_CACHE_VERSION
));
164 * Allocate the mapping data structure...
167 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
169 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
170 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
184 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
186 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
187 "linenum=%d", line
, value
, linenum
));
191 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
193 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
196 else if (!_cups_strcasecmp(line
, "Filter"))
199 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
200 (cups_acopy_func_t
)_cupsStrAlloc
,
201 (cups_afree_func_t
)_cupsStrFree
);
203 cupsArrayAdd(pc
->filters
, value
);
205 else if (!_cups_strcasecmp(line
, "PreFilter"))
208 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
209 (cups_acopy_func_t
)_cupsStrAlloc
,
210 (cups_afree_func_t
)_cupsStrFree
);
212 cupsArrayAdd(pc
->prefilters
, value
);
214 else if (!_cups_strcasecmp(line
, "Product"))
216 pc
->product
= _cupsStrAlloc(value
);
218 else if (!_cups_strcasecmp(line
, "SingleFile"))
220 pc
->single_file
= !_cups_strcasecmp(value
, "true");
222 else if (!_cups_strcasecmp(line
, "IPP"))
224 off_t pos
= cupsFileTell(fp
), /* Position in file */
225 length
= strtol(value
, NULL
, 10);
226 /* Length of IPP attributes */
230 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
231 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
234 else if (length
<= 0)
236 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
237 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
244 * Read IPP attributes into the provided variable...
249 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
252 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
253 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
260 * Skip the IPP data entirely...
263 cupsFileSeek(fp
, pos
+ length
);
266 if (cupsFileTell(fp
) != (pos
+ length
))
268 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
269 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
273 else if (!_cups_strcasecmp(line
, "NumBins"))
277 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
278 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
282 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
284 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
285 "%d.", num_sizes
, linenum
));
286 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
290 if ((pc
->bins
= calloc(num_bins
, sizeof(_pwg_map_t
))) == NULL
)
292 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
294 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
298 else if (!_cups_strcasecmp(line
, "Bin"))
300 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
302 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
303 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
307 if (pc
->num_bins
>= num_bins
)
309 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
311 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
315 map
= pc
->bins
+ pc
->num_bins
;
316 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
317 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
321 else if (!_cups_strcasecmp(line
, "NumSizes"))
325 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
326 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
330 if ((num_sizes
= atoi(value
)) <= 0 || num_sizes
> 65536)
332 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
333 "%d.", num_sizes
, linenum
));
334 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
338 if ((pc
->sizes
= calloc(num_sizes
, sizeof(_pwg_size_t
))) == NULL
)
340 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
342 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
346 else if (!_cups_strcasecmp(line
, "Size"))
348 if (pc
->num_sizes
>= num_sizes
)
350 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
352 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
356 size
= pc
->sizes
+ pc
->num_sizes
;
358 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
359 &(size
->width
), &(size
->length
), &(size
->left
),
360 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
362 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
364 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
368 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
369 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
373 else if (!_cups_strcasecmp(line
, "CustomSize"))
375 if (pc
->custom_max_width
> 0)
377 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
379 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
383 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
384 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
385 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
386 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
387 &(pc
->custom_size
.top
)) != 8)
389 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
391 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
395 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
396 pc
->custom_max_width
, pc
->custom_max_length
);
397 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
399 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
400 pc
->custom_min_width
, pc
->custom_min_length
);
401 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
403 else if (!_cups_strcasecmp(line
, "SourceOption"))
405 pc
->source_option
= _cupsStrAlloc(value
);
407 else if (!_cups_strcasecmp(line
, "NumSources"))
411 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
413 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
417 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
419 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
420 "line %d.", num_sources
, linenum
));
421 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
425 if ((pc
->sources
= calloc(num_sources
, sizeof(_pwg_map_t
))) == NULL
)
427 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
429 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
433 else if (!_cups_strcasecmp(line
, "Source"))
435 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
437 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
439 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
443 if (pc
->num_sources
>= num_sources
)
445 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
447 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
451 map
= pc
->sources
+ pc
->num_sources
;
452 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
453 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
457 else if (!_cups_strcasecmp(line
, "NumTypes"))
461 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
462 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
466 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
468 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
469 "line %d.", num_types
, linenum
));
470 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
474 if ((pc
->types
= calloc(num_types
, sizeof(_pwg_map_t
))) == NULL
)
476 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
478 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
482 else if (!_cups_strcasecmp(line
, "Type"))
484 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
486 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
488 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
492 if (pc
->num_types
>= num_types
)
494 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
496 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
500 map
= pc
->types
+ pc
->num_types
;
501 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
502 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
506 else if (!_cups_strcasecmp(line
, "Preset"))
509 * Preset output-mode print-quality name=value ...
512 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
513 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
515 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
516 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
517 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
518 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
519 valueptr
== value
|| !*valueptr
)
521 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
523 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
527 pc
->num_presets
[print_color_mode
][print_quality
] =
528 cupsParseOptions(valueptr
, 0,
529 pc
->presets
[print_color_mode
] + print_quality
);
531 else if (!_cups_strcasecmp(line
, "SidesOption"))
532 pc
->sides_option
= _cupsStrAlloc(value
);
533 else if (!_cups_strcasecmp(line
, "Sides1Sided"))
534 pc
->sides_1sided
= _cupsStrAlloc(value
);
535 else if (!_cups_strcasecmp(line
, "Sides2SidedLong"))
536 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
537 else if (!_cups_strcasecmp(line
, "Sides2SidedShort"))
538 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
539 else if (!_cups_strcasecmp(line
, "Finishings"))
543 cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
545 (cups_afree_func_t
)pwg_free_finishings
);
547 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
550 finishings
->value
= strtol(value
, &valueptr
, 10);
551 finishings
->num_options
= cupsParseOptions(valueptr
, 0,
552 &(finishings
->options
));
554 cupsArrayAdd(pc
->finishings
, finishings
);
558 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
563 if (pc
->num_sizes
< num_sizes
)
565 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
566 pc
->num_sizes
, num_sizes
));
567 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
571 if (pc
->num_sources
< num_sources
)
573 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
574 pc
->num_sources
, num_sources
));
575 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
579 if (pc
->num_types
< num_types
)
581 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
582 pc
->num_types
, num_types
));
583 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
592 * If we get here the file was bad - free any data and return...
598 _ppdCacheDestroy(pc
);
611 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
614 _ppd_cache_t
* /* O - PPD cache and mapping data */
615 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
617 int i
, j
, k
; /* Looping vars */
618 _ppd_cache_t
*pc
; /* PWG mapping data */
619 ppd_option_t
*input_slot
, /* InputSlot option */
620 *media_type
, /* MediaType option */
621 *output_bin
, /* OutputBin option */
622 *color_model
, /* ColorModel option */
623 *duplex
; /* Duplex option */
624 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
625 _pwg_map_t
*map
; /* Current source/type map */
626 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
627 int num_options
; /* Number of preset options and props */
628 cups_option_t
*options
; /* Preset options and properties */
629 ppd_size_t
*ppd_size
; /* Current PPD size */
630 _pwg_size_t
*pwg_size
; /* Current PWG size */
631 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
632 /* PWG keyword string */
633 ppd_name
[PPD_MAX_NAME
];
634 /* Normalized PPD name */
635 const char *pwg_name
; /* Standard PWG media name */
636 _pwg_media_t
*pwg_media
; /* PWG media data */
637 _pwg_print_color_mode_t pwg_print_color_mode
;
638 /* print-color-mode index */
639 _pwg_print_quality_t pwg_print_quality
;
640 /* print-quality index */
641 int similar
; /* Are the old and new size similar? */
642 _pwg_size_t
*old_size
; /* Current old size */
643 int old_imageable
, /* Old imageable length in 2540ths */
644 old_borderless
, /* Old borderless state */
645 old_known_pwg
; /* Old PWG name is well-known */
646 int new_width
, /* New width in 2540ths */
647 new_length
, /* New length in 2540ths */
648 new_left
, /* New left margin in 2540ths */
649 new_bottom
, /* New bottom margin in 2540ths */
650 new_right
, /* New right margin in 2540ths */
651 new_top
, /* New top margin in 2540ths */
652 new_imageable
, /* New imageable length in 2540ths */
653 new_borderless
, /* New borderless state */
654 new_known_pwg
; /* New PWG name is well-known */
655 _pwg_size_t
*new_size
; /* New size to add, if any */
656 const char *filter
; /* Current filter */
657 _pwg_finishings_t
*finishings
; /* Current finishings value */
660 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
663 * Range check input...
673 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
675 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
680 * Copy and convert size data...
683 if (ppd
->num_sizes
== 0)
685 DEBUG_puts("_ppdCacheCreateWithPPD: No page sizes in PPD.");
689 if ((pc
->sizes
= calloc(ppd
->num_sizes
, sizeof(_pwg_size_t
))) == NULL
)
691 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
692 "_pwg_size_t's.", ppd
->num_sizes
));
696 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
701 * Don't copy over custom size...
704 if (!_cups_strcasecmp(ppd_size
->name
, "Custom"))
708 * Convert the PPD size name to the corresponding PWG keyword name.
711 if ((pwg_media
= _pwgMediaForPPD(ppd_size
->name
)) != NULL
)
714 * Standard name, do we have conflicts?
717 for (j
= 0; j
< pc
->num_sizes
; j
++)
718 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
728 * Standard name and no conflicts, use it!
731 pwg_name
= pwg_media
->pwg
;
737 * Not a standard name; convert it to a PWG vendor name of the form:
739 * pp_lowerppd_WIDTHxHEIGHTuu
742 pwg_name
= pwg_keyword
;
745 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
));
746 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
747 _PWG_FROMPTS(ppd_size
->width
),
748 _PWG_FROMPTS(ppd_size
->length
));
752 * If we have a similar paper with non-zero margins then we only
753 * want to keep it if it has a larger imageable area length.
756 pwg_media
= _pwgMediaForSize(_PWG_FROMPTS(ppd_size
->width
),
757 _PWG_FROMPTS(ppd_size
->length
));
758 new_width
= pwg_media
->width
;
759 new_length
= pwg_media
->length
;
760 new_left
= _PWG_FROMPTS(ppd_size
->left
);
761 new_bottom
= _PWG_FROMPTS(ppd_size
->bottom
);
762 new_right
= _PWG_FROMPTS(ppd_size
->width
- ppd_size
->right
);
763 new_top
= _PWG_FROMPTS(ppd_size
->length
- ppd_size
->top
);
764 new_imageable
= new_length
- new_top
- new_bottom
;
765 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
766 new_left
== 0 && new_right
== 0;
768 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
772 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
773 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
774 old_size
->right
== 0 && old_size
->top
== 0;
775 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
776 strncmp(old_size
->map
.pwg
, "om_", 3);
778 similar
= old_borderless
== new_borderless
&&
779 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
780 _PWG_EQUIVALENT(old_size
->length
, new_length
);
783 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
786 * The new paper has a larger imageable area so it could replace
787 * the older paper. Regardless of the imageable area, we always
788 * prefer the size with a well-known PWG name.
792 _cupsStrFree(old_size
->map
.ppd
);
793 _cupsStrFree(old_size
->map
.pwg
);
800 * The paper was unique enough to deserve its own entry so add it to the
804 new_size
= pwg_size
++;
814 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
815 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
816 new_size
->width
= new_width
;
817 new_size
->length
= new_length
;
818 new_size
->left
= new_left
;
819 new_size
->bottom
= new_bottom
;
820 new_size
->right
= new_right
;
821 new_size
->top
= new_top
;
825 if (ppd
->variable_sizes
)
828 * Generate custom size data...
831 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
832 _PWG_FROMPTS(ppd
->custom_max
[0]),
833 _PWG_FROMPTS(ppd
->custom_max
[1]));
834 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
835 pc
->custom_max_width
= _PWG_FROMPTS(ppd
->custom_max
[0]);
836 pc
->custom_max_length
= _PWG_FROMPTS(ppd
->custom_max
[1]);
838 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
839 _PWG_FROMPTS(ppd
->custom_min
[0]),
840 _PWG_FROMPTS(ppd
->custom_min
[1]));
841 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
842 pc
->custom_min_width
= _PWG_FROMPTS(ppd
->custom_min
[0]);
843 pc
->custom_min_length
= _PWG_FROMPTS(ppd
->custom_min
[1]);
845 pc
->custom_size
.left
= _PWG_FROMPTS(ppd
->custom_margins
[0]);
846 pc
->custom_size
.bottom
= _PWG_FROMPTS(ppd
->custom_margins
[1]);
847 pc
->custom_size
.right
= _PWG_FROMPTS(ppd
->custom_margins
[2]);
848 pc
->custom_size
.top
= _PWG_FROMPTS(ppd
->custom_margins
[3]);
852 * Copy and convert InputSlot data...
855 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
856 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
860 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
862 if ((pc
->sources
= calloc(input_slot
->num_choices
,
863 sizeof(_pwg_map_t
))) == NULL
)
865 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
866 "_pwg_map_t's for InputSlot.", input_slot
->num_choices
));
870 pc
->num_sources
= input_slot
->num_choices
;
872 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
875 i
--, choice
++, map
++)
877 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
878 !_cups_strcasecmp(choice
->choice
, "Default"))
880 else if (!_cups_strcasecmp(choice
->choice
, "Cassette"))
882 else if (!_cups_strcasecmp(choice
->choice
, "PhotoTray"))
884 else if (!_cups_strcasecmp(choice
->choice
, "CDTray"))
886 else if (!_cups_strncasecmp(choice
->choice
, "Multipurpose", 12) ||
887 !_cups_strcasecmp(choice
->choice
, "MP") ||
888 !_cups_strcasecmp(choice
->choice
, "MPTray"))
889 pwg_name
= "alternate";
890 else if (!_cups_strcasecmp(choice
->choice
, "LargeCapacity"))
891 pwg_name
= "large-capacity";
892 else if (!_cups_strncasecmp(choice
->choice
, "Lower", 5))
894 else if (!_cups_strncasecmp(choice
->choice
, "Middle", 6))
896 else if (!_cups_strncasecmp(choice
->choice
, "Upper", 5))
898 else if (!_cups_strncasecmp(choice
->choice
, "Side", 4))
900 else if (!_cups_strcasecmp(choice
->choice
, "Roll"))
901 pwg_name
= "main-roll";
905 * Convert PPD name to lowercase...
908 pwg_name
= pwg_keyword
;
909 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
912 map
->pwg
= _cupsStrAlloc(pwg_name
);
913 map
->ppd
= _cupsStrAlloc(choice
->choice
);
918 * Copy and convert MediaType data...
921 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
923 if ((pc
->types
= calloc(media_type
->num_choices
,
924 sizeof(_pwg_map_t
))) == NULL
)
926 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
927 "_pwg_map_t's for MediaType.", media_type
->num_choices
));
931 pc
->num_types
= media_type
->num_choices
;
933 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
936 i
--, choice
++, map
++)
938 if (!_cups_strncasecmp(choice
->choice
, "Auto", 4) ||
939 !_cups_strcasecmp(choice
->choice
, "Any") ||
940 !_cups_strcasecmp(choice
->choice
, "Default"))
942 else if (!_cups_strncasecmp(choice
->choice
, "Card", 4))
943 pwg_name
= "cardstock";
944 else if (!_cups_strncasecmp(choice
->choice
, "Env", 3))
945 pwg_name
= "envelope";
946 else if (!_cups_strncasecmp(choice
->choice
, "Gloss", 5))
947 pwg_name
= "photographic-glossy";
948 else if (!_cups_strcasecmp(choice
->choice
, "HighGloss"))
949 pwg_name
= "photographic-high-gloss";
950 else if (!_cups_strcasecmp(choice
->choice
, "Matte"))
951 pwg_name
= "photographic-matte";
952 else if (!_cups_strncasecmp(choice
->choice
, "Plain", 5))
953 pwg_name
= "stationery";
954 else if (!_cups_strncasecmp(choice
->choice
, "Coated", 6))
955 pwg_name
= "stationery-coated";
956 else if (!_cups_strcasecmp(choice
->choice
, "Inkjet"))
957 pwg_name
= "stationery-inkjet";
958 else if (!_cups_strcasecmp(choice
->choice
, "Letterhead"))
959 pwg_name
= "stationery-letterhead";
960 else if (!_cups_strncasecmp(choice
->choice
, "Preprint", 8))
961 pwg_name
= "stationery-preprinted";
962 else if (!_cups_strcasecmp(choice
->choice
, "Recycled"))
963 pwg_name
= "stationery-recycled";
964 else if (!_cups_strncasecmp(choice
->choice
, "Transparen", 10))
965 pwg_name
= "transparency";
969 * Convert PPD name to lowercase...
972 pwg_name
= pwg_keyword
;
973 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
976 map
->pwg
= _cupsStrAlloc(pwg_name
);
977 map
->ppd
= _cupsStrAlloc(choice
->choice
);
982 * Copy and convert OutputBin data...
985 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
987 if ((pc
->bins
= calloc(output_bin
->num_choices
,
988 sizeof(_pwg_map_t
))) == NULL
)
990 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
991 "_pwg_map_t's for OutputBin.", output_bin
->num_choices
));
995 pc
->num_bins
= output_bin
->num_choices
;
997 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
1000 i
--, choice
++, map
++)
1002 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
1004 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
1005 map
->ppd
= _cupsStrAlloc(choice
->choice
);
1009 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
1012 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
1015 const char *quality
, /* com.apple.print.preset.quality value */
1016 *output_mode
, /* com.apple.print.preset.output-mode value */
1017 *color_model_val
, /* ColorModel choice */
1018 *graphicsType
, /* com.apple.print.preset.graphicsType value */
1019 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
1023 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
1026 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
1027 num_options
, options
)) != NULL
)
1030 * Get the print-quality for this preset...
1033 if (!strcmp(quality
, "low"))
1034 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1035 else if (!strcmp(quality
, "high"))
1036 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1038 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1041 * Ignore graphicsType "Photo" presets that are not high quality.
1044 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1045 num_options
, options
);
1047 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1048 !strcmp(graphicsType
, "Photo"))
1052 * Ignore presets for normal and draft quality where the coating
1053 * isn't "none" or "autodetect".
1056 media_front_coating
= cupsGetOption(
1057 "com.apple.print.preset.media-front-coating",
1058 num_options
, options
);
1060 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1061 media_front_coating
&&
1062 strcmp(media_front_coating
, "none") &&
1063 strcmp(media_front_coating
, "autodetect"))
1067 * Get the output mode for this preset...
1070 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1071 num_options
, options
);
1072 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1076 if (!strcmp(output_mode
, "monochrome"))
1077 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1079 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1081 else if (color_model_val
)
1083 if (!_cups_strcasecmp(color_model_val
, "Gray"))
1084 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1086 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1089 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1092 * Save the options for this combination as needed...
1095 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1096 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1097 _ppdParseOptions(ppd_attr
->value
, 0,
1098 pc
->presets
[pwg_print_color_mode
] +
1099 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1102 cupsFreeOptions(num_options
, options
);
1104 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1107 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1108 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1109 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1112 * Try adding some common color options to create grayscale presets. These
1113 * are listed in order of popularity...
1116 const char *color_option
= NULL
, /* Color control option */
1117 *gray_choice
= NULL
; /* Choice to select grayscale */
1119 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1120 ppdFindChoice(color_model
, "Gray"))
1122 color_option
= "ColorModel";
1123 gray_choice
= "Gray";
1125 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1126 ppdFindChoice(color_model
, "grayscale"))
1128 color_option
= "HPColorMode";
1129 gray_choice
= "grayscale";
1131 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1132 ppdFindChoice(color_model
, "Mono"))
1134 color_option
= "BRMonoColor";
1135 gray_choice
= "Mono";
1137 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1138 ppdFindChoice(color_model
, "1"))
1140 color_option
= "CNIJSGrayScale";
1143 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1144 ppdFindChoice(color_model
, "True"))
1146 color_option
= "HPColorAsGray";
1147 gray_choice
= "True";
1150 if (color_option
&& gray_choice
)
1153 * Copy and convert ColorModel (output-mode) data...
1156 cups_option_t
*coption
, /* Color option */
1157 *moption
; /* Monochrome option */
1159 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1160 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1161 pwg_print_quality
++)
1163 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1166 * Copy the color options...
1169 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1170 [pwg_print_quality
];
1171 options
= calloc(sizeof(cups_option_t
), num_options
);
1175 for (i
= num_options
, moption
= options
,
1176 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1177 [pwg_print_quality
];
1179 i
--, moption
++, coption
++)
1181 moption
->name
= _cupsStrRetain(coption
->name
);
1182 moption
->value
= _cupsStrRetain(coption
->value
);
1185 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1187 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1191 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1195 * Add the grayscale option to the preset...
1198 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1199 cupsAddOption(color_option
, gray_choice
,
1200 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1201 [pwg_print_quality
],
1202 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1209 * Copy and convert Duplex (sides) data...
1212 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1213 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1214 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1215 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1216 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1220 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1222 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1226 if ((!_cups_strcasecmp(choice
->choice
, "None") ||
1227 !_cups_strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1228 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1229 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1230 !_cups_strcasecmp(choice
->choice
, "LongEdge") ||
1231 !_cups_strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1232 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1233 else if ((!_cups_strcasecmp(choice
->choice
, "DuplexTumble") ||
1234 !_cups_strcasecmp(choice
->choice
, "ShortEdge") ||
1235 !_cups_strcasecmp(choice
->choice
, "Bottom")) &&
1236 !pc
->sides_2sided_short
)
1237 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1242 * Copy filters and pre-filters...
1245 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1246 (cups_acopy_func_t
)_cupsStrAlloc
,
1247 (cups_afree_func_t
)_cupsStrFree
);
1249 cupsArrayAdd(pc
->filters
,
1250 "application/vnd.cups-raw application/octet-stream 0 -");
1252 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1256 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1258 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1260 else if (ppd
->num_filters
> 0)
1262 for (i
= 0; i
< ppd
->num_filters
; i
++)
1263 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1266 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1269 * See if we have a command filter...
1272 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1274 filter
= (const char *)cupsArrayNext(pc
->filters
))
1275 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1276 _cups_isspace(filter
[28]))
1280 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1281 _cups_strcasecmp(ppd_attr
->value
, "none")))
1284 * No command filter and no cupsCommands keyword telling us not to use one.
1285 * See if this is a PostScript printer, and if so add a PostScript command
1289 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1291 filter
= (const char *)cupsArrayNext(pc
->filters
))
1292 if (!_cups_strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1293 _cups_isspace(filter
[31]))
1297 cupsArrayAdd(pc
->filters
,
1298 "application/vnd.cups-command application/postscript 100 "
1302 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1304 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1305 (cups_acopy_func_t
)_cupsStrAlloc
,
1306 (cups_afree_func_t
)_cupsStrFree
);
1310 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1312 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1315 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1316 pc
->single_file
= !_cups_strcasecmp(ppd_attr
->value
, "true");
1319 * Copy the product string, if any...
1323 pc
->product
= _cupsStrAlloc(ppd
->product
);
1326 * Copy finishings mapping data...
1329 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsIPPFinishings", NULL
)) != NULL
)
1331 pc
->finishings
= cupsArrayNew3((cups_array_func_t
)pwg_compare_finishings
,
1332 NULL
, NULL
, 0, NULL
,
1333 (cups_afree_func_t
)pwg_free_finishings
);
1337 if ((finishings
= calloc(1, sizeof(_pwg_finishings_t
))) == NULL
)
1340 finishings
->value
= atoi(ppd_attr
->spec
);
1341 finishings
->num_options
= _ppdParseOptions(ppd_attr
->value
, 0,
1342 &(finishings
->options
),
1343 _PPD_PARSE_OPTIONS
);
1345 cupsArrayAdd(pc
->finishings
, finishings
);
1347 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsIPPFinishings",
1352 * Return the cache data...
1358 * If we get here we need to destroy the PWG mapping data and return NULL...
1363 _cupsSetError(IPP_INTERNAL_ERROR
, _("Out of memory."), 1);
1364 _ppdCacheDestroy(pc
);
1371 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1375 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1377 int i
; /* Looping var */
1378 _pwg_map_t
*map
; /* Current map */
1379 _pwg_size_t
*size
; /* Current size */
1383 * Range check input...
1390 * Free memory as needed...
1395 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1397 _cupsStrFree(map
->pwg
);
1398 _cupsStrFree(map
->ppd
);
1406 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1408 _cupsStrFree(size
->map
.pwg
);
1409 _cupsStrFree(size
->map
.ppd
);
1415 if (pc
->source_option
)
1416 _cupsStrFree(pc
->source_option
);
1420 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1422 _cupsStrFree(map
->pwg
);
1423 _cupsStrFree(map
->ppd
);
1431 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1433 _cupsStrFree(map
->pwg
);
1434 _cupsStrFree(map
->ppd
);
1440 if (pc
->custom_max_keyword
)
1441 _cupsStrFree(pc
->custom_max_keyword
);
1443 if (pc
->custom_min_keyword
)
1444 _cupsStrFree(pc
->custom_min_keyword
);
1446 _cupsStrFree(pc
->product
);
1447 cupsArrayDelete(pc
->filters
);
1448 cupsArrayDelete(pc
->prefilters
);
1449 cupsArrayDelete(pc
->finishings
);
1456 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1460 const char * /* O - output-bin or NULL */
1462 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1463 const char *output_bin
) /* I - PPD OutputBin string */
1465 int i
; /* Looping var */
1469 * Range check input...
1472 if (!pc
|| !output_bin
)
1476 * Look up the OutputBin string...
1480 for (i
= 0; i
< pc
->num_bins
; i
++)
1481 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1482 return (pc
->bins
[i
].pwg
);
1489 * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given
1490 * IPP finishings value(s).
1493 int /* O - New number of options */
1494 _ppdCacheGetFinishingOptions(
1495 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1496 ipp_t
*job
, /* I - Job attributes or NULL */
1497 ipp_finish_t value
, /* I - IPP finishings value of IPP_FINISHINGS_NONE */
1498 int num_options
, /* I - Number of options */
1499 cups_option_t
**options
) /* IO - Options */
1501 int i
; /* Looping var */
1502 _pwg_finishings_t
*f
, /* PWG finishings options */
1503 key
; /* Search key */
1504 ipp_attribute_t
*attr
; /* Finishings attribute */
1505 cups_option_t
*option
; /* Current finishings option */
1509 * Range check input...
1512 if (!pc
|| cupsArrayCount(pc
->finishings
) == 0 || !options
||
1513 (!job
&& value
== IPP_FINISHINGS_NONE
))
1514 return (num_options
);
1517 * Apply finishing options...
1520 if (job
&& (attr
= ippFindAttribute(job
, "finishings", IPP_TAG_ENUM
)) != NULL
)
1522 int num_values
= ippGetCount(attr
); /* Number of values */
1524 for (i
= 0; i
< num_values
; i
++)
1526 key
.value
= ippGetInteger(attr
, i
);
1528 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
1530 int j
; /* Another looping var */
1532 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
1533 num_options
= cupsAddOption(option
->name
, option
->value
,
1534 num_options
, options
);
1538 else if (value
!= IPP_FINISHINGS_NONE
)
1542 if ((f
= cupsArrayFind(pc
->finishings
, &key
)) != NULL
)
1544 int j
; /* Another looping var */
1546 for (j
= f
->num_options
, option
= f
->options
; j
> 0; j
--, option
++)
1547 num_options
= cupsAddOption(option
->name
, option
->value
,
1548 num_options
, options
);
1552 return (num_options
);
1557 * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given
1561 int /* O - Number of finishings values */
1562 _ppdCacheGetFinishingValues(
1563 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1564 int num_options
, /* I - Number of options */
1565 cups_option_t
*options
, /* I - Options */
1566 int max_values
, /* I - Maximum number of finishings values */
1567 int *values
) /* O - Finishings values */
1569 int i
, /* Looping var */
1570 num_values
= 0; /* Number of values */
1571 _pwg_finishings_t
*f
; /* Current finishings option */
1572 cups_option_t
*option
; /* Current option */
1573 const char *val
; /* Value for option */
1577 * Range check input...
1580 if (!pc
|| !pc
->finishings
|| num_options
< 1 || max_values
< 1 || !values
)
1584 * Go through the finishings options and see what is set...
1587 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
1589 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
1591 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
1592 if ((val
= cupsGetOption(option
->name
, num_options
, options
)) == NULL
||
1593 _cups_strcasecmp(option
->value
, val
))
1598 values
[num_values
++] = f
->value
;
1600 if (num_values
>= max_values
)
1605 return (num_values
);
1610 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
1611 * attributes or a keyword string.
1614 const char * /* O - PPD InputSlot or NULL */
1615 _ppdCacheGetInputSlot(
1616 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1617 ipp_t
*job
, /* I - Job attributes or NULL */
1618 const char *keyword
) /* I - Keyword string or NULL */
1621 * Range check input...
1624 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
1627 if (job
&& !keyword
)
1630 * Lookup the media-col attribute and any media-source found there...
1633 ipp_attribute_t
*media_col
, /* media-col attribute */
1634 *media_source
; /* media-source attribute */
1635 _pwg_size_t size
; /* Dimensional size */
1636 int margins_set
; /* Were the margins set? */
1638 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
1640 (media_source
= ippFindAttribute(ippGetCollection(media_col
, 0),
1642 IPP_TAG_KEYWORD
)) != NULL
)
1645 * Use the media-source value from media-col...
1648 keyword
= ippGetString(media_source
, 0, NULL
);
1650 else if (_pwgInitSize(&size
, job
, &margins_set
))
1653 * For media <= 5x7, look for a photo tray...
1656 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
1663 int i
; /* Looping var */
1665 for (i
= 0; i
< pc
->num_sources
; i
++)
1666 if (!_cups_strcasecmp(keyword
, pc
->sources
[i
].pwg
))
1667 return (pc
->sources
[i
].ppd
);
1675 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
1676 * attributes or a keyword string.
1679 const char * /* O - PPD MediaType or NULL */
1680 _ppdCacheGetMediaType(
1681 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1682 ipp_t
*job
, /* I - Job attributes or NULL */
1683 const char *keyword
) /* I - Keyword string or NULL */
1686 * Range check input...
1689 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
1692 if (job
&& !keyword
)
1695 * Lookup the media-col attribute and any media-source found there...
1698 ipp_attribute_t
*media_col
, /* media-col attribute */
1699 *media_type
; /* media-type attribute */
1701 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
1704 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
1706 IPP_TAG_KEYWORD
)) == NULL
)
1707 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
1708 "media-type", IPP_TAG_NAME
);
1711 keyword
= media_type
->values
[0].string
.text
;
1717 int i
; /* Looping var */
1719 for (i
= 0; i
< pc
->num_types
; i
++)
1720 if (!_cups_strcasecmp(keyword
, pc
->types
[i
].pwg
))
1721 return (pc
->types
[i
].ppd
);
1729 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
1733 const char * /* O - PPD OutputBin or NULL */
1734 _ppdCacheGetOutputBin(
1735 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1736 const char *output_bin
) /* I - Keyword string */
1738 int i
; /* Looping var */
1742 * Range check input...
1745 if (!pc
|| !output_bin
)
1749 * Look up the OutputBin string...
1753 for (i
= 0; i
< pc
->num_bins
; i
++)
1754 if (!_cups_strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
1755 return (pc
->bins
[i
].ppd
);
1762 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
1763 * attributes or a keyword string.
1766 const char * /* O - PPD PageSize or NULL */
1767 _ppdCacheGetPageSize(
1768 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1769 ipp_t
*job
, /* I - Job attributes or NULL */
1770 const char *keyword
, /* I - Keyword string or NULL */
1771 int *exact
) /* O - 1 if exact match, 0 otherwise */
1773 int i
; /* Looping var */
1774 _pwg_size_t
*size
, /* Current size */
1775 *closest
, /* Closest size */
1776 jobsize
; /* Size data from job */
1777 int margins_set
, /* Were the margins set? */
1778 dwidth
, /* Difference in width */
1779 dlength
, /* Difference in length */
1780 dleft
, /* Difference in left margins */
1781 dright
, /* Difference in right margins */
1782 dbottom
, /* Difference in bottom margins */
1783 dtop
, /* Difference in top margins */
1784 dmin
, /* Minimum difference */
1785 dclosest
; /* Closest difference */
1786 const char *ppd_name
; /* PPD media name */
1789 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
1790 pc
, job
, keyword
, exact
));
1793 * Range check input...
1796 if (!pc
|| (!job
&& !keyword
))
1807 * Try getting the PPD media name from the job attributes...
1810 ipp_attribute_t
*attr
; /* Job attribute */
1812 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
1813 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
1814 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
1818 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
1819 attr
->name
, ippTagString(attr
->value_tag
)));
1821 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
1824 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
1825 attr
->value_tag
== IPP_TAG_KEYWORD
))
1826 ppd_name
= attr
->values
[0].string
.text
;
1829 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
1834 * Try looking up the named PPD size first...
1837 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1839 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
1840 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
1842 if (!_cups_strcasecmp(ppd_name
, size
->map
.ppd
) ||
1843 !_cups_strcasecmp(ppd_name
, size
->map
.pwg
))
1848 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
1850 return (size
->map
.ppd
);
1855 if (job
&& !keyword
)
1858 * Get the size using media-col or media, with the preference being
1862 if (!_pwgInitSize(&jobsize
, job
, &margins_set
))
1868 * Get the size using a media keyword...
1871 _pwg_media_t
*media
; /* Media definition */
1874 if ((media
= _pwgMediaForPWG(keyword
)) == NULL
)
1875 if ((media
= _pwgMediaForLegacy(keyword
)) == NULL
)
1876 if ((media
= _pwgMediaForPPD(keyword
)) == NULL
)
1879 jobsize
.width
= media
->width
;
1880 jobsize
.length
= media
->length
;
1885 * Now that we have the dimensions and possibly the margins, look at the
1886 * available sizes and find the match...
1890 dclosest
= 999999999;
1892 if (!ppd_name
|| _cups_strncasecmp(ppd_name
, "Custom.", 7) ||
1893 _cups_strncasecmp(ppd_name
, "custom_", 7))
1895 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1898 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
1899 * is just about 176/2540ths...
1902 dwidth
= size
->width
- jobsize
.width
;
1903 dlength
= size
->length
- jobsize
.length
;
1905 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
1911 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
1914 dleft
= size
->left
- jobsize
.left
;
1915 dright
= size
->right
- jobsize
.right
;
1916 dtop
= size
->top
- jobsize
.top
;
1917 dbottom
= size
->bottom
- jobsize
.bottom
;
1919 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
1920 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
1922 dleft
= dleft
< 0 ? -dleft
: dleft
;
1923 dright
= dright
< 0 ? -dright
: dright
;
1924 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
1925 dtop
= dtop
< 0 ? -dtop
: dtop
;
1926 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
1928 if (dmin
< dclosest
)
1941 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
1943 return (size
->map
.ppd
);
1949 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
1952 return (closest
->map
.ppd
);
1956 * If we get here we need to check for custom page size support...
1959 if (jobsize
.width
>= pc
->custom_min_width
&&
1960 jobsize
.width
<= pc
->custom_max_width
&&
1961 jobsize
.length
>= pc
->custom_min_length
&&
1962 jobsize
.length
<= pc
->custom_max_length
)
1965 * In range, format as Custom.WWWWxLLLL (points).
1968 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
1969 (int)_PWG_TOPTS(jobsize
.width
), (int)_PWG_TOPTS(jobsize
.length
));
1971 if (margins_set
&& exact
)
1973 dleft
= pc
->custom_size
.left
- jobsize
.left
;
1974 dright
= pc
->custom_size
.right
- jobsize
.right
;
1975 dtop
= pc
->custom_size
.top
- jobsize
.top
;
1976 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
1978 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
1979 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
1985 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
1986 pc
->custom_ppd_size
));
1988 return (pc
->custom_ppd_size
);
1992 * No custom page size support or the size is out of range - return NULL.
1995 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
2002 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
2005 _pwg_size_t
* /* O - PWG size or NULL */
2007 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2008 const char *page_size
) /* I - PPD PageSize */
2010 int i
; /* Looping var */
2011 _pwg_media_t
*media
; /* Media */
2012 _pwg_size_t
*size
; /* Current size */
2016 * Range check input...
2019 if (!pc
|| !page_size
)
2022 if (!_cups_strncasecmp(page_size
, "Custom.", 7))
2025 * Custom size; size name can be one of the following:
2027 * Custom.WIDTHxLENGTHin - Size in inches
2028 * Custom.WIDTHxLENGTHft - Size in feet
2029 * Custom.WIDTHxLENGTHcm - Size in centimeters
2030 * Custom.WIDTHxLENGTHmm - Size in millimeters
2031 * Custom.WIDTHxLENGTHm - Size in meters
2032 * Custom.WIDTHxLENGTH[pt] - Size in points
2035 double w
, l
; /* Width and length of page */
2036 char *ptr
; /* Pointer into PageSize */
2037 struct lconv
*loc
; /* Locale data */
2040 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
2041 if (!ptr
|| *ptr
!= 'x')
2044 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
2048 if (!_cups_strcasecmp(ptr
, "in"))
2053 else if (!_cups_strcasecmp(ptr
, "ft"))
2058 else if (!_cups_strcasecmp(ptr
, "mm"))
2063 else if (!_cups_strcasecmp(ptr
, "cm"))
2068 else if (!_cups_strcasecmp(ptr
, "m"))
2079 pc
->custom_size
.width
= (int)w
;
2080 pc
->custom_size
.length
= (int)l
;
2082 return (&(pc
->custom_size
));
2086 * Not a custom size - look it up...
2089 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2090 if (!_cups_strcasecmp(page_size
, size
->map
.ppd
) ||
2091 !_cups_strcasecmp(page_size
, size
->map
.pwg
))
2095 * Look up standard sizes...
2098 if ((media
= _pwgMediaForPPD(page_size
)) == NULL
)
2099 if ((media
= _pwgMediaForLegacy(page_size
)) == NULL
)
2100 media
= _pwgMediaForPWG(page_size
);
2104 pc
->custom_size
.width
= media
->width
;
2105 pc
->custom_size
.length
= media
->length
;
2107 return (&(pc
->custom_size
));
2115 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
2119 const char * /* O - PWG media-source keyword */
2121 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2122 const char *input_slot
) /* I - PPD InputSlot */
2124 int i
; /* Looping var */
2125 _pwg_map_t
*source
; /* Current source */
2129 * Range check input...
2132 if (!pc
|| !input_slot
)
2135 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
2136 if (!_cups_strcasecmp(input_slot
, source
->ppd
))
2137 return (source
->pwg
);
2144 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
2148 const char * /* O - PWG media-type keyword */
2150 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2151 const char *media_type
) /* I - PPD MediaType */
2153 int i
; /* Looping var */
2154 _pwg_map_t
*type
; /* Current type */
2158 * Range check input...
2161 if (!pc
|| !media_type
)
2164 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
2165 if (!_cups_strcasecmp(media_type
, type
->ppd
))
2173 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
2176 int /* O - 1 on success, 0 on failure */
2178 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
2179 const char *filename
, /* I - File to write */
2180 ipp_t
*attrs
) /* I - Attributes to write, if any */
2182 int i
, j
, k
; /* Looping vars */
2183 cups_file_t
*fp
; /* Output file */
2184 _pwg_size_t
*size
; /* Current size */
2185 _pwg_map_t
*map
; /* Current map */
2186 _pwg_finishings_t
*f
; /* Current finishing option */
2187 cups_option_t
*option
; /* Current option */
2188 const char *value
; /* Filter/pre-filter value */
2189 char newfile
[1024]; /* New filename */
2193 * Range check input...
2196 if (!pc
|| !filename
)
2198 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
2203 * Open the file and write with compression...
2206 snprintf(newfile
, sizeof(newfile
), "%s.N", filename
);
2207 if ((fp
= cupsFileOpen(newfile
, "w9")) == NULL
)
2209 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
2214 * Standard header...
2217 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2223 if (pc
->num_bins
> 0)
2225 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2226 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2227 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2234 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2235 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2236 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2237 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2238 size
->bottom
, size
->right
, size
->top
);
2239 if (pc
->custom_max_width
> 0)
2240 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2241 pc
->custom_max_width
, pc
->custom_max_length
,
2242 pc
->custom_min_width
, pc
->custom_min_length
,
2243 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2244 pc
->custom_size
.right
, pc
->custom_size
.top
);
2250 if (pc
->source_option
)
2251 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2253 if (pc
->num_sources
> 0)
2255 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2256 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2257 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2264 if (pc
->num_types
> 0)
2266 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2267 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2268 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2275 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2276 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2277 if (pc
->num_presets
[i
][j
])
2279 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2280 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2283 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2284 cupsFilePutChar(fp
, '\n');
2291 if (pc
->sides_option
)
2292 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2294 if (pc
->sides_1sided
)
2295 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2297 if (pc
->sides_2sided_long
)
2298 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2300 if (pc
->sides_2sided_short
)
2301 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2304 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2308 cupsFilePutConf(fp
, "Product", pc
->product
);
2310 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2312 value
= (const char *)cupsArrayNext(pc
->filters
))
2313 cupsFilePutConf(fp
, "Filter", value
);
2315 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2317 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2318 cupsFilePutConf(fp
, "PreFilter", value
);
2320 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2323 * Finishing options...
2326 for (f
= (_pwg_finishings_t
*)cupsArrayFirst(pc
->finishings
);
2328 f
= (_pwg_finishings_t
*)cupsArrayNext(pc
->finishings
))
2330 cupsFilePrintf(fp
, "Finishings %d", f
->value
);
2331 for (i
= f
->num_options
, option
= f
->options
; i
> 0; i
--, option
++)
2332 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2333 cupsFilePutChar(fp
, '\n');
2337 * IPP attributes, if any...
2342 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2344 attrs
->state
= IPP_IDLE
;
2345 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2349 * Close and return...
2352 if (cupsFileClose(fp
))
2359 return (!rename(newfile
, filename
));
2364 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
2368 const char * /* O - InputSlot name */
2369 _pwgInputSlotForSource(
2370 const char *media_source
, /* I - PWG media-source */
2371 char *name
, /* I - Name buffer */
2372 size_t namesize
) /* I - Size of name buffer */
2375 * Range check input...
2378 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
2381 if (_cups_strcasecmp(media_source
, "main"))
2382 strlcpy(name
, "Cassette", namesize
);
2383 else if (_cups_strcasecmp(media_source
, "alternate"))
2384 strlcpy(name
, "Multipurpose", namesize
);
2385 else if (_cups_strcasecmp(media_source
, "large-capacity"))
2386 strlcpy(name
, "LargeCapacity", namesize
);
2387 else if (_cups_strcasecmp(media_source
, "bottom"))
2388 strlcpy(name
, "Lower", namesize
);
2389 else if (_cups_strcasecmp(media_source
, "middle"))
2390 strlcpy(name
, "Middle", namesize
);
2391 else if (_cups_strcasecmp(media_source
, "top"))
2392 strlcpy(name
, "Upper", namesize
);
2393 else if (_cups_strcasecmp(media_source
, "rear"))
2394 strlcpy(name
, "Rear", namesize
);
2395 else if (_cups_strcasecmp(media_source
, "side"))
2396 strlcpy(name
, "Side", namesize
);
2397 else if (_cups_strcasecmp(media_source
, "envelope"))
2398 strlcpy(name
, "Envelope", namesize
);
2399 else if (_cups_strcasecmp(media_source
, "main-roll"))
2400 strlcpy(name
, "Roll", namesize
);
2401 else if (_cups_strcasecmp(media_source
, "alternate-roll"))
2402 strlcpy(name
, "Roll2", namesize
);
2404 pwg_ppdize_name(media_source
, name
, namesize
);
2411 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
2415 const char * /* O - MediaType name */
2416 _pwgMediaTypeForType(
2417 const char *media_type
, /* I - PWG media-type */
2418 char *name
, /* I - Name buffer */
2419 size_t namesize
) /* I - Size of name buffer */
2422 * Range check input...
2425 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
2428 if (_cups_strcasecmp(media_type
, "auto"))
2429 strlcpy(name
, "Auto", namesize
);
2430 else if (_cups_strcasecmp(media_type
, "cardstock"))
2431 strlcpy(name
, "Cardstock", namesize
);
2432 else if (_cups_strcasecmp(media_type
, "envelope"))
2433 strlcpy(name
, "Envelope", namesize
);
2434 else if (_cups_strcasecmp(media_type
, "photographic-glossy"))
2435 strlcpy(name
, "Glossy", namesize
);
2436 else if (_cups_strcasecmp(media_type
, "photographic-high-gloss"))
2437 strlcpy(name
, "HighGloss", namesize
);
2438 else if (_cups_strcasecmp(media_type
, "photographic-matte"))
2439 strlcpy(name
, "Matte", namesize
);
2440 else if (_cups_strcasecmp(media_type
, "stationery"))
2441 strlcpy(name
, "Plain", namesize
);
2442 else if (_cups_strcasecmp(media_type
, "stationery-coated"))
2443 strlcpy(name
, "Coated", namesize
);
2444 else if (_cups_strcasecmp(media_type
, "stationery-inkjet"))
2445 strlcpy(name
, "Inkjet", namesize
);
2446 else if (_cups_strcasecmp(media_type
, "stationery-letterhead"))
2447 strlcpy(name
, "Letterhead", namesize
);
2448 else if (_cups_strcasecmp(media_type
, "stationery-preprinted"))
2449 strlcpy(name
, "Preprinted", namesize
);
2450 else if (_cups_strcasecmp(media_type
, "transparency"))
2451 strlcpy(name
, "Transparency", namesize
);
2453 pwg_ppdize_name(media_type
, name
, namesize
);
2460 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
2463 const char * /* O - PageSize name */
2464 _pwgPageSizeForMedia(
2465 _pwg_media_t
*media
, /* I - Media */
2466 char *name
, /* I - PageSize name buffer */
2467 size_t namesize
) /* I - Size of name buffer */
2469 const char *sizeptr
, /* Pointer to size in PWG name */
2470 *dimptr
; /* Pointer to dimensions in PWG name */
2474 * Range check input...
2477 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
2481 * Copy or generate a PageSize name...
2487 * Use a standard Adobe name...
2490 strlcpy(name
, media
->ppd
, namesize
);
2492 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
2493 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
2494 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
2495 (size_t)(dimptr
- sizeptr
) > namesize
)
2498 * Use a name of the form "wNNNhNNN"...
2501 snprintf(name
, namesize
, "w%dh%d", (int)_PWG_TOPTS(media
->width
),
2502 (int)_PWG_TOPTS(media
->length
));
2507 * Copy the size name from class_sizename_dimensions...
2510 memcpy(name
, sizeptr
+ 1, dimptr
- sizeptr
- 1);
2511 name
[dimptr
- sizeptr
- 1] = '\0';
2519 * 'pwg_compare_finishings()' - Compare two finishings values.
2522 static int /* O- Result of comparison */
2523 pwg_compare_finishings(
2524 _pwg_finishings_t
*a
, /* I - First finishings value */
2525 _pwg_finishings_t
*b
) /* I - Second finishings value */
2527 return (b
->value
- a
->value
);
2532 * 'pwg_free_finishings()' - Free a finishings value.
2536 pwg_free_finishings(
2537 _pwg_finishings_t
*f
) /* I - Finishings value */
2539 cupsFreeOptions(f
->num_options
, f
->options
);
2545 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
2549 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
2550 char *name
, /* I - Name buffer */
2551 size_t namesize
) /* I - Size of name buffer */
2553 char *ptr
, /* Pointer into name buffer */
2554 *end
; /* End of name buffer */
2557 *name
= toupper(*ipp
++);
2559 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
2561 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
2564 *ptr
++ = toupper(*ipp
++ & 255);
2575 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
2579 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
2580 char *name
, /* I - Name buffer */
2581 size_t namesize
) /* I - Size of name buffer */
2583 char *ptr
, /* Pointer into name buffer */
2584 *end
; /* End of name buffer */
2587 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
2589 if (_cups_isalnum(*ppd
) || *ppd
== '-')
2590 *ptr
++ = tolower(*ppd
& 255);
2591 else if (*ppd
== '_' || *ppd
== '.')
2594 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
2595 _cups_isupper(ppd
[1]) && ptr
< end
)