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 void pwg_ppdize_name(const char *ipp
, char *name
, size_t namesize
);
69 static void pwg_unppdize_name(const char *ppd
, char *name
, size_t namesize
);
73 * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a
76 * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a
80 _ppd_cache_t
* /* O - PPD cache and mapping data */
81 _ppdCacheCreateWithFile(
82 const char *filename
, /* I - File to read */
83 ipp_t
**attrs
) /* IO - IPP attributes, if any */
85 cups_file_t
*fp
; /* File */
86 _ppd_cache_t
*pc
; /* PWG mapping data */
87 _pwg_size_t
*size
; /* Current size */
88 _pwg_map_t
*map
; /* Current map */
89 int linenum
, /* Current line number */
90 num_bins
, /* Number of bins in file */
91 num_sizes
, /* Number of sizes in file */
92 num_sources
, /* Number of sources in file */
93 num_types
; /* Number of types in file */
94 char line
[2048], /* Current line */
95 *value
, /* Pointer to value in line */
96 *valueptr
, /* Pointer into value */
97 pwg_keyword
[128], /* PWG keyword */
98 ppd_keyword
[PPD_MAX_NAME
];
100 _pwg_print_color_mode_t print_color_mode
;
101 /* Print color mode for preset */
102 _pwg_print_quality_t print_quality
; /* Print quality for preset */
105 DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename
));
108 * Range check input...
116 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
124 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
126 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
131 * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it...
134 if (!cupsFileGets(fp
, line
, sizeof(line
)))
136 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
137 DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line.");
142 if (strncmp(line
, "#CUPS-PPD-CACHE-", 16) ||
143 atoi(line
+ 16) != _PPD_CACHE_VERSION
)
145 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
146 DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line
));
152 * Allocate the mapping data structure...
155 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
157 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
158 DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t.");
172 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
174 DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", "
175 "linenum=%d", line
, value
, linenum
));
179 DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.",
181 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
184 else if (!strcasecmp(line
, "Filter"))
187 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
188 (cups_acopy_func_t
)_cupsStrAlloc
,
189 (cups_afree_func_t
)_cupsStrFree
);
191 cupsArrayAdd(pc
->filters
, value
);
193 else if (!strcasecmp(line
, "PreFilter"))
196 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
197 (cups_acopy_func_t
)_cupsStrAlloc
,
198 (cups_afree_func_t
)_cupsStrFree
);
200 cupsArrayAdd(pc
->prefilters
, value
);
202 else if (!strcasecmp(line
, "Product"))
204 pc
->product
= _cupsStrAlloc(value
);
206 else if (!strcasecmp(line
, "SingleFile"))
208 pc
->single_file
= !strcasecmp(value
, "true");
210 else if (!strcasecmp(line
, "IPP"))
212 off_t pos
= cupsFileTell(fp
), /* Position in file */
213 length
= strtol(value
, NULL
, 10);
214 /* Length of IPP attributes */
218 DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times.");
219 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
222 else if (length
<= 0)
224 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length.");
225 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
232 * Read IPP attributes into the provided variable...
237 if (ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
240 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
241 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
248 * Skip the IPP data entirely...
251 cupsFileSeek(fp
, pos
+ length
);
254 if (cupsFileTell(fp
) != (pos
+ length
))
256 DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data.");
257 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
261 else if (!strcasecmp(line
, "NumBins"))
265 DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times.");
266 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
270 if ((num_bins
= atoi(value
)) <= 0 || num_bins
> 65536)
272 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line "
273 "%d.", num_sizes
, linenum
));
274 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
278 if ((pc
->bins
= calloc(num_bins
, sizeof(_pwg_map_t
))) == NULL
)
280 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
282 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
286 else if (!strcasecmp(line
, "Bin"))
288 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
290 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum
));
291 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
295 if (pc
->num_bins
>= num_bins
)
297 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.",
299 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
303 map
= pc
->bins
+ pc
->num_bins
;
304 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
305 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
309 else if (!strcasecmp(line
, "NumSizes"))
313 DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times.");
314 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
318 if ((num_sizes
= atoi(value
)) <= 0 || num_sizes
> 65536)
320 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line "
321 "%d.", num_sizes
, linenum
));
322 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
326 if ((pc
->sizes
= calloc(num_sizes
, sizeof(_pwg_size_t
))) == NULL
)
328 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
330 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
334 else if (!strcasecmp(line
, "Size"))
336 if (pc
->num_sizes
>= num_sizes
)
338 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.",
340 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
344 size
= pc
->sizes
+ pc
->num_sizes
;
346 if (sscanf(value
, "%127s%40s%d%d%d%d%d%d", pwg_keyword
, ppd_keyword
,
347 &(size
->width
), &(size
->length
), &(size
->left
),
348 &(size
->bottom
), &(size
->right
), &(size
->top
)) != 8)
350 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.",
352 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
356 size
->map
.pwg
= _cupsStrAlloc(pwg_keyword
);
357 size
->map
.ppd
= _cupsStrAlloc(ppd_keyword
);
361 else if (!strcasecmp(line
, "CustomSize"))
363 if (pc
->custom_max_width
> 0)
365 DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line "
367 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
371 if (sscanf(value
, "%d%d%d%d%d%d%d%d", &(pc
->custom_max_width
),
372 &(pc
->custom_max_length
), &(pc
->custom_min_width
),
373 &(pc
->custom_min_length
), &(pc
->custom_size
.left
),
374 &(pc
->custom_size
.bottom
), &(pc
->custom_size
.right
),
375 &(pc
->custom_size
.top
)) != 8)
377 DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.",
379 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
383 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
384 pc
->custom_max_width
, pc
->custom_max_length
);
385 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
387 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
388 pc
->custom_min_width
, pc
->custom_min_length
);
389 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
391 else if (!strcasecmp(line
, "SourceOption"))
393 pc
->source_option
= _cupsStrAlloc(value
);
395 else if (!strcasecmp(line
, "NumSources"))
399 DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple "
401 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
405 if ((num_sources
= atoi(value
)) <= 0 || num_sources
> 65536)
407 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on "
408 "line %d.", num_sources
, linenum
));
409 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
413 if ((pc
->sources
= calloc(num_sources
, sizeof(_pwg_map_t
))) == NULL
)
415 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
417 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
421 else if (!strcasecmp(line
, "Source"))
423 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
425 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.",
427 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
431 if (pc
->num_sources
>= num_sources
)
433 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.",
435 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
439 map
= pc
->sources
+ pc
->num_sources
;
440 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
441 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
445 else if (!strcasecmp(line
, "NumTypes"))
449 DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times.");
450 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
454 if ((num_types
= atoi(value
)) <= 0 || num_types
> 65536)
456 DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on "
457 "line %d.", num_types
, linenum
));
458 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
462 if ((pc
->types
= calloc(num_types
, sizeof(_pwg_map_t
))) == NULL
)
464 DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
466 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
470 else if (!strcasecmp(line
, "Type"))
472 if (sscanf(value
, "%127s%40s", pwg_keyword
, ppd_keyword
) != 2)
474 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.",
476 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
480 if (pc
->num_types
>= num_types
)
482 DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.",
484 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
488 map
= pc
->types
+ pc
->num_types
;
489 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
490 map
->ppd
= _cupsStrAlloc(ppd_keyword
);
494 else if (!strcasecmp(line
, "Preset"))
497 * Preset output-mode print-quality name=value ...
500 print_color_mode
= (_pwg_print_color_mode_t
)strtol(value
, &valueptr
, 10);
501 print_quality
= (_pwg_print_quality_t
)strtol(valueptr
, &valueptr
, 10);
503 if (print_color_mode
< _PWG_PRINT_COLOR_MODE_MONOCHROME
||
504 print_color_mode
>= _PWG_PRINT_COLOR_MODE_MAX
||
505 print_quality
< _PWG_PRINT_QUALITY_DRAFT
||
506 print_quality
>= _PWG_PRINT_QUALITY_MAX
||
507 valueptr
== value
|| !*valueptr
)
509 DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.",
511 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
515 pc
->num_presets
[print_color_mode
][print_quality
] =
516 cupsParseOptions(valueptr
, 0,
517 pc
->presets
[print_color_mode
] + print_quality
);
519 else if (!strcasecmp(line
, "SidesOption"))
520 pc
->sides_option
= _cupsStrAlloc(value
);
521 else if (!strcasecmp(line
, "Sides1Sided"))
522 pc
->sides_1sided
= _cupsStrAlloc(value
);
523 else if (!strcasecmp(line
, "Sides2SidedLong"))
524 pc
->sides_2sided_long
= _cupsStrAlloc(value
);
525 else if (!strcasecmp(line
, "Sides2SidedShort"))
526 pc
->sides_2sided_short
= _cupsStrAlloc(value
);
529 DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line
,
531 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
536 if (pc
->num_sizes
< num_sizes
)
538 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).",
539 pc
->num_sizes
, num_sizes
));
540 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
544 if (pc
->num_sources
< num_sources
)
546 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).",
547 pc
->num_sources
, num_sources
));
548 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
552 if (pc
->num_types
< num_types
)
554 DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).",
555 pc
->num_types
, num_types
));
556 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad PPD cache file."), 1);
565 * If we get here the file was bad - free any data and return...
571 _ppdCacheDestroy(pc
);
581 * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file.
584 _ppd_cache_t
* /* O - PPD cache and mapping data */
585 _ppdCacheCreateWithPPD(ppd_file_t
*ppd
) /* I - PPD file */
587 int i
, j
, k
; /* Looping vars */
588 _ppd_cache_t
*pc
; /* PWG mapping data */
589 ppd_option_t
*input_slot
, /* InputSlot option */
590 *media_type
, /* MediaType option */
591 *output_bin
, /* OutputBin option */
592 *color_model
, /* ColorModel option */
593 *duplex
; /* Duplex option */
594 ppd_choice_t
*choice
; /* Current InputSlot/MediaType */
595 _pwg_map_t
*map
; /* Current source/type map */
596 ppd_attr_t
*ppd_attr
; /* Current PPD preset attribute */
597 int num_options
; /* Number of preset options and props */
598 cups_option_t
*options
; /* Preset options and properties */
599 ppd_size_t
*ppd_size
; /* Current PPD size */
600 _pwg_size_t
*pwg_size
; /* Current PWG size */
601 char pwg_keyword
[3 + PPD_MAX_NAME
+ 1 + 12 + 1 + 12 + 3],
602 /* PWG keyword string */
603 ppd_name
[PPD_MAX_NAME
];
604 /* Normalized PPD name */
605 const char *pwg_name
; /* Standard PWG media name */
606 _pwg_media_t
*pwg_media
; /* PWG media data */
607 _pwg_print_color_mode_t pwg_print_color_mode
;
608 /* print-color-mode index */
609 _pwg_print_quality_t pwg_print_quality
;
610 /* print-quality index */
611 int similar
; /* Are the old and new size similar? */
612 _pwg_size_t
*old_size
; /* Current old size */
613 int old_imageable
, /* Old imageable length in 2540ths */
614 old_borderless
, /* Old borderless state */
615 old_known_pwg
; /* Old PWG name is well-known */
616 int new_width
, /* New width in 2540ths */
617 new_length
, /* New length in 2540ths */
618 new_left
, /* New left margin in 2540ths */
619 new_bottom
, /* New bottom margin in 2540ths */
620 new_right
, /* New right margin in 2540ths */
621 new_top
, /* New top margin in 2540ths */
622 new_imageable
, /* New imageable length in 2540ths */
623 new_borderless
, /* New borderless state */
624 new_known_pwg
; /* New PWG name is well-known */
625 _pwg_size_t
*new_size
; /* New size to add, if any */
626 const char *filter
; /* Current filter */
629 DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd
));
632 * Range check input...
642 if ((pc
= calloc(1, sizeof(_ppd_cache_t
))) == NULL
)
644 DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t.");
649 * Copy and convert size data...
652 if (ppd
->num_sizes
== 0)
654 DEBUG_puts("_ppdCacheCreateWithPPD: No page sizes in PPD.");
658 if ((pc
->sizes
= calloc(ppd
->num_sizes
, sizeof(_pwg_size_t
))) == NULL
)
660 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
661 "_pwg_size_t's.", ppd
->num_sizes
));
665 for (i
= ppd
->num_sizes
, pwg_size
= pc
->sizes
, ppd_size
= ppd
->sizes
;
670 * Don't copy over custom size...
673 if (!strcasecmp(ppd_size
->name
, "Custom"))
677 * Convert the PPD size name to the corresponding PWG keyword name.
680 if ((pwg_media
= _pwgMediaForPPD(ppd_size
->name
)) != NULL
)
683 * Standard name, do we have conflicts?
686 for (j
= 0; j
< pc
->num_sizes
; j
++)
687 if (!strcmp(pc
->sizes
[j
].map
.pwg
, pwg_media
->pwg
))
697 * Standard name and no conflicts, use it!
700 pwg_name
= pwg_media
->pwg
;
706 * Not a standard name; convert it to a PWG vendor name of the form:
708 * pp_lowerppd_WIDTHxHEIGHTuu
711 pwg_name
= pwg_keyword
;
714 pwg_unppdize_name(ppd_size
->name
, ppd_name
, sizeof(ppd_name
));
715 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), NULL
, ppd_name
,
716 _PWG_FROMPTS(ppd_size
->width
),
717 _PWG_FROMPTS(ppd_size
->length
));
721 * If we have a similar paper with non-zero margins then we only
722 * want to keep it if it has a larger imageable area length.
725 new_width
= _PWG_FROMPTS(ppd_size
->width
);
726 new_length
= _PWG_FROMPTS(ppd_size
->length
);
727 new_left
= _PWG_FROMPTS(ppd_size
->left
);
728 new_bottom
= _PWG_FROMPTS(ppd_size
->bottom
);
729 new_right
= _PWG_FROMPTS(ppd_size
->width
- ppd_size
->right
);
730 new_top
= _PWG_FROMPTS(ppd_size
->length
- ppd_size
->top
);
731 new_imageable
= new_length
- new_top
- new_bottom
;
732 new_borderless
= new_bottom
== 0 && new_top
== 0 &&
733 new_left
== 0 && new_right
== 0;
735 for (k
= pc
->num_sizes
, similar
= 0, old_size
= pc
->sizes
, new_size
= NULL
;
739 old_imageable
= old_size
->length
- old_size
->top
- old_size
->bottom
;
740 old_borderless
= old_size
->left
== 0 && old_size
->bottom
== 0 &&
741 old_size
->right
== 0 && old_size
->top
== 0;
742 old_known_pwg
= strncmp(old_size
->map
.pwg
, "oe_", 3) &&
743 strncmp(old_size
->map
.pwg
, "om_", 3);
745 similar
= old_borderless
== new_borderless
&&
746 _PWG_EQUIVALENT(old_size
->width
, new_width
) &&
747 _PWG_EQUIVALENT(old_size
->length
, new_length
);
750 (new_known_pwg
|| (!old_known_pwg
&& new_imageable
> old_imageable
)))
753 * The new paper has a larger imageable area so it could replace
754 * the older paper. Regardless of the imageable area, we always
755 * prefer the size with a well-known PWG name.
759 _cupsStrFree(old_size
->map
.ppd
);
760 _cupsStrFree(old_size
->map
.pwg
);
767 * The paper was unique enough to deserve its own entry so add it to the
771 new_size
= pwg_size
++;
781 new_size
->map
.ppd
= _cupsStrAlloc(ppd_size
->name
);
782 new_size
->map
.pwg
= _cupsStrAlloc(pwg_name
);
783 new_size
->width
= new_width
;
784 new_size
->length
= new_length
;
785 new_size
->left
= new_left
;
786 new_size
->bottom
= new_bottom
;
787 new_size
->right
= new_right
;
788 new_size
->top
= new_top
;
792 if (ppd
->variable_sizes
)
795 * Generate custom size data...
798 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "max",
799 _PWG_FROMPTS(ppd
->custom_max
[0]),
800 _PWG_FROMPTS(ppd
->custom_max
[1]));
801 pc
->custom_max_keyword
= _cupsStrAlloc(pwg_keyword
);
802 pc
->custom_max_width
= _PWG_FROMPTS(ppd
->custom_max
[0]);
803 pc
->custom_max_length
= _PWG_FROMPTS(ppd
->custom_max
[1]);
805 _pwgGenerateSize(pwg_keyword
, sizeof(pwg_keyword
), "custom", "min",
806 _PWG_FROMPTS(ppd
->custom_min
[0]),
807 _PWG_FROMPTS(ppd
->custom_min
[1]));
808 pc
->custom_min_keyword
= _cupsStrAlloc(pwg_keyword
);
809 pc
->custom_min_width
= _PWG_FROMPTS(ppd
->custom_min
[0]);
810 pc
->custom_min_length
= _PWG_FROMPTS(ppd
->custom_min
[1]);
812 pc
->custom_size
.left
= _PWG_FROMPTS(ppd
->custom_margins
[0]);
813 pc
->custom_size
.bottom
= _PWG_FROMPTS(ppd
->custom_margins
[1]);
814 pc
->custom_size
.right
= _PWG_FROMPTS(ppd
->custom_margins
[2]);
815 pc
->custom_size
.top
= _PWG_FROMPTS(ppd
->custom_margins
[3]);
819 * Copy and convert InputSlot data...
822 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) == NULL
)
823 input_slot
= ppdFindOption(ppd
, "HPPaperSource");
827 pc
->source_option
= _cupsStrAlloc(input_slot
->keyword
);
829 if ((pc
->sources
= calloc(input_slot
->num_choices
,
830 sizeof(_pwg_map_t
))) == NULL
)
832 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
833 "_pwg_map_t's for InputSlot.", input_slot
->num_choices
));
837 pc
->num_sources
= input_slot
->num_choices
;
839 for (i
= input_slot
->num_choices
, choice
= input_slot
->choices
,
842 i
--, choice
++, map
++)
844 if (!strncasecmp(choice
->choice
, "Auto", 4) ||
845 !strcasecmp(choice
->choice
, "Default"))
847 else if (!strcasecmp(choice
->choice
, "Cassette"))
849 else if (!strcasecmp(choice
->choice
, "PhotoTray"))
851 else if (!strcasecmp(choice
->choice
, "CDTray"))
853 else if (!strncasecmp(choice
->choice
, "Multipurpose", 12) ||
854 !strcasecmp(choice
->choice
, "MP") ||
855 !strcasecmp(choice
->choice
, "MPTray"))
856 pwg_name
= "alternate";
857 else if (!strcasecmp(choice
->choice
, "LargeCapacity"))
858 pwg_name
= "large-capacity";
859 else if (!strncasecmp(choice
->choice
, "Lower", 5))
861 else if (!strncasecmp(choice
->choice
, "Middle", 6))
863 else if (!strncasecmp(choice
->choice
, "Upper", 5))
865 else if (!strncasecmp(choice
->choice
, "Side", 4))
867 else if (!strcasecmp(choice
->choice
, "Roll") ||
868 !strcasecmp(choice
->choice
, "Roll1"))
869 pwg_name
= "main-roll";
870 else if (!strcasecmp(choice
->choice
, "Roll2"))
871 pwg_name
= "alternate-roll";
875 * Convert PPD name to lowercase...
878 pwg_name
= pwg_keyword
;
879 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
882 map
->pwg
= _cupsStrAlloc(pwg_name
);
883 map
->ppd
= _cupsStrAlloc(choice
->choice
);
888 * Copy and convert MediaType data...
891 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
893 if ((pc
->types
= calloc(media_type
->num_choices
,
894 sizeof(_pwg_map_t
))) == NULL
)
896 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
897 "_pwg_map_t's for MediaType.", media_type
->num_choices
));
901 pc
->num_types
= media_type
->num_choices
;
903 for (i
= media_type
->num_choices
, choice
= media_type
->choices
,
906 i
--, choice
++, map
++)
908 if (!strncasecmp(choice
->choice
, "Auto", 4) ||
909 !strcasecmp(choice
->choice
, "Any") ||
910 !strcasecmp(choice
->choice
, "Default"))
912 else if (!strncasecmp(choice
->choice
, "Card", 4))
913 pwg_name
= "cardstock";
914 else if (!strncasecmp(choice
->choice
, "Env", 3))
915 pwg_name
= "envelope";
916 else if (!strncasecmp(choice
->choice
, "Gloss", 5))
917 pwg_name
= "photographic-glossy";
918 else if (!strcasecmp(choice
->choice
, "HighGloss"))
919 pwg_name
= "photographic-high-gloss";
920 else if (!strcasecmp(choice
->choice
, "Matte"))
921 pwg_name
= "photographic-matte";
922 else if (!strncasecmp(choice
->choice
, "Plain", 5))
923 pwg_name
= "stationery";
924 else if (!strncasecmp(choice
->choice
, "Coated", 6))
925 pwg_name
= "stationery-coated";
926 else if (!strcasecmp(choice
->choice
, "Inkjet"))
927 pwg_name
= "stationery-inkjet";
928 else if (!strcasecmp(choice
->choice
, "Letterhead"))
929 pwg_name
= "stationery-letterhead";
930 else if (!strncasecmp(choice
->choice
, "Preprint", 8))
931 pwg_name
= "stationery-preprinted";
932 else if (!strncasecmp(choice
->choice
, "Transparen", 10))
933 pwg_name
= "transparency";
937 * Convert PPD name to lowercase...
940 pwg_name
= pwg_keyword
;
941 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
944 map
->pwg
= _cupsStrAlloc(pwg_name
);
945 map
->ppd
= _cupsStrAlloc(choice
->choice
);
950 * Copy and convert OutputBin data...
953 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
955 if ((pc
->bins
= calloc(output_bin
->num_choices
,
956 sizeof(_pwg_map_t
))) == NULL
)
958 DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
959 "_pwg_map_t's for OutputBin.", output_bin
->num_choices
));
963 pc
->num_bins
= output_bin
->num_choices
;
965 for (i
= output_bin
->num_choices
, choice
= output_bin
->choices
,
968 i
--, choice
++, map
++)
970 pwg_unppdize_name(choice
->choice
, pwg_keyword
, sizeof(pwg_keyword
));
972 map
->pwg
= _cupsStrAlloc(pwg_keyword
);
973 map
->ppd
= _cupsStrAlloc(choice
->choice
);
977 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
980 * Copy and convert APPrinterPreset (output-mode + print-quality) data...
983 const char *quality
, /* com.apple.print.preset.quality value */
984 *output_mode
, /* com.apple.print.preset.output-mode value */
985 *color_model_val
, /* ColorModel choice */
986 *graphicsType
, /* com.apple.print.preset.graphicsType value */
987 *media_front_coating
; /* com.apple.print.preset.media-front-coating value */
991 num_options
= _ppdParseOptions(ppd_attr
->value
, 0, &options
,
994 if ((quality
= cupsGetOption("com.apple.print.preset.quality",
995 num_options
, options
)) != NULL
)
998 * Get the print-quality for this preset...
1001 if (!strcmp(quality
, "low"))
1002 pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1003 else if (!strcmp(quality
, "high"))
1004 pwg_print_quality
= _PWG_PRINT_QUALITY_HIGH
;
1006 pwg_print_quality
= _PWG_PRINT_QUALITY_NORMAL
;
1009 * Ignore graphicsType "Photo" presets that are not high quality.
1012 graphicsType
= cupsGetOption("com.apple.print.preset.graphicsType",
1013 num_options
, options
);
1015 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&& graphicsType
&&
1016 !strcmp(graphicsType
, "Photo"))
1020 * Ignore presets for normal and draft quality where the coating
1021 * isn't "none" or "autodetect".
1024 media_front_coating
= cupsGetOption(
1025 "com.apple.print.preset.media-front-coating",
1026 num_options
, options
);
1028 if (pwg_print_quality
!= _PWG_PRINT_QUALITY_HIGH
&&
1029 media_front_coating
&&
1030 strcmp(media_front_coating
, "none") &&
1031 strcmp(media_front_coating
, "autodetect"))
1035 * Get the output mode for this preset...
1038 output_mode
= cupsGetOption("com.apple.print.preset.output-mode",
1039 num_options
, options
);
1040 color_model_val
= cupsGetOption("ColorModel", num_options
, options
);
1044 if (!strcmp(output_mode
, "monochrome"))
1045 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1047 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1049 else if (color_model_val
)
1051 if (!strcasecmp(color_model_val
, "Gray"))
1052 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_MONOCHROME
;
1054 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1057 pwg_print_color_mode
= _PWG_PRINT_COLOR_MODE_COLOR
;
1060 * Save the options for this combination as needed...
1063 if (!pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
])
1064 pc
->num_presets
[pwg_print_color_mode
][pwg_print_quality
] =
1065 _ppdParseOptions(ppd_attr
->value
, 0,
1066 pc
->presets
[pwg_print_color_mode
] +
1067 pwg_print_quality
, _PPD_PARSE_OPTIONS
);
1070 cupsFreeOptions(num_options
, options
);
1072 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
);
1075 if (!pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_DRAFT
] &&
1076 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_NORMAL
] &&
1077 !pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][_PWG_PRINT_QUALITY_HIGH
])
1080 * Try adding some common color options to create grayscale presets. These
1081 * are listed in order of popularity...
1084 const char *color_option
= NULL
, /* Color control option */
1085 *gray_choice
= NULL
; /* Choice to select grayscale */
1087 if ((color_model
= ppdFindOption(ppd
, "ColorModel")) != NULL
&&
1088 ppdFindChoice(color_model
, "Gray"))
1090 color_option
= "ColorModel";
1091 gray_choice
= "Gray";
1093 else if ((color_model
= ppdFindOption(ppd
, "HPColorMode")) != NULL
&&
1094 ppdFindChoice(color_model
, "grayscale"))
1096 color_option
= "HPColorMode";
1097 gray_choice
= "grayscale";
1099 else if ((color_model
= ppdFindOption(ppd
, "BRMonoColor")) != NULL
&&
1100 ppdFindChoice(color_model
, "Mono"))
1102 color_option
= "BRMonoColor";
1103 gray_choice
= "Mono";
1105 else if ((color_model
= ppdFindOption(ppd
, "CNIJSGrayScale")) != NULL
&&
1106 ppdFindChoice(color_model
, "1"))
1108 color_option
= "CNIJSGrayScale";
1111 else if ((color_model
= ppdFindOption(ppd
, "HPColorAsGray")) != NULL
&&
1112 ppdFindChoice(color_model
, "True"))
1114 color_option
= "HPColorAsGray";
1115 gray_choice
= "True";
1118 if (color_option
&& gray_choice
)
1121 * Copy and convert ColorModel (output-mode) data...
1124 cups_option_t
*coption
, /* Color option */
1125 *moption
; /* Monochrome option */
1127 for (pwg_print_quality
= _PWG_PRINT_QUALITY_DRAFT
;
1128 pwg_print_quality
< _PWG_PRINT_QUALITY_MAX
;
1129 pwg_print_quality
++)
1131 if (pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
][pwg_print_quality
])
1134 * Copy the color options...
1137 num_options
= pc
->num_presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1138 [pwg_print_quality
];
1139 options
= calloc(sizeof(cups_option_t
), num_options
);
1143 for (i
= num_options
, moption
= options
,
1144 coption
= pc
->presets
[_PWG_PRINT_COLOR_MODE_COLOR
]
1145 [pwg_print_quality
];
1147 i
--, moption
++, coption
++)
1149 moption
->name
= _cupsStrRetain(coption
->name
);
1150 moption
->value
= _cupsStrRetain(coption
->value
);
1153 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1155 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1159 else if (pwg_print_quality
!= _PWG_PRINT_QUALITY_NORMAL
)
1163 * Add the grayscale option to the preset...
1166 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
][pwg_print_quality
] =
1167 cupsAddOption(color_option
, gray_choice
,
1168 pc
->num_presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
]
1169 [pwg_print_quality
],
1170 pc
->presets
[_PWG_PRINT_COLOR_MODE_MONOCHROME
] +
1177 * Copy and convert Duplex (sides) data...
1180 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1181 if ((duplex
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1182 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1183 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1184 duplex
= ppdFindOption(ppd
, "KD03Duplex");
1188 pc
->sides_option
= _cupsStrAlloc(duplex
->keyword
);
1190 for (i
= duplex
->num_choices
, choice
= duplex
->choices
;
1194 if ((!strcasecmp(choice
->choice
, "None") ||
1195 !strcasecmp(choice
->choice
, "False")) && !pc
->sides_1sided
)
1196 pc
->sides_1sided
= _cupsStrAlloc(choice
->choice
);
1197 else if ((!strcasecmp(choice
->choice
, "DuplexNoTumble") ||
1198 !strcasecmp(choice
->choice
, "LongEdge") ||
1199 !strcasecmp(choice
->choice
, "Top")) && !pc
->sides_2sided_long
)
1200 pc
->sides_2sided_long
= _cupsStrAlloc(choice
->choice
);
1201 else if ((!strcasecmp(choice
->choice
, "DuplexTumble") ||
1202 !strcasecmp(choice
->choice
, "ShortEdge") ||
1203 !strcasecmp(choice
->choice
, "Bottom")) &&
1204 !pc
->sides_2sided_short
)
1205 pc
->sides_2sided_short
= _cupsStrAlloc(choice
->choice
);
1210 * Copy filters and pre-filters...
1213 pc
->filters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1214 (cups_acopy_func_t
)_cupsStrAlloc
,
1215 (cups_afree_func_t
)_cupsStrFree
);
1217 cupsArrayAdd(pc
->filters
,
1218 "application/vnd.cups-raw application/octet-stream 0 -");
1220 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFilter2", NULL
)) != NULL
)
1224 cupsArrayAdd(pc
->filters
, ppd_attr
->value
);
1226 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsFilter2", NULL
)) != NULL
);
1228 else if (ppd
->num_filters
> 0)
1230 for (i
= 0; i
< ppd
->num_filters
; i
++)
1231 cupsArrayAdd(pc
->filters
, ppd
->filters
[i
]);
1234 cupsArrayAdd(pc
->filters
, "application/vnd.cups-postscript 0 -");
1237 * See if we have a command filter...
1240 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1242 filter
= (const char *)cupsArrayNext(pc
->filters
))
1243 if (!strncasecmp(filter
, "application/vnd.cups-command", 28) &&
1244 _cups_isspace(filter
[28]))
1248 ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) == NULL
||
1249 strcasecmp(ppd_attr
->value
, "none")))
1252 * No command filter and no cupsCommands keyword telling us not to use one.
1253 * See if this is a PostScript printer, and if so add a PostScript command
1257 for (filter
= (const char *)cupsArrayFirst(pc
->filters
);
1259 filter
= (const char *)cupsArrayNext(pc
->filters
))
1260 if (!strncasecmp(filter
, "application/vnd.cups-postscript", 31) &&
1261 _cups_isspace(filter
[31]))
1265 cupsArrayAdd(pc
->filters
,
1266 "application/vnd.cups-command application/postscript 0 -");
1269 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
1271 pc
->prefilters
= cupsArrayNew3(NULL
, NULL
, NULL
, 0,
1272 (cups_acopy_func_t
)_cupsStrAlloc
,
1273 (cups_afree_func_t
)_cupsStrFree
);
1277 cupsArrayAdd(pc
->prefilters
, ppd_attr
->value
);
1279 while ((ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
);
1282 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsSingleFile", NULL
)) != NULL
)
1283 pc
->single_file
= !strcasecmp(ppd_attr
->value
, "true");
1286 * Copy the product string, if any...
1290 pc
->product
= _cupsStrAlloc(ppd
->product
);
1293 * Return the cache data...
1299 * If we get here we need to destroy the PWG mapping data and return NULL...
1304 _cupsSetError(IPP_INTERNAL_ERROR
, _("Out of memory."), 1);
1305 _ppdCacheDestroy(pc
);
1312 * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data.
1316 _ppdCacheDestroy(_ppd_cache_t
*pc
) /* I - PPD cache and mapping data */
1318 int i
; /* Looping var */
1319 _pwg_map_t
*map
; /* Current map */
1320 _pwg_size_t
*size
; /* Current size */
1324 * Range check input...
1331 * Free memory as needed...
1336 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
1338 _cupsStrFree(map
->pwg
);
1339 _cupsStrFree(map
->ppd
);
1347 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1349 _cupsStrFree(size
->map
.pwg
);
1350 _cupsStrFree(size
->map
.ppd
);
1356 if (pc
->source_option
)
1357 _cupsStrFree(pc
->source_option
);
1361 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
1363 _cupsStrFree(map
->pwg
);
1364 _cupsStrFree(map
->ppd
);
1372 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
1374 _cupsStrFree(map
->pwg
);
1375 _cupsStrFree(map
->ppd
);
1381 if (pc
->custom_max_keyword
)
1382 _cupsStrFree(pc
->custom_max_keyword
);
1384 if (pc
->custom_min_keyword
)
1385 _cupsStrFree(pc
->custom_min_keyword
);
1387 _cupsStrFree(pc
->product
);
1388 cupsArrayDelete(pc
->filters
);
1389 cupsArrayDelete(pc
->prefilters
);
1396 * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD
1400 const char * /* O - output-bin or NULL */
1402 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1403 const char *output_bin
) /* I - PPD OutputBin string */
1405 int i
; /* Looping var */
1409 * Range check input...
1412 if (!pc
|| !output_bin
)
1416 * Look up the OutputBin string...
1420 for (i
= 0; i
< pc
->num_bins
; i
++)
1421 if (!strcasecmp(output_bin
, pc
->bins
[i
].ppd
))
1422 return (pc
->bins
[i
].pwg
);
1429 * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job
1430 * attributes or a keyword string.
1433 const char * /* O - PPD InputSlot or NULL */
1434 _ppdCacheGetInputSlot(
1435 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1436 ipp_t
*job
, /* I - Job attributes or NULL */
1437 const char *keyword
) /* I - Keyword string or NULL */
1440 * Range check input...
1443 if (!pc
|| pc
->num_sources
== 0 || (!job
&& !keyword
))
1446 if (job
&& !keyword
)
1449 * Lookup the media-col attribute and any media-source found there...
1452 ipp_attribute_t
*media_col
, /* media-col attribute */
1453 *media_source
; /* media-source attribute */
1454 _pwg_size_t size
; /* Dimensional size */
1455 int margins_set
; /* Were the margins set? */
1457 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
1459 (media_source
= ippFindAttribute(media_col
->values
[0].collection
,
1461 IPP_TAG_KEYWORD
)) != NULL
)
1464 * Use the media-source value from media-col...
1467 keyword
= media_source
->values
[0].string
.text
;
1469 else if (_pwgInitSize(&size
, job
, &margins_set
))
1472 * For media <= 5x7, look for a photo tray...
1475 if (size
.width
<= (5 * 2540) && size
.length
<= (7 * 2540))
1482 int i
; /* Looping var */
1484 for (i
= 0; i
< pc
->num_sources
; i
++)
1485 if (!strcasecmp(keyword
, pc
->sources
[i
].pwg
))
1486 return (pc
->sources
[i
].ppd
);
1494 * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job
1495 * attributes or a keyword string.
1498 const char * /* O - PPD MediaType or NULL */
1499 _ppdCacheGetMediaType(
1500 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1501 ipp_t
*job
, /* I - Job attributes or NULL */
1502 const char *keyword
) /* I - Keyword string or NULL */
1505 * Range check input...
1508 if (!pc
|| pc
->num_types
== 0 || (!job
&& !keyword
))
1511 if (job
&& !keyword
)
1514 * Lookup the media-col attribute and any media-source found there...
1517 ipp_attribute_t
*media_col
, /* media-col attribute */
1518 *media_type
; /* media-type attribute */
1520 media_col
= ippFindAttribute(job
, "media-col", IPP_TAG_BEGIN_COLLECTION
);
1523 if ((media_type
= ippFindAttribute(media_col
->values
[0].collection
,
1525 IPP_TAG_KEYWORD
)) == NULL
)
1526 media_type
= ippFindAttribute(media_col
->values
[0].collection
,
1527 "media-type", IPP_TAG_NAME
);
1530 keyword
= media_type
->values
[0].string
.text
;
1536 int i
; /* Looping var */
1538 for (i
= 0; i
< pc
->num_types
; i
++)
1539 if (!strcasecmp(keyword
, pc
->types
[i
].pwg
))
1540 return (pc
->types
[i
].ppd
);
1548 * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword
1552 const char * /* O - PPD OutputBin or NULL */
1553 _ppdCacheGetOutputBin(
1554 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1555 const char *output_bin
) /* I - Keyword string */
1557 int i
; /* Looping var */
1561 * Range check input...
1564 if (!pc
|| !output_bin
)
1568 * Look up the OutputBin string...
1572 for (i
= 0; i
< pc
->num_bins
; i
++)
1573 if (!strcasecmp(output_bin
, pc
->bins
[i
].pwg
))
1574 return (pc
->bins
[i
].ppd
);
1581 * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job
1582 * attributes or a keyword string.
1585 const char * /* O - PPD PageSize or NULL */
1586 _ppdCacheGetPageSize(
1587 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1588 ipp_t
*job
, /* I - Job attributes or NULL */
1589 const char *keyword
, /* I - Keyword string or NULL */
1590 int *exact
) /* O - 1 if exact match, 0 otherwise */
1592 int i
; /* Looping var */
1593 _pwg_size_t
*size
, /* Current size */
1594 *closest
, /* Closest size */
1595 jobsize
; /* Size data from job */
1596 int margins_set
, /* Were the margins set? */
1597 dwidth
, /* Difference in width */
1598 dlength
, /* Difference in length */
1599 dleft
, /* Difference in left margins */
1600 dright
, /* Difference in right margins */
1601 dbottom
, /* Difference in bottom margins */
1602 dtop
, /* Difference in top margins */
1603 dmin
, /* Minimum difference */
1604 dclosest
; /* Closest difference */
1605 const char *ppd_name
; /* PPD media name */
1608 DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)",
1609 pc
, job
, keyword
, exact
));
1612 * Range check input...
1615 if (!pc
|| (!job
&& !keyword
))
1626 * Try getting the PPD media name from the job attributes...
1629 ipp_attribute_t
*attr
; /* Job attribute */
1631 if ((attr
= ippFindAttribute(job
, "PageSize", IPP_TAG_ZERO
)) == NULL
)
1632 if ((attr
= ippFindAttribute(job
, "PageRegion", IPP_TAG_ZERO
)) == NULL
)
1633 attr
= ippFindAttribute(job
, "media", IPP_TAG_ZERO
);
1637 DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)",
1638 attr
->name
, ippTagString(attr
->value_tag
)));
1640 DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute.");
1643 if (attr
&& (attr
->value_tag
== IPP_TAG_NAME
||
1644 attr
->value_tag
== IPP_TAG_KEYWORD
))
1645 ppd_name
= attr
->values
[0].string
.text
;
1648 DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name
));
1653 * Try looking up the named PPD size first...
1656 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1658 DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]",
1659 (int)(size
- pc
->sizes
), size
->map
.pwg
, size
->map
.ppd
));
1661 if (!strcasecmp(ppd_name
, size
->map
.ppd
) ||
1662 !strcasecmp(ppd_name
, size
->map
.pwg
))
1667 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name
));
1669 return (size
->map
.ppd
);
1674 if (job
&& !keyword
)
1677 * Get the size using media-col or media, with the preference being
1681 if (!_pwgInitSize(&jobsize
, job
, &margins_set
))
1687 * Get the size using a media keyword...
1690 _pwg_media_t
*media
; /* Media definition */
1693 if ((media
= _pwgMediaForPWG(keyword
)) == NULL
)
1694 if ((media
= _pwgMediaForLegacy(keyword
)) == NULL
)
1695 if ((media
= _pwgMediaForPPD(keyword
)) == NULL
)
1698 jobsize
.width
= media
->width
;
1699 jobsize
.length
= media
->length
;
1704 * Now that we have the dimensions and possibly the margins, look at the
1705 * available sizes and find the match...
1709 dclosest
= 999999999;
1711 if (!ppd_name
|| strncasecmp(ppd_name
, "Custom.", 7) ||
1712 strncasecmp(ppd_name
, "custom_", 7))
1714 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1717 * Adobe uses a size matching algorithm with an epsilon of 5 points, which
1718 * is just about 176/2540ths...
1721 dwidth
= size
->width
- jobsize
.width
;
1722 dlength
= size
->length
- jobsize
.length
;
1724 if (dwidth
<= -176 || dwidth
>= 176 || dlength
<= -176 || dlength
>= 176)
1730 * Use a tighter epsilon of 1 point (35/2540ths) for margins...
1733 dleft
= size
->left
- jobsize
.left
;
1734 dright
= size
->right
- jobsize
.right
;
1735 dtop
= size
->top
- jobsize
.top
;
1736 dbottom
= size
->bottom
- jobsize
.bottom
;
1738 if (dleft
<= -35 || dleft
>= 35 || dright
<= -35 || dright
>= 35 ||
1739 dtop
<= -35 || dtop
>= 35 || dbottom
<= -35 || dbottom
>= 35)
1741 dleft
= dleft
< 0 ? -dleft
: dleft
;
1742 dright
= dright
< 0 ? -dright
: dright
;
1743 dbottom
= dbottom
< 0 ? -dbottom
: dbottom
;
1744 dtop
= dtop
< 0 ? -dtop
: dtop
;
1745 dmin
= dleft
+ dright
+ dbottom
+ dtop
;
1747 if (dmin
< dclosest
)
1760 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size
->map
.ppd
));
1762 return (size
->map
.ppd
);
1768 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)",
1771 return (closest
->map
.ppd
);
1775 * If we get here we need to check for custom page size support...
1778 if (jobsize
.width
>= pc
->custom_min_width
&&
1779 jobsize
.width
<= pc
->custom_max_width
&&
1780 jobsize
.length
>= pc
->custom_min_length
&&
1781 jobsize
.length
<= pc
->custom_max_length
)
1784 * In range, format as Custom.WWWWxLLLL (points).
1787 snprintf(pc
->custom_ppd_size
, sizeof(pc
->custom_ppd_size
), "Custom.%dx%d",
1788 (int)_PWG_TOPTS(jobsize
.width
), (int)_PWG_TOPTS(jobsize
.length
));
1790 if (margins_set
&& exact
)
1792 dleft
= pc
->custom_size
.left
- jobsize
.left
;
1793 dright
= pc
->custom_size
.right
- jobsize
.right
;
1794 dtop
= pc
->custom_size
.top
- jobsize
.top
;
1795 dbottom
= pc
->custom_size
.bottom
- jobsize
.bottom
;
1797 if (dleft
> -35 && dleft
< 35 && dright
> -35 && dright
< 35 &&
1798 dtop
> -35 && dtop
< 35 && dbottom
> -35 && dbottom
< 35)
1804 DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)",
1805 pc
->custom_ppd_size
));
1807 return (pc
->custom_ppd_size
);
1811 * No custom page size support or the size is out of range - return NULL.
1814 DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL");
1821 * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
1824 _pwg_size_t
* /* O - PWG size or NULL */
1826 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1827 const char *page_size
) /* I - PPD PageSize */
1830 _pwg_size_t
*size
; /* Current size */
1834 * Range check input...
1837 if (!pc
|| !page_size
)
1840 if (!strncasecmp(page_size
, "Custom.", 7))
1843 * Custom size; size name can be one of the following:
1845 * Custom.WIDTHxLENGTHin - Size in inches
1846 * Custom.WIDTHxLENGTHft - Size in feet
1847 * Custom.WIDTHxLENGTHcm - Size in centimeters
1848 * Custom.WIDTHxLENGTHmm - Size in millimeters
1849 * Custom.WIDTHxLENGTHm - Size in meters
1850 * Custom.WIDTHxLENGTH[pt] - Size in points
1853 double w
, l
; /* Width and length of page */
1854 char *ptr
; /* Pointer into PageSize */
1855 struct lconv
*loc
; /* Locale data */
1858 w
= (float)_cupsStrScand(page_size
+ 7, &ptr
, loc
);
1859 if (!ptr
|| *ptr
!= 'x')
1862 l
= (float)_cupsStrScand(ptr
+ 1, &ptr
, loc
);
1866 if (!strcasecmp(ptr
, "in"))
1871 else if (!strcasecmp(ptr
, "ft"))
1876 else if (!strcasecmp(ptr
, "mm"))
1881 else if (!strcasecmp(ptr
, "cm"))
1886 else if (!strcasecmp(ptr
, "m"))
1897 pc
->custom_size
.width
= (int)w
;
1898 pc
->custom_size
.length
= (int)l
;
1900 return (&(pc
->custom_size
));
1904 * Not a custom size - look it up...
1907 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
1908 if (!strcasecmp(page_size
, size
->map
.ppd
))
1916 * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD
1920 const char * /* O - PWG media-source keyword */
1922 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1923 const char *input_slot
) /* I - PPD InputSlot */
1925 int i
; /* Looping var */
1926 _pwg_map_t
*source
; /* Current source */
1930 * Range check input...
1933 if (!pc
|| !input_slot
)
1936 for (i
= pc
->num_sources
, source
= pc
->sources
; i
> 0; i
--, source
++)
1937 if (!strcasecmp(input_slot
, source
->ppd
))
1938 return (source
->pwg
);
1945 * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD
1949 const char * /* O - PWG media-type keyword */
1951 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1952 const char *media_type
) /* I - PPD MediaType */
1954 int i
; /* Looping var */
1955 _pwg_map_t
*type
; /* Current type */
1959 * Range check input...
1962 if (!pc
|| !media_type
)
1965 for (i
= pc
->num_types
, type
= pc
->types
; i
> 0; i
--, type
++)
1966 if (!strcasecmp(media_type
, type
->ppd
))
1974 * '_ppdCacheWriteFile()' - Write PWG mapping data to a file.
1977 int /* O - 1 on success, 0 on failure */
1979 _ppd_cache_t
*pc
, /* I - PPD cache and mapping data */
1980 const char *filename
, /* I - File to write */
1981 ipp_t
*attrs
) /* I - Attributes to write, if any */
1983 int i
, j
, k
; /* Looping vars */
1984 cups_file_t
*fp
; /* Output file */
1985 _pwg_size_t
*size
; /* Current size */
1986 _pwg_map_t
*map
; /* Current map */
1987 cups_option_t
*option
; /* Current option */
1988 const char *value
; /* Filter/pre-filter value */
1992 * Range check input...
1995 if (!pc
|| !filename
)
1997 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
2002 * Open the file and write with compression...
2005 if ((fp
= cupsFileOpen(filename
, "w9")) == NULL
)
2007 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
), 0);
2012 * Standard header...
2015 cupsFilePrintf(fp
, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION
);
2021 if (pc
->num_bins
> 0)
2023 cupsFilePrintf(fp
, "NumBins %d\n", pc
->num_bins
);
2024 for (i
= pc
->num_bins
, map
= pc
->bins
; i
> 0; i
--, map
++)
2025 cupsFilePrintf(fp
, "Bin %s %s\n", map
->pwg
, map
->ppd
);
2032 cupsFilePrintf(fp
, "NumSizes %d\n", pc
->num_sizes
);
2033 for (i
= pc
->num_sizes
, size
= pc
->sizes
; i
> 0; i
--, size
++)
2034 cupsFilePrintf(fp
, "Size %s %s %d %d %d %d %d %d\n", size
->map
.pwg
,
2035 size
->map
.ppd
, size
->width
, size
->length
, size
->left
,
2036 size
->bottom
, size
->right
, size
->top
);
2037 if (pc
->custom_max_width
> 0)
2038 cupsFilePrintf(fp
, "CustomSize %d %d %d %d %d %d %d %d\n",
2039 pc
->custom_max_width
, pc
->custom_max_length
,
2040 pc
->custom_min_width
, pc
->custom_min_length
,
2041 pc
->custom_size
.left
, pc
->custom_size
.bottom
,
2042 pc
->custom_size
.right
, pc
->custom_size
.top
);
2048 if (pc
->source_option
)
2049 cupsFilePrintf(fp
, "SourceOption %s\n", pc
->source_option
);
2051 if (pc
->num_sources
> 0)
2053 cupsFilePrintf(fp
, "NumSources %d\n", pc
->num_sources
);
2054 for (i
= pc
->num_sources
, map
= pc
->sources
; i
> 0; i
--, map
++)
2055 cupsFilePrintf(fp
, "Source %s %s\n", map
->pwg
, map
->ppd
);
2062 if (pc
->num_types
> 0)
2064 cupsFilePrintf(fp
, "NumTypes %d\n", pc
->num_types
);
2065 for (i
= pc
->num_types
, map
= pc
->types
; i
> 0; i
--, map
++)
2066 cupsFilePrintf(fp
, "Type %s %s\n", map
->pwg
, map
->ppd
);
2073 for (i
= _PWG_PRINT_COLOR_MODE_MONOCHROME
; i
< _PWG_PRINT_COLOR_MODE_MAX
; i
++)
2074 for (j
= _PWG_PRINT_QUALITY_DRAFT
; j
< _PWG_PRINT_QUALITY_MAX
; j
++)
2075 if (pc
->num_presets
[i
][j
])
2077 cupsFilePrintf(fp
, "Preset %d %d", i
, j
);
2078 for (k
= pc
->num_presets
[i
][j
], option
= pc
->presets
[i
][j
];
2081 cupsFilePrintf(fp
, " %s=%s", option
->name
, option
->value
);
2082 cupsFilePutChar(fp
, '\n');
2089 if (pc
->sides_option
)
2090 cupsFilePrintf(fp
, "SidesOption %s\n", pc
->sides_option
);
2092 if (pc
->sides_1sided
)
2093 cupsFilePrintf(fp
, "Sides1Sided %s\n", pc
->sides_1sided
);
2095 if (pc
->sides_2sided_long
)
2096 cupsFilePrintf(fp
, "Sides2SidedLong %s\n", pc
->sides_2sided_long
);
2098 if (pc
->sides_2sided_short
)
2099 cupsFilePrintf(fp
, "Sides2SidedShort %s\n", pc
->sides_2sided_short
);
2102 * Product, cupsFilter, cupsFilter2, and cupsPreFilter...
2106 cupsFilePutConf(fp
, "Product", pc
->product
);
2108 for (value
= (const char *)cupsArrayFirst(pc
->filters
);
2110 value
= (const char *)cupsArrayNext(pc
->filters
))
2111 cupsFilePutConf(fp
, "Filter", value
);
2113 for (value
= (const char *)cupsArrayFirst(pc
->prefilters
);
2115 value
= (const char *)cupsArrayNext(pc
->prefilters
))
2116 cupsFilePutConf(fp
, "PreFilter", value
);
2118 cupsFilePrintf(fp
, "SingleFile %s\n", pc
->single_file
? "true" : "false");
2121 * IPP attributes, if any...
2126 cupsFilePrintf(fp
, "IPP " CUPS_LLFMT
"\n", CUPS_LLCAST
ippLength(attrs
));
2128 attrs
->state
= IPP_IDLE
;
2129 ippWriteIO(fp
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
, attrs
);
2133 * Close and return...
2136 return (!cupsFileClose(fp
));
2141 * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG
2145 const char * /* O - InputSlot name */
2146 _pwgInputSlotForSource(
2147 const char *media_source
, /* I - PWG media-source */
2148 char *name
, /* I - Name buffer */
2149 size_t namesize
) /* I - Size of name buffer */
2152 * Range check input...
2155 if (!media_source
|| !name
|| namesize
< PPD_MAX_NAME
)
2158 if (strcasecmp(media_source
, "main"))
2159 strlcpy(name
, "Cassette", namesize
);
2160 else if (strcasecmp(media_source
, "alternate"))
2161 strlcpy(name
, "Multipurpose", namesize
);
2162 else if (strcasecmp(media_source
, "large-capacity"))
2163 strlcpy(name
, "LargeCapacity", namesize
);
2164 else if (strcasecmp(media_source
, "bottom"))
2165 strlcpy(name
, "Lower", namesize
);
2166 else if (strcasecmp(media_source
, "middle"))
2167 strlcpy(name
, "Middle", namesize
);
2168 else if (strcasecmp(media_source
, "top"))
2169 strlcpy(name
, "Upper", namesize
);
2170 else if (strcasecmp(media_source
, "rear"))
2171 strlcpy(name
, "Rear", namesize
);
2172 else if (strcasecmp(media_source
, "side"))
2173 strlcpy(name
, "Side", namesize
);
2174 else if (strcasecmp(media_source
, "envelope"))
2175 strlcpy(name
, "Envelope", namesize
);
2176 else if (strcasecmp(media_source
, "main-roll"))
2177 strlcpy(name
, "Roll", namesize
);
2178 else if (strcasecmp(media_source
, "alternate-roll"))
2179 strlcpy(name
, "Roll2", namesize
);
2181 pwg_ppdize_name(media_source
, name
, namesize
);
2188 * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
2192 const char * /* O - MediaType name */
2193 _pwgMediaTypeForType(
2194 const char *media_type
, /* I - PWG media-type */
2195 char *name
, /* I - Name buffer */
2196 size_t namesize
) /* I - Size of name buffer */
2199 * Range check input...
2202 if (!media_type
|| !name
|| namesize
< PPD_MAX_NAME
)
2205 if (strcasecmp(media_type
, "auto"))
2206 strlcpy(name
, "Auto", namesize
);
2207 else if (strcasecmp(media_type
, "cardstock"))
2208 strlcpy(name
, "Cardstock", namesize
);
2209 else if (strcasecmp(media_type
, "envelope"))
2210 strlcpy(name
, "Envelope", namesize
);
2211 else if (strcasecmp(media_type
, "photographic-glossy"))
2212 strlcpy(name
, "Glossy", namesize
);
2213 else if (strcasecmp(media_type
, "photographic-high-gloss"))
2214 strlcpy(name
, "HighGloss", namesize
);
2215 else if (strcasecmp(media_type
, "photographic-matte"))
2216 strlcpy(name
, "Matte", namesize
);
2217 else if (strcasecmp(media_type
, "stationery"))
2218 strlcpy(name
, "Plain", namesize
);
2219 else if (strcasecmp(media_type
, "stationery-coated"))
2220 strlcpy(name
, "Coated", namesize
);
2221 else if (strcasecmp(media_type
, "stationery-inkjet"))
2222 strlcpy(name
, "Inkjet", namesize
);
2223 else if (strcasecmp(media_type
, "stationery-letterhead"))
2224 strlcpy(name
, "Letterhead", namesize
);
2225 else if (strcasecmp(media_type
, "stationery-preprinted"))
2226 strlcpy(name
, "Preprinted", namesize
);
2227 else if (strcasecmp(media_type
, "transparency"))
2228 strlcpy(name
, "Transparency", namesize
);
2230 pwg_ppdize_name(media_type
, name
, namesize
);
2237 * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media.
2240 const char * /* O - PageSize name */
2241 _pwgPageSizeForMedia(
2242 _pwg_media_t
*media
, /* I - Media */
2243 char *name
, /* I - PageSize name buffer */
2244 size_t namesize
) /* I - Size of name buffer */
2246 const char *sizeptr
, /* Pointer to size in PWG name */
2247 *dimptr
; /* Pointer to dimensions in PWG name */
2251 * Range check input...
2254 if (!media
|| !name
|| namesize
< PPD_MAX_NAME
)
2258 * Copy or generate a PageSize name...
2264 * Use a standard Adobe name...
2267 strlcpy(name
, media
->ppd
, namesize
);
2269 else if (!media
->pwg
|| !strncmp(media
->pwg
, "custom_", 7) ||
2270 (sizeptr
= strchr(media
->pwg
, '_')) == NULL
||
2271 (dimptr
= strchr(sizeptr
+ 1, '_')) == NULL
||
2272 (size_t)(dimptr
- sizeptr
) > namesize
)
2275 * Use a name of the form "wNNNhNNN"...
2278 snprintf(name
, namesize
, "w%dh%d", (int)_PWG_TOPTS(media
->width
),
2279 (int)_PWG_TOPTS(media
->length
));
2284 * Copy the size name from class_sizename_dimensions...
2287 memcpy(name
, sizeptr
+ 1, dimptr
- sizeptr
- 1);
2288 name
[dimptr
- sizeptr
- 1] = '\0';
2296 * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword.
2300 pwg_ppdize_name(const char *ipp
, /* I - IPP keyword */
2301 char *name
, /* I - Name buffer */
2302 size_t namesize
) /* I - Size of name buffer */
2304 char *ptr
, /* Pointer into name buffer */
2305 *end
; /* End of name buffer */
2308 *name
= toupper(*ipp
++);
2310 for (ptr
= name
+ 1, end
= name
+ namesize
- 1; *ipp
&& ptr
< end
;)
2312 if (*ipp
== '-' && _cups_isalpha(ipp
[1]))
2315 *ptr
++ = toupper(*ipp
++ & 255);
2326 * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword.
2330 pwg_unppdize_name(const char *ppd
, /* I - PPD keyword */
2331 char *name
, /* I - Name buffer */
2332 size_t namesize
) /* I - Size of name buffer */
2334 char *ptr
, /* Pointer into name buffer */
2335 *end
; /* End of name buffer */
2338 for (ptr
= name
, end
= name
+ namesize
- 1; *ppd
&& ptr
< end
; ppd
++)
2340 if (_cups_isalnum(*ppd
) || *ppd
== '-')
2341 *ptr
++ = tolower(*ppd
& 255);
2342 else if (*ppd
== '_' || *ppd
== '.')
2345 if (!_cups_isupper(*ppd
) && _cups_isalnum(*ppd
) &&
2346 _cups_isupper(ppd
[1]) && ptr
< end
)