]>
Commit | Line | Data |
---|---|---|
f14324a7 | 1 | /* |
7e86f2f6 | 2 | * PPD cache implementation for CUPS. |
f14324a7 | 3 | * |
e6062e8e | 4 | * Copyright © 2010-2018 by Apple Inc. |
f14324a7 | 5 | * |
e6062e8e MS |
6 | * Licensed under Apache License v2.0. See the file "LICENSE" for more |
7 | * information. | |
f14324a7 MS |
8 | */ |
9 | ||
10 | /* | |
11 | * Include necessary headers... | |
12 | */ | |
13 | ||
14 | #include "cups-private.h" | |
f787e1e3 | 15 | #include "ppd-private.h" |
fb863569 | 16 | #include "debug-internal.h" |
f14324a7 MS |
17 | #include <math.h> |
18 | ||
19 | ||
20 | /* | |
21 | * Macro to test for two almost-equal PWG measurements. | |
22 | */ | |
23 | ||
24 | #define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2) | |
25 | ||
26 | ||
27 | /* | |
28 | * Local functions... | |
29 | */ | |
30 | ||
89550f3f | 31 | static int cups_get_url(http_t **http, const char *url, char *name, size_t namesize); |
1fbd0cab | 32 | static void pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value); |
2fa1ba3c | 33 | static void pwg_add_message(cups_array_t *a, const char *msg, const char *str); |
982be458 MS |
34 | static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b); |
35 | static int pwg_compare_sizes(cups_size_t *a, cups_size_t *b); | |
36 | static cups_size_t *pwg_copy_size(cups_size_t *size); | |
dcb445bc | 37 | static void pwg_free_finishings(_pwg_finishings_t *f); |
f14324a7 | 38 | static void pwg_ppdize_name(const char *ipp, char *name, size_t namesize); |
d9fc71e4 | 39 | static void pwg_ppdize_resolution(ipp_attribute_t *attr, int element, int *xres, int *yres, char *name, size_t namesize); |
c1420c87 MS |
40 | static void pwg_unppdize_name(const char *ppd, char *name, size_t namesize, |
41 | const char *dashchars); | |
f14324a7 MS |
42 | |
43 | ||
f099325e MS |
44 | /* |
45 | * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes. | |
46 | * | |
47 | * This functions converts PPD and CUPS-specific options to their standard IPP | |
48 | * attributes and values and adds them to the specified IPP request. | |
49 | */ | |
50 | ||
a740a849 MS |
51 | int /* O - New number of copies */ |
52 | _cupsConvertOptions( | |
53 | ipp_t *request, /* I - IPP request */ | |
54 | ppd_file_t *ppd, /* I - PPD file */ | |
55 | _ppd_cache_t *pc, /* I - PPD cache info */ | |
56 | ipp_attribute_t *media_col_sup, /* I - media-col-supported values */ | |
57 | ipp_attribute_t *doc_handling_sup, /* I - multiple-document-handling-supported values */ | |
58 | ipp_attribute_t *print_color_mode_sup, | |
59 | /* I - Printer supports print-color-mode */ | |
60 | const char *user, /* I - User info */ | |
61 | const char *format, /* I - document-format value */ | |
62 | int copies, /* I - Number of copies */ | |
63 | int num_options, /* I - Number of options */ | |
64 | cups_option_t *options) /* I - Options */ | |
f099325e MS |
65 | { |
66 | int i; /* Looping var */ | |
5ae9fbb3 MS |
67 | const char *keyword, /* PWG keyword */ |
68 | *password; /* Password string */ | |
f099325e MS |
69 | pwg_size_t *size; /* PWG media size */ |
70 | ipp_t *media_col, /* media-col value */ | |
71 | *media_size; /* media-size value */ | |
72 | const char *media_source, /* media-source value */ | |
73 | *media_type, /* media-type value */ | |
74 | *collate_str, /* multiple-document-handling value */ | |
75 | *color_attr_name, /* Supported color attribute */ | |
4f63d6cd MS |
76 | *mandatory, /* Mandatory attributes */ |
77 | *finishing_template; /* Finishing template */ | |
f099325e MS |
78 | int num_finishings = 0, /* Number of finishing values */ |
79 | finishings[10]; /* Finishing enum values */ | |
80 | ppd_choice_t *choice; /* Marked choice */ | |
49f495c3 MS |
81 | int finishings_copies = copies; |
82 | /* Number of copies for finishings */ | |
f099325e MS |
83 | |
84 | ||
85 | /* | |
86 | * Send standard IPP attributes... | |
87 | */ | |
88 | ||
5ae9fbb3 | 89 | if (pc->password && (password = cupsGetOption("job-password", num_options, options)) != NULL && ippGetOperation(request) != IPP_OP_VALIDATE_JOB) |
f099325e | 90 | { |
5ae9fbb3 | 91 | ipp_attribute_t *attr = NULL; /* job-password attribute */ |
f099325e MS |
92 | |
93 | if ((keyword = cupsGetOption("job-password-encryption", num_options, options)) == NULL) | |
94 | keyword = "none"; | |
95 | ||
5ae9fbb3 MS |
96 | if (!strcmp(keyword, "none")) |
97 | { | |
98 | /* | |
99 | * Add plain-text job-password... | |
100 | */ | |
101 | ||
102 | attr = ippAddOctetString(request, IPP_TAG_OPERATION, "job-password", password, (int)strlen(password)); | |
103 | } | |
104 | else | |
105 | { | |
106 | /* | |
107 | * Add hashed job-password... | |
108 | */ | |
109 | ||
110 | unsigned char hash[64]; /* Hash of password */ | |
111 | ssize_t hashlen; /* Length of hash */ | |
112 | ||
113 | if ((hashlen = cupsHashData(keyword, password, strlen(password), hash, sizeof(hash))) > 0) | |
114 | attr = ippAddOctetString(request, IPP_TAG_OPERATION, "job-password", hash, (int)hashlen); | |
115 | } | |
116 | ||
117 | if (attr) | |
118 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "job-password-encryption", NULL, keyword); | |
f099325e MS |
119 | } |
120 | ||
121 | if (pc->account_id) | |
122 | { | |
123 | if ((keyword = cupsGetOption("job-account-id", num_options, options)) == NULL) | |
124 | keyword = cupsGetOption("job-billing", num_options, options); | |
125 | ||
126 | if (keyword) | |
127 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_NAME, "job-account-id", NULL, keyword); | |
128 | } | |
129 | ||
130 | if (pc->accounting_user_id) | |
131 | { | |
132 | if ((keyword = cupsGetOption("job-accounting-user-id", num_options, options)) == NULL) | |
133 | keyword = user; | |
134 | ||
135 | if (keyword) | |
136 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_NAME, "job-accounting-user-id", NULL, keyword); | |
137 | } | |
138 | ||
139 | for (mandatory = (const char *)cupsArrayFirst(pc->mandatory); mandatory; mandatory = (const char *)cupsArrayNext(pc->mandatory)) | |
140 | { | |
141 | if (strcmp(mandatory, "copies") && | |
142 | strcmp(mandatory, "destination-uris") && | |
143 | strcmp(mandatory, "finishings") && | |
4f63d6cd MS |
144 | strcmp(mandatory, "finishings-col") && |
145 | strcmp(mandatory, "finishing-template") && | |
f099325e MS |
146 | strcmp(mandatory, "job-account-id") && |
147 | strcmp(mandatory, "job-accounting-user-id") && | |
148 | strcmp(mandatory, "job-password") && | |
149 | strcmp(mandatory, "job-password-encryption") && | |
150 | strcmp(mandatory, "media") && | |
151 | strncmp(mandatory, "media-col", 9) && | |
152 | strcmp(mandatory, "multiple-document-handling") && | |
153 | strcmp(mandatory, "output-bin") && | |
154 | strcmp(mandatory, "print-color-mode") && | |
155 | strcmp(mandatory, "print-quality") && | |
156 | strcmp(mandatory, "sides") && | |
157 | (keyword = cupsGetOption(mandatory, num_options, options)) != NULL) | |
158 | { | |
159 | _ipp_option_t *opt = _ippFindOption(mandatory); | |
160 | /* Option type */ | |
161 | ipp_tag_t value_tag = opt ? opt->value_tag : IPP_TAG_NAME; | |
162 | /* Value type */ | |
163 | ||
164 | switch (value_tag) | |
165 | { | |
166 | case IPP_TAG_INTEGER : | |
167 | case IPP_TAG_ENUM : | |
168 | ippAddInteger(request, IPP_TAG_JOB, value_tag, mandatory, atoi(keyword)); | |
169 | break; | |
170 | case IPP_TAG_BOOLEAN : | |
171 | ippAddBoolean(request, IPP_TAG_JOB, mandatory, !_cups_strcasecmp(keyword, "true")); | |
172 | break; | |
173 | case IPP_TAG_RANGE : | |
174 | { | |
175 | int lower, upper; /* Range */ | |
176 | ||
177 | if (sscanf(keyword, "%d-%d", &lower, &upper) != 2) | |
178 | lower = upper = atoi(keyword); | |
179 | ||
180 | ippAddRange(request, IPP_TAG_JOB, mandatory, lower, upper); | |
181 | } | |
182 | break; | |
183 | case IPP_TAG_STRING : | |
184 | ippAddOctetString(request, IPP_TAG_JOB, mandatory, keyword, (int)strlen(keyword)); | |
185 | break; | |
186 | default : | |
187 | if (!strcmp(mandatory, "print-color-mode") && !strcmp(keyword, "monochrome")) | |
188 | { | |
189 | if (ippContainsString(print_color_mode_sup, "auto-monochrome")) | |
190 | keyword = "auto-monochrome"; | |
191 | else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome")) | |
192 | keyword = "process-monochrome"; | |
193 | } | |
194 | ||
195 | ippAddString(request, IPP_TAG_JOB, value_tag, mandatory, NULL, keyword); | |
196 | break; | |
197 | } | |
198 | } | |
199 | } | |
200 | ||
201 | if ((keyword = cupsGetOption("PageSize", num_options, options)) == NULL) | |
202 | keyword = cupsGetOption("media", num_options, options); | |
203 | ||
40c80860 MS |
204 | media_source = _ppdCacheGetSource(pc, cupsGetOption("InputSlot", num_options, options)); |
205 | media_type = _ppdCacheGetType(pc, cupsGetOption("MediaType", num_options, options)); | |
206 | size = _ppdCacheGetSize(pc, keyword); | |
207 | ||
208 | if (size || media_source || media_type) | |
f099325e MS |
209 | { |
210 | /* | |
211 | * Add a media-col value... | |
212 | */ | |
213 | ||
f099325e | 214 | media_col = ippNew(); |
f099325e | 215 | |
40c80860 MS |
216 | if (size) |
217 | { | |
218 | media_size = ippNew(); | |
219 | ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER, | |
220 | "x-dimension", size->width); | |
221 | ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER, | |
222 | "y-dimension", size->length); | |
223 | ||
224 | ippAddCollection(media_col, IPP_TAG_ZERO, "media-size", media_size); | |
225 | } | |
f099325e MS |
226 | |
227 | for (i = 0; i < media_col_sup->num_values; i ++) | |
228 | { | |
40c80860 | 229 | if (size && !strcmp(media_col_sup->values[i].string.text, "media-left-margin")) |
f099325e | 230 | ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-left-margin", size->left); |
40c80860 | 231 | else if (size && !strcmp(media_col_sup->values[i].string.text, "media-bottom-margin")) |
f099325e | 232 | ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-bottom-margin", size->bottom); |
40c80860 | 233 | else if (size && !strcmp(media_col_sup->values[i].string.text, "media-right-margin")) |
f099325e | 234 | ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-right-margin", size->right); |
40c80860 | 235 | else if (size && !strcmp(media_col_sup->values[i].string.text, "media-top-margin")) |
f099325e | 236 | ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-top-margin", size->top); |
40c80860 | 237 | else if (media_source && !strcmp(media_col_sup->values[i].string.text, "media-source")) |
f099325e | 238 | ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD, "media-source", NULL, media_source); |
40c80860 | 239 | else if (media_type && !strcmp(media_col_sup->values[i].string.text, "media-type")) |
f099325e MS |
240 | ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD, "media-type", NULL, media_type); |
241 | } | |
242 | ||
243 | ippAddCollection(request, IPP_TAG_JOB, "media-col", media_col); | |
244 | } | |
245 | ||
246 | if ((keyword = cupsGetOption("output-bin", num_options, options)) == NULL) | |
247 | { | |
248 | if ((choice = ppdFindMarkedChoice(ppd, "OutputBin")) != NULL) | |
249 | keyword = _ppdCacheGetBin(pc, choice->choice); | |
250 | } | |
251 | ||
252 | if (keyword) | |
253 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-bin", NULL, keyword); | |
254 | ||
255 | color_attr_name = print_color_mode_sup ? "print-color-mode" : "output-mode"; | |
256 | ||
257 | if ((keyword = cupsGetOption("print-color-mode", num_options, options)) == NULL) | |
258 | { | |
259 | if ((choice = ppdFindMarkedChoice(ppd, "ColorModel")) != NULL) | |
260 | { | |
261 | if (!_cups_strcasecmp(choice->choice, "Gray")) | |
262 | keyword = "monochrome"; | |
263 | else | |
264 | keyword = "color"; | |
265 | } | |
266 | } | |
267 | ||
268 | if (keyword && !strcmp(keyword, "monochrome")) | |
269 | { | |
270 | if (ippContainsString(print_color_mode_sup, "auto-monochrome")) | |
271 | keyword = "auto-monochrome"; | |
272 | else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome")) | |
273 | keyword = "process-monochrome"; | |
274 | } | |
275 | ||
276 | if (keyword) | |
277 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, color_attr_name, NULL, keyword); | |
278 | ||
279 | if ((keyword = cupsGetOption("print-quality", num_options, options)) != NULL) | |
280 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", atoi(keyword)); | |
281 | else if ((choice = ppdFindMarkedChoice(ppd, "cupsPrintQuality")) != NULL) | |
282 | { | |
283 | if (!_cups_strcasecmp(choice->choice, "draft")) | |
284 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_DRAFT); | |
285 | else if (!_cups_strcasecmp(choice->choice, "normal")) | |
286 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_NORMAL); | |
287 | else if (!_cups_strcasecmp(choice->choice, "high")) | |
288 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_HIGH); | |
289 | } | |
290 | ||
291 | if ((keyword = cupsGetOption("sides", num_options, options)) != NULL) | |
292 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, keyword); | |
293 | else if (pc->sides_option && (choice = ppdFindMarkedChoice(ppd, pc->sides_option)) != NULL) | |
294 | { | |
295 | if (!_cups_strcasecmp(choice->choice, pc->sides_1sided)) | |
296 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "one-sided"); | |
297 | else if (!_cups_strcasecmp(choice->choice, pc->sides_2sided_long)) | |
298 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "two-sided-long-edge"); | |
299 | if (!_cups_strcasecmp(choice->choice, pc->sides_2sided_short)) | |
300 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "two-sided-short-edge"); | |
301 | } | |
302 | ||
303 | /* | |
304 | * Copies... | |
305 | */ | |
306 | ||
307 | if ((keyword = cupsGetOption("multiple-document-handling", num_options, options)) != NULL) | |
308 | { | |
309 | if (strstr(keyword, "uncollated")) | |
310 | keyword = "false"; | |
311 | else | |
312 | keyword = "true"; | |
313 | } | |
314 | else if ((keyword = cupsGetOption("collate", num_options, options)) == NULL) | |
315 | keyword = "true"; | |
316 | ||
317 | if (format) | |
318 | { | |
319 | if (!_cups_strcasecmp(format, "image/gif") || | |
320 | !_cups_strcasecmp(format, "image/jp2") || | |
321 | !_cups_strcasecmp(format, "image/jpeg") || | |
322 | !_cups_strcasecmp(format, "image/png") || | |
323 | !_cups_strcasecmp(format, "image/tiff") || | |
324 | !_cups_strncasecmp(format, "image/x-", 8)) | |
325 | { | |
326 | /* | |
327 | * Collation makes no sense for single page image formats... | |
328 | */ | |
329 | ||
330 | keyword = "false"; | |
331 | } | |
332 | else if (!_cups_strncasecmp(format, "image/", 6) || | |
333 | !_cups_strcasecmp(format, "application/vnd.cups-raster")) | |
334 | { | |
335 | /* | |
336 | * Multi-page image formats will have copies applied by the upstream | |
337 | * filters... | |
338 | */ | |
339 | ||
340 | copies = 1; | |
341 | } | |
342 | } | |
343 | ||
344 | if (doc_handling_sup) | |
345 | { | |
346 | if (!_cups_strcasecmp(keyword, "true")) | |
347 | collate_str = "separate-documents-collated-copies"; | |
348 | else | |
349 | collate_str = "separate-documents-uncollated-copies"; | |
350 | ||
351 | for (i = 0; i < doc_handling_sup->num_values; i ++) | |
352 | { | |
353 | if (!strcmp(doc_handling_sup->values[i].string.text, collate_str)) | |
354 | { | |
355 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "multiple-document-handling", NULL, collate_str); | |
356 | break; | |
357 | } | |
358 | } | |
359 | ||
360 | if (i >= doc_handling_sup->num_values) | |
361 | copies = 1; | |
362 | } | |
363 | ||
364 | /* | |
365 | * Map finishing options... | |
366 | */ | |
367 | ||
4f63d6cd MS |
368 | if ((finishing_template = cupsGetOption("cupsFinishingTemplate", num_options, options)) == NULL) |
369 | finishing_template = cupsGetOption("finishing-template", num_options, options); | |
370 | ||
d128cfc6 | 371 | if (finishing_template && strcmp(finishing_template, "none")) |
f099325e | 372 | { |
4f63d6cd MS |
373 | ipp_t *fin_col = ippNew(); /* finishings-col value */ |
374 | ||
375 | ippAddString(fin_col, IPP_TAG_JOB, IPP_TAG_KEYWORD, "finishing-template", NULL, finishing_template); | |
376 | ippAddCollection(request, IPP_TAG_JOB, "finishings-col", fin_col); | |
377 | ippDelete(fin_col); | |
f099325e | 378 | |
49f495c3 | 379 | if (copies != finishings_copies && (keyword = cupsGetOption("job-impressions", num_options, options)) != NULL) |
f099325e MS |
380 | { |
381 | /* | |
382 | * Send job-pages-per-set attribute to apply finishings correctly... | |
383 | */ | |
384 | ||
49f495c3 | 385 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-pages-per-set", atoi(keyword) / finishings_copies); |
f099325e MS |
386 | } |
387 | } | |
4f63d6cd MS |
388 | else |
389 | { | |
117bf0d1 | 390 | num_finishings = _ppdCacheGetFinishingValues(ppd, pc, (int)(sizeof(finishings) / sizeof(finishings[0])), finishings); |
4f63d6cd MS |
391 | if (num_finishings > 0) |
392 | { | |
393 | ippAddIntegers(request, IPP_TAG_JOB, IPP_TAG_ENUM, "finishings", num_finishings, finishings); | |
394 | ||
395 | if (copies != finishings_copies && (keyword = cupsGetOption("job-impressions", num_options, options)) != NULL) | |
396 | { | |
397 | /* | |
398 | * Send job-pages-per-set attribute to apply finishings correctly... | |
399 | */ | |
400 | ||
401 | ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-pages-per-set", atoi(keyword) / finishings_copies); | |
402 | } | |
403 | } | |
404 | } | |
f099325e MS |
405 | |
406 | return (copies); | |
407 | } | |
408 | ||
409 | ||
f14324a7 MS |
410 | /* |
411 | * '_ppdCacheCreateWithFile()' - Create PPD cache and mapping data from a | |
412 | * written file. | |
413 | * | |
414 | * Use the @link _ppdCacheWriteFile@ function to write PWG mapping data to a | |
415 | * file. | |
416 | */ | |
417 | ||
418 | _ppd_cache_t * /* O - PPD cache and mapping data */ | |
419 | _ppdCacheCreateWithFile( | |
420 | const char *filename, /* I - File to read */ | |
421 | ipp_t **attrs) /* IO - IPP attributes, if any */ | |
422 | { | |
423 | cups_file_t *fp; /* File */ | |
424 | _ppd_cache_t *pc; /* PWG mapping data */ | |
6961465f MS |
425 | pwg_size_t *size; /* Current size */ |
426 | pwg_map_t *map; /* Current map */ | |
dcb445bc | 427 | _pwg_finishings_t *finishings; /* Current finishings option */ |
f14324a7 MS |
428 | int linenum, /* Current line number */ |
429 | num_bins, /* Number of bins in file */ | |
430 | num_sizes, /* Number of sizes in file */ | |
431 | num_sources, /* Number of sources in file */ | |
432 | num_types; /* Number of types in file */ | |
433 | char line[2048], /* Current line */ | |
434 | *value, /* Pointer to value in line */ | |
435 | *valueptr, /* Pointer into value */ | |
436 | pwg_keyword[128], /* PWG keyword */ | |
437 | ppd_keyword[PPD_MAX_NAME]; | |
438 | /* PPD keyword */ | |
439 | _pwg_print_color_mode_t print_color_mode; | |
440 | /* Print color mode for preset */ | |
441 | _pwg_print_quality_t print_quality; /* Print quality for preset */ | |
442 | ||
443 | ||
444 | DEBUG_printf(("_ppdCacheCreateWithFile(filename=\"%s\")", filename)); | |
445 | ||
446 | /* | |
447 | * Range check input... | |
448 | */ | |
449 | ||
450 | if (attrs) | |
451 | *attrs = NULL; | |
452 | ||
453 | if (!filename) | |
454 | { | |
cb7f98ee | 455 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
f14324a7 MS |
456 | return (NULL); |
457 | } | |
458 | ||
459 | /* | |
460 | * Open the file... | |
461 | */ | |
462 | ||
463 | if ((fp = cupsFileOpen(filename, "r")) == NULL) | |
464 | { | |
cb7f98ee | 465 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
466 | return (NULL); |
467 | } | |
468 | ||
469 | /* | |
470 | * Read the first line and make sure it has "#CUPS-PPD-CACHE-version" in it... | |
471 | */ | |
472 | ||
473 | if (!cupsFileGets(fp, line, sizeof(line))) | |
474 | { | |
cb7f98ee | 475 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
476 | DEBUG_puts("_ppdCacheCreateWithFile: Unable to read first line."); |
477 | cupsFileClose(fp); | |
478 | return (NULL); | |
479 | } | |
480 | ||
22c9029b | 481 | if (strncmp(line, "#CUPS-PPD-CACHE-", 16)) |
f14324a7 | 482 | { |
cb7f98ee | 483 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
484 | DEBUG_printf(("_ppdCacheCreateWithFile: Wrong first line \"%s\".", line)); |
485 | cupsFileClose(fp); | |
486 | return (NULL); | |
487 | } | |
488 | ||
22c9029b MS |
489 | if (atoi(line + 16) != _PPD_CACHE_VERSION) |
490 | { | |
cb7f98ee | 491 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Out of date PPD cache file."), 1); |
22c9029b MS |
492 | DEBUG_printf(("_ppdCacheCreateWithFile: Cache file has version %s, " |
493 | "expected %d.", line + 16, _PPD_CACHE_VERSION)); | |
494 | cupsFileClose(fp); | |
495 | return (NULL); | |
496 | } | |
497 | ||
f14324a7 MS |
498 | /* |
499 | * Allocate the mapping data structure... | |
500 | */ | |
501 | ||
502 | if ((pc = calloc(1, sizeof(_ppd_cache_t))) == NULL) | |
503 | { | |
cb7f98ee | 504 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
505 | DEBUG_puts("_ppdCacheCreateWithFile: Unable to allocate _ppd_cache_t."); |
506 | goto create_error; | |
507 | } | |
508 | ||
3e7fe0ca MS |
509 | pc->max_copies = 9999; |
510 | ||
f14324a7 MS |
511 | /* |
512 | * Read the file... | |
513 | */ | |
514 | ||
515 | linenum = 0; | |
516 | num_bins = 0; | |
517 | num_sizes = 0; | |
518 | num_sources = 0; | |
519 | num_types = 0; | |
520 | ||
521 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
522 | { | |
523 | DEBUG_printf(("_ppdCacheCreateWithFile: line=\"%s\", value=\"%s\", " | |
524 | "linenum=%d", line, value, linenum)); | |
525 | ||
526 | if (!value) | |
527 | { | |
528 | DEBUG_printf(("_ppdCacheCreateWithFile: Missing value on line %d.", | |
529 | linenum)); | |
cb7f98ee | 530 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
531 | goto create_error; |
532 | } | |
88f9aafc | 533 | else if (!_cups_strcasecmp(line, "Filter")) |
f14324a7 MS |
534 | { |
535 | if (!pc->filters) | |
536 | pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, | |
537 | (cups_acopy_func_t)_cupsStrAlloc, | |
538 | (cups_afree_func_t)_cupsStrFree); | |
539 | ||
540 | cupsArrayAdd(pc->filters, value); | |
541 | } | |
88f9aafc | 542 | else if (!_cups_strcasecmp(line, "PreFilter")) |
f14324a7 MS |
543 | { |
544 | if (!pc->prefilters) | |
545 | pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, | |
546 | (cups_acopy_func_t)_cupsStrAlloc, | |
547 | (cups_afree_func_t)_cupsStrFree); | |
548 | ||
549 | cupsArrayAdd(pc->prefilters, value); | |
550 | } | |
88f9aafc | 551 | else if (!_cups_strcasecmp(line, "Product")) |
f14324a7 MS |
552 | { |
553 | pc->product = _cupsStrAlloc(value); | |
554 | } | |
88f9aafc | 555 | else if (!_cups_strcasecmp(line, "SingleFile")) |
82f97232 | 556 | { |
88f9aafc | 557 | pc->single_file = !_cups_strcasecmp(value, "true"); |
82f97232 | 558 | } |
88f9aafc | 559 | else if (!_cups_strcasecmp(line, "IPP")) |
f14324a7 MS |
560 | { |
561 | off_t pos = cupsFileTell(fp), /* Position in file */ | |
562 | length = strtol(value, NULL, 10); | |
563 | /* Length of IPP attributes */ | |
564 | ||
565 | if (attrs && *attrs) | |
566 | { | |
567 | DEBUG_puts("_ppdCacheCreateWithFile: IPP listed multiple times."); | |
cb7f98ee | 568 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
569 | goto create_error; |
570 | } | |
571 | else if (length <= 0) | |
572 | { | |
573 | DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP length."); | |
cb7f98ee | 574 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
575 | goto create_error; |
576 | } | |
577 | ||
578 | if (attrs) | |
579 | { | |
580 | /* | |
581 | * Read IPP attributes into the provided variable... | |
582 | */ | |
583 | ||
584 | *attrs = ippNew(); | |
585 | ||
586 | if (ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, | |
cb7f98ee | 587 | *attrs) != IPP_STATE_DATA) |
f14324a7 MS |
588 | { |
589 | DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data."); | |
cb7f98ee | 590 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
591 | goto create_error; |
592 | } | |
593 | } | |
594 | else | |
595 | { | |
596 | /* | |
597 | * Skip the IPP data entirely... | |
598 | */ | |
599 | ||
600 | cupsFileSeek(fp, pos + length); | |
601 | } | |
602 | ||
603 | if (cupsFileTell(fp) != (pos + length)) | |
604 | { | |
605 | DEBUG_puts("_ppdCacheCreateWithFile: Bad IPP data."); | |
cb7f98ee | 606 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
607 | goto create_error; |
608 | } | |
609 | } | |
88f9aafc | 610 | else if (!_cups_strcasecmp(line, "NumBins")) |
f14324a7 MS |
611 | { |
612 | if (num_bins > 0) | |
613 | { | |
614 | DEBUG_puts("_ppdCacheCreateWithFile: NumBins listed multiple times."); | |
cb7f98ee | 615 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
616 | goto create_error; |
617 | } | |
618 | ||
619 | if ((num_bins = atoi(value)) <= 0 || num_bins > 65536) | |
620 | { | |
621 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumBins value %d on line " | |
622 | "%d.", num_sizes, linenum)); | |
cb7f98ee | 623 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
624 | goto create_error; |
625 | } | |
626 | ||
7e86f2f6 | 627 | if ((pc->bins = calloc((size_t)num_bins, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
628 | { |
629 | DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.", | |
630 | num_sizes)); | |
cb7f98ee | 631 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
632 | goto create_error; |
633 | } | |
634 | } | |
88f9aafc | 635 | else if (!_cups_strcasecmp(line, "Bin")) |
f14324a7 MS |
636 | { |
637 | if (sscanf(value, "%127s%40s", pwg_keyword, ppd_keyword) != 2) | |
638 | { | |
639 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad Bin on line %d.", linenum)); | |
cb7f98ee | 640 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
641 | goto create_error; |
642 | } | |
643 | ||
644 | if (pc->num_bins >= num_bins) | |
645 | { | |
646 | DEBUG_printf(("_ppdCacheCreateWithFile: Too many Bin's on line %d.", | |
647 | linenum)); | |
cb7f98ee | 648 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
649 | goto create_error; |
650 | } | |
651 | ||
652 | map = pc->bins + pc->num_bins; | |
653 | map->pwg = _cupsStrAlloc(pwg_keyword); | |
654 | map->ppd = _cupsStrAlloc(ppd_keyword); | |
655 | ||
656 | pc->num_bins ++; | |
657 | } | |
88f9aafc | 658 | else if (!_cups_strcasecmp(line, "NumSizes")) |
f14324a7 MS |
659 | { |
660 | if (num_sizes > 0) | |
661 | { | |
662 | DEBUG_puts("_ppdCacheCreateWithFile: NumSizes listed multiple times."); | |
cb7f98ee | 663 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
664 | goto create_error; |
665 | } | |
666 | ||
5a9febac | 667 | if ((num_sizes = atoi(value)) < 0 || num_sizes > 65536) |
f14324a7 MS |
668 | { |
669 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSizes value %d on line " | |
670 | "%d.", num_sizes, linenum)); | |
cb7f98ee | 671 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
672 | goto create_error; |
673 | } | |
674 | ||
5a9febac | 675 | if (num_sizes > 0) |
f14324a7 | 676 | { |
7e86f2f6 | 677 | if ((pc->sizes = calloc((size_t)num_sizes, sizeof(pwg_size_t))) == NULL) |
5a9febac MS |
678 | { |
679 | DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.", | |
680 | num_sizes)); | |
cb7f98ee | 681 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
5a9febac MS |
682 | goto create_error; |
683 | } | |
f14324a7 MS |
684 | } |
685 | } | |
88f9aafc | 686 | else if (!_cups_strcasecmp(line, "Size")) |
f14324a7 MS |
687 | { |
688 | if (pc->num_sizes >= num_sizes) | |
689 | { | |
690 | DEBUG_printf(("_ppdCacheCreateWithFile: Too many Size's on line %d.", | |
691 | linenum)); | |
cb7f98ee | 692 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
693 | goto create_error; |
694 | } | |
695 | ||
696 | size = pc->sizes + pc->num_sizes; | |
697 | ||
698 | if (sscanf(value, "%127s%40s%d%d%d%d%d%d", pwg_keyword, ppd_keyword, | |
699 | &(size->width), &(size->length), &(size->left), | |
700 | &(size->bottom), &(size->right), &(size->top)) != 8) | |
701 | { | |
702 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad Size on line %d.", | |
703 | linenum)); | |
cb7f98ee | 704 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
705 | goto create_error; |
706 | } | |
707 | ||
708 | size->map.pwg = _cupsStrAlloc(pwg_keyword); | |
709 | size->map.ppd = _cupsStrAlloc(ppd_keyword); | |
710 | ||
711 | pc->num_sizes ++; | |
712 | } | |
88f9aafc | 713 | else if (!_cups_strcasecmp(line, "CustomSize")) |
f14324a7 MS |
714 | { |
715 | if (pc->custom_max_width > 0) | |
716 | { | |
717 | DEBUG_printf(("_ppdCacheCreateWithFile: Too many CustomSize's on line " | |
718 | "%d.", linenum)); | |
cb7f98ee | 719 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
720 | goto create_error; |
721 | } | |
722 | ||
723 | if (sscanf(value, "%d%d%d%d%d%d%d%d", &(pc->custom_max_width), | |
724 | &(pc->custom_max_length), &(pc->custom_min_width), | |
725 | &(pc->custom_min_length), &(pc->custom_size.left), | |
726 | &(pc->custom_size.bottom), &(pc->custom_size.right), | |
727 | &(pc->custom_size.top)) != 8) | |
728 | { | |
729 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad CustomSize on line %d.", | |
730 | linenum)); | |
cb7f98ee | 731 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
732 | goto create_error; |
733 | } | |
734 | ||
6961465f MS |
735 | pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max", |
736 | pc->custom_max_width, pc->custom_max_length, NULL); | |
f14324a7 MS |
737 | pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword); |
738 | ||
6961465f MS |
739 | pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min", |
740 | pc->custom_min_width, pc->custom_min_length, NULL); | |
f14324a7 MS |
741 | pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword); |
742 | } | |
88f9aafc | 743 | else if (!_cups_strcasecmp(line, "SourceOption")) |
f14324a7 MS |
744 | { |
745 | pc->source_option = _cupsStrAlloc(value); | |
746 | } | |
88f9aafc | 747 | else if (!_cups_strcasecmp(line, "NumSources")) |
f14324a7 MS |
748 | { |
749 | if (num_sources > 0) | |
750 | { | |
751 | DEBUG_puts("_ppdCacheCreateWithFile: NumSources listed multiple " | |
752 | "times."); | |
cb7f98ee | 753 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
754 | goto create_error; |
755 | } | |
756 | ||
757 | if ((num_sources = atoi(value)) <= 0 || num_sources > 65536) | |
758 | { | |
759 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumSources value %d on " | |
760 | "line %d.", num_sources, linenum)); | |
cb7f98ee | 761 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
762 | goto create_error; |
763 | } | |
764 | ||
7e86f2f6 | 765 | if ((pc->sources = calloc((size_t)num_sources, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
766 | { |
767 | DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.", | |
768 | num_sources)); | |
cb7f98ee | 769 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
770 | goto create_error; |
771 | } | |
772 | } | |
88f9aafc | 773 | else if (!_cups_strcasecmp(line, "Source")) |
f14324a7 MS |
774 | { |
775 | if (sscanf(value, "%127s%40s", pwg_keyword, ppd_keyword) != 2) | |
776 | { | |
777 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad Source on line %d.", | |
778 | linenum)); | |
cb7f98ee | 779 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
780 | goto create_error; |
781 | } | |
782 | ||
783 | if (pc->num_sources >= num_sources) | |
784 | { | |
785 | DEBUG_printf(("_ppdCacheCreateWithFile: Too many Source's on line %d.", | |
786 | linenum)); | |
cb7f98ee | 787 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
788 | goto create_error; |
789 | } | |
790 | ||
791 | map = pc->sources + pc->num_sources; | |
792 | map->pwg = _cupsStrAlloc(pwg_keyword); | |
793 | map->ppd = _cupsStrAlloc(ppd_keyword); | |
794 | ||
795 | pc->num_sources ++; | |
796 | } | |
88f9aafc | 797 | else if (!_cups_strcasecmp(line, "NumTypes")) |
f14324a7 MS |
798 | { |
799 | if (num_types > 0) | |
800 | { | |
801 | DEBUG_puts("_ppdCacheCreateWithFile: NumTypes listed multiple times."); | |
cb7f98ee | 802 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
803 | goto create_error; |
804 | } | |
805 | ||
806 | if ((num_types = atoi(value)) <= 0 || num_types > 65536) | |
807 | { | |
808 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad NumTypes value %d on " | |
809 | "line %d.", num_types, linenum)); | |
cb7f98ee | 810 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
811 | goto create_error; |
812 | } | |
813 | ||
7e86f2f6 | 814 | if ((pc->types = calloc((size_t)num_types, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
815 | { |
816 | DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.", | |
817 | num_types)); | |
cb7f98ee | 818 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
819 | goto create_error; |
820 | } | |
821 | } | |
88f9aafc | 822 | else if (!_cups_strcasecmp(line, "Type")) |
f14324a7 MS |
823 | { |
824 | if (sscanf(value, "%127s%40s", pwg_keyword, ppd_keyword) != 2) | |
825 | { | |
826 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad Type on line %d.", | |
827 | linenum)); | |
cb7f98ee | 828 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
829 | goto create_error; |
830 | } | |
831 | ||
832 | if (pc->num_types >= num_types) | |
833 | { | |
834 | DEBUG_printf(("_ppdCacheCreateWithFile: Too many Type's on line %d.", | |
835 | linenum)); | |
cb7f98ee | 836 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
837 | goto create_error; |
838 | } | |
839 | ||
840 | map = pc->types + pc->num_types; | |
841 | map->pwg = _cupsStrAlloc(pwg_keyword); | |
842 | map->ppd = _cupsStrAlloc(ppd_keyword); | |
843 | ||
844 | pc->num_types ++; | |
845 | } | |
88f9aafc | 846 | else if (!_cups_strcasecmp(line, "Preset")) |
f14324a7 MS |
847 | { |
848 | /* | |
849 | * Preset output-mode print-quality name=value ... | |
850 | */ | |
851 | ||
852 | print_color_mode = (_pwg_print_color_mode_t)strtol(value, &valueptr, 10); | |
853 | print_quality = (_pwg_print_quality_t)strtol(valueptr, &valueptr, 10); | |
854 | ||
855 | if (print_color_mode < _PWG_PRINT_COLOR_MODE_MONOCHROME || | |
856 | print_color_mode >= _PWG_PRINT_COLOR_MODE_MAX || | |
857 | print_quality < _PWG_PRINT_QUALITY_DRAFT || | |
858 | print_quality >= _PWG_PRINT_QUALITY_MAX || | |
859 | valueptr == value || !*valueptr) | |
860 | { | |
861 | DEBUG_printf(("_ppdCacheCreateWithFile: Bad Preset on line %d.", | |
862 | linenum)); | |
cb7f98ee | 863 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
864 | goto create_error; |
865 | } | |
866 | ||
867 | pc->num_presets[print_color_mode][print_quality] = | |
868 | cupsParseOptions(valueptr, 0, | |
869 | pc->presets[print_color_mode] + print_quality); | |
870 | } | |
88f9aafc | 871 | else if (!_cups_strcasecmp(line, "SidesOption")) |
f14324a7 | 872 | pc->sides_option = _cupsStrAlloc(value); |
88f9aafc | 873 | else if (!_cups_strcasecmp(line, "Sides1Sided")) |
f14324a7 | 874 | pc->sides_1sided = _cupsStrAlloc(value); |
88f9aafc | 875 | else if (!_cups_strcasecmp(line, "Sides2SidedLong")) |
f14324a7 | 876 | pc->sides_2sided_long = _cupsStrAlloc(value); |
88f9aafc | 877 | else if (!_cups_strcasecmp(line, "Sides2SidedShort")) |
f14324a7 | 878 | pc->sides_2sided_short = _cupsStrAlloc(value); |
dcb445bc MS |
879 | else if (!_cups_strcasecmp(line, "Finishings")) |
880 | { | |
881 | if (!pc->finishings) | |
882 | pc->finishings = | |
883 | cupsArrayNew3((cups_array_func_t)pwg_compare_finishings, | |
884 | NULL, NULL, 0, NULL, | |
885 | (cups_afree_func_t)pwg_free_finishings); | |
886 | ||
887 | if ((finishings = calloc(1, sizeof(_pwg_finishings_t))) == NULL) | |
888 | goto create_error; | |
889 | ||
7e86f2f6 | 890 | finishings->value = (ipp_finishings_t)strtol(value, &valueptr, 10); |
dcb445bc MS |
891 | finishings->num_options = cupsParseOptions(valueptr, 0, |
892 | &(finishings->options)); | |
893 | ||
894 | cupsArrayAdd(pc->finishings, finishings); | |
895 | } | |
4f63d6cd MS |
896 | else if (!_cups_strcasecmp(line, "FinishingTemplate")) |
897 | { | |
898 | if (!pc->templates) | |
899 | pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree); | |
900 | ||
901 | cupsArrayAdd(pc->templates, value); | |
902 | } | |
3e7fe0ca MS |
903 | else if (!_cups_strcasecmp(line, "MaxCopies")) |
904 | pc->max_copies = atoi(value); | |
a469f8a5 MS |
905 | else if (!_cups_strcasecmp(line, "ChargeInfoURI")) |
906 | pc->charge_info_uri = _cupsStrAlloc(value); | |
5a9febac MS |
907 | else if (!_cups_strcasecmp(line, "JobAccountId")) |
908 | pc->account_id = !_cups_strcasecmp(value, "true"); | |
909 | else if (!_cups_strcasecmp(line, "JobAccountingUserId")) | |
910 | pc->accounting_user_id = !_cups_strcasecmp(value, "true"); | |
911 | else if (!_cups_strcasecmp(line, "JobPassword")) | |
912 | pc->password = _cupsStrAlloc(value); | |
913 | else if (!_cups_strcasecmp(line, "Mandatory")) | |
914 | { | |
915 | if (pc->mandatory) | |
916 | _cupsArrayAddStrings(pc->mandatory, value, ' '); | |
917 | else | |
918 | pc->mandatory = _cupsArrayNewStrings(value, ' '); | |
919 | } | |
c1420c87 MS |
920 | else if (!_cups_strcasecmp(line, "SupportFile")) |
921 | { | |
922 | if (!pc->support_files) | |
923 | pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, | |
924 | (cups_acopy_func_t)_cupsStrAlloc, | |
925 | (cups_afree_func_t)_cupsStrFree); | |
926 | ||
927 | cupsArrayAdd(pc->support_files, value); | |
928 | } | |
f14324a7 MS |
929 | else |
930 | { | |
931 | DEBUG_printf(("_ppdCacheCreateWithFile: Unknown %s on line %d.", line, | |
932 | linenum)); | |
f14324a7 MS |
933 | } |
934 | } | |
935 | ||
936 | if (pc->num_sizes < num_sizes) | |
937 | { | |
938 | DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sizes (%d < %d).", | |
939 | pc->num_sizes, num_sizes)); | |
cb7f98ee | 940 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
941 | goto create_error; |
942 | } | |
943 | ||
944 | if (pc->num_sources < num_sources) | |
945 | { | |
946 | DEBUG_printf(("_ppdCacheCreateWithFile: Not enough sources (%d < %d).", | |
947 | pc->num_sources, num_sources)); | |
cb7f98ee | 948 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
949 | goto create_error; |
950 | } | |
951 | ||
952 | if (pc->num_types < num_types) | |
953 | { | |
954 | DEBUG_printf(("_ppdCacheCreateWithFile: Not enough types (%d < %d).", | |
955 | pc->num_types, num_types)); | |
cb7f98ee | 956 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad PPD cache file."), 1); |
f14324a7 MS |
957 | goto create_error; |
958 | } | |
959 | ||
960 | cupsFileClose(fp); | |
961 | ||
962 | return (pc); | |
963 | ||
964 | /* | |
965 | * If we get here the file was bad - free any data and return... | |
966 | */ | |
967 | ||
968 | create_error: | |
969 | ||
970 | cupsFileClose(fp); | |
971 | _ppdCacheDestroy(pc); | |
972 | ||
973 | if (attrs) | |
22c9029b | 974 | { |
f14324a7 | 975 | ippDelete(*attrs); |
22c9029b MS |
976 | *attrs = NULL; |
977 | } | |
f14324a7 MS |
978 | |
979 | return (NULL); | |
980 | } | |
981 | ||
982 | ||
983 | /* | |
984 | * '_ppdCacheCreateWithPPD()' - Create PWG mapping data from a PPD file. | |
985 | */ | |
986 | ||
987 | _ppd_cache_t * /* O - PPD cache and mapping data */ | |
988 | _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ | |
989 | { | |
990 | int i, j, k; /* Looping vars */ | |
991 | _ppd_cache_t *pc; /* PWG mapping data */ | |
992 | ppd_option_t *input_slot, /* InputSlot option */ | |
993 | *media_type, /* MediaType option */ | |
994 | *output_bin, /* OutputBin option */ | |
995 | *color_model, /* ColorModel option */ | |
4f63d6cd MS |
996 | *duplex, /* Duplex option */ |
997 | *ppd_option; /* Other PPD option */ | |
f14324a7 | 998 | ppd_choice_t *choice; /* Current InputSlot/MediaType */ |
6961465f | 999 | pwg_map_t *map; /* Current source/type map */ |
f14324a7 MS |
1000 | ppd_attr_t *ppd_attr; /* Current PPD preset attribute */ |
1001 | int num_options; /* Number of preset options and props */ | |
1002 | cups_option_t *options; /* Preset options and properties */ | |
1003 | ppd_size_t *ppd_size; /* Current PPD size */ | |
6961465f | 1004 | pwg_size_t *pwg_size; /* Current PWG size */ |
f14324a7 MS |
1005 | char pwg_keyword[3 + PPD_MAX_NAME + 1 + 12 + 1 + 12 + 3], |
1006 | /* PWG keyword string */ | |
1007 | ppd_name[PPD_MAX_NAME]; | |
1008 | /* Normalized PPD name */ | |
1009 | const char *pwg_name; /* Standard PWG media name */ | |
6961465f | 1010 | pwg_media_t *pwg_media; /* PWG media data */ |
f14324a7 MS |
1011 | _pwg_print_color_mode_t pwg_print_color_mode; |
1012 | /* print-color-mode index */ | |
1013 | _pwg_print_quality_t pwg_print_quality; | |
1014 | /* print-quality index */ | |
1015 | int similar; /* Are the old and new size similar? */ | |
6961465f | 1016 | pwg_size_t *old_size; /* Current old size */ |
f14324a7 MS |
1017 | int old_imageable, /* Old imageable length in 2540ths */ |
1018 | old_borderless, /* Old borderless state */ | |
1019 | old_known_pwg; /* Old PWG name is well-known */ | |
1020 | int new_width, /* New width in 2540ths */ | |
1021 | new_length, /* New length in 2540ths */ | |
1022 | new_left, /* New left margin in 2540ths */ | |
1023 | new_bottom, /* New bottom margin in 2540ths */ | |
1024 | new_right, /* New right margin in 2540ths */ | |
1025 | new_top, /* New top margin in 2540ths */ | |
1026 | new_imageable, /* New imageable length in 2540ths */ | |
1027 | new_borderless, /* New borderless state */ | |
1028 | new_known_pwg; /* New PWG name is well-known */ | |
6961465f | 1029 | pwg_size_t *new_size; /* New size to add, if any */ |
f14324a7 | 1030 | const char *filter; /* Current filter */ |
dcb445bc | 1031 | _pwg_finishings_t *finishings; /* Current finishings value */ |
2fa1ba3c | 1032 | char msg_id[256]; /* Message identifier */ |
f14324a7 MS |
1033 | |
1034 | ||
1035 | DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd)); | |
1036 | ||
1037 | /* | |
1038 | * Range check input... | |
1039 | */ | |
1040 | ||
1041 | if (!ppd) | |
1042 | return (NULL); | |
1043 | ||
1044 | /* | |
1045 | * Allocate memory... | |
1046 | */ | |
1047 | ||
1048 | if ((pc = calloc(1, sizeof(_ppd_cache_t))) == NULL) | |
1049 | { | |
1050 | DEBUG_puts("_ppdCacheCreateWithPPD: Unable to allocate _ppd_cache_t."); | |
1051 | goto create_error; | |
1052 | } | |
1053 | ||
2fa1ba3c MS |
1054 | pc->strings = _cupsMessageNew(NULL); |
1055 | ||
f14324a7 MS |
1056 | /* |
1057 | * Copy and convert size data... | |
1058 | */ | |
1059 | ||
5a9febac | 1060 | if (ppd->num_sizes > 0) |
f14324a7 | 1061 | { |
7e86f2f6 | 1062 | if ((pc->sizes = calloc((size_t)ppd->num_sizes, sizeof(pwg_size_t))) == NULL) |
f14324a7 | 1063 | { |
5a9febac | 1064 | DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d " |
6961465f | 1065 | "pwg_size_t's.", ppd->num_sizes)); |
5a9febac | 1066 | goto create_error; |
f14324a7 MS |
1067 | } |
1068 | ||
5a9febac MS |
1069 | for (i = ppd->num_sizes, pwg_size = pc->sizes, ppd_size = ppd->sizes; |
1070 | i > 0; | |
1071 | i --, ppd_size ++) | |
f14324a7 MS |
1072 | { |
1073 | /* | |
5a9febac | 1074 | * Don't copy over custom size... |
f14324a7 MS |
1075 | */ |
1076 | ||
5a9febac MS |
1077 | if (!_cups_strcasecmp(ppd_size->name, "Custom")) |
1078 | continue; | |
1079 | ||
f14324a7 | 1080 | /* |
5a9febac | 1081 | * Convert the PPD size name to the corresponding PWG keyword name. |
f14324a7 MS |
1082 | */ |
1083 | ||
6961465f | 1084 | if ((pwg_media = pwgMediaForPPD(ppd_size->name)) != NULL) |
5a9febac MS |
1085 | { |
1086 | /* | |
1087 | * Standard name, do we have conflicts? | |
1088 | */ | |
f14324a7 | 1089 | |
5a9febac MS |
1090 | for (j = 0; j < pc->num_sizes; j ++) |
1091 | if (!strcmp(pc->sizes[j].map.pwg, pwg_media->pwg)) | |
1092 | { | |
1093 | pwg_media = NULL; | |
1094 | break; | |
1095 | } | |
1096 | } | |
f14324a7 | 1097 | |
5a9febac MS |
1098 | if (pwg_media) |
1099 | { | |
1100 | /* | |
1101 | * Standard name and no conflicts, use it! | |
1102 | */ | |
f14324a7 | 1103 | |
5a9febac MS |
1104 | pwg_name = pwg_media->pwg; |
1105 | new_known_pwg = 1; | |
1106 | } | |
1107 | else | |
f14324a7 MS |
1108 | { |
1109 | /* | |
5a9febac MS |
1110 | * Not a standard name; convert it to a PWG vendor name of the form: |
1111 | * | |
1112 | * pp_lowerppd_WIDTHxHEIGHTuu | |
f14324a7 MS |
1113 | */ |
1114 | ||
5a9febac MS |
1115 | pwg_name = pwg_keyword; |
1116 | new_known_pwg = 0; | |
1117 | ||
c1420c87 | 1118 | pwg_unppdize_name(ppd_size->name, ppd_name, sizeof(ppd_name), "_."); |
6961465f MS |
1119 | pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), NULL, ppd_name, |
1120 | PWG_FROM_POINTS(ppd_size->width), | |
1121 | PWG_FROM_POINTS(ppd_size->length), NULL); | |
f14324a7 | 1122 | } |
f14324a7 | 1123 | |
f14324a7 | 1124 | /* |
5a9febac MS |
1125 | * If we have a similar paper with non-zero margins then we only want to |
1126 | * keep it if it has a larger imageable area length. The NULL check is for | |
1127 | * dimensions that are <= 0... | |
f14324a7 MS |
1128 | */ |
1129 | ||
c3ebc4c6 MS |
1130 | if ((pwg_media = _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size->width), |
1131 | PWG_FROM_POINTS(ppd_size->length), | |
1132 | 0)) == NULL) | |
5a9febac | 1133 | continue; |
f14324a7 | 1134 | |
5a9febac MS |
1135 | new_width = pwg_media->width; |
1136 | new_length = pwg_media->length; | |
6961465f MS |
1137 | new_left = PWG_FROM_POINTS(ppd_size->left); |
1138 | new_bottom = PWG_FROM_POINTS(ppd_size->bottom); | |
1139 | new_right = PWG_FROM_POINTS(ppd_size->width - ppd_size->right); | |
1140 | new_top = PWG_FROM_POINTS(ppd_size->length - ppd_size->top); | |
5a9febac MS |
1141 | new_imageable = new_length - new_top - new_bottom; |
1142 | new_borderless = new_bottom == 0 && new_top == 0 && | |
1143 | new_left == 0 && new_right == 0; | |
1144 | ||
1145 | for (k = pc->num_sizes, similar = 0, old_size = pc->sizes, new_size = NULL; | |
1146 | k > 0 && !similar; | |
1147 | k --, old_size ++) | |
1148 | { | |
1149 | old_imageable = old_size->length - old_size->top - old_size->bottom; | |
1150 | old_borderless = old_size->left == 0 && old_size->bottom == 0 && | |
1151 | old_size->right == 0 && old_size->top == 0; | |
1152 | old_known_pwg = strncmp(old_size->map.pwg, "oe_", 3) && | |
1153 | strncmp(old_size->map.pwg, "om_", 3); | |
1154 | ||
1155 | similar = old_borderless == new_borderless && | |
1156 | _PWG_EQUIVALENT(old_size->width, new_width) && | |
1157 | _PWG_EQUIVALENT(old_size->length, new_length); | |
1158 | ||
1159 | if (similar && | |
1160 | (new_known_pwg || (!old_known_pwg && new_imageable > old_imageable))) | |
1161 | { | |
1162 | /* | |
1163 | * The new paper has a larger imageable area so it could replace | |
1164 | * the older paper. Regardless of the imageable area, we always | |
1165 | * prefer the size with a well-known PWG name. | |
1166 | */ | |
1167 | ||
1168 | new_size = old_size; | |
1169 | _cupsStrFree(old_size->map.ppd); | |
1170 | _cupsStrFree(old_size->map.pwg); | |
1171 | } | |
1172 | } | |
1173 | ||
1174 | if (!similar) | |
1175 | { | |
1176 | /* | |
1177 | * The paper was unique enough to deserve its own entry so add it to the | |
1178 | * end. | |
1179 | */ | |
1180 | ||
1181 | new_size = pwg_size ++; | |
1182 | pc->num_sizes ++; | |
1183 | } | |
1184 | ||
1185 | if (new_size) | |
1186 | { | |
1187 | /* | |
1188 | * Save this size... | |
1189 | */ | |
f14324a7 | 1190 | |
5a9febac MS |
1191 | new_size->map.ppd = _cupsStrAlloc(ppd_size->name); |
1192 | new_size->map.pwg = _cupsStrAlloc(pwg_name); | |
1193 | new_size->width = new_width; | |
1194 | new_size->length = new_length; | |
1195 | new_size->left = new_left; | |
1196 | new_size->bottom = new_bottom; | |
1197 | new_size->right = new_right; | |
1198 | new_size->top = new_top; | |
1199 | } | |
f14324a7 MS |
1200 | } |
1201 | } | |
1202 | ||
1203 | if (ppd->variable_sizes) | |
1204 | { | |
1205 | /* | |
1206 | * Generate custom size data... | |
1207 | */ | |
1208 | ||
6961465f MS |
1209 | pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max", |
1210 | PWG_FROM_POINTS(ppd->custom_max[0]), | |
1211 | PWG_FROM_POINTS(ppd->custom_max[1]), NULL); | |
f14324a7 | 1212 | pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword); |
6961465f MS |
1213 | pc->custom_max_width = PWG_FROM_POINTS(ppd->custom_max[0]); |
1214 | pc->custom_max_length = PWG_FROM_POINTS(ppd->custom_max[1]); | |
f14324a7 | 1215 | |
6961465f MS |
1216 | pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min", |
1217 | PWG_FROM_POINTS(ppd->custom_min[0]), | |
1218 | PWG_FROM_POINTS(ppd->custom_min[1]), NULL); | |
f14324a7 | 1219 | pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword); |
6961465f MS |
1220 | pc->custom_min_width = PWG_FROM_POINTS(ppd->custom_min[0]); |
1221 | pc->custom_min_length = PWG_FROM_POINTS(ppd->custom_min[1]); | |
f14324a7 | 1222 | |
6961465f MS |
1223 | pc->custom_size.left = PWG_FROM_POINTS(ppd->custom_margins[0]); |
1224 | pc->custom_size.bottom = PWG_FROM_POINTS(ppd->custom_margins[1]); | |
1225 | pc->custom_size.right = PWG_FROM_POINTS(ppd->custom_margins[2]); | |
1226 | pc->custom_size.top = PWG_FROM_POINTS(ppd->custom_margins[3]); | |
f14324a7 MS |
1227 | } |
1228 | ||
1229 | /* | |
1230 | * Copy and convert InputSlot data... | |
1231 | */ | |
1232 | ||
1233 | if ((input_slot = ppdFindOption(ppd, "InputSlot")) == NULL) | |
1234 | input_slot = ppdFindOption(ppd, "HPPaperSource"); | |
1235 | ||
1236 | if (input_slot) | |
1237 | { | |
1238 | pc->source_option = _cupsStrAlloc(input_slot->keyword); | |
1239 | ||
7e86f2f6 | 1240 | if ((pc->sources = calloc((size_t)input_slot->num_choices, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
1241 | { |
1242 | DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d " | |
6961465f | 1243 | "pwg_map_t's for InputSlot.", input_slot->num_choices)); |
f14324a7 MS |
1244 | goto create_error; |
1245 | } | |
1246 | ||
1247 | pc->num_sources = input_slot->num_choices; | |
1248 | ||
1249 | for (i = input_slot->num_choices, choice = input_slot->choices, | |
1250 | map = pc->sources; | |
1251 | i > 0; | |
1252 | i --, choice ++, map ++) | |
1253 | { | |
88f9aafc MS |
1254 | if (!_cups_strncasecmp(choice->choice, "Auto", 4) || |
1255 | !_cups_strcasecmp(choice->choice, "Default")) | |
f14324a7 | 1256 | pwg_name = "auto"; |
88f9aafc | 1257 | else if (!_cups_strcasecmp(choice->choice, "Cassette")) |
f14324a7 | 1258 | pwg_name = "main"; |
88f9aafc | 1259 | else if (!_cups_strcasecmp(choice->choice, "PhotoTray")) |
f14324a7 | 1260 | pwg_name = "photo"; |
88f9aafc | 1261 | else if (!_cups_strcasecmp(choice->choice, "CDTray")) |
f14324a7 | 1262 | pwg_name = "disc"; |
88f9aafc MS |
1263 | else if (!_cups_strncasecmp(choice->choice, "Multipurpose", 12) || |
1264 | !_cups_strcasecmp(choice->choice, "MP") || | |
1265 | !_cups_strcasecmp(choice->choice, "MPTray")) | |
12f89d24 | 1266 | pwg_name = "by-pass-tray"; |
88f9aafc | 1267 | else if (!_cups_strcasecmp(choice->choice, "LargeCapacity")) |
f14324a7 | 1268 | pwg_name = "large-capacity"; |
88f9aafc | 1269 | else if (!_cups_strncasecmp(choice->choice, "Lower", 5)) |
f14324a7 | 1270 | pwg_name = "bottom"; |
88f9aafc | 1271 | else if (!_cups_strncasecmp(choice->choice, "Middle", 6)) |
f14324a7 | 1272 | pwg_name = "middle"; |
88f9aafc | 1273 | else if (!_cups_strncasecmp(choice->choice, "Upper", 5)) |
f14324a7 | 1274 | pwg_name = "top"; |
88f9aafc | 1275 | else if (!_cups_strncasecmp(choice->choice, "Side", 4)) |
f14324a7 | 1276 | pwg_name = "side"; |
a4845881 | 1277 | else if (!_cups_strcasecmp(choice->choice, "Roll")) |
f14324a7 | 1278 | pwg_name = "main-roll"; |
f14324a7 MS |
1279 | else |
1280 | { | |
1281 | /* | |
1282 | * Convert PPD name to lowercase... | |
1283 | */ | |
1284 | ||
1285 | pwg_name = pwg_keyword; | |
c1420c87 MS |
1286 | pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword), |
1287 | "_"); | |
f14324a7 MS |
1288 | } |
1289 | ||
1290 | map->pwg = _cupsStrAlloc(pwg_name); | |
1291 | map->ppd = _cupsStrAlloc(choice->choice); | |
2fa1ba3c MS |
1292 | |
1293 | /* | |
1294 | * Add localized text for PWG keyword to message catalog... | |
1295 | */ | |
1296 | ||
1297 | snprintf(msg_id, sizeof(msg_id), "media-source.%s", pwg_name); | |
1298 | pwg_add_message(pc->strings, msg_id, choice->text); | |
f14324a7 MS |
1299 | } |
1300 | } | |
1301 | ||
1302 | /* | |
1303 | * Copy and convert MediaType data... | |
1304 | */ | |
1305 | ||
1306 | if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL) | |
1307 | { | |
7e86f2f6 | 1308 | if ((pc->types = calloc((size_t)media_type->num_choices, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
1309 | { |
1310 | DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d " | |
6961465f | 1311 | "pwg_map_t's for MediaType.", media_type->num_choices)); |
f14324a7 MS |
1312 | goto create_error; |
1313 | } | |
1314 | ||
1315 | pc->num_types = media_type->num_choices; | |
1316 | ||
1317 | for (i = media_type->num_choices, choice = media_type->choices, | |
1318 | map = pc->types; | |
1319 | i > 0; | |
1320 | i --, choice ++, map ++) | |
1321 | { | |
88f9aafc MS |
1322 | if (!_cups_strncasecmp(choice->choice, "Auto", 4) || |
1323 | !_cups_strcasecmp(choice->choice, "Any") || | |
1324 | !_cups_strcasecmp(choice->choice, "Default")) | |
f14324a7 | 1325 | pwg_name = "auto"; |
88f9aafc | 1326 | else if (!_cups_strncasecmp(choice->choice, "Card", 4)) |
f14324a7 | 1327 | pwg_name = "cardstock"; |
88f9aafc | 1328 | else if (!_cups_strncasecmp(choice->choice, "Env", 3)) |
f14324a7 | 1329 | pwg_name = "envelope"; |
88f9aafc | 1330 | else if (!_cups_strncasecmp(choice->choice, "Gloss", 5)) |
f14324a7 | 1331 | pwg_name = "photographic-glossy"; |
88f9aafc | 1332 | else if (!_cups_strcasecmp(choice->choice, "HighGloss")) |
f14324a7 | 1333 | pwg_name = "photographic-high-gloss"; |
88f9aafc | 1334 | else if (!_cups_strcasecmp(choice->choice, "Matte")) |
f14324a7 | 1335 | pwg_name = "photographic-matte"; |
88f9aafc | 1336 | else if (!_cups_strncasecmp(choice->choice, "Plain", 5)) |
f14324a7 | 1337 | pwg_name = "stationery"; |
88f9aafc | 1338 | else if (!_cups_strncasecmp(choice->choice, "Coated", 6)) |
f14324a7 | 1339 | pwg_name = "stationery-coated"; |
88f9aafc | 1340 | else if (!_cups_strcasecmp(choice->choice, "Inkjet")) |
f14324a7 | 1341 | pwg_name = "stationery-inkjet"; |
88f9aafc | 1342 | else if (!_cups_strcasecmp(choice->choice, "Letterhead")) |
f14324a7 | 1343 | pwg_name = "stationery-letterhead"; |
88f9aafc | 1344 | else if (!_cups_strncasecmp(choice->choice, "Preprint", 8)) |
f14324a7 | 1345 | pwg_name = "stationery-preprinted"; |
a4845881 MS |
1346 | else if (!_cups_strcasecmp(choice->choice, "Recycled")) |
1347 | pwg_name = "stationery-recycled"; | |
88f9aafc | 1348 | else if (!_cups_strncasecmp(choice->choice, "Transparen", 10)) |
f14324a7 MS |
1349 | pwg_name = "transparency"; |
1350 | else | |
1351 | { | |
1352 | /* | |
1353 | * Convert PPD name to lowercase... | |
1354 | */ | |
1355 | ||
1356 | pwg_name = pwg_keyword; | |
c1420c87 MS |
1357 | pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword), |
1358 | "_"); | |
f14324a7 MS |
1359 | } |
1360 | ||
1361 | map->pwg = _cupsStrAlloc(pwg_name); | |
1362 | map->ppd = _cupsStrAlloc(choice->choice); | |
2fa1ba3c MS |
1363 | |
1364 | /* | |
1365 | * Add localized text for PWG keyword to message catalog... | |
1366 | */ | |
1367 | ||
1368 | snprintf(msg_id, sizeof(msg_id), "media-type.%s", pwg_name); | |
1369 | pwg_add_message(pc->strings, msg_id, choice->text); | |
f14324a7 MS |
1370 | } |
1371 | } | |
1372 | ||
f14324a7 MS |
1373 | /* |
1374 | * Copy and convert OutputBin data... | |
1375 | */ | |
1376 | ||
1377 | if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL) | |
1378 | { | |
7e86f2f6 | 1379 | if ((pc->bins = calloc((size_t)output_bin->num_choices, sizeof(pwg_map_t))) == NULL) |
f14324a7 MS |
1380 | { |
1381 | DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d " | |
6961465f | 1382 | "pwg_map_t's for OutputBin.", output_bin->num_choices)); |
f14324a7 MS |
1383 | goto create_error; |
1384 | } | |
1385 | ||
1386 | pc->num_bins = output_bin->num_choices; | |
1387 | ||
1388 | for (i = output_bin->num_choices, choice = output_bin->choices, | |
1389 | map = pc->bins; | |
1390 | i > 0; | |
1391 | i --, choice ++, map ++) | |
1392 | { | |
c1420c87 | 1393 | pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword), "_"); |
f14324a7 MS |
1394 | |
1395 | map->pwg = _cupsStrAlloc(pwg_keyword); | |
1396 | map->ppd = _cupsStrAlloc(choice->choice); | |
2fa1ba3c MS |
1397 | |
1398 | /* | |
1399 | * Add localized text for PWG keyword to message catalog... | |
1400 | */ | |
1401 | ||
1402 | snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_name); | |
1403 | pwg_add_message(pc->strings, msg_id, choice->text); | |
f14324a7 MS |
1404 | } |
1405 | } | |
1406 | ||
1407 | if ((ppd_attr = ppdFindAttr(ppd, "APPrinterPreset", NULL)) != NULL) | |
1408 | { | |
1409 | /* | |
1410 | * Copy and convert APPrinterPreset (output-mode + print-quality) data... | |
1411 | */ | |
1412 | ||
1413 | const char *quality, /* com.apple.print.preset.quality value */ | |
1414 | *output_mode, /* com.apple.print.preset.output-mode value */ | |
1415 | *color_model_val, /* ColorModel choice */ | |
1416 | *graphicsType, /* com.apple.print.preset.graphicsType value */ | |
1417 | *media_front_coating; /* com.apple.print.preset.media-front-coating value */ | |
1418 | ||
1419 | do | |
1420 | { | |
2fa1ba3c MS |
1421 | /* |
1422 | * Add localized text for PWG keyword to message catalog... | |
1423 | */ | |
1424 | ||
1425 | snprintf(msg_id, sizeof(msg_id), "preset-name.%s", ppd_attr->spec); | |
1426 | pwg_add_message(pc->strings, msg_id, ppd_attr->text); | |
1427 | ||
1428 | /* | |
1429 | * Get the options for this preset... | |
1430 | */ | |
1431 | ||
f14324a7 MS |
1432 | num_options = _ppdParseOptions(ppd_attr->value, 0, &options, |
1433 | _PPD_PARSE_ALL); | |
1434 | ||
1435 | if ((quality = cupsGetOption("com.apple.print.preset.quality", | |
1436 | num_options, options)) != NULL) | |
1437 | { | |
1438 | /* | |
1439 | * Get the print-quality for this preset... | |
1440 | */ | |
1441 | ||
1442 | if (!strcmp(quality, "low")) | |
1443 | pwg_print_quality = _PWG_PRINT_QUALITY_DRAFT; | |
1444 | else if (!strcmp(quality, "high")) | |
1445 | pwg_print_quality = _PWG_PRINT_QUALITY_HIGH; | |
1446 | else | |
1447 | pwg_print_quality = _PWG_PRINT_QUALITY_NORMAL; | |
1448 | ||
1449 | /* | |
1450 | * Ignore graphicsType "Photo" presets that are not high quality. | |
1451 | */ | |
1452 | ||
1453 | graphicsType = cupsGetOption("com.apple.print.preset.graphicsType", | |
1454 | num_options, options); | |
1455 | ||
1456 | if (pwg_print_quality != _PWG_PRINT_QUALITY_HIGH && graphicsType && | |
1457 | !strcmp(graphicsType, "Photo")) | |
1458 | continue; | |
1459 | ||
1460 | /* | |
1461 | * Ignore presets for normal and draft quality where the coating | |
1462 | * isn't "none" or "autodetect". | |
1463 | */ | |
1464 | ||
1465 | media_front_coating = cupsGetOption( | |
1466 | "com.apple.print.preset.media-front-coating", | |
1467 | num_options, options); | |
1468 | ||
1469 | if (pwg_print_quality != _PWG_PRINT_QUALITY_HIGH && | |
1470 | media_front_coating && | |
1471 | strcmp(media_front_coating, "none") && | |
1472 | strcmp(media_front_coating, "autodetect")) | |
1473 | continue; | |
1474 | ||
1475 | /* | |
1476 | * Get the output mode for this preset... | |
1477 | */ | |
1478 | ||
1479 | output_mode = cupsGetOption("com.apple.print.preset.output-mode", | |
1480 | num_options, options); | |
1481 | color_model_val = cupsGetOption("ColorModel", num_options, options); | |
1482 | ||
1483 | if (output_mode) | |
1484 | { | |
1485 | if (!strcmp(output_mode, "monochrome")) | |
1486 | pwg_print_color_mode = _PWG_PRINT_COLOR_MODE_MONOCHROME; | |
1487 | else | |
1488 | pwg_print_color_mode = _PWG_PRINT_COLOR_MODE_COLOR; | |
1489 | } | |
1490 | else if (color_model_val) | |
1491 | { | |
88f9aafc | 1492 | if (!_cups_strcasecmp(color_model_val, "Gray")) |
f14324a7 MS |
1493 | pwg_print_color_mode = _PWG_PRINT_COLOR_MODE_MONOCHROME; |
1494 | else | |
1495 | pwg_print_color_mode = _PWG_PRINT_COLOR_MODE_COLOR; | |
1496 | } | |
1497 | else | |
1498 | pwg_print_color_mode = _PWG_PRINT_COLOR_MODE_COLOR; | |
1499 | ||
1500 | /* | |
1501 | * Save the options for this combination as needed... | |
1502 | */ | |
1503 | ||
1504 | if (!pc->num_presets[pwg_print_color_mode][pwg_print_quality]) | |
1505 | pc->num_presets[pwg_print_color_mode][pwg_print_quality] = | |
1506 | _ppdParseOptions(ppd_attr->value, 0, | |
1507 | pc->presets[pwg_print_color_mode] + | |
1508 | pwg_print_quality, _PPD_PARSE_OPTIONS); | |
1509 | } | |
1510 | ||
1511 | cupsFreeOptions(num_options, options); | |
1512 | } | |
1513 | while ((ppd_attr = ppdFindNextAttr(ppd, "APPrinterPreset", NULL)) != NULL); | |
1514 | } | |
1515 | ||
1516 | if (!pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][_PWG_PRINT_QUALITY_DRAFT] && | |
1517 | !pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][_PWG_PRINT_QUALITY_NORMAL] && | |
1518 | !pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][_PWG_PRINT_QUALITY_HIGH]) | |
1519 | { | |
1520 | /* | |
1521 | * Try adding some common color options to create grayscale presets. These | |
1522 | * are listed in order of popularity... | |
1523 | */ | |
1524 | ||
1525 | const char *color_option = NULL, /* Color control option */ | |
1526 | *gray_choice = NULL; /* Choice to select grayscale */ | |
1527 | ||
1528 | if ((color_model = ppdFindOption(ppd, "ColorModel")) != NULL && | |
1529 | ppdFindChoice(color_model, "Gray")) | |
1530 | { | |
1531 | color_option = "ColorModel"; | |
1532 | gray_choice = "Gray"; | |
1533 | } | |
1534 | else if ((color_model = ppdFindOption(ppd, "HPColorMode")) != NULL && | |
1535 | ppdFindChoice(color_model, "grayscale")) | |
1536 | { | |
1537 | color_option = "HPColorMode"; | |
1538 | gray_choice = "grayscale"; | |
1539 | } | |
1540 | else if ((color_model = ppdFindOption(ppd, "BRMonoColor")) != NULL && | |
1541 | ppdFindChoice(color_model, "Mono")) | |
1542 | { | |
1543 | color_option = "BRMonoColor"; | |
1544 | gray_choice = "Mono"; | |
1545 | } | |
1546 | else if ((color_model = ppdFindOption(ppd, "CNIJSGrayScale")) != NULL && | |
1547 | ppdFindChoice(color_model, "1")) | |
1548 | { | |
1549 | color_option = "CNIJSGrayScale"; | |
1550 | gray_choice = "1"; | |
1551 | } | |
1552 | else if ((color_model = ppdFindOption(ppd, "HPColorAsGray")) != NULL && | |
1553 | ppdFindChoice(color_model, "True")) | |
1554 | { | |
1555 | color_option = "HPColorAsGray"; | |
1556 | gray_choice = "True"; | |
1557 | } | |
1558 | ||
1559 | if (color_option && gray_choice) | |
1560 | { | |
1561 | /* | |
1562 | * Copy and convert ColorModel (output-mode) data... | |
1563 | */ | |
1564 | ||
1565 | cups_option_t *coption, /* Color option */ | |
1566 | *moption; /* Monochrome option */ | |
1567 | ||
1568 | for (pwg_print_quality = _PWG_PRINT_QUALITY_DRAFT; | |
1569 | pwg_print_quality < _PWG_PRINT_QUALITY_MAX; | |
1570 | pwg_print_quality ++) | |
1571 | { | |
1572 | if (pc->num_presets[_PWG_PRINT_COLOR_MODE_COLOR][pwg_print_quality]) | |
1573 | { | |
1574 | /* | |
1575 | * Copy the color options... | |
1576 | */ | |
1577 | ||
1578 | num_options = pc->num_presets[_PWG_PRINT_COLOR_MODE_COLOR] | |
1579 | [pwg_print_quality]; | |
7e86f2f6 | 1580 | options = calloc(sizeof(cups_option_t), (size_t)num_options); |
f14324a7 MS |
1581 | |
1582 | if (options) | |
1583 | { | |
1584 | for (i = num_options, moption = options, | |
1585 | coption = pc->presets[_PWG_PRINT_COLOR_MODE_COLOR] | |
1586 | [pwg_print_quality]; | |
1587 | i > 0; | |
1588 | i --, moption ++, coption ++) | |
1589 | { | |
1590 | moption->name = _cupsStrRetain(coption->name); | |
1591 | moption->value = _cupsStrRetain(coption->value); | |
1592 | } | |
1593 | ||
1594 | pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][pwg_print_quality] = | |
1595 | num_options; | |
1596 | pc->presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][pwg_print_quality] = | |
1597 | options; | |
1598 | } | |
1599 | } | |
1600 | else if (pwg_print_quality != _PWG_PRINT_QUALITY_NORMAL) | |
1601 | continue; | |
1602 | ||
1603 | /* | |
1604 | * Add the grayscale option to the preset... | |
1605 | */ | |
1606 | ||
1607 | pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME][pwg_print_quality] = | |
1608 | cupsAddOption(color_option, gray_choice, | |
1609 | pc->num_presets[_PWG_PRINT_COLOR_MODE_MONOCHROME] | |
1610 | [pwg_print_quality], | |
1611 | pc->presets[_PWG_PRINT_COLOR_MODE_MONOCHROME] + | |
1612 | pwg_print_quality); | |
1613 | } | |
1614 | } | |
1615 | } | |
1616 | ||
1617 | /* | |
1618 | * Copy and convert Duplex (sides) data... | |
1619 | */ | |
1620 | ||
1621 | if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL) | |
1622 | if ((duplex = ppdFindOption(ppd, "JCLDuplex")) == NULL) | |
1623 | if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL) | |
1624 | if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL) | |
1625 | duplex = ppdFindOption(ppd, "KD03Duplex"); | |
1626 | ||
1627 | if (duplex) | |
1628 | { | |
1629 | pc->sides_option = _cupsStrAlloc(duplex->keyword); | |
1630 | ||
1631 | for (i = duplex->num_choices, choice = duplex->choices; | |
1632 | i > 0; | |
1633 | i --, choice ++) | |
1634 | { | |
88f9aafc MS |
1635 | if ((!_cups_strcasecmp(choice->choice, "None") || |
1636 | !_cups_strcasecmp(choice->choice, "False")) && !pc->sides_1sided) | |
f14324a7 | 1637 | pc->sides_1sided = _cupsStrAlloc(choice->choice); |
88f9aafc MS |
1638 | else if ((!_cups_strcasecmp(choice->choice, "DuplexNoTumble") || |
1639 | !_cups_strcasecmp(choice->choice, "LongEdge") || | |
1640 | !_cups_strcasecmp(choice->choice, "Top")) && !pc->sides_2sided_long) | |
f14324a7 | 1641 | pc->sides_2sided_long = _cupsStrAlloc(choice->choice); |
88f9aafc MS |
1642 | else if ((!_cups_strcasecmp(choice->choice, "DuplexTumble") || |
1643 | !_cups_strcasecmp(choice->choice, "ShortEdge") || | |
1644 | !_cups_strcasecmp(choice->choice, "Bottom")) && | |
f14324a7 MS |
1645 | !pc->sides_2sided_short) |
1646 | pc->sides_2sided_short = _cupsStrAlloc(choice->choice); | |
1647 | } | |
1648 | } | |
1649 | ||
1650 | /* | |
1651 | * Copy filters and pre-filters... | |
1652 | */ | |
1653 | ||
1654 | pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, | |
1655 | (cups_acopy_func_t)_cupsStrAlloc, | |
1656 | (cups_afree_func_t)_cupsStrFree); | |
1657 | ||
1658 | cupsArrayAdd(pc->filters, | |
1659 | "application/vnd.cups-raw application/octet-stream 0 -"); | |
1660 | ||
1661 | if ((ppd_attr = ppdFindAttr(ppd, "cupsFilter2", NULL)) != NULL) | |
1662 | { | |
1663 | do | |
1664 | { | |
1665 | cupsArrayAdd(pc->filters, ppd_attr->value); | |
1666 | } | |
1667 | while ((ppd_attr = ppdFindNextAttr(ppd, "cupsFilter2", NULL)) != NULL); | |
1668 | } | |
1669 | else if (ppd->num_filters > 0) | |
1670 | { | |
1671 | for (i = 0; i < ppd->num_filters; i ++) | |
1672 | cupsArrayAdd(pc->filters, ppd->filters[i]); | |
1673 | } | |
1674 | else | |
1675 | cupsArrayAdd(pc->filters, "application/vnd.cups-postscript 0 -"); | |
1676 | ||
1677 | /* | |
1678 | * See if we have a command filter... | |
1679 | */ | |
1680 | ||
1681 | for (filter = (const char *)cupsArrayFirst(pc->filters); | |
1682 | filter; | |
1683 | filter = (const char *)cupsArrayNext(pc->filters)) | |
88f9aafc | 1684 | if (!_cups_strncasecmp(filter, "application/vnd.cups-command", 28) && |
f14324a7 MS |
1685 | _cups_isspace(filter[28])) |
1686 | break; | |
1687 | ||
1688 | if (!filter && | |
1689 | ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) == NULL || | |
88f9aafc | 1690 | _cups_strcasecmp(ppd_attr->value, "none"))) |
f14324a7 MS |
1691 | { |
1692 | /* | |
1693 | * No command filter and no cupsCommands keyword telling us not to use one. | |
1694 | * See if this is a PostScript printer, and if so add a PostScript command | |
1695 | * filter... | |
1696 | */ | |
1697 | ||
1698 | for (filter = (const char *)cupsArrayFirst(pc->filters); | |
1699 | filter; | |
1700 | filter = (const char *)cupsArrayNext(pc->filters)) | |
88f9aafc | 1701 | if (!_cups_strncasecmp(filter, "application/vnd.cups-postscript", 31) && |
f14324a7 MS |
1702 | _cups_isspace(filter[31])) |
1703 | break; | |
1704 | ||
1705 | if (filter) | |
1706 | cupsArrayAdd(pc->filters, | |
a2326b5b MS |
1707 | "application/vnd.cups-command application/postscript 100 " |
1708 | "commandtops"); | |
f14324a7 MS |
1709 | } |
1710 | ||
1711 | if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL) | |
1712 | { | |
1713 | pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, | |
1714 | (cups_acopy_func_t)_cupsStrAlloc, | |
1715 | (cups_afree_func_t)_cupsStrFree); | |
1716 | ||
1717 | do | |
1718 | { | |
1719 | cupsArrayAdd(pc->prefilters, ppd_attr->value); | |
1720 | } | |
1721 | while ((ppd_attr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL)) != NULL); | |
1722 | } | |
1723 | ||
82f97232 | 1724 | if ((ppd_attr = ppdFindAttr(ppd, "cupsSingleFile", NULL)) != NULL) |
88f9aafc | 1725 | pc->single_file = !_cups_strcasecmp(ppd_attr->value, "true"); |
82f97232 | 1726 | |
f14324a7 MS |
1727 | /* |
1728 | * Copy the product string, if any... | |
1729 | */ | |
1730 | ||
1731 | if (ppd->product) | |
1732 | pc->product = _cupsStrAlloc(ppd->product); | |
1733 | ||
dcb445bc MS |
1734 | /* |
1735 | * Copy finishings mapping data... | |
1736 | */ | |
1737 | ||
1738 | if ((ppd_attr = ppdFindAttr(ppd, "cupsIPPFinishings", NULL)) != NULL) | |
1739 | { | |
1fbd0cab MS |
1740 | /* |
1741 | * Have proper vendor mapping of IPP finishings values to PPD options... | |
1742 | */ | |
1743 | ||
dcb445bc MS |
1744 | pc->finishings = cupsArrayNew3((cups_array_func_t)pwg_compare_finishings, |
1745 | NULL, NULL, 0, NULL, | |
1746 | (cups_afree_func_t)pwg_free_finishings); | |
1747 | ||
1748 | do | |
1749 | { | |
1750 | if ((finishings = calloc(1, sizeof(_pwg_finishings_t))) == NULL) | |
1751 | goto create_error; | |
1752 | ||
7e86f2f6 | 1753 | finishings->value = (ipp_finishings_t)atoi(ppd_attr->spec); |
dcb445bc MS |
1754 | finishings->num_options = _ppdParseOptions(ppd_attr->value, 0, |
1755 | &(finishings->options), | |
1756 | _PPD_PARSE_OPTIONS); | |
1757 | ||
1758 | cupsArrayAdd(pc->finishings, finishings); | |
1759 | } | |
1760 | while ((ppd_attr = ppdFindNextAttr(ppd, "cupsIPPFinishings", | |
1761 | NULL)) != NULL); | |
1762 | } | |
1fbd0cab MS |
1763 | else |
1764 | { | |
1765 | /* | |
1766 | * No IPP mapping data, try to map common/standard PPD keywords... | |
1767 | */ | |
1768 | ||
1fbd0cab MS |
1769 | pc->finishings = cupsArrayNew3((cups_array_func_t)pwg_compare_finishings, NULL, NULL, 0, NULL, (cups_afree_func_t)pwg_free_finishings); |
1770 | ||
1771 | if ((ppd_option = ppdFindOption(ppd, "StapleLocation")) != NULL) | |
1772 | { | |
1773 | /* | |
1774 | * Add staple finishings... | |
1775 | */ | |
1776 | ||
1777 | if (ppdFindChoice(ppd_option, "SinglePortrait")) | |
1778 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_STAPLE_TOP_LEFT, "StapleLocation", "SinglePortrait"); | |
1779 | if (ppdFindChoice(ppd_option, "UpperLeft")) /* Ricoh extension */ | |
1780 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_STAPLE_TOP_LEFT, "StapleLocation", "UpperLeft"); | |
1781 | if (ppdFindChoice(ppd_option, "UpperRight")) /* Ricoh extension */ | |
1782 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_STAPLE_TOP_RIGHT, "StapleLocation", "UpperRight"); | |
1783 | if (ppdFindChoice(ppd_option, "SingleLandscape")) | |
1784 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_STAPLE_BOTTOM_LEFT, "StapleLocation", "SingleLandscape"); | |
1785 | if (ppdFindChoice(ppd_option, "DualLandscape")) | |
1786 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_STAPLE_DUAL_LEFT, "StapleLocation", "DualLandscape"); | |
1787 | } | |
1788 | ||
1789 | if ((ppd_option = ppdFindOption(ppd, "RIPunch")) != NULL) | |
1790 | { | |
1791 | /* | |
1792 | * Add (Ricoh) punch finishings... | |
1793 | */ | |
1794 | ||
1795 | if (ppdFindChoice(ppd_option, "Left2")) | |
1796 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_DUAL_LEFT, "RIPunch", "Left2"); | |
1797 | if (ppdFindChoice(ppd_option, "Left3")) | |
1798 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_TRIPLE_LEFT, "RIPunch", "Left3"); | |
1799 | if (ppdFindChoice(ppd_option, "Left4")) | |
1800 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_QUAD_LEFT, "RIPunch", "Left4"); | |
1801 | if (ppdFindChoice(ppd_option, "Right2")) | |
1802 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_DUAL_RIGHT, "RIPunch", "Right2"); | |
1803 | if (ppdFindChoice(ppd_option, "Right3")) | |
1804 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT, "RIPunch", "Right3"); | |
1805 | if (ppdFindChoice(ppd_option, "Right4")) | |
1806 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_QUAD_RIGHT, "RIPunch", "Right4"); | |
1807 | if (ppdFindChoice(ppd_option, "Upper2")) | |
1808 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_DUAL_TOP, "RIPunch", "Upper2"); | |
1809 | if (ppdFindChoice(ppd_option, "Upper3")) | |
1810 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_TRIPLE_TOP, "RIPunch", "Upper3"); | |
1811 | if (ppdFindChoice(ppd_option, "Upper4")) | |
1812 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_PUNCH_QUAD_TOP, "RIPunch", "Upper4"); | |
1813 | } | |
1814 | ||
1815 | if ((ppd_option = ppdFindOption(ppd, "BindEdge")) != NULL) | |
1816 | { | |
1817 | /* | |
1818 | * Add bind finishings... | |
1819 | */ | |
1820 | ||
1821 | if (ppdFindChoice(ppd_option, "Left")) | |
1822 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_BIND_LEFT, "BindEdge", "Left"); | |
1823 | if (ppdFindChoice(ppd_option, "Right")) | |
1824 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_BIND_RIGHT, "BindEdge", "Right"); | |
1825 | if (ppdFindChoice(ppd_option, "Top")) | |
1826 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_BIND_TOP, "BindEdge", "Top"); | |
1827 | if (ppdFindChoice(ppd_option, "Bottom")) | |
1828 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_BIND_BOTTOM, "BindEdge", "Bottom"); | |
1829 | } | |
1830 | ||
1831 | if ((ppd_option = ppdFindOption(ppd, "FoldType")) != NULL) | |
1832 | { | |
1833 | /* | |
1834 | * Add (Adobe) fold finishings... | |
1835 | */ | |
1836 | ||
1837 | if (ppdFindChoice(ppd_option, "ZFold")) | |
1838 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_Z, "FoldType", "ZFold"); | |
1839 | if (ppdFindChoice(ppd_option, "Saddle")) | |
1840 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_HALF, "FoldType", "Saddle"); | |
1841 | if (ppdFindChoice(ppd_option, "DoubleGate")) | |
1842 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_DOUBLE_GATE, "FoldType", "DoubleGate"); | |
1843 | if (ppdFindChoice(ppd_option, "LeftGate")) | |
1844 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_LEFT_GATE, "FoldType", "LeftGate"); | |
1845 | if (ppdFindChoice(ppd_option, "RightGate")) | |
1846 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_RIGHT_GATE, "FoldType", "RightGate"); | |
1847 | if (ppdFindChoice(ppd_option, "Letter")) | |
1848 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_LETTER, "FoldType", "Letter"); | |
1849 | if (ppdFindChoice(ppd_option, "XFold")) | |
1850 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_POSTER, "FoldType", "XFold"); | |
1851 | } | |
1852 | ||
1853 | if ((ppd_option = ppdFindOption(ppd, "RIFoldType")) != NULL) | |
1854 | { | |
1855 | /* | |
1856 | * Add (Ricoh) fold finishings... | |
1857 | */ | |
1858 | ||
1859 | if (ppdFindChoice(ppd_option, "OutsideTwoFold")) | |
1860 | pwg_add_finishing(pc->finishings, IPP_FINISHINGS_FOLD_LETTER, "RIFoldType", "OutsideTwoFold"); | |
1861 | } | |
1862 | ||
1863 | if (cupsArrayCount(pc->finishings) == 0) | |
1864 | { | |
1865 | cupsArrayDelete(pc->finishings); | |
1866 | pc->finishings = NULL; | |
1867 | } | |
1868 | } | |
dcb445bc | 1869 | |
4f63d6cd MS |
1870 | if ((ppd_option = ppdFindOption(ppd, "cupsFinishingTemplate")) != NULL) |
1871 | { | |
1872 | pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree); | |
1873 | ||
1874 | for (choice = ppd_option->choices, i = ppd_option->num_choices; i > 0; choice ++, i --) | |
2fa1ba3c | 1875 | { |
4f63d6cd | 1876 | cupsArrayAdd(pc->templates, (void *)choice->choice); |
2fa1ba3c MS |
1877 | |
1878 | /* | |
1879 | * Add localized text for PWG keyword to message catalog... | |
1880 | */ | |
1881 | ||
1882 | snprintf(msg_id, sizeof(msg_id), "finishing-template.%s", choice->choice); | |
1883 | pwg_add_message(pc->strings, msg_id, choice->text); | |
1884 | } | |
4f63d6cd MS |
1885 | } |
1886 | ||
3e7fe0ca MS |
1887 | /* |
1888 | * Max copies... | |
1889 | */ | |
1890 | ||
1891 | if ((ppd_attr = ppdFindAttr(ppd, "cupsMaxCopies", NULL)) != NULL) | |
1892 | pc->max_copies = atoi(ppd_attr->value); | |
1893 | else if (ppd->manual_copies) | |
1894 | pc->max_copies = 1; | |
1895 | else | |
1896 | pc->max_copies = 9999; | |
1897 | ||
5a9febac | 1898 | /* |
a469f8a5 MS |
1899 | * cupsChargeInfoURI, cupsJobAccountId, cupsJobAccountingUserId, |
1900 | * cupsJobPassword, and cupsMandatory. | |
5a9febac MS |
1901 | */ |
1902 | ||
a469f8a5 MS |
1903 | if ((ppd_attr = ppdFindAttr(ppd, "cupsChargeInfoURI", NULL)) != NULL) |
1904 | pc->charge_info_uri = _cupsStrAlloc(ppd_attr->value); | |
1905 | ||
5a9febac MS |
1906 | if ((ppd_attr = ppdFindAttr(ppd, "cupsJobAccountId", NULL)) != NULL) |
1907 | pc->account_id = !_cups_strcasecmp(ppd_attr->value, "true"); | |
1908 | ||
1909 | if ((ppd_attr = ppdFindAttr(ppd, "cupsJobAccountingUserId", NULL)) != NULL) | |
1910 | pc->accounting_user_id = !_cups_strcasecmp(ppd_attr->value, "true"); | |
1911 | ||
1912 | if ((ppd_attr = ppdFindAttr(ppd, "cupsJobPassword", NULL)) != NULL) | |
1913 | pc->password = _cupsStrAlloc(ppd_attr->value); | |
1914 | ||
1915 | if ((ppd_attr = ppdFindAttr(ppd, "cupsMandatory", NULL)) != NULL) | |
1916 | pc->mandatory = _cupsArrayNewStrings(ppd_attr->value, ' '); | |
1917 | ||
c1420c87 MS |
1918 | /* |
1919 | * Support files... | |
1920 | */ | |
1921 | ||
1922 | pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, | |
1923 | (cups_acopy_func_t)_cupsStrAlloc, | |
1924 | (cups_afree_func_t)_cupsStrFree); | |
1925 | ||
1926 | for (ppd_attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); | |
1927 | ppd_attr; | |
1928 | ppd_attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) | |
1929 | cupsArrayAdd(pc->support_files, ppd_attr->value); | |
1930 | ||
1931 | if ((ppd_attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL)) != NULL) | |
1932 | cupsArrayAdd(pc->support_files, ppd_attr->value); | |
1933 | ||
f14324a7 MS |
1934 | /* |
1935 | * Return the cache data... | |
1936 | */ | |
1937 | ||
1938 | return (pc); | |
1939 | ||
1940 | /* | |
1941 | * If we get here we need to destroy the PWG mapping data and return NULL... | |
1942 | */ | |
1943 | ||
1944 | create_error: | |
1945 | ||
cb7f98ee | 1946 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Out of memory."), 1); |
f14324a7 MS |
1947 | _ppdCacheDestroy(pc); |
1948 | ||
1949 | return (NULL); | |
1950 | } | |
1951 | ||
1952 | ||
1953 | /* | |
1954 | * '_ppdCacheDestroy()' - Free all memory used for PWG mapping data. | |
1955 | */ | |
1956 | ||
1957 | void | |
1958 | _ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */ | |
1959 | { | |
1960 | int i; /* Looping var */ | |
6961465f MS |
1961 | pwg_map_t *map; /* Current map */ |
1962 | pwg_size_t *size; /* Current size */ | |
f14324a7 MS |
1963 | |
1964 | ||
1965 | /* | |
1966 | * Range check input... | |
1967 | */ | |
1968 | ||
1969 | if (!pc) | |
1970 | return; | |
1971 | ||
1972 | /* | |
1973 | * Free memory as needed... | |
1974 | */ | |
1975 | ||
1976 | if (pc->bins) | |
1977 | { | |
1978 | for (i = pc->num_bins, map = pc->bins; i > 0; i --, map ++) | |
1979 | { | |
1980 | _cupsStrFree(map->pwg); | |
1981 | _cupsStrFree(map->ppd); | |
1982 | } | |
1983 | ||
1984 | free(pc->bins); | |
1985 | } | |
1986 | ||
1987 | if (pc->sizes) | |
1988 | { | |
1989 | for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) | |
1990 | { | |
1991 | _cupsStrFree(size->map.pwg); | |
1992 | _cupsStrFree(size->map.ppd); | |
1993 | } | |
1994 | ||
1995 | free(pc->sizes); | |
1996 | } | |
1997 | ||
1998 | if (pc->source_option) | |
1999 | _cupsStrFree(pc->source_option); | |
2000 | ||
2001 | if (pc->sources) | |
2002 | { | |
2003 | for (i = pc->num_sources, map = pc->sources; i > 0; i --, map ++) | |
2004 | { | |
2005 | _cupsStrFree(map->pwg); | |
2006 | _cupsStrFree(map->ppd); | |
2007 | } | |
2008 | ||
2009 | free(pc->sources); | |
2010 | } | |
2011 | ||
2012 | if (pc->types) | |
2013 | { | |
2014 | for (i = pc->num_types, map = pc->types; i > 0; i --, map ++) | |
2015 | { | |
2016 | _cupsStrFree(map->pwg); | |
2017 | _cupsStrFree(map->ppd); | |
2018 | } | |
2019 | ||
2020 | free(pc->types); | |
2021 | } | |
2022 | ||
2023 | if (pc->custom_max_keyword) | |
2024 | _cupsStrFree(pc->custom_max_keyword); | |
2025 | ||
2026 | if (pc->custom_min_keyword) | |
2027 | _cupsStrFree(pc->custom_min_keyword); | |
2028 | ||
2029 | _cupsStrFree(pc->product); | |
2030 | cupsArrayDelete(pc->filters); | |
2031 | cupsArrayDelete(pc->prefilters); | |
dcb445bc | 2032 | cupsArrayDelete(pc->finishings); |
f14324a7 | 2033 | |
a469f8a5 | 2034 | _cupsStrFree(pc->charge_info_uri); |
5a9febac MS |
2035 | _cupsStrFree(pc->password); |
2036 | ||
2037 | cupsArrayDelete(pc->mandatory); | |
2038 | ||
c1420c87 MS |
2039 | cupsArrayDelete(pc->support_files); |
2040 | ||
2fa1ba3c MS |
2041 | cupsArrayDelete(pc->strings); |
2042 | ||
f14324a7 MS |
2043 | free(pc); |
2044 | } | |
2045 | ||
2046 | ||
2047 | /* | |
2048 | * '_ppdCacheGetBin()' - Get the PWG output-bin keyword associated with a PPD | |
2049 | * OutputBin. | |
2050 | */ | |
2051 | ||
2052 | const char * /* O - output-bin or NULL */ | |
2053 | _ppdCacheGetBin( | |
2054 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2055 | const char *output_bin) /* I - PPD OutputBin string */ | |
2056 | { | |
2057 | int i; /* Looping var */ | |
2058 | ||
2059 | ||
2060 | /* | |
2061 | * Range check input... | |
2062 | */ | |
2063 | ||
2064 | if (!pc || !output_bin) | |
2065 | return (NULL); | |
2066 | ||
2067 | /* | |
2068 | * Look up the OutputBin string... | |
2069 | */ | |
2070 | ||
2071 | ||
2072 | for (i = 0; i < pc->num_bins; i ++) | |
88f9aafc | 2073 | if (!_cups_strcasecmp(output_bin, pc->bins[i].ppd)) |
f14324a7 MS |
2074 | return (pc->bins[i].pwg); |
2075 | ||
2076 | return (NULL); | |
2077 | } | |
2078 | ||
2079 | ||
dcb445bc MS |
2080 | /* |
2081 | * '_ppdCacheGetFinishingOptions()' - Get PPD finishing options for the given | |
2082 | * IPP finishings value(s). | |
2083 | */ | |
2084 | ||
2085 | int /* O - New number of options */ | |
2086 | _ppdCacheGetFinishingOptions( | |
cb7f98ee MS |
2087 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ |
2088 | ipp_t *job, /* I - Job attributes or NULL */ | |
2089 | ipp_finishings_t value, /* I - IPP finishings value of IPP_FINISHINGS_NONE */ | |
2090 | int num_options, /* I - Number of options */ | |
2091 | cups_option_t **options) /* IO - Options */ | |
dcb445bc MS |
2092 | { |
2093 | int i; /* Looping var */ | |
2094 | _pwg_finishings_t *f, /* PWG finishings options */ | |
2095 | key; /* Search key */ | |
2096 | ipp_attribute_t *attr; /* Finishings attribute */ | |
2097 | cups_option_t *option; /* Current finishings option */ | |
2098 | ||
2099 | ||
2100 | /* | |
2101 | * Range check input... | |
2102 | */ | |
2103 | ||
2104 | if (!pc || cupsArrayCount(pc->finishings) == 0 || !options || | |
2105 | (!job && value == IPP_FINISHINGS_NONE)) | |
2106 | return (num_options); | |
2107 | ||
2108 | /* | |
2109 | * Apply finishing options... | |
2110 | */ | |
2111 | ||
2112 | if (job && (attr = ippFindAttribute(job, "finishings", IPP_TAG_ENUM)) != NULL) | |
2113 | { | |
2114 | int num_values = ippGetCount(attr); /* Number of values */ | |
2115 | ||
2116 | for (i = 0; i < num_values; i ++) | |
2117 | { | |
7e86f2f6 | 2118 | key.value = (ipp_finishings_t)ippGetInteger(attr, i); |
dcb445bc MS |
2119 | |
2120 | if ((f = cupsArrayFind(pc->finishings, &key)) != NULL) | |
2121 | { | |
2122 | int j; /* Another looping var */ | |
2123 | ||
2124 | for (j = f->num_options, option = f->options; j > 0; j --, option ++) | |
2125 | num_options = cupsAddOption(option->name, option->value, | |
2126 | num_options, options); | |
2127 | } | |
2128 | } | |
2129 | } | |
2130 | else if (value != IPP_FINISHINGS_NONE) | |
2131 | { | |
2132 | key.value = value; | |
2133 | ||
2134 | if ((f = cupsArrayFind(pc->finishings, &key)) != NULL) | |
2135 | { | |
2136 | int j; /* Another looping var */ | |
2137 | ||
2138 | for (j = f->num_options, option = f->options; j > 0; j --, option ++) | |
2139 | num_options = cupsAddOption(option->name, option->value, | |
2140 | num_options, options); | |
2141 | } | |
2142 | } | |
2143 | ||
2144 | return (num_options); | |
2145 | } | |
2146 | ||
2147 | ||
2148 | /* | |
2149 | * '_ppdCacheGetFinishingValues()' - Get IPP finishings value(s) from the given | |
2150 | * PPD options. | |
2151 | */ | |
2152 | ||
2153 | int /* O - Number of finishings values */ | |
2154 | _ppdCacheGetFinishingValues( | |
117bf0d1 | 2155 | ppd_file_t *ppd, /* I - Marked PPD file */ |
dcb445bc | 2156 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ |
dcb445bc MS |
2157 | int max_values, /* I - Maximum number of finishings values */ |
2158 | int *values) /* O - Finishings values */ | |
2159 | { | |
2160 | int i, /* Looping var */ | |
2161 | num_values = 0; /* Number of values */ | |
2162 | _pwg_finishings_t *f; /* Current finishings option */ | |
2163 | cups_option_t *option; /* Current option */ | |
117bf0d1 | 2164 | ppd_choice_t *choice; /* Marked PPD choice */ |
dcb445bc MS |
2165 | |
2166 | ||
2167 | /* | |
2168 | * Range check input... | |
2169 | */ | |
2170 | ||
117bf0d1 | 2171 | DEBUG_printf(("_ppdCacheGetFinishingValues(ppd=%p, pc=%p, max_values=%d, values=%p)", ppd, pc, max_values, values)); |
b2b9911d | 2172 | |
117bf0d1 | 2173 | if (!ppd || !pc || max_values < 1 || !values) |
b2b9911d MS |
2174 | { |
2175 | DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0."); | |
dcb445bc | 2176 | return (0); |
b2b9911d | 2177 | } |
e44bdfe7 MS |
2178 | else if (!pc->finishings) |
2179 | { | |
2180 | DEBUG_puts("_ppdCacheGetFinishingValues: No finishings support, returning 0."); | |
2181 | return (0); | |
2182 | } | |
dcb445bc MS |
2183 | |
2184 | /* | |
2185 | * Go through the finishings options and see what is set... | |
2186 | */ | |
2187 | ||
2188 | for (f = (_pwg_finishings_t *)cupsArrayFirst(pc->finishings); | |
2189 | f; | |
2190 | f = (_pwg_finishings_t *)cupsArrayNext(pc->finishings)) | |
2191 | { | |
b2b9911d MS |
2192 | DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f->value, ippEnumString("finishings", f->value))); |
2193 | ||
dcb445bc | 2194 | for (i = f->num_options, option = f->options; i > 0; i --, option ++) |
b2b9911d MS |
2195 | { |
2196 | DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option->name, option->value)); | |
2197 | ||
117bf0d1 | 2198 | if ((choice = ppdFindMarkedChoice(ppd, option->name)) == NULL || _cups_strcasecmp(option->value, choice->choice)) |
b2b9911d MS |
2199 | { |
2200 | DEBUG_puts("_ppdCacheGetFinishingValues: NO"); | |
dcb445bc | 2201 | break; |
b2b9911d MS |
2202 | } |
2203 | } | |
dcb445bc MS |
2204 | |
2205 | if (i == 0) | |
2206 | { | |
e44bdfe7 | 2207 | DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d (%s)", f->value, ippEnumString("finishings", f->value))); |
b2b9911d | 2208 | |
dcb445bc MS |
2209 | values[num_values ++] = f->value; |
2210 | ||
2211 | if (num_values >= max_values) | |
2212 | break; | |
2213 | } | |
2214 | } | |
2215 | ||
e44bdfe7 MS |
2216 | if (num_values == 0) |
2217 | { | |
2218 | /* | |
2219 | * Always have at least "finishings" = 'none'... | |
2220 | */ | |
2221 | ||
2222 | DEBUG_puts("_ppdCacheGetFinishingValues: Adding 3 (none)."); | |
2223 | values[0] = IPP_FINISHINGS_NONE; | |
2224 | num_values ++; | |
2225 | } | |
2226 | ||
b2b9911d MS |
2227 | DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values)); |
2228 | ||
dcb445bc MS |
2229 | return (num_values); |
2230 | } | |
2231 | ||
2232 | ||
f14324a7 MS |
2233 | /* |
2234 | * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job | |
2235 | * attributes or a keyword string. | |
2236 | */ | |
2237 | ||
2238 | const char * /* O - PPD InputSlot or NULL */ | |
2239 | _ppdCacheGetInputSlot( | |
2240 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2241 | ipp_t *job, /* I - Job attributes or NULL */ | |
2242 | const char *keyword) /* I - Keyword string or NULL */ | |
2243 | { | |
2244 | /* | |
2245 | * Range check input... | |
2246 | */ | |
2247 | ||
2248 | if (!pc || pc->num_sources == 0 || (!job && !keyword)) | |
2249 | return (NULL); | |
2250 | ||
2251 | if (job && !keyword) | |
2252 | { | |
2253 | /* | |
2254 | * Lookup the media-col attribute and any media-source found there... | |
2255 | */ | |
2256 | ||
2257 | ipp_attribute_t *media_col, /* media-col attribute */ | |
2258 | *media_source; /* media-source attribute */ | |
6961465f | 2259 | pwg_size_t size; /* Dimensional size */ |
f14324a7 MS |
2260 | int margins_set; /* Were the margins set? */ |
2261 | ||
2262 | media_col = ippFindAttribute(job, "media-col", IPP_TAG_BEGIN_COLLECTION); | |
2263 | if (media_col && | |
dcb445bc | 2264 | (media_source = ippFindAttribute(ippGetCollection(media_col, 0), |
f14324a7 MS |
2265 | "media-source", |
2266 | IPP_TAG_KEYWORD)) != NULL) | |
2267 | { | |
2268 | /* | |
2269 | * Use the media-source value from media-col... | |
2270 | */ | |
2271 | ||
dcb445bc | 2272 | keyword = ippGetString(media_source, 0, NULL); |
f14324a7 | 2273 | } |
6961465f | 2274 | else if (pwgInitSize(&size, job, &margins_set)) |
f14324a7 MS |
2275 | { |
2276 | /* | |
2277 | * For media <= 5x7, look for a photo tray... | |
2278 | */ | |
2279 | ||
2280 | if (size.width <= (5 * 2540) && size.length <= (7 * 2540)) | |
2281 | keyword = "photo"; | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | if (keyword) | |
2286 | { | |
2287 | int i; /* Looping var */ | |
2288 | ||
2289 | for (i = 0; i < pc->num_sources; i ++) | |
88f9aafc | 2290 | if (!_cups_strcasecmp(keyword, pc->sources[i].pwg)) |
f14324a7 MS |
2291 | return (pc->sources[i].ppd); |
2292 | } | |
2293 | ||
2294 | return (NULL); | |
2295 | } | |
2296 | ||
2297 | ||
2298 | /* | |
2299 | * '_ppdCacheGetMediaType()' - Get the PPD MediaType associated with the job | |
2300 | * attributes or a keyword string. | |
2301 | */ | |
2302 | ||
2303 | const char * /* O - PPD MediaType or NULL */ | |
2304 | _ppdCacheGetMediaType( | |
2305 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2306 | ipp_t *job, /* I - Job attributes or NULL */ | |
2307 | const char *keyword) /* I - Keyword string or NULL */ | |
2308 | { | |
2309 | /* | |
2310 | * Range check input... | |
2311 | */ | |
2312 | ||
2313 | if (!pc || pc->num_types == 0 || (!job && !keyword)) | |
2314 | return (NULL); | |
2315 | ||
2316 | if (job && !keyword) | |
2317 | { | |
2318 | /* | |
2319 | * Lookup the media-col attribute and any media-source found there... | |
2320 | */ | |
2321 | ||
2322 | ipp_attribute_t *media_col, /* media-col attribute */ | |
2323 | *media_type; /* media-type attribute */ | |
2324 | ||
2325 | media_col = ippFindAttribute(job, "media-col", IPP_TAG_BEGIN_COLLECTION); | |
2326 | if (media_col) | |
2327 | { | |
2328 | if ((media_type = ippFindAttribute(media_col->values[0].collection, | |
2329 | "media-type", | |
2330 | IPP_TAG_KEYWORD)) == NULL) | |
2331 | media_type = ippFindAttribute(media_col->values[0].collection, | |
2332 | "media-type", IPP_TAG_NAME); | |
2333 | ||
2334 | if (media_type) | |
2335 | keyword = media_type->values[0].string.text; | |
2336 | } | |
2337 | } | |
2338 | ||
2339 | if (keyword) | |
2340 | { | |
2341 | int i; /* Looping var */ | |
2342 | ||
2343 | for (i = 0; i < pc->num_types; i ++) | |
88f9aafc | 2344 | if (!_cups_strcasecmp(keyword, pc->types[i].pwg)) |
f14324a7 MS |
2345 | return (pc->types[i].ppd); |
2346 | } | |
2347 | ||
2348 | return (NULL); | |
2349 | } | |
2350 | ||
2351 | ||
2352 | /* | |
2353 | * '_ppdCacheGetOutputBin()' - Get the PPD OutputBin associated with the keyword | |
2354 | * string. | |
2355 | */ | |
2356 | ||
2357 | const char * /* O - PPD OutputBin or NULL */ | |
2358 | _ppdCacheGetOutputBin( | |
2359 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2360 | const char *output_bin) /* I - Keyword string */ | |
2361 | { | |
2362 | int i; /* Looping var */ | |
2363 | ||
2364 | ||
2365 | /* | |
2366 | * Range check input... | |
2367 | */ | |
2368 | ||
2369 | if (!pc || !output_bin) | |
2370 | return (NULL); | |
2371 | ||
2372 | /* | |
2373 | * Look up the OutputBin string... | |
2374 | */ | |
2375 | ||
2376 | ||
2377 | for (i = 0; i < pc->num_bins; i ++) | |
88f9aafc | 2378 | if (!_cups_strcasecmp(output_bin, pc->bins[i].pwg)) |
f14324a7 MS |
2379 | return (pc->bins[i].ppd); |
2380 | ||
2381 | return (NULL); | |
2382 | } | |
2383 | ||
2384 | ||
2385 | /* | |
2386 | * '_ppdCacheGetPageSize()' - Get the PPD PageSize associated with the job | |
2387 | * attributes or a keyword string. | |
2388 | */ | |
2389 | ||
2390 | const char * /* O - PPD PageSize or NULL */ | |
2391 | _ppdCacheGetPageSize( | |
2392 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2393 | ipp_t *job, /* I - Job attributes or NULL */ | |
2394 | const char *keyword, /* I - Keyword string or NULL */ | |
2395 | int *exact) /* O - 1 if exact match, 0 otherwise */ | |
2396 | { | |
2397 | int i; /* Looping var */ | |
6961465f | 2398 | pwg_size_t *size, /* Current size */ |
f14324a7 MS |
2399 | *closest, /* Closest size */ |
2400 | jobsize; /* Size data from job */ | |
2401 | int margins_set, /* Were the margins set? */ | |
2402 | dwidth, /* Difference in width */ | |
2403 | dlength, /* Difference in length */ | |
2404 | dleft, /* Difference in left margins */ | |
2405 | dright, /* Difference in right margins */ | |
2406 | dbottom, /* Difference in bottom margins */ | |
2407 | dtop, /* Difference in top margins */ | |
2408 | dmin, /* Minimum difference */ | |
2409 | dclosest; /* Closest difference */ | |
2410 | const char *ppd_name; /* PPD media name */ | |
2411 | ||
2412 | ||
2413 | DEBUG_printf(("_ppdCacheGetPageSize(pc=%p, job=%p, keyword=\"%s\", exact=%p)", | |
2414 | pc, job, keyword, exact)); | |
2415 | ||
2416 | /* | |
2417 | * Range check input... | |
2418 | */ | |
2419 | ||
2420 | if (!pc || (!job && !keyword)) | |
2421 | return (NULL); | |
2422 | ||
2423 | if (exact) | |
2424 | *exact = 0; | |
2425 | ||
2426 | ppd_name = keyword; | |
2427 | ||
2428 | if (job) | |
2429 | { | |
2430 | /* | |
2431 | * Try getting the PPD media name from the job attributes... | |
2432 | */ | |
2433 | ||
2434 | ipp_attribute_t *attr; /* Job attribute */ | |
2435 | ||
2436 | if ((attr = ippFindAttribute(job, "PageSize", IPP_TAG_ZERO)) == NULL) | |
2437 | if ((attr = ippFindAttribute(job, "PageRegion", IPP_TAG_ZERO)) == NULL) | |
2438 | attr = ippFindAttribute(job, "media", IPP_TAG_ZERO); | |
2439 | ||
2440 | #ifdef DEBUG | |
2441 | if (attr) | |
2442 | DEBUG_printf(("1_ppdCacheGetPageSize: Found attribute %s (%s)", | |
2443 | attr->name, ippTagString(attr->value_tag))); | |
2444 | else | |
2445 | DEBUG_puts("1_ppdCacheGetPageSize: Did not find media attribute."); | |
2446 | #endif /* DEBUG */ | |
2447 | ||
2448 | if (attr && (attr->value_tag == IPP_TAG_NAME || | |
2449 | attr->value_tag == IPP_TAG_KEYWORD)) | |
2450 | ppd_name = attr->values[0].string.text; | |
2451 | } | |
2452 | ||
2453 | DEBUG_printf(("1_ppdCacheGetPageSize: ppd_name=\"%s\"", ppd_name)); | |
2454 | ||
2455 | if (ppd_name) | |
2456 | { | |
2457 | /* | |
2458 | * Try looking up the named PPD size first... | |
2459 | */ | |
2460 | ||
2461 | for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) | |
2462 | { | |
2463 | DEBUG_printf(("2_ppdCacheGetPageSize: size[%d]=[\"%s\" \"%s\"]", | |
2464 | (int)(size - pc->sizes), size->map.pwg, size->map.ppd)); | |
2465 | ||
88f9aafc MS |
2466 | if (!_cups_strcasecmp(ppd_name, size->map.ppd) || |
2467 | !_cups_strcasecmp(ppd_name, size->map.pwg)) | |
f14324a7 MS |
2468 | { |
2469 | if (exact) | |
2470 | *exact = 1; | |
2471 | ||
2472 | DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", ppd_name)); | |
2473 | ||
2474 | return (size->map.ppd); | |
2475 | } | |
2476 | } | |
2477 | } | |
2478 | ||
2479 | if (job && !keyword) | |
2480 | { | |
2481 | /* | |
2482 | * Get the size using media-col or media, with the preference being | |
2483 | * media-col. | |
2484 | */ | |
2485 | ||
6961465f | 2486 | if (!pwgInitSize(&jobsize, job, &margins_set)) |
f14324a7 MS |
2487 | return (NULL); |
2488 | } | |
2489 | else | |
2490 | { | |
2491 | /* | |
2492 | * Get the size using a media keyword... | |
2493 | */ | |
2494 | ||
6961465f | 2495 | pwg_media_t *media; /* Media definition */ |
f14324a7 MS |
2496 | |
2497 | ||
6961465f MS |
2498 | if ((media = pwgMediaForPWG(keyword)) == NULL) |
2499 | if ((media = pwgMediaForLegacy(keyword)) == NULL) | |
2500 | if ((media = pwgMediaForPPD(keyword)) == NULL) | |
f14324a7 MS |
2501 | return (NULL); |
2502 | ||
2503 | jobsize.width = media->width; | |
2504 | jobsize.length = media->length; | |
2505 | margins_set = 0; | |
2506 | } | |
2507 | ||
2508 | /* | |
2509 | * Now that we have the dimensions and possibly the margins, look at the | |
2510 | * available sizes and find the match... | |
2511 | */ | |
2512 | ||
2513 | closest = NULL; | |
2514 | dclosest = 999999999; | |
2515 | ||
88f9aafc MS |
2516 | if (!ppd_name || _cups_strncasecmp(ppd_name, "Custom.", 7) || |
2517 | _cups_strncasecmp(ppd_name, "custom_", 7)) | |
f14324a7 MS |
2518 | { |
2519 | for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) | |
2520 | { | |
2521 | /* | |
2522 | * Adobe uses a size matching algorithm with an epsilon of 5 points, which | |
2523 | * is just about 176/2540ths... | |
2524 | */ | |
2525 | ||
2526 | dwidth = size->width - jobsize.width; | |
2527 | dlength = size->length - jobsize.length; | |
2528 | ||
2529 | if (dwidth <= -176 || dwidth >= 176 || dlength <= -176 || dlength >= 176) | |
2530 | continue; | |
2531 | ||
2532 | if (margins_set) | |
2533 | { | |
2534 | /* | |
2535 | * Use a tighter epsilon of 1 point (35/2540ths) for margins... | |
2536 | */ | |
2537 | ||
2538 | dleft = size->left - jobsize.left; | |
2539 | dright = size->right - jobsize.right; | |
2540 | dtop = size->top - jobsize.top; | |
2541 | dbottom = size->bottom - jobsize.bottom; | |
2542 | ||
2543 | if (dleft <= -35 || dleft >= 35 || dright <= -35 || dright >= 35 || | |
2544 | dtop <= -35 || dtop >= 35 || dbottom <= -35 || dbottom >= 35) | |
2545 | { | |
2546 | dleft = dleft < 0 ? -dleft : dleft; | |
2547 | dright = dright < 0 ? -dright : dright; | |
2548 | dbottom = dbottom < 0 ? -dbottom : dbottom; | |
2549 | dtop = dtop < 0 ? -dtop : dtop; | |
2550 | dmin = dleft + dright + dbottom + dtop; | |
2551 | ||
2552 | if (dmin < dclosest) | |
2553 | { | |
2554 | dclosest = dmin; | |
2555 | closest = size; | |
2556 | } | |
2557 | ||
2558 | continue; | |
2559 | } | |
2560 | } | |
2561 | ||
2562 | if (exact) | |
2563 | *exact = 1; | |
2564 | ||
2565 | DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\"", size->map.ppd)); | |
2566 | ||
2567 | return (size->map.ppd); | |
2568 | } | |
2569 | } | |
2570 | ||
2571 | if (closest) | |
2572 | { | |
2573 | DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (closest)", | |
2574 | closest->map.ppd)); | |
2575 | ||
2576 | return (closest->map.ppd); | |
2577 | } | |
2578 | ||
2579 | /* | |
2580 | * If we get here we need to check for custom page size support... | |
2581 | */ | |
2582 | ||
2583 | if (jobsize.width >= pc->custom_min_width && | |
2584 | jobsize.width <= pc->custom_max_width && | |
2585 | jobsize.length >= pc->custom_min_length && | |
2586 | jobsize.length <= pc->custom_max_length) | |
2587 | { | |
2588 | /* | |
2589 | * In range, format as Custom.WWWWxLLLL (points). | |
2590 | */ | |
2591 | ||
2592 | snprintf(pc->custom_ppd_size, sizeof(pc->custom_ppd_size), "Custom.%dx%d", | |
6961465f | 2593 | (int)PWG_TO_POINTS(jobsize.width), (int)PWG_TO_POINTS(jobsize.length)); |
f14324a7 MS |
2594 | |
2595 | if (margins_set && exact) | |
2596 | { | |
2597 | dleft = pc->custom_size.left - jobsize.left; | |
2598 | dright = pc->custom_size.right - jobsize.right; | |
2599 | dtop = pc->custom_size.top - jobsize.top; | |
2600 | dbottom = pc->custom_size.bottom - jobsize.bottom; | |
2601 | ||
2602 | if (dleft > -35 && dleft < 35 && dright > -35 && dright < 35 && | |
2603 | dtop > -35 && dtop < 35 && dbottom > -35 && dbottom < 35) | |
2604 | *exact = 1; | |
2605 | } | |
2606 | else if (exact) | |
2607 | *exact = 1; | |
2608 | ||
2609 | DEBUG_printf(("1_ppdCacheGetPageSize: Returning \"%s\" (custom)", | |
2610 | pc->custom_ppd_size)); | |
2611 | ||
2612 | return (pc->custom_ppd_size); | |
2613 | } | |
2614 | ||
2615 | /* | |
2616 | * No custom page size support or the size is out of range - return NULL. | |
2617 | */ | |
2618 | ||
2619 | DEBUG_puts("1_ppdCacheGetPageSize: Returning NULL"); | |
2620 | ||
2621 | return (NULL); | |
2622 | } | |
2623 | ||
2624 | ||
2625 | /* | |
2626 | * '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize. | |
2627 | */ | |
2628 | ||
6961465f | 2629 | pwg_size_t * /* O - PWG size or NULL */ |
f14324a7 MS |
2630 | _ppdCacheGetSize( |
2631 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2632 | const char *page_size) /* I - PPD PageSize */ | |
2633 | { | |
dcb445bc | 2634 | int i; /* Looping var */ |
6961465f MS |
2635 | pwg_media_t *media; /* Media */ |
2636 | pwg_size_t *size; /* Current size */ | |
f14324a7 MS |
2637 | |
2638 | ||
2639 | /* | |
2640 | * Range check input... | |
2641 | */ | |
2642 | ||
2643 | if (!pc || !page_size) | |
2644 | return (NULL); | |
2645 | ||
88f9aafc | 2646 | if (!_cups_strncasecmp(page_size, "Custom.", 7)) |
f14324a7 MS |
2647 | { |
2648 | /* | |
2649 | * Custom size; size name can be one of the following: | |
2650 | * | |
2651 | * Custom.WIDTHxLENGTHin - Size in inches | |
2652 | * Custom.WIDTHxLENGTHft - Size in feet | |
2653 | * Custom.WIDTHxLENGTHcm - Size in centimeters | |
2654 | * Custom.WIDTHxLENGTHmm - Size in millimeters | |
2655 | * Custom.WIDTHxLENGTHm - Size in meters | |
2656 | * Custom.WIDTHxLENGTH[pt] - Size in points | |
2657 | */ | |
2658 | ||
2659 | double w, l; /* Width and length of page */ | |
2660 | char *ptr; /* Pointer into PageSize */ | |
2661 | struct lconv *loc; /* Locale data */ | |
2662 | ||
2663 | loc = localeconv(); | |
2664 | w = (float)_cupsStrScand(page_size + 7, &ptr, loc); | |
2665 | if (!ptr || *ptr != 'x') | |
2666 | return (NULL); | |
2667 | ||
2668 | l = (float)_cupsStrScand(ptr + 1, &ptr, loc); | |
2669 | if (!ptr) | |
2670 | return (NULL); | |
2671 | ||
88f9aafc | 2672 | if (!_cups_strcasecmp(ptr, "in")) |
f14324a7 MS |
2673 | { |
2674 | w *= 2540.0; | |
2675 | l *= 2540.0; | |
2676 | } | |
88f9aafc | 2677 | else if (!_cups_strcasecmp(ptr, "ft")) |
f14324a7 MS |
2678 | { |
2679 | w *= 12.0 * 2540.0; | |
2680 | l *= 12.0 * 2540.0; | |
2681 | } | |
88f9aafc | 2682 | else if (!_cups_strcasecmp(ptr, "mm")) |
f14324a7 MS |
2683 | { |
2684 | w *= 100.0; | |
2685 | l *= 100.0; | |
2686 | } | |
88f9aafc | 2687 | else if (!_cups_strcasecmp(ptr, "cm")) |
f14324a7 MS |
2688 | { |
2689 | w *= 1000.0; | |
2690 | l *= 1000.0; | |
2691 | } | |
88f9aafc | 2692 | else if (!_cups_strcasecmp(ptr, "m")) |
f14324a7 MS |
2693 | { |
2694 | w *= 100000.0; | |
2695 | l *= 100000.0; | |
2696 | } | |
2697 | else | |
2698 | { | |
2699 | w *= 2540.0 / 72.0; | |
2700 | l *= 2540.0 / 72.0; | |
2701 | } | |
2702 | ||
2703 | pc->custom_size.width = (int)w; | |
2704 | pc->custom_size.length = (int)l; | |
2705 | ||
2706 | return (&(pc->custom_size)); | |
2707 | } | |
2708 | ||
2709 | /* | |
2710 | * Not a custom size - look it up... | |
2711 | */ | |
2712 | ||
2713 | for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) | |
dcb445bc MS |
2714 | if (!_cups_strcasecmp(page_size, size->map.ppd) || |
2715 | !_cups_strcasecmp(page_size, size->map.pwg)) | |
f14324a7 MS |
2716 | return (size); |
2717 | ||
dcb445bc MS |
2718 | /* |
2719 | * Look up standard sizes... | |
2720 | */ | |
2721 | ||
6961465f MS |
2722 | if ((media = pwgMediaForPPD(page_size)) == NULL) |
2723 | if ((media = pwgMediaForLegacy(page_size)) == NULL) | |
2724 | media = pwgMediaForPWG(page_size); | |
dcb445bc MS |
2725 | |
2726 | if (media) | |
2727 | { | |
2728 | pc->custom_size.width = media->width; | |
2729 | pc->custom_size.length = media->length; | |
2730 | ||
2731 | return (&(pc->custom_size)); | |
2732 | } | |
2733 | ||
f14324a7 MS |
2734 | return (NULL); |
2735 | } | |
2736 | ||
2737 | ||
2738 | /* | |
2739 | * '_ppdCacheGetSource()' - Get the PWG media-source associated with a PPD | |
2740 | * InputSlot. | |
2741 | */ | |
2742 | ||
2743 | const char * /* O - PWG media-source keyword */ | |
2744 | _ppdCacheGetSource( | |
2745 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2746 | const char *input_slot) /* I - PPD InputSlot */ | |
2747 | { | |
2748 | int i; /* Looping var */ | |
6961465f | 2749 | pwg_map_t *source; /* Current source */ |
f14324a7 MS |
2750 | |
2751 | ||
2752 | /* | |
2753 | * Range check input... | |
2754 | */ | |
2755 | ||
2756 | if (!pc || !input_slot) | |
2757 | return (NULL); | |
2758 | ||
2759 | for (i = pc->num_sources, source = pc->sources; i > 0; i --, source ++) | |
88f9aafc | 2760 | if (!_cups_strcasecmp(input_slot, source->ppd)) |
f14324a7 MS |
2761 | return (source->pwg); |
2762 | ||
2763 | return (NULL); | |
2764 | } | |
2765 | ||
2766 | ||
2767 | /* | |
2768 | * '_ppdCacheGetType()' - Get the PWG media-type associated with a PPD | |
2769 | * MediaType. | |
2770 | */ | |
2771 | ||
2772 | const char * /* O - PWG media-type keyword */ | |
2773 | _ppdCacheGetType( | |
2774 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2775 | const char *media_type) /* I - PPD MediaType */ | |
2776 | { | |
2777 | int i; /* Looping var */ | |
6961465f | 2778 | pwg_map_t *type; /* Current type */ |
f14324a7 MS |
2779 | |
2780 | ||
2781 | /* | |
2782 | * Range check input... | |
2783 | */ | |
2784 | ||
2785 | if (!pc || !media_type) | |
2786 | return (NULL); | |
2787 | ||
2788 | for (i = pc->num_types, type = pc->types; i > 0; i --, type ++) | |
88f9aafc | 2789 | if (!_cups_strcasecmp(media_type, type->ppd)) |
f14324a7 MS |
2790 | return (type->pwg); |
2791 | ||
2792 | return (NULL); | |
2793 | } | |
2794 | ||
2795 | ||
2796 | /* | |
2797 | * '_ppdCacheWriteFile()' - Write PWG mapping data to a file. | |
2798 | */ | |
2799 | ||
2800 | int /* O - 1 on success, 0 on failure */ | |
2801 | _ppdCacheWriteFile( | |
2802 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ | |
2803 | const char *filename, /* I - File to write */ | |
2804 | ipp_t *attrs) /* I - Attributes to write, if any */ | |
2805 | { | |
dcb445bc MS |
2806 | int i, j, k; /* Looping vars */ |
2807 | cups_file_t *fp; /* Output file */ | |
6961465f MS |
2808 | pwg_size_t *size; /* Current size */ |
2809 | pwg_map_t *map; /* Current map */ | |
dcb445bc MS |
2810 | _pwg_finishings_t *f; /* Current finishing option */ |
2811 | cups_option_t *option; /* Current option */ | |
4f63d6cd | 2812 | const char *value; /* String value */ |
dcb445bc | 2813 | char newfile[1024]; /* New filename */ |
f14324a7 MS |
2814 | |
2815 | ||
2816 | /* | |
2817 | * Range check input... | |
2818 | */ | |
2819 | ||
2820 | if (!pc || !filename) | |
2821 | { | |
cb7f98ee | 2822 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
f14324a7 MS |
2823 | return (0); |
2824 | } | |
2825 | ||
2826 | /* | |
2827 | * Open the file and write with compression... | |
2828 | */ | |
2829 | ||
321d8d57 MS |
2830 | snprintf(newfile, sizeof(newfile), "%s.N", filename); |
2831 | if ((fp = cupsFileOpen(newfile, "w9")) == NULL) | |
f14324a7 | 2832 | { |
cb7f98ee | 2833 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
f14324a7 MS |
2834 | return (0); |
2835 | } | |
2836 | ||
2837 | /* | |
2838 | * Standard header... | |
2839 | */ | |
2840 | ||
2841 | cupsFilePrintf(fp, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION); | |
2842 | ||
2843 | /* | |
2844 | * Output bins... | |
2845 | */ | |
2846 | ||
2847 | if (pc->num_bins > 0) | |
2848 | { | |
2849 | cupsFilePrintf(fp, "NumBins %d\n", pc->num_bins); | |
2850 | for (i = pc->num_bins, map = pc->bins; i > 0; i --, map ++) | |
2851 | cupsFilePrintf(fp, "Bin %s %s\n", map->pwg, map->ppd); | |
2852 | } | |
2853 | ||
2854 | /* | |
2855 | * Media sizes... | |
2856 | */ | |
2857 | ||
2858 | cupsFilePrintf(fp, "NumSizes %d\n", pc->num_sizes); | |
2859 | for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) | |
2860 | cupsFilePrintf(fp, "Size %s %s %d %d %d %d %d %d\n", size->map.pwg, | |
2861 | size->map.ppd, size->width, size->length, size->left, | |
2862 | size->bottom, size->right, size->top); | |
2863 | if (pc->custom_max_width > 0) | |
2864 | cupsFilePrintf(fp, "CustomSize %d %d %d %d %d %d %d %d\n", | |
2865 | pc->custom_max_width, pc->custom_max_length, | |
2866 | pc->custom_min_width, pc->custom_min_length, | |
2867 | pc->custom_size.left, pc->custom_size.bottom, | |
2868 | pc->custom_size.right, pc->custom_size.top); | |
2869 | ||
2870 | /* | |
2871 | * Media sources... | |
2872 | */ | |
2873 | ||
2874 | if (pc->source_option) | |
2875 | cupsFilePrintf(fp, "SourceOption %s\n", pc->source_option); | |
2876 | ||
2877 | if (pc->num_sources > 0) | |
2878 | { | |
2879 | cupsFilePrintf(fp, "NumSources %d\n", pc->num_sources); | |
2880 | for (i = pc->num_sources, map = pc->sources; i > 0; i --, map ++) | |
2881 | cupsFilePrintf(fp, "Source %s %s\n", map->pwg, map->ppd); | |
2882 | } | |
2883 | ||
2884 | /* | |
2885 | * Media types... | |
2886 | */ | |
2887 | ||
2888 | if (pc->num_types > 0) | |
2889 | { | |
2890 | cupsFilePrintf(fp, "NumTypes %d\n", pc->num_types); | |
2891 | for (i = pc->num_types, map = pc->types; i > 0; i --, map ++) | |
2892 | cupsFilePrintf(fp, "Type %s %s\n", map->pwg, map->ppd); | |
2893 | } | |
2894 | ||
2895 | /* | |
2896 | * Presets... | |
2897 | */ | |
2898 | ||
2899 | for (i = _PWG_PRINT_COLOR_MODE_MONOCHROME; i < _PWG_PRINT_COLOR_MODE_MAX; i ++) | |
2900 | for (j = _PWG_PRINT_QUALITY_DRAFT; j < _PWG_PRINT_QUALITY_MAX; j ++) | |
2901 | if (pc->num_presets[i][j]) | |
2902 | { | |
2903 | cupsFilePrintf(fp, "Preset %d %d", i, j); | |
2904 | for (k = pc->num_presets[i][j], option = pc->presets[i][j]; | |
2905 | k > 0; | |
2906 | k --, option ++) | |
2907 | cupsFilePrintf(fp, " %s=%s", option->name, option->value); | |
2908 | cupsFilePutChar(fp, '\n'); | |
2909 | } | |
2910 | ||
2911 | /* | |
2912 | * Duplex/sides... | |
2913 | */ | |
2914 | ||
2915 | if (pc->sides_option) | |
2916 | cupsFilePrintf(fp, "SidesOption %s\n", pc->sides_option); | |
2917 | ||
2918 | if (pc->sides_1sided) | |
2919 | cupsFilePrintf(fp, "Sides1Sided %s\n", pc->sides_1sided); | |
2920 | ||
2921 | if (pc->sides_2sided_long) | |
2922 | cupsFilePrintf(fp, "Sides2SidedLong %s\n", pc->sides_2sided_long); | |
2923 | ||
2924 | if (pc->sides_2sided_short) | |
2925 | cupsFilePrintf(fp, "Sides2SidedShort %s\n", pc->sides_2sided_short); | |
2926 | ||
2927 | /* | |
2928 | * Product, cupsFilter, cupsFilter2, and cupsPreFilter... | |
2929 | */ | |
2930 | ||
2931 | if (pc->product) | |
2932 | cupsFilePutConf(fp, "Product", pc->product); | |
2933 | ||
2934 | for (value = (const char *)cupsArrayFirst(pc->filters); | |
2935 | value; | |
2936 | value = (const char *)cupsArrayNext(pc->filters)) | |
2937 | cupsFilePutConf(fp, "Filter", value); | |
2938 | ||
2939 | for (value = (const char *)cupsArrayFirst(pc->prefilters); | |
2940 | value; | |
2941 | value = (const char *)cupsArrayNext(pc->prefilters)) | |
2942 | cupsFilePutConf(fp, "PreFilter", value); | |
2943 | ||
82f97232 MS |
2944 | cupsFilePrintf(fp, "SingleFile %s\n", pc->single_file ? "true" : "false"); |
2945 | ||
dcb445bc MS |
2946 | /* |
2947 | * Finishing options... | |
2948 | */ | |
2949 | ||
2950 | for (f = (_pwg_finishings_t *)cupsArrayFirst(pc->finishings); | |
2951 | f; | |
2952 | f = (_pwg_finishings_t *)cupsArrayNext(pc->finishings)) | |
2953 | { | |
2954 | cupsFilePrintf(fp, "Finishings %d", f->value); | |
2955 | for (i = f->num_options, option = f->options; i > 0; i --, option ++) | |
2956 | cupsFilePrintf(fp, " %s=%s", option->name, option->value); | |
2957 | cupsFilePutChar(fp, '\n'); | |
2958 | } | |
2959 | ||
4f63d6cd MS |
2960 | for (value = (const char *)cupsArrayFirst(pc->templates); value; value = (const char *)cupsArrayNext(pc->templates)) |
2961 | cupsFilePutConf(fp, "FinishingTemplate", value); | |
2962 | ||
3e7fe0ca MS |
2963 | /* |
2964 | * Max copies... | |
2965 | */ | |
2966 | ||
2967 | cupsFilePrintf(fp, "MaxCopies %d\n", pc->max_copies); | |
2968 | ||
5a9febac MS |
2969 | /* |
2970 | * Accounting/quota/PIN/managed printing values... | |
2971 | */ | |
2972 | ||
a469f8a5 MS |
2973 | if (pc->charge_info_uri) |
2974 | cupsFilePutConf(fp, "ChargeInfoURI", pc->charge_info_uri); | |
2975 | ||
5a9febac MS |
2976 | cupsFilePrintf(fp, "AccountId %s\n", pc->account_id ? "true" : "false"); |
2977 | cupsFilePrintf(fp, "AccountingUserId %s\n", | |
2978 | pc->accounting_user_id ? "true" : "false"); | |
2979 | ||
2980 | if (pc->password) | |
2981 | cupsFilePutConf(fp, "Password", pc->password); | |
2982 | ||
2983 | for (value = (char *)cupsArrayFirst(pc->mandatory); | |
2984 | value; | |
2985 | value = (char *)cupsArrayNext(pc->mandatory)) | |
2986 | cupsFilePutConf(fp, "Mandatory", value); | |
2987 | ||
c1420c87 MS |
2988 | /* |
2989 | * Support files... | |
2990 | */ | |
2991 | ||
2992 | for (value = (char *)cupsArrayFirst(pc->support_files); | |
2993 | value; | |
2994 | value = (char *)cupsArrayNext(pc->support_files)) | |
2995 | cupsFilePutConf(fp, "SupportFile", value); | |
2996 | ||
f14324a7 MS |
2997 | /* |
2998 | * IPP attributes, if any... | |
2999 | */ | |
3000 | ||
3001 | if (attrs) | |
3002 | { | |
3003 | cupsFilePrintf(fp, "IPP " CUPS_LLFMT "\n", CUPS_LLCAST ippLength(attrs)); | |
3004 | ||
cb7f98ee | 3005 | attrs->state = IPP_STATE_IDLE; |
f14324a7 MS |
3006 | ippWriteIO(fp, (ipp_iocb_t)cupsFileWrite, 1, NULL, attrs); |
3007 | } | |
3008 | ||
3009 | /* | |
3010 | * Close and return... | |
3011 | */ | |
3012 | ||
321d8d57 MS |
3013 | if (cupsFileClose(fp)) |
3014 | { | |
3015 | unlink(newfile); | |
3016 | return (0); | |
3017 | } | |
3018 | ||
3019 | unlink(filename); | |
3020 | return (!rename(newfile, filename)); | |
f14324a7 MS |
3021 | } |
3022 | ||
3023 | ||
d9fc71e4 MS |
3024 | /* |
3025 | * '_ppdCreateFromIPP()' - Create a PPD file describing the capabilities | |
3026 | * of an IPP printer. | |
3027 | */ | |
3028 | ||
d4259b45 | 3029 | char * /* O - PPD filename or @code NULL@ on error */ |
d9fc71e4 MS |
3030 | _ppdCreateFromIPP(char *buffer, /* I - Filename buffer */ |
3031 | size_t bufsize, /* I - Size of filename buffer */ | |
3032 | ipp_t *response) /* I - Get-Printer-Attributes response */ | |
3033 | { | |
3034 | cups_file_t *fp; /* PPD file */ | |
982be458 MS |
3035 | cups_array_t *sizes; /* Media sizes supported by printer */ |
3036 | cups_size_t *size; /* Current media size */ | |
d9fc71e4 MS |
3037 | ipp_attribute_t *attr, /* xxx-supported */ |
3038 | *defattr, /* xxx-default */ | |
3b6c3c8e | 3039 | *quality, /* print-quality-supported */ |
d9fc71e4 | 3040 | *x_dim, *y_dim; /* Media dimensions */ |
982be458 MS |
3041 | ipp_t *media_col, /* Media collection */ |
3042 | *media_size; /* Media size collection */ | |
d9fc71e4 MS |
3043 | char make[256], /* Make and model */ |
3044 | *model, /* Model name */ | |
3045 | ppdname[PPD_MAX_NAME]; | |
3046 | /* PPD keyword */ | |
3047 | int i, j, /* Looping vars */ | |
3048 | count, /* Number of values */ | |
3049 | bottom, /* Largest bottom margin */ | |
3050 | left, /* Largest left margin */ | |
3051 | right, /* Largest right margin */ | |
d4259b45 | 3052 | top, /* Largest top margin */ |
982be458 MS |
3053 | max_length = 0, /* Maximum custom size */ |
3054 | max_width = 0, | |
3055 | min_length = INT_MAX, | |
3056 | /* Minimum custom size */ | |
3057 | min_width = INT_MAX, | |
d4259b45 MS |
3058 | is_apple = 0, /* Does the printer support Apple raster? */ |
3059 | is_pdf = 0, /* Does the printer support PDF? */ | |
3060 | is_pwg = 0; /* Does the printer support PWG Raster? */ | |
d9fc71e4 MS |
3061 | pwg_media_t *pwg; /* PWG media size */ |
3062 | int xres, yres; /* Resolution values */ | |
fa76bc3d MS |
3063 | int resolutions[1000]; |
3064 | /* Array of resolution indices */ | |
edf09ba9 MS |
3065 | char msgid[256]; /* Message identifier (attr.value) */ |
3066 | const char *keyword, /* Keyword value */ | |
3067 | *msgstr; /* Localized string */ | |
c0886523 MS |
3068 | cups_lang_t *lang = cupsLangDefault(); |
3069 | /* Localization info */ | |
89550f3f | 3070 | cups_array_t *strings = NULL;/* Printer strings file */ |
560634d3 MS |
3071 | struct lconv *loc = localeconv(); |
3072 | /* Locale data */ | |
27ee2c4d MS |
3073 | cups_array_t *fin_options = NULL; |
3074 | /* Finishing options */ | |
d9fc71e4 MS |
3075 | |
3076 | ||
3077 | /* | |
3078 | * Range check input... | |
3079 | */ | |
3080 | ||
fffed089 MS |
3081 | if (buffer) |
3082 | *buffer = '\0'; | |
3083 | ||
a946858f MS |
3084 | if (!buffer || bufsize < 1) |
3085 | { | |
3086 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); | |
d9fc71e4 | 3087 | return (NULL); |
a946858f MS |
3088 | } |
3089 | ||
3090 | if (!response) | |
3091 | { | |
3092 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No IPP attributes."), 1); | |
3093 | return (NULL); | |
3094 | } | |
d9fc71e4 MS |
3095 | |
3096 | /* | |
3097 | * Open a temporary file for the PPD... | |
3098 | */ | |
3099 | ||
3100 | if ((fp = cupsTempFile2(buffer, (int)bufsize)) == NULL) | |
a946858f MS |
3101 | { |
3102 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); | |
d9fc71e4 | 3103 | return (NULL); |
a946858f | 3104 | } |
d9fc71e4 MS |
3105 | |
3106 | /* | |
3107 | * Standard stuff for PPD file... | |
3108 | */ | |
3109 | ||
3110 | cupsFilePuts(fp, "*PPD-Adobe: \"4.3\"\n"); | |
3111 | cupsFilePuts(fp, "*FormatVersion: \"4.3\"\n"); | |
3112 | cupsFilePrintf(fp, "*FileVersion: \"%d.%d\"\n", CUPS_VERSION_MAJOR, CUPS_VERSION_MINOR); | |
3113 | cupsFilePuts(fp, "*LanguageVersion: English\n"); | |
3114 | cupsFilePuts(fp, "*LanguageEncoding: ISOLatin1\n"); | |
3115 | cupsFilePuts(fp, "*PSVersion: \"(3010.000) 0\"\n"); | |
3116 | cupsFilePuts(fp, "*LanguageLevel: \"3\"\n"); | |
3117 | cupsFilePuts(fp, "*FileSystem: False\n"); | |
3118 | cupsFilePuts(fp, "*PCFileName: \"ippeve.ppd\"\n"); | |
3119 | ||
3120 | if ((attr = ippFindAttribute(response, "printer-make-and-model", IPP_TAG_TEXT)) != NULL) | |
3121 | strlcpy(make, ippGetString(attr, 0, NULL), sizeof(make)); | |
3122 | else | |
3123 | strlcpy(make, "Unknown Printer", sizeof(make)); | |
3124 | ||
3125 | if (!_cups_strncasecmp(make, "Hewlett Packard ", 16) || | |
3126 | !_cups_strncasecmp(make, "Hewlett-Packard ", 16)) | |
3127 | { | |
3128 | model = make + 16; | |
3129 | strlcpy(make, "HP", sizeof(make)); | |
3130 | } | |
3131 | else if ((model = strchr(make, ' ')) != NULL) | |
3132 | *model++ = '\0'; | |
3133 | else | |
3134 | model = make; | |
3135 | ||
3136 | cupsFilePrintf(fp, "*Manufacturer: \"%s\"\n", make); | |
3137 | cupsFilePrintf(fp, "*ModelName: \"%s\"\n", model); | |
3138 | cupsFilePrintf(fp, "*Product: \"(%s)\"\n", model); | |
de72bb61 MS |
3139 | cupsFilePrintf(fp, "*NickName: \"%s - IPP Everywhere\"\n", model); |
3140 | cupsFilePrintf(fp, "*ShortNickName: \"%s - IPP Everywhere\"\n", model); | |
d9fc71e4 | 3141 | |
fb2d5470 MS |
3142 | if ((attr = ippFindAttribute(response, "color-supported", IPP_TAG_BOOLEAN)) != NULL && ippGetBoolean(attr, 0)) |
3143 | cupsFilePuts(fp, "*ColorDevice: True\n"); | |
3144 | else | |
3145 | cupsFilePuts(fp, "*ColorDevice: False\n"); | |
3146 | ||
d9fc71e4 MS |
3147 | cupsFilePrintf(fp, "*cupsVersion: %d.%d\n", CUPS_VERSION_MAJOR, CUPS_VERSION_MINOR); |
3148 | cupsFilePuts(fp, "*cupsSNMPSupplies: False\n"); | |
89550f3f MS |
3149 | cupsFilePrintf(fp, "*cupsLanguages: \"%s\"\n", lang->language); |
3150 | ||
3151 | if ((attr = ippFindAttribute(response, "printer-more-info", IPP_TAG_URI)) != NULL) | |
3152 | cupsFilePrintf(fp, "*APSupplies: \"%s\"\n", ippGetString(attr, 0, NULL)); | |
3153 | ||
3154 | if ((attr = ippFindAttribute(response, "printer-charge-info-uri", IPP_TAG_URI)) != NULL) | |
3155 | cupsFilePrintf(fp, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr, 0, NULL)); | |
3156 | ||
3157 | if ((attr = ippFindAttribute(response, "printer-strings-uri", IPP_TAG_URI)) != NULL) | |
3158 | { | |
3159 | http_t *http = NULL; /* Connection to printer */ | |
3160 | char stringsfile[1024]; /* Temporary strings file */ | |
3161 | ||
3162 | if (cups_get_url(&http, ippGetString(attr, 0, NULL), stringsfile, sizeof(stringsfile))) | |
3163 | { | |
3164 | cupsFilePrintf(fp, "*cupsStringsURI: \"%s\"\n", ippGetString(attr, 0, NULL)); | |
3165 | ||
3166 | strings = _cupsMessageLoad(stringsfile, _CUPS_MESSAGE_STRINGS | _CUPS_MESSAGE_UNQUOTE); | |
3167 | ||
3168 | unlink(stringsfile); | |
3169 | } | |
3170 | ||
3171 | if (http) | |
3172 | httpClose(http); | |
3173 | } | |
d9fc71e4 | 3174 | |
658c64bf MS |
3175 | /* |
3176 | * Password/PIN printing... | |
3177 | */ | |
3178 | ||
3179 | if ((attr = ippFindAttribute(response, "job-password-supported", IPP_TAG_INTEGER)) != NULL) | |
3180 | { | |
3181 | char pattern[33]; /* Password pattern */ | |
3182 | int maxlen = ippGetInteger(attr, 0); | |
3183 | /* Maximum length */ | |
3184 | const char *repertoire = ippGetString(ippFindAttribute(response, "job-password-repertoire-configured", IPP_TAG_KEYWORD), 0, NULL); | |
3185 | /* Type of password */ | |
3186 | ||
3187 | if (maxlen > (int)(sizeof(pattern) - 1)) | |
3188 | maxlen = sizeof(pattern) - 1; | |
3189 | ||
3190 | if (!repertoire || !strcmp(repertoire, "iana_us-ascii_digits")) | |
3191 | memset(pattern, '1', maxlen); | |
3192 | else if (!strcmp(repertoire, "iana_us-ascii_letters")) | |
3193 | memset(pattern, 'A', maxlen); | |
3194 | else if (!strcmp(repertoire, "iana_us-ascii_complex")) | |
3195 | memset(pattern, 'C', maxlen); | |
3196 | else if (!strcmp(repertoire, "iana_us-ascii_any")) | |
3197 | memset(pattern, '.', maxlen); | |
3198 | else if (!strcmp(repertoire, "iana_utf-8_digits")) | |
3199 | memset(pattern, 'N', maxlen); | |
3200 | else if (!strcmp(repertoire, "iana_utf-8_letters")) | |
3201 | memset(pattern, 'U', maxlen); | |
3202 | else | |
3203 | memset(pattern, '*', maxlen); | |
3204 | ||
3205 | pattern[maxlen] = '\0'; | |
3206 | ||
3207 | cupsFilePrintf(fp, "*cupsPassword: \"%s\"\n", pattern); | |
3208 | } | |
3209 | ||
d9fc71e4 MS |
3210 | /* |
3211 | * Filters... | |
3212 | */ | |
3213 | ||
3214 | if ((attr = ippFindAttribute(response, "document-format-supported", IPP_TAG_MIMETYPE)) != NULL) | |
3215 | { | |
d4259b45 MS |
3216 | is_apple = ippContainsString(attr, "image/urf"); |
3217 | is_pdf = ippContainsString(attr, "application/pdf"); | |
e6062e8e MS |
3218 | is_pwg = ippContainsString(attr, "image/pwg-raster") && !is_apple; |
3219 | ||
3220 | if (ippContainsString(attr, "image/jpeg")) | |
3221 | cupsFilePuts(fp, "*cupsFilter2: \"image/jpeg image/jpeg 0 -\"\n"); | |
3222 | if (ippContainsString(attr, "image/png")) | |
3223 | cupsFilePuts(fp, "*cupsFilter2: \"image/png image/png 0 -\"\n"); | |
3224 | if (is_pdf) | |
fd7190c1 MS |
3225 | { |
3226 | /* | |
3227 | * Don't locally filter PDF content when printing to a CUPS shared | |
3228 | * printer, otherwise the options will be applied twice... | |
3229 | */ | |
3230 | ||
3231 | if (ippContainsString(attr, "application/vnd.cups-pdf")) | |
3232 | cupsFilePuts(fp, "*cupsFilter2: \"application/pdf application/pdf 0 -\"\n"); | |
3233 | else | |
3234 | cupsFilePuts(fp, "*cupsFilter2: \"application/vnd.cups-pdf application/pdf 10 -\"\n"); | |
3235 | } | |
e6062e8e MS |
3236 | if (is_apple) |
3237 | cupsFilePuts(fp, "*cupsFilter2: \"image/urf image/urf 100 -\"\n"); | |
3238 | if (is_pwg) | |
3239 | cupsFilePuts(fp, "*cupsFilter2: \"image/pwg-raster image/pwg-raster 100 -\"\n"); | |
d9fc71e4 MS |
3240 | } |
3241 | ||
d4259b45 MS |
3242 | if (!is_apple && !is_pdf && !is_pwg) |
3243 | goto bad_ppd; | |
3244 | ||
d9fc71e4 MS |
3245 | /* |
3246 | * PageSize/PageRegion/ImageableArea/PaperDimension | |
3247 | */ | |
3248 | ||
3249 | if ((attr = ippFindAttribute(response, "media-bottom-margin-supported", IPP_TAG_INTEGER)) != NULL) | |
3250 | { | |
3251 | for (i = 1, bottom = ippGetInteger(attr, 0), count = ippGetCount(attr); i < count; i ++) | |
3252 | if (ippGetInteger(attr, i) > bottom) | |
3253 | bottom = ippGetInteger(attr, i); | |
3254 | } | |
3255 | else | |
3256 | bottom = 1270; | |
3257 | ||
3258 | if ((attr = ippFindAttribute(response, "media-left-margin-supported", IPP_TAG_INTEGER)) != NULL) | |
3259 | { | |
3260 | for (i = 1, left = ippGetInteger(attr, 0), count = ippGetCount(attr); i < count; i ++) | |
3261 | if (ippGetInteger(attr, i) > left) | |
3262 | left = ippGetInteger(attr, i); | |
3263 | } | |
3264 | else | |
3265 | left = 635; | |
3266 | ||
3267 | if ((attr = ippFindAttribute(response, "media-right-margin-supported", IPP_TAG_INTEGER)) != NULL) | |
3268 | { | |
3269 | for (i = 1, right = ippGetInteger(attr, 0), count = ippGetCount(attr); i < count; i ++) | |
3270 | if (ippGetInteger(attr, i) > right) | |
3271 | right = ippGetInteger(attr, i); | |
3272 | } | |
3273 | else | |
3274 | right = 635; | |
3275 | ||
3276 | if ((attr = ippFindAttribute(response, "media-top-margin-supported", IPP_TAG_INTEGER)) != NULL) | |
3277 | { | |
3278 | for (i = 1, top = ippGetInteger(attr, 0), count = ippGetCount(attr); i < count; i ++) | |
3279 | if (ippGetInteger(attr, i) > top) | |
3280 | top = ippGetInteger(attr, i); | |
3281 | } | |
3282 | else | |
3283 | top = 1270; | |
3284 | ||
3285 | if ((defattr = ippFindAttribute(response, "media-col-default", IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
3286 | { | |
3287 | if ((attr = ippFindAttribute(ippGetCollection(defattr, 0), "media-size", IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
3288 | { | |
3289 | media_size = ippGetCollection(attr, 0); | |
3290 | x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_INTEGER); | |
3291 | y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_INTEGER); | |
3292 | ||
2a8afc20 | 3293 | if (x_dim && y_dim && (pwg = pwgMediaForSize(ippGetInteger(x_dim, 0), ippGetInteger(y_dim, 0))) != NULL) |
d9fc71e4 | 3294 | strlcpy(ppdname, pwg->ppd, sizeof(ppdname)); |
d9fc71e4 MS |
3295 | else |
3296 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
3297 | } | |
3298 | else | |
3299 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
3300 | } | |
670172ea MS |
3301 | else if ((pwg = pwgMediaForPWG(ippGetString(ippFindAttribute(response, "media-default", IPP_TAG_ZERO), 0, NULL))) != NULL) |
3302 | strlcpy(ppdname, pwg->ppd, sizeof(ppdname)); | |
3303 | else | |
3304 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
d9fc71e4 | 3305 | |
982be458 | 3306 | sizes = cupsArrayNew3((cups_array_func_t)pwg_compare_sizes, NULL, NULL, 0, (cups_acopy_func_t)pwg_copy_size, (cups_afree_func_t)free); |
7fad1ee9 | 3307 | |
982be458 MS |
3308 | if ((attr = ippFindAttribute(response, "media-col-database", IPP_TAG_BEGIN_COLLECTION)) != NULL) |
3309 | { | |
d9fc71e4 MS |
3310 | for (i = 0, count = ippGetCount(attr); i < count; i ++) |
3311 | { | |
982be458 MS |
3312 | cups_size_t temp; /* Current size */ |
3313 | ipp_attribute_t *margin; /* media-xxx-margin attribute */ | |
d9fc71e4 | 3314 | |
982be458 MS |
3315 | media_col = ippGetCollection(attr, i); |
3316 | media_size = ippGetCollection(ippFindAttribute(media_col, "media-size", IPP_TAG_BEGIN_COLLECTION), 0); | |
3317 | x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO); | |
3318 | y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_ZERO); | |
3319 | pwg = pwgMediaForSize(ippGetInteger(x_dim, 0), ippGetInteger(y_dim, 0)); | |
670172ea MS |
3320 | |
3321 | if (pwg) | |
d9fc71e4 | 3322 | { |
982be458 MS |
3323 | temp.width = pwg->width; |
3324 | temp.length = pwg->length; | |
560634d3 | 3325 | |
982be458 MS |
3326 | if ((margin = ippFindAttribute(media_col, "media-bottom-margin", IPP_TAG_INTEGER)) != NULL) |
3327 | temp.bottom = ippGetInteger(margin, 0); | |
3328 | else | |
3329 | temp.bottom = bottom; | |
7fad1ee9 | 3330 | |
982be458 MS |
3331 | if ((margin = ippFindAttribute(media_col, "media-left-margin", IPP_TAG_INTEGER)) != NULL) |
3332 | temp.left = ippGetInteger(margin, 0); | |
3333 | else | |
3334 | temp.left = left; | |
3335 | ||
3336 | if ((margin = ippFindAttribute(media_col, "media-right-margin", IPP_TAG_INTEGER)) != NULL) | |
3337 | temp.right = ippGetInteger(margin, 0); | |
3338 | else | |
3339 | temp.right = right; | |
7fad1ee9 | 3340 | |
982be458 MS |
3341 | if ((margin = ippFindAttribute(media_col, "media-top-margin", IPP_TAG_INTEGER)) != NULL) |
3342 | temp.top = ippGetInteger(margin, 0); | |
3343 | else | |
3344 | temp.top = top; | |
560634d3 | 3345 | |
982be458 MS |
3346 | if (temp.bottom == 0 && temp.left == 0 && temp.right == 0 && temp.top == 0) |
3347 | snprintf(temp.media, sizeof(temp.media), "%s.Borderless", pwg->ppd); | |
3348 | else | |
3349 | strlcpy(temp.media, pwg->ppd, sizeof(temp.media)); | |
3350 | ||
3351 | if (!cupsArrayFind(sizes, &temp)) | |
3352 | cupsArrayAdd(sizes, &temp); | |
d9fc71e4 | 3353 | } |
982be458 MS |
3354 | else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE || ippGetValueTag(y_dim) == IPP_TAG_RANGE) |
3355 | { | |
3356 | /* | |
3357 | * Custom size - record the min/max values... | |
3358 | */ | |
d9fc71e4 | 3359 | |
982be458 | 3360 | int lower, upper; /* Range values */ |
7fad1ee9 | 3361 | |
982be458 MS |
3362 | if (ippGetValueTag(x_dim) == IPP_TAG_RANGE) |
3363 | lower = ippGetRange(x_dim, 0, &upper); | |
3364 | else | |
3365 | lower = upper = ippGetInteger(x_dim, 0); | |
3366 | ||
3367 | if (lower < min_width) | |
3368 | min_width = lower; | |
3369 | if (upper > max_width) | |
3370 | max_width = upper; | |
3371 | ||
3372 | if (ippGetValueTag(y_dim) == IPP_TAG_RANGE) | |
3373 | lower = ippGetRange(y_dim, 0, &upper); | |
3374 | else | |
3375 | lower = upper = ippGetInteger(y_dim, 0); | |
3376 | ||
3377 | if (lower < min_length) | |
3378 | min_length = lower; | |
3379 | if (upper > max_length) | |
3380 | max_length = upper; | |
3381 | } | |
3382 | } | |
3383 | ||
3384 | if ((max_width == 0 || max_length == 0) && (attr = ippFindAttribute(response, "media-size-supported", IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
d9fc71e4 | 3385 | { |
982be458 MS |
3386 | /* |
3387 | * Some printers don't list custom size support in media-col-database... | |
3388 | */ | |
3389 | ||
3390 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
3be8e026 | 3391 | { |
982be458 MS |
3392 | media_size = ippGetCollection(attr, i); |
3393 | x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO); | |
3394 | y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_ZERO); | |
3395 | ||
3396 | if (ippGetValueTag(x_dim) == IPP_TAG_RANGE || ippGetValueTag(y_dim) == IPP_TAG_RANGE) | |
3397 | { | |
3398 | /* | |
3399 | * Custom size - record the min/max values... | |
3400 | */ | |
d9fc71e4 | 3401 | |
982be458 MS |
3402 | int lower, upper; /* Range values */ |
3403 | ||
3404 | if (ippGetValueTag(x_dim) == IPP_TAG_RANGE) | |
3405 | lower = ippGetRange(x_dim, 0, &upper); | |
3406 | else | |
3407 | lower = upper = ippGetInteger(x_dim, 0); | |
3408 | ||
3409 | if (lower < min_width) | |
3410 | min_width = lower; | |
3411 | if (upper > max_width) | |
3412 | max_width = upper; | |
3413 | ||
3414 | if (ippGetValueTag(y_dim) == IPP_TAG_RANGE) | |
3415 | lower = ippGetRange(y_dim, 0, &upper); | |
3416 | else | |
3417 | lower = upper = ippGetInteger(y_dim, 0); | |
3418 | ||
3419 | if (lower < min_length) | |
3420 | min_length = lower; | |
3421 | if (upper > max_length) | |
3422 | max_length = upper; | |
3423 | } | |
3be8e026 | 3424 | } |
982be458 MS |
3425 | } |
3426 | } | |
3427 | else if ((attr = ippFindAttribute(response, "media-size-supported", IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
3428 | { | |
3429 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
3430 | { | |
3431 | cups_size_t temp; /* Current size */ | |
3432 | ||
3433 | media_size = ippGetCollection(attr, i); | |
3434 | x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO); | |
3435 | y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_ZERO); | |
3436 | pwg = pwgMediaForSize(ippGetInteger(x_dim, 0), ippGetInteger(y_dim, 0)); | |
3be8e026 MS |
3437 | |
3438 | if (pwg) | |
d9fc71e4 | 3439 | { |
982be458 MS |
3440 | temp.width = pwg->width; |
3441 | temp.length = pwg->length; | |
3442 | temp.bottom = bottom; | |
3443 | temp.left = left; | |
3444 | temp.right = right; | |
3445 | temp.top = top; | |
3446 | ||
3447 | if (temp.bottom == 0 && temp.left == 0 && temp.right == 0 && temp.top == 0) | |
3448 | snprintf(temp.media, sizeof(temp.media), "%s.Borderless", pwg->ppd); | |
3449 | else | |
3450 | strlcpy(temp.media, pwg->ppd, sizeof(temp.media)); | |
560634d3 | 3451 | |
982be458 MS |
3452 | if (!cupsArrayFind(sizes, &temp)) |
3453 | cupsArrayAdd(sizes, &temp); | |
3454 | } | |
3455 | else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE || ippGetValueTag(y_dim) == IPP_TAG_RANGE) | |
3456 | { | |
3457 | /* | |
3458 | * Custom size - record the min/max values... | |
3459 | */ | |
7fad1ee9 | 3460 | |
982be458 | 3461 | int lower, upper; /* Range values */ |
7fad1ee9 | 3462 | |
982be458 MS |
3463 | if (ippGetValueTag(x_dim) == IPP_TAG_RANGE) |
3464 | lower = ippGetRange(x_dim, 0, &upper); | |
3465 | else | |
3466 | lower = upper = ippGetInteger(x_dim, 0); | |
560634d3 | 3467 | |
982be458 MS |
3468 | if (lower < min_width) |
3469 | min_width = lower; | |
3470 | if (upper > max_width) | |
3471 | max_width = upper; | |
d9fc71e4 | 3472 | |
982be458 MS |
3473 | if (ippGetValueTag(y_dim) == IPP_TAG_RANGE) |
3474 | lower = ippGetRange(y_dim, 0, &upper); | |
3475 | else | |
3476 | lower = upper = ippGetInteger(y_dim, 0); | |
7fad1ee9 | 3477 | |
982be458 MS |
3478 | if (lower < min_length) |
3479 | min_length = lower; | |
3480 | if (upper > max_length) | |
3481 | max_length = upper; | |
3482 | } | |
3483 | } | |
3484 | } | |
3485 | else if ((attr = ippFindAttribute(response, "media-supported", IPP_TAG_ZERO)) != NULL) | |
3486 | { | |
d9fc71e4 MS |
3487 | for (i = 0, count = ippGetCount(attr); i < count; i ++) |
3488 | { | |
982be458 MS |
3489 | const char *pwg_size = ippGetString(attr, i, NULL); |
3490 | /* PWG size name */ | |
3491 | cups_size_t temp; /* Current size */ | |
3492 | ||
3493 | if ((pwg = pwgMediaForPWG(pwg_size)) != NULL) | |
3be8e026 | 3494 | { |
982be458 MS |
3495 | if (strstr(pwg_size, "_max_") || strstr(pwg_size, "_max.")) |
3496 | { | |
3497 | if (pwg->width > max_width) | |
3498 | max_width = pwg->width; | |
3499 | if (pwg->length > max_length) | |
3500 | max_length = pwg->length; | |
3501 | } | |
3502 | else if (strstr(pwg_size, "_min_") || strstr(pwg_size, "_min.")) | |
3503 | { | |
3504 | if (pwg->width < min_width) | |
3505 | min_width = pwg->width; | |
3506 | if (pwg->length < min_length) | |
3507 | min_length = pwg->length; | |
3508 | } | |
3509 | else | |
3510 | { | |
3511 | temp.width = pwg->width; | |
3512 | temp.length = pwg->length; | |
3513 | temp.bottom = bottom; | |
3514 | temp.left = left; | |
3515 | temp.right = right; | |
3516 | temp.top = top; | |
3517 | ||
3518 | if (temp.bottom == 0 && temp.left == 0 && temp.right == 0 && temp.top == 0) | |
3519 | snprintf(temp.media, sizeof(temp.media), "%s.Borderless", pwg->ppd); | |
3520 | else | |
3521 | strlcpy(temp.media, pwg->ppd, sizeof(temp.media)); | |
d9fc71e4 | 3522 | |
982be458 MS |
3523 | if (!cupsArrayFind(sizes, &temp)) |
3524 | cupsArrayAdd(sizes, &temp); | |
3525 | } | |
3be8e026 | 3526 | } |
982be458 MS |
3527 | } |
3528 | } | |
3be8e026 | 3529 | |
982be458 MS |
3530 | if (cupsArrayCount(sizes) > 0) |
3531 | { | |
3532 | /* | |
3533 | * List all of the standard sizes... | |
3534 | */ | |
3535 | ||
3536 | char tleft[256], /* Left string */ | |
560634d3 MS |
3537 | tbottom[256], /* Bottom string */ |
3538 | tright[256], /* Right string */ | |
3539 | ttop[256], /* Top string */ | |
3540 | twidth[256], /* Width string */ | |
3541 | tlength[256]; /* Length string */ | |
3542 | ||
982be458 MS |
3543 | cupsFilePrintf(fp, "*OpenUI *PageSize: PickOne\n" |
3544 | "*OrderDependency: 10 AnySetup *PageSize\n" | |
3545 | "*DefaultPageSize: %s\n", ppdname); | |
3546 | for (size = (cups_size_t *)cupsArrayFirst(sizes); size; size = (cups_size_t *)cupsArrayNext(sizes)) | |
3547 | { | |
3548 | _cupsStrFormatd(twidth, twidth + sizeof(twidth), size->width * 72.0 / 2540.0, loc); | |
3549 | _cupsStrFormatd(tlength, tlength + sizeof(tlength), size->length * 72.0 / 2540.0, loc); | |
7fad1ee9 | 3550 | |
982be458 MS |
3551 | cupsFilePrintf(fp, "*PageSize %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size->media, twidth, tlength); |
3552 | } | |
3553 | cupsFilePuts(fp, "*CloseUI: *PageSize\n"); | |
7fad1ee9 | 3554 | |
982be458 MS |
3555 | cupsFilePrintf(fp, "*OpenUI *PageRegion: PickOne\n" |
3556 | "*OrderDependency: 10 AnySetup *PageRegion\n" | |
3557 | "*DefaultPageRegion: %s\n", ppdname); | |
3558 | for (size = (cups_size_t *)cupsArrayFirst(sizes); size; size = (cups_size_t *)cupsArrayNext(sizes)) | |
3559 | { | |
3560 | _cupsStrFormatd(twidth, twidth + sizeof(twidth), size->width * 72.0 / 2540.0, loc); | |
3561 | _cupsStrFormatd(tlength, tlength + sizeof(tlength), size->length * 72.0 / 2540.0, loc); | |
560634d3 | 3562 | |
982be458 MS |
3563 | cupsFilePrintf(fp, "*PageRegion %s: \"<</PageSize[%s %s]>>setpagedevice\"\n", size->media, twidth, tlength); |
3564 | } | |
3565 | cupsFilePuts(fp, "*CloseUI: *PageRegion\n"); | |
3566 | ||
3567 | cupsFilePrintf(fp, "*DefaultImageableArea: %s\n" | |
3568 | "*DefaultPaperDimension: %s\n", ppdname, ppdname); | |
3569 | ||
3570 | for (size = (cups_size_t *)cupsArrayFirst(sizes); size; size = (cups_size_t *)cupsArrayNext(sizes)) | |
3571 | { | |
3572 | _cupsStrFormatd(tleft, tleft + sizeof(tleft), size->left * 72.0 / 2540.0, loc); | |
3573 | _cupsStrFormatd(tbottom, tbottom + sizeof(tbottom), size->bottom * 72.0 / 2540.0, loc); | |
3574 | _cupsStrFormatd(tright, tright + sizeof(tright), (size->width - size->right) * 72.0 / 2540.0, loc); | |
3575 | _cupsStrFormatd(ttop, ttop + sizeof(ttop), (size->length - size->top) * 72.0 / 2540.0, loc); | |
3576 | _cupsStrFormatd(twidth, twidth + sizeof(twidth), size->width * 72.0 / 2540.0, loc); | |
3577 | _cupsStrFormatd(tlength, tlength + sizeof(tlength), size->length * 72.0 / 2540.0, loc); | |
3578 | ||
3579 | cupsFilePrintf(fp, "*ImageableArea %s: \"%s %s %s %s\"\n", size->media, tleft, tbottom, tright, ttop); | |
3580 | cupsFilePrintf(fp, "*PaperDimension %s: \"%s %s\"\n", size->media, twidth, tlength); | |
d9fc71e4 | 3581 | } |
7fad1ee9 MS |
3582 | |
3583 | cupsArrayDelete(sizes); | |
982be458 MS |
3584 | |
3585 | /* | |
3586 | * Custom size support... | |
3587 | */ | |
3588 | ||
3589 | if (max_width > 0 && min_width < INT_MAX && max_length > 0 && min_length < INT_MAX) | |
3590 | { | |
3591 | char tmax[256], tmin[256]; /* Min/max values */ | |
3592 | ||
3593 | _cupsStrFormatd(tleft, tleft + sizeof(tleft), left * 72.0 / 2540.0, loc); | |
3594 | _cupsStrFormatd(tbottom, tbottom + sizeof(tbottom), bottom * 72.0 / 2540.0, loc); | |
3595 | _cupsStrFormatd(tright, tright + sizeof(tright), right * 72.0 / 2540.0, loc); | |
3596 | _cupsStrFormatd(ttop, ttop + sizeof(ttop), top * 72.0 / 2540.0, loc); | |
3597 | ||
3598 | cupsFilePrintf(fp, "*HWMargins: \"%s %s %s %s\"\n", tleft, tbottom, tright, ttop); | |
3599 | ||
3600 | _cupsStrFormatd(tmax, tmax + sizeof(tmax), max_width * 72.0 / 2540.0, loc); | |
3601 | _cupsStrFormatd(tmin, tmin + sizeof(tmin), min_width * 72.0 / 2540.0, loc); | |
3602 | cupsFilePrintf(fp, "*ParamCustomPageSize Width: 1 points %s %s\n", tmin, tmax); | |
3603 | ||
3604 | _cupsStrFormatd(tmax, tmax + sizeof(tmax), max_length * 72.0 / 2540.0, loc); | |
3605 | _cupsStrFormatd(tmin, tmin + sizeof(tmin), min_length * 72.0 / 2540.0, loc); | |
3606 | cupsFilePrintf(fp, "*ParamCustomPageSize Height: 2 points %s %s\n", tmin, tmax); | |
3607 | ||
3608 | cupsFilePuts(fp, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n"); | |
3609 | cupsFilePuts(fp, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n"); | |
3610 | cupsFilePuts(fp, "*ParamCustomPageSize Orientation: 5 int 0 3\n"); | |
3611 | cupsFilePuts(fp, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n"); | |
3612 | } | |
d9fc71e4 | 3613 | } |
d4259b45 | 3614 | else |
982be458 MS |
3615 | { |
3616 | cupsArrayDelete(sizes); | |
d4259b45 | 3617 | goto bad_ppd; |
982be458 | 3618 | } |
d9fc71e4 MS |
3619 | |
3620 | /* | |
3621 | * InputSlot... | |
3622 | */ | |
3623 | ||
670172ea | 3624 | if ((attr = ippFindAttribute(ippGetCollection(defattr, 0), "media-source", IPP_TAG_ZERO)) != NULL) |
d9fc71e4 MS |
3625 | pwg_ppdize_name(ippGetString(attr, 0, NULL), ppdname, sizeof(ppdname)); |
3626 | else | |
3627 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
3628 | ||
670172ea | 3629 | if ((attr = ippFindAttribute(response, "media-source-supported", IPP_TAG_ZERO)) != NULL && (count = ippGetCount(attr)) > 1) |
d9fc71e4 | 3630 | { |
edf09ba9 MS |
3631 | static const char * const sources[] = |
3632 | { /* Standard "media-source" strings */ | |
3633 | "auto", | |
3634 | "main", | |
3635 | "alternate", | |
3636 | "large-capacity", | |
3637 | "manual", | |
3638 | "envelope", | |
3639 | "disc", | |
3640 | "photo", | |
3641 | "hagaki", | |
3642 | "main-roll", | |
3643 | "alternate-roll", | |
3644 | "top", | |
3645 | "middle", | |
3646 | "bottom", | |
3647 | "side", | |
3648 | "left", | |
3649 | "right", | |
3650 | "center", | |
3651 | "rear", | |
3652 | "by-pass-tray", | |
3653 | "tray-1", | |
3654 | "tray-2", | |
3655 | "tray-3", | |
3656 | "tray-4", | |
3657 | "tray-5", | |
3658 | "tray-6", | |
3659 | "tray-7", | |
3660 | "tray-8", | |
3661 | "tray-9", | |
3662 | "tray-10", | |
3663 | "tray-11", | |
3664 | "tray-12", | |
3665 | "tray-13", | |
3666 | "tray-14", | |
3667 | "tray-15", | |
3668 | "tray-16", | |
3669 | "tray-17", | |
3670 | "tray-18", | |
3671 | "tray-19", | |
3672 | "tray-20", | |
3673 | "roll-1", | |
3674 | "roll-2", | |
3675 | "roll-3", | |
3676 | "roll-4", | |
3677 | "roll-5", | |
3678 | "roll-6", | |
3679 | "roll-7", | |
3680 | "roll-8", | |
3681 | "roll-9", | |
3682 | "roll-10" | |
d9fc71e4 MS |
3683 | }; |
3684 | ||
3685 | cupsFilePrintf(fp, "*OpenUI *InputSlot: PickOne\n" | |
3686 | "*OrderDependency: 10 AnySetup *InputSlot\n" | |
3687 | "*DefaultInputSlot: %s\n", ppdname); | |
3688 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
3689 | { | |
edf09ba9 MS |
3690 | keyword = ippGetString(attr, i, NULL); |
3691 | ||
3692 | pwg_ppdize_name(keyword, ppdname, sizeof(ppdname)); | |
d9fc71e4 MS |
3693 | |
3694 | for (j = 0; j < (int)(sizeof(sources) / sizeof(sources[0])); j ++) | |
edf09ba9 | 3695 | if (!strcmp(sources[j], keyword)) |
d9fc71e4 | 3696 | { |
edf09ba9 | 3697 | snprintf(msgid, sizeof(msgid), "media-source.%s", keyword); |
c96cc7c0 MS |
3698 | cupsFilePrintf(fp, "*InputSlot %s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname, j); |
3699 | cupsFilePrintf(fp, "*%s.InputSlot %s/%s: \"\"\n", lang->language, ppdname, _cupsLangString(lang, msgid)); | |
d9fc71e4 MS |
3700 | break; |
3701 | } | |
3702 | } | |
3703 | cupsFilePuts(fp, "*CloseUI: *InputSlot\n"); | |
3704 | } | |
3705 | ||
3706 | /* | |
3707 | * MediaType... | |
3708 | */ | |
3709 | ||
670172ea | 3710 | if ((attr = ippFindAttribute(ippGetCollection(defattr, 0), "media-type", IPP_TAG_ZERO)) != NULL) |
d9fc71e4 MS |
3711 | pwg_ppdize_name(ippGetString(attr, 0, NULL), ppdname, sizeof(ppdname)); |
3712 | else | |
3713 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
3714 | ||
670172ea | 3715 | if ((attr = ippFindAttribute(response, "media-type-supported", IPP_TAG_ZERO)) != NULL && (count = ippGetCount(attr)) > 1) |
d9fc71e4 | 3716 | { |
d9fc71e4 MS |
3717 | cupsFilePrintf(fp, "*OpenUI *MediaType: PickOne\n" |
3718 | "*OrderDependency: 10 AnySetup *MediaType\n" | |
3719 | "*DefaultMediaType: %s\n", ppdname); | |
3ae6282d | 3720 | for (i = 0; i < count; i ++) |
d9fc71e4 | 3721 | { |
edf09ba9 | 3722 | keyword = ippGetString(attr, i, NULL); |
d9fc71e4 | 3723 | |
3ae6282d | 3724 | pwg_ppdize_name(keyword, ppdname, sizeof(ppdname)); |
d9fc71e4 | 3725 | |
edf09ba9 MS |
3726 | snprintf(msgid, sizeof(msgid), "media-type.%s", keyword); |
3727 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
3728 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
3729 | msgstr = keyword; | |
89550f3f | 3730 | |
c96cc7c0 MS |
3731 | cupsFilePrintf(fp, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname, ppdname); |
3732 | cupsFilePrintf(fp, "*%s.MediaType %s/%s: \"\"\n", lang->language, ppdname, msgstr); | |
d9fc71e4 MS |
3733 | } |
3734 | cupsFilePuts(fp, "*CloseUI: *MediaType\n"); | |
3735 | } | |
3736 | ||
3737 | /* | |
3738 | * ColorModel... | |
3739 | */ | |
3740 | ||
fa76bc3d MS |
3741 | if ((attr = ippFindAttribute(response, "urf-supported", IPP_TAG_KEYWORD)) == NULL) |
3742 | if ((attr = ippFindAttribute(response, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD)) == NULL) | |
670172ea MS |
3743 | if ((attr = ippFindAttribute(response, "print-color-mode-supported", IPP_TAG_KEYWORD)) == NULL) |
3744 | attr = ippFindAttribute(response, "output-mode-supported", IPP_TAG_KEYWORD); | |
d9fc71e4 MS |
3745 | |
3746 | if (attr) | |
3747 | { | |
314e45c2 | 3748 | int wrote_color = 0; |
d9fc71e4 MS |
3749 | const char *default_color = NULL; /* Default */ |
3750 | ||
d9fc71e4 MS |
3751 | for (i = 0, count = ippGetCount(attr); i < count; i ++) |
3752 | { | |
edf09ba9 | 3753 | keyword = ippGetString(attr, i, NULL); |
d9fc71e4 | 3754 | |
c96cc7c0 MS |
3755 | #define PRINTF_COLORMODEL if (!wrote_color) { cupsFilePrintf(fp, "*OpenUI *ColorModel: PickOne\n*OrderDependency: 10 AnySetup *ColorModel\n*%s.Translation ColorModel/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Color Mode"))); wrote_color = 1; } |
3756 | #define PRINTF_COLOROPTION(name,text,cspace,bpp) { cupsFilePrintf(fp, "*ColorModel %s: \"<</cupsColorSpace %d/cupsBitsPerColor %d/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n", name, cspace, bpp); cupsFilePrintf(fp, "*%s.ColorModel %s/%s: \"\"\n", lang->language, name, _cupsLangString(lang, text)); } | |
314e45c2 | 3757 | |
d2817c9f | 3758 | if (!strcasecmp(keyword, "black_1") || !strcmp(keyword, "bi-level") || !strcmp(keyword, "process-bi-level")) |
d9fc71e4 | 3759 | { |
26dbc8a6 | 3760 | PRINTF_COLORMODEL |
5e7464ec | 3761 | |
c96cc7c0 | 3762 | PRINTF_COLOROPTION("FastGray", _("Fast Grayscale"), CUPS_CSPACE_K, 1) |
d9fc71e4 | 3763 | |
26dbc8a6 | 3764 | if (!default_color) |
d9fc71e4 MS |
3765 | default_color = "FastGray"; |
3766 | } | |
d2817c9f | 3767 | else if (!strcasecmp(keyword, "sgray_8") || !strcmp(keyword, "W8") || !strcmp(keyword, "monochrome") || !strcmp(keyword, "process-monochrome")) |
d9fc71e4 | 3768 | { |
26dbc8a6 | 3769 | PRINTF_COLORMODEL |
5e7464ec | 3770 | |
c96cc7c0 | 3771 | PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW, 8) |
d9fc71e4 | 3772 | |
26dbc8a6 | 3773 | if (!default_color || !strcmp(default_color, "FastGray")) |
d9fc71e4 MS |
3774 | default_color = "Gray"; |
3775 | } | |
c283f46d MS |
3776 | else if (!strcasecmp(keyword, "sgray_16") || !strcmp(keyword, "W8-16")) |
3777 | { | |
26dbc8a6 | 3778 | PRINTF_COLORMODEL |
c283f46d | 3779 | |
26dbc8a6 MS |
3780 | if (!strcmp(keyword, "W8-16")) |
3781 | { | |
c96cc7c0 | 3782 | PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW, 8) |
c283f46d MS |
3783 | |
3784 | if (!default_color || !strcmp(default_color, "FastGray")) | |
3785 | default_color = "Gray"; | |
26dbc8a6 | 3786 | } |
c283f46d | 3787 | |
c96cc7c0 | 3788 | PRINTF_COLOROPTION("Gray16", _("Deep Gray"), CUPS_CSPACE_SW, 16) |
c283f46d MS |
3789 | } |
3790 | else if (!strcasecmp(keyword, "srgb_8") || !strncmp(keyword, "SRGB24", 7) || !strcmp(keyword, "color")) | |
d9fc71e4 | 3791 | { |
26dbc8a6 | 3792 | PRINTF_COLORMODEL |
5e7464ec | 3793 | |
c96cc7c0 | 3794 | PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB, 8) |
d9fc71e4 MS |
3795 | |
3796 | default_color = "RGB"; | |
3797 | } | |
c283f46d | 3798 | else if (!strcasecmp(keyword, "adobe-rgb_16") || !strcmp(keyword, "ADOBERGB48") || !strcmp(keyword, "ADOBERGB24-48")) |
2a8afc20 | 3799 | { |
26dbc8a6 | 3800 | PRINTF_COLORMODEL |
2a8afc20 | 3801 | |
c96cc7c0 | 3802 | PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB, 16) |
c283f46d | 3803 | |
26dbc8a6 | 3804 | if (!default_color) |
c283f46d MS |
3805 | default_color = "AdobeRGB"; |
3806 | } | |
3807 | else if ((!strcasecmp(keyword, "adobe-rgb_8") && !ippContainsString(attr, "adobe-rgb_16")) || !strcmp(keyword, "ADOBERGB24")) | |
3808 | { | |
26dbc8a6 | 3809 | PRINTF_COLORMODEL |
c283f46d | 3810 | |
c96cc7c0 | 3811 | PRINTF_COLOROPTION("AdobeRGB", _("Deep Color"), CUPS_CSPACE_ADOBERGB, 8) |
2a8afc20 | 3812 | |
26dbc8a6 | 3813 | if (!default_color) |
d4259b45 | 3814 | default_color = "AdobeRGB"; |
2a8afc20 | 3815 | } |
314e45c2 MS |
3816 | else if ((!strcasecmp(keyword, "black_8") && !ippContainsString(attr, "black_16")) || !strcmp(keyword, "DEVW8")) |
3817 | { | |
26dbc8a6 | 3818 | PRINTF_COLORMODEL |
314e45c2 | 3819 | |
26dbc8a6 | 3820 | PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W, 8) |
314e45c2 MS |
3821 | } |
3822 | else if (!strcasecmp(keyword, "black_16") || !strcmp(keyword, "DEVW16") || !strcmp(keyword, "DEVW8-16")) | |
3823 | { | |
26dbc8a6 | 3824 | PRINTF_COLORMODEL |
314e45c2 | 3825 | |
c96cc7c0 | 3826 | PRINTF_COLOROPTION("DeviceGray", _("Device Gray"), CUPS_CSPACE_W, 16) |
314e45c2 MS |
3827 | } |
3828 | else if ((!strcasecmp(keyword, "cmyk_8") && !ippContainsString(attr, "cmyk_16")) || !strcmp(keyword, "DEVCMYK32")) | |
3829 | { | |
26dbc8a6 | 3830 | PRINTF_COLORMODEL |
314e45c2 | 3831 | |
26dbc8a6 | 3832 | PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK, 8) |
314e45c2 MS |
3833 | } |
3834 | else if (!strcasecmp(keyword, "cmyk_16") || !strcmp(keyword, "DEVCMYK32-64") || !strcmp(keyword, "DEVCMYK64")) | |
3835 | { | |
26dbc8a6 | 3836 | PRINTF_COLORMODEL |
314e45c2 | 3837 | |
26dbc8a6 | 3838 | PRINTF_COLOROPTION("CMYK", _("Device CMYK"), CUPS_CSPACE_CMYK, 16) |
314e45c2 MS |
3839 | } |
3840 | else if ((!strcasecmp(keyword, "rgb_8") && ippContainsString(attr, "rgb_16")) || !strcmp(keyword, "DEVRGB24")) | |
3841 | { | |
26dbc8a6 | 3842 | PRINTF_COLORMODEL |
314e45c2 | 3843 | |
26dbc8a6 | 3844 | PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB, 8) |
314e45c2 MS |
3845 | } |
3846 | else if (!strcasecmp(keyword, "rgb_16") || !strcmp(keyword, "DEVRGB24-48") || !strcmp(keyword, "DEVRGB48")) | |
3847 | { | |
26dbc8a6 | 3848 | PRINTF_COLORMODEL |
314e45c2 | 3849 | |
26dbc8a6 | 3850 | PRINTF_COLOROPTION("DeviceRGB", _("Device RGB"), CUPS_CSPACE_RGB, 16) |
314e45c2 | 3851 | } |
d9fc71e4 MS |
3852 | } |
3853 | ||
3854 | if (default_color) | |
3855 | cupsFilePrintf(fp, "*DefaultColorModel: %s\n", default_color); | |
314e45c2 | 3856 | if (wrote_color) |
5e7464ec | 3857 | cupsFilePuts(fp, "*CloseUI: *ColorModel\n"); |
d9fc71e4 MS |
3858 | } |
3859 | ||
3860 | /* | |
3861 | * Duplex... | |
3862 | */ | |
3863 | ||
3864 | if ((attr = ippFindAttribute(response, "sides-supported", IPP_TAG_KEYWORD)) != NULL && ippContainsString(attr, "two-sided-long-edge")) | |
3865 | { | |
c96cc7c0 | 3866 | cupsFilePrintf(fp, "*OpenUI *Duplex: PickOne\n" |
c0886523 | 3867 | "*OrderDependency: 10 AnySetup *Duplex\n" |
c96cc7c0 | 3868 | "*%s.Translation Duplex/%s: \"\"\n" |
c0886523 | 3869 | "*DefaultDuplex: None\n" |
c96cc7c0 MS |
3870 | "*Duplex None: \"<</Duplex false>>setpagedevice\"\n" |
3871 | "*%s.Duplex None/%s: \"\"\n" | |
3872 | "*Duplex DuplexNoTumble: \"<</Duplex true/Tumble false>>setpagedevice\"\n" | |
3873 | "*%s.Duplex DuplexNoTumble/%s: \"\"\n" | |
3874 | "*Duplex DuplexTumble: \"<</Duplex true/Tumble true>>setpagedevice\"\n" | |
3875 | "*%s.Duplex DuplexTumble/%s: \"\"\n" | |
3876 | "*CloseUI: *Duplex\n", lang->language, _cupsLangString(lang, _("2-Sided Printing")), lang->language, _cupsLangString(lang, _("Off (1-Sided)")), lang->language, _cupsLangString(lang, _("Long-Edge (Portrait)")), lang->language, _cupsLangString(lang, _("Short-Edge (Landscape)"))); | |
d9fc71e4 | 3877 | |
fa76bc3d MS |
3878 | if ((attr = ippFindAttribute(response, "urf-supported", IPP_TAG_KEYWORD)) != NULL) |
3879 | { | |
3880 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
3881 | { | |
3882 | const char *dm = ippGetString(attr, i, NULL); | |
3883 | /* DM value */ | |
3884 | ||
3885 | if (!_cups_strcasecmp(dm, "DM1")) | |
3886 | { | |
3887 | cupsFilePuts(fp, "*cupsBackSide: Normal\n"); | |
3888 | break; | |
3889 | } | |
3890 | else if (!_cups_strcasecmp(dm, "DM2")) | |
3891 | { | |
3892 | cupsFilePuts(fp, "*cupsBackSide: Flipped\n"); | |
3893 | break; | |
3894 | } | |
3895 | else if (!_cups_strcasecmp(dm, "DM3")) | |
3896 | { | |
3897 | cupsFilePuts(fp, "*cupsBackSide: Rotated\n"); | |
3898 | break; | |
3899 | } | |
3900 | else if (!_cups_strcasecmp(dm, "DM4")) | |
3901 | { | |
3902 | cupsFilePuts(fp, "*cupsBackSide: ManualTumble\n"); | |
3903 | break; | |
3904 | } | |
3905 | } | |
3906 | } | |
3907 | else if ((attr = ippFindAttribute(response, "pwg-raster-document-sheet-back", IPP_TAG_KEYWORD)) != NULL) | |
d9fc71e4 | 3908 | { |
edf09ba9 | 3909 | keyword = ippGetString(attr, 0, NULL); |
d9fc71e4 MS |
3910 | |
3911 | if (!strcmp(keyword, "flipped")) | |
3912 | cupsFilePuts(fp, "*cupsBackSide: Flipped\n"); | |
3913 | else if (!strcmp(keyword, "manual-tumble")) | |
3914 | cupsFilePuts(fp, "*cupsBackSide: ManualTumble\n"); | |
3915 | else if (!strcmp(keyword, "normal")) | |
3916 | cupsFilePuts(fp, "*cupsBackSide: Normal\n"); | |
3917 | else | |
3918 | cupsFilePuts(fp, "*cupsBackSide: Rotated\n"); | |
3919 | } | |
3920 | } | |
3921 | ||
1999164d MS |
3922 | /* |
3923 | * Output bin... | |
3924 | */ | |
3925 | ||
3926 | if ((attr = ippFindAttribute(response, "output-bin-default", IPP_TAG_ZERO)) != NULL) | |
3927 | pwg_ppdize_name(ippGetString(attr, 0, NULL), ppdname, sizeof(ppdname)); | |
3928 | else | |
3929 | strlcpy(ppdname, "Unknown", sizeof(ppdname)); | |
3930 | ||
3942a9c8 | 3931 | if ((attr = ippFindAttribute(response, "output-bin-supported", IPP_TAG_ZERO)) != NULL && (count = ippGetCount(attr)) > 1) |
1999164d | 3932 | { |
bf86060f MS |
3933 | ipp_attribute_t *trays = ippFindAttribute(response, "printer-output-tray", IPP_TAG_STRING); |
3934 | /* printer-output-tray attribute, if any */ | |
3935 | const char *tray_ptr; /* printer-output-tray value */ | |
3936 | int tray_len; /* Len of printer-output-tray value */ | |
3937 | char tray[IPP_MAX_OCTETSTRING]; | |
3938 | /* printer-output-tray string value */ | |
3939 | ||
1999164d MS |
3940 | cupsFilePrintf(fp, "*OpenUI *OutputBin: PickOne\n" |
3941 | "*OrderDependency: 10 AnySetup *OutputBin\n" | |
3942 | "*DefaultOutputBin: %s\n", ppdname); | |
bf86060f MS |
3943 | if (!strcmp(ppdname, "FaceUp")) |
3944 | cupsFilePuts(fp, "*DefaultOutputOrder: Reverse\n"); | |
3945 | else | |
3946 | cupsFilePuts(fp, "*DefaultOutputOrder: Normal\n"); | |
3947 | ||
edf09ba9 | 3948 | for (i = 0; i < count; i ++) |
1999164d | 3949 | { |
edf09ba9 MS |
3950 | keyword = ippGetString(attr, i, NULL); |
3951 | ||
3952 | pwg_ppdize_name(keyword, ppdname, sizeof(ppdname)); | |
1999164d | 3953 | |
edf09ba9 MS |
3954 | snprintf(msgid, sizeof(msgid), "output-bin.%s", keyword); |
3955 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
3956 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
3957 | msgstr = keyword; | |
1999164d | 3958 | |
c96cc7c0 MS |
3959 | cupsFilePrintf(fp, "*OutputBin %s: \"\"\n", ppdname); |
3960 | cupsFilePrintf(fp, "*%s.OutputBin %s/%s: \"\"\n", lang->language, ppdname, msgstr); | |
bf86060f MS |
3961 | |
3962 | if ((tray_ptr = ippGetOctetString(trays, i, &tray_len)) != NULL) | |
3963 | { | |
3964 | if (tray_len >= (int)sizeof(tray)) | |
3965 | tray_len = (int)sizeof(tray) - 1; | |
3966 | ||
3967 | memcpy(tray, tray_ptr, tray_len); | |
3968 | tray[tray_len] = '\0'; | |
3969 | ||
3970 | if (strstr(tray, "stackingorder=lastToFirst;")) | |
3971 | cupsFilePrintf(fp, "*PageStackOrder %s: Reverse\n", ppdname); | |
3972 | else | |
3973 | cupsFilePrintf(fp, "*PageStackOrder %s: Normal\n", ppdname); | |
3974 | } | |
3975 | else if (!strcmp(ppdname, "FaceUp")) | |
3976 | cupsFilePrintf(fp, "*PageStackOrder %s: Reverse\n", ppdname); | |
3977 | else | |
3978 | cupsFilePrintf(fp, "*PageStackOrder %s: Normal\n", ppdname); | |
1999164d MS |
3979 | } |
3980 | cupsFilePuts(fp, "*CloseUI: *OutputBin\n"); | |
3981 | } | |
3982 | ||
c0886523 MS |
3983 | /* |
3984 | * Finishing options... | |
3985 | */ | |
3986 | ||
a740a849 | 3987 | if ((attr = ippFindAttribute(response, "finishings-supported", IPP_TAG_ENUM)) != NULL) |
c0886523 | 3988 | { |
a740a849 | 3989 | int value; /* Enum value */ |
30ea7759 | 3990 | cups_array_t *names; /* Names we've added */ |
c0886523 | 3991 | |
27ee2c4d MS |
3992 | count = ippGetCount(attr); |
3993 | names = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); | |
3994 | fin_options = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
c0886523 | 3995 | |
a740a849 MS |
3996 | /* |
3997 | * Staple/Bind/Stitch | |
3998 | */ | |
c0886523 MS |
3999 | |
4000 | for (i = 0; i < count; i ++) | |
4001 | { | |
edf09ba9 MS |
4002 | value = ippGetInteger(attr, i); |
4003 | keyword = ippEnumString("finishings", value); | |
c0886523 | 4004 | |
edf09ba9 | 4005 | if (!strncmp(keyword, "staple-", 7) || !strncmp(keyword, "bind-", 5) || !strncmp(keyword, "edge-stitch-", 12) || !strcmp(keyword, "saddle-stitch")) |
a740a849 MS |
4006 | break; |
4007 | } | |
30ea7759 | 4008 | |
a740a849 MS |
4009 | if (i < count) |
4010 | { | |
27ee2c4d MS |
4011 | cupsArrayAdd(fin_options, "*StapleLocation"); |
4012 | ||
c96cc7c0 | 4013 | cupsFilePuts(fp, "*OpenUI *StapleLocation: PickOne\n"); |
a740a849 | 4014 | cupsFilePuts(fp, "*OrderDependency: 10 AnySetup *StapleLocation\n"); |
c96cc7c0 | 4015 | cupsFilePrintf(fp, "*%s.Translation StapleLocation/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Staple"))); |
a740a849 | 4016 | cupsFilePuts(fp, "*DefaultStapleLocation: None\n"); |
c96cc7c0 MS |
4017 | cupsFilePuts(fp, "*StapleLocation None: \"\"\n"); |
4018 | cupsFilePrintf(fp, "*%s.StapleLocation None/%s: \"\"\n", lang->language, _cupsLangString(lang, _("None"))); | |
30ea7759 | 4019 | |
a740a849 | 4020 | for (; i < count; i ++) |
c0886523 | 4021 | { |
edf09ba9 MS |
4022 | value = ippGetInteger(attr, i); |
4023 | keyword = ippEnumString("finishings", value); | |
c0886523 | 4024 | |
edf09ba9 | 4025 | if (strncmp(keyword, "staple-", 7) && strncmp(keyword, "bind-", 5) && strncmp(keyword, "edge-stitch-", 12) && strcmp(keyword, "saddle-stitch")) |
a740a849 | 4026 | continue; |
c0886523 | 4027 | |
edf09ba9 | 4028 | if (cupsArrayFind(names, (char *)keyword)) |
a740a849 MS |
4029 | continue; /* Already did this finishing template */ |
4030 | ||
edf09ba9 | 4031 | cupsArrayAdd(names, (char *)keyword); |
a740a849 | 4032 | |
edf09ba9 MS |
4033 | snprintf(msgid, sizeof(msgid), "finishings.%d", value); |
4034 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
4035 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
4036 | msgstr = keyword; | |
4037 | ||
c96cc7c0 MS |
4038 | cupsFilePrintf(fp, "*StapleLocation %s: \"\"\n", keyword); |
4039 | cupsFilePrintf(fp, "*%s.StapleLocation %s/%s: \"\"\n", lang->language, keyword, msgstr); | |
edf09ba9 | 4040 | cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value, keyword, keyword); |
c0886523 | 4041 | } |
a740a849 MS |
4042 | |
4043 | cupsFilePuts(fp, "*CloseUI: *StapleLocation\n"); | |
c0886523 MS |
4044 | } |
4045 | ||
a740a849 MS |
4046 | /* |
4047 | * Fold | |
4048 | */ | |
30ea7759 | 4049 | |
a740a849 MS |
4050 | for (i = 0; i < count; i ++) |
4051 | { | |
edf09ba9 MS |
4052 | value = ippGetInteger(attr, i); |
4053 | keyword = ippEnumString("finishings", value); | |
c0886523 | 4054 | |
edf09ba9 | 4055 | if (!strncmp(keyword, "fold-", 5)) |
a740a849 MS |
4056 | break; |
4057 | } | |
4058 | ||
4059 | if (i < count) | |
4060 | { | |
27ee2c4d MS |
4061 | cupsArrayAdd(fin_options, "*FoldType"); |
4062 | ||
c96cc7c0 | 4063 | cupsFilePuts(fp, "*OpenUI *FoldType: PickOne\n"); |
a740a849 | 4064 | cupsFilePuts(fp, "*OrderDependency: 10 AnySetup *FoldType\n"); |
c96cc7c0 | 4065 | cupsFilePrintf(fp, "*%s.Translation FoldType/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Fold"))); |
a740a849 | 4066 | cupsFilePuts(fp, "*DefaultFoldType: None\n"); |
c96cc7c0 MS |
4067 | cupsFilePuts(fp, "*FoldType None: \"\"\n"); |
4068 | cupsFilePrintf(fp, "*%s.FoldType None/%s: \"\"\n", lang->language, _cupsLangString(lang, _("None"))); | |
a740a849 MS |
4069 | |
4070 | for (; i < count; i ++) | |
4071 | { | |
edf09ba9 MS |
4072 | value = ippGetInteger(attr, i); |
4073 | keyword = ippEnumString("finishings", value); | |
a740a849 | 4074 | |
edf09ba9 | 4075 | if (strncmp(keyword, "fold-", 5)) |
a740a849 | 4076 | continue; |
c0886523 | 4077 | |
edf09ba9 | 4078 | if (cupsArrayFind(names, (char *)keyword)) |
a740a849 MS |
4079 | continue; /* Already did this finishing template */ |
4080 | ||
edf09ba9 | 4081 | cupsArrayAdd(names, (char *)keyword); |
a740a849 | 4082 | |
edf09ba9 MS |
4083 | snprintf(msgid, sizeof(msgid), "finishings.%d", value); |
4084 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
4085 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
4086 | msgstr = keyword; | |
4087 | ||
c96cc7c0 MS |
4088 | cupsFilePrintf(fp, "*FoldType %s: \"\"\n", keyword); |
4089 | cupsFilePrintf(fp, "*%s.FoldType %s/%s: \"\"\n", lang->language, keyword, msgstr); | |
edf09ba9 | 4090 | cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value, keyword, keyword); |
a740a849 MS |
4091 | } |
4092 | ||
4093 | cupsFilePuts(fp, "*CloseUI: *FoldType\n"); | |
4094 | } | |
4095 | ||
4096 | /* | |
4097 | * Punch | |
4098 | */ | |
c0886523 MS |
4099 | |
4100 | for (i = 0; i < count; i ++) | |
4101 | { | |
edf09ba9 MS |
4102 | value = ippGetInteger(attr, i); |
4103 | keyword = ippEnumString("finishings", value); | |
a740a849 | 4104 | |
edf09ba9 | 4105 | if (!strncmp(keyword, "punch-", 6)) |
a740a849 MS |
4106 | break; |
4107 | } | |
4108 | ||
4109 | if (i < count) | |
4110 | { | |
27ee2c4d MS |
4111 | cupsArrayAdd(fin_options, "*PunchMedia"); |
4112 | ||
c96cc7c0 | 4113 | cupsFilePuts(fp, "*OpenUI *PunchMedia: PickOne\n"); |
a740a849 | 4114 | cupsFilePuts(fp, "*OrderDependency: 10 AnySetup *PunchMedia\n"); |
c96cc7c0 | 4115 | cupsFilePrintf(fp, "*%s.Translation PunchMedia/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Punch"))); |
a740a849 | 4116 | cupsFilePuts(fp, "*DefaultPunchMedia: None\n"); |
c96cc7c0 MS |
4117 | cupsFilePuts(fp, "*PunchMedia None: \"\"\n"); |
4118 | cupsFilePrintf(fp, "*%s.PunchMedia None/%s: \"\"\n", lang->language, _cupsLangString(lang, _("None"))); | |
c0886523 | 4119 | |
a740a849 | 4120 | for (i = 0; i < count; i ++) |
c0886523 | 4121 | { |
edf09ba9 MS |
4122 | value = ippGetInteger(attr, i); |
4123 | keyword = ippEnumString("finishings", value); | |
a740a849 | 4124 | |
edf09ba9 | 4125 | if (strncmp(keyword, "punch-", 6)) |
a740a849 MS |
4126 | continue; |
4127 | ||
edf09ba9 | 4128 | if (cupsArrayFind(names, (char *)keyword)) |
a740a849 MS |
4129 | continue; /* Already did this finishing template */ |
4130 | ||
edf09ba9 | 4131 | cupsArrayAdd(names, (char *)keyword); |
a740a849 | 4132 | |
edf09ba9 MS |
4133 | snprintf(msgid, sizeof(msgid), "finishings.%d", value); |
4134 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
4135 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
4136 | msgstr = keyword; | |
4137 | ||
c96cc7c0 MS |
4138 | cupsFilePrintf(fp, "*PunchMedia %s: \"\"\n", keyword); |
4139 | cupsFilePrintf(fp, "*%s.PunchMedia %s/%s: \"\"\n", lang->language, keyword, msgstr); | |
edf09ba9 | 4140 | cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value, keyword, keyword); |
c0886523 | 4141 | } |
a740a849 MS |
4142 | |
4143 | cupsFilePuts(fp, "*CloseUI: *PunchMedia\n"); | |
4144 | } | |
4145 | ||
4146 | /* | |
4147 | * Booklet | |
4148 | */ | |
4149 | ||
4150 | if (ippContainsInteger(attr, IPP_FINISHINGS_BOOKLET_MAKER)) | |
4151 | { | |
27ee2c4d MS |
4152 | cupsArrayAdd(fin_options, "*Booklet"); |
4153 | ||
c96cc7c0 | 4154 | cupsFilePuts(fp, "*OpenUI *Booklet: Boolean\n"); |
a740a849 | 4155 | cupsFilePuts(fp, "*OrderDependency: 10 AnySetup *Booklet\n"); |
c96cc7c0 | 4156 | cupsFilePrintf(fp, "*%s.Translation Booklet/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Booklet"))); |
a740a849 MS |
4157 | cupsFilePuts(fp, "*DefaultBooklet: False\n"); |
4158 | cupsFilePuts(fp, "*Booklet False: \"\"\n"); | |
4159 | cupsFilePuts(fp, "*Booklet True: \"\"\n"); | |
4160 | cupsFilePrintf(fp, "*cupsIPPFinishings %d/booklet-maker: \"*Booklet True\"\n", IPP_FINISHINGS_BOOKLET_MAKER); | |
4161 | cupsFilePuts(fp, "*CloseUI: *Booklet\n"); | |
c0886523 MS |
4162 | } |
4163 | ||
a740a849 | 4164 | cupsArrayDelete(names); |
c0886523 MS |
4165 | } |
4166 | ||
27ee2c4d MS |
4167 | if ((attr = ippFindAttribute(response, "finishings-col-database", IPP_TAG_BEGIN_COLLECTION)) != NULL) |
4168 | { | |
4169 | ipp_t *finishing_col; /* Current finishing collection */ | |
edf09ba9 | 4170 | ipp_attribute_t *finishing_attr; /* Current finishing member attribute */ |
27ee2c4d MS |
4171 | cups_array_t *templates; /* Finishing templates */ |
4172 | ||
c96cc7c0 | 4173 | cupsFilePuts(fp, "*OpenUI *cupsFinishingTemplate: PickOne\n"); |
27ee2c4d | 4174 | cupsFilePuts(fp, "*OrderDependency: 10 AnySetup *cupsFinishingTemplate\n"); |
c96cc7c0 | 4175 | cupsFilePrintf(fp, "*%s.Translation cupsFinishingTemplate/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Finishing Preset"))); |
4f63d6cd | 4176 | cupsFilePuts(fp, "*DefaultcupsFinishingTemplate: none\n"); |
c96cc7c0 MS |
4177 | cupsFilePuts(fp, "*cupsFinishingTemplate none: \"\"\n"); |
4178 | cupsFilePrintf(fp, "*%s.cupsFinishingTemplate none/%s: \"\"\n", lang->language, _cupsLangString(lang, _("None"))); | |
27ee2c4d MS |
4179 | |
4180 | templates = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
4181 | count = ippGetCount(attr); | |
4182 | ||
4183 | for (i = 0; i < count; i ++) | |
4184 | { | |
4185 | finishing_col = ippGetCollection(attr, i); | |
01dee74c | 4186 | keyword = ippGetString(ippFindAttribute(finishing_col, "finishing-template", IPP_TAG_ZERO), 0, NULL); |
27ee2c4d | 4187 | |
edf09ba9 | 4188 | if (!keyword || cupsArrayFind(templates, (void *)keyword)) |
27ee2c4d MS |
4189 | continue; |
4190 | ||
edf09ba9 | 4191 | if (strncmp(keyword, "fold-", 5) && (strstr(keyword, "-bottom") || strstr(keyword, "-left") || strstr(keyword, "-right") || strstr(keyword, "-top"))) |
27ee2c4d MS |
4192 | continue; |
4193 | ||
edf09ba9 | 4194 | cupsArrayAdd(templates, (void *)keyword); |
27ee2c4d | 4195 | |
edf09ba9 MS |
4196 | snprintf(msgid, sizeof(msgid), "finishing-template.%s", keyword); |
4197 | if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr)) | |
4198 | if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid) | |
4199 | msgstr = keyword; | |
27ee2c4d | 4200 | |
c96cc7c0 | 4201 | cupsFilePrintf(fp, "*cupsFinishingTemplate %s: \"\n", keyword); |
edf09ba9 | 4202 | for (finishing_attr = ippFirstAttribute(finishing_col); finishing_attr; finishing_attr = ippNextAttribute(finishing_col)) |
27ee2c4d | 4203 | { |
edf09ba9 MS |
4204 | if (ippGetValueTag(finishing_attr) == IPP_TAG_BEGIN_COLLECTION) |
4205 | { | |
4206 | const char *name = ippGetName(finishing_attr); | |
4207 | /* Member attribute name */ | |
27ee2c4d | 4208 | |
edf09ba9 | 4209 | if (strcmp(name, "media-size")) |
342395f9 | 4210 | cupsFilePrintf(fp, "%% %s\n", name); |
edf09ba9 | 4211 | } |
27ee2c4d | 4212 | } |
edf09ba9 | 4213 | cupsFilePuts(fp, "\"\n"); |
c96cc7c0 | 4214 | cupsFilePrintf(fp, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang->language, keyword, msgstr); |
edf09ba9 | 4215 | cupsFilePuts(fp, "*End\n"); |
27ee2c4d MS |
4216 | } |
4217 | ||
4218 | cupsFilePuts(fp, "*CloseUI: *cupsFinishingTemplate\n"); | |
4219 | ||
4220 | if (cupsArrayCount(fin_options)) | |
4221 | { | |
4222 | const char *fin_option; /* Current finishing option */ | |
4223 | ||
01dee74c | 4224 | cupsFilePuts(fp, "*cupsUIConstraint finishing-template: \"*cupsFinishingTemplate"); |
27ee2c4d MS |
4225 | for (fin_option = (const char *)cupsArrayFirst(fin_options); fin_option; fin_option = (const char *)cupsArrayNext(fin_options)) |
4226 | cupsFilePrintf(fp, " %s", fin_option); | |
4227 | cupsFilePuts(fp, "\"\n"); | |
4228 | ||
01dee74c | 4229 | cupsFilePuts(fp, "*cupsUIResolver finishing-template: \"*cupsFinishingTemplate None"); |
27ee2c4d MS |
4230 | for (fin_option = (const char *)cupsArrayFirst(fin_options); fin_option; fin_option = (const char *)cupsArrayNext(fin_options)) |
4231 | cupsFilePrintf(fp, " %s None", fin_option); | |
4232 | cupsFilePuts(fp, "\"\n"); | |
4233 | } | |
4234 | ||
4235 | cupsArrayDelete(templates); | |
4236 | } | |
4237 | ||
4238 | cupsArrayDelete(fin_options); | |
4239 | ||
d9fc71e4 MS |
4240 | /* |
4241 | * cupsPrintQuality and DefaultResolution... | |
4242 | */ | |
4243 | ||
3b6c3c8e MS |
4244 | quality = ippFindAttribute(response, "print-quality-supported", IPP_TAG_ENUM); |
4245 | ||
fa76bc3d | 4246 | if ((attr = ippFindAttribute(response, "urf-supported", IPP_TAG_KEYWORD)) != NULL) |
d9fc71e4 | 4247 | { |
fa76bc3d | 4248 | int lowdpi = 0, hidpi = 0; /* Lower and higher resolution */ |
fb2d5470 MS |
4249 | |
4250 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
4251 | { | |
4252 | const char *rs = ippGetString(attr, i, NULL); | |
fa76bc3d | 4253 | /* RS value */ |
fb2d5470 MS |
4254 | |
4255 | if (_cups_strncasecmp(rs, "RS", 2)) | |
4256 | continue; | |
4257 | ||
4258 | lowdpi = atoi(rs + 2); | |
4259 | if ((rs = strrchr(rs, '-')) != NULL) | |
4260 | hidpi = atoi(rs + 1); | |
4261 | else | |
4262 | hidpi = lowdpi; | |
4263 | break; | |
4264 | } | |
4265 | ||
4266 | if (lowdpi == 0) | |
4267 | { | |
4268 | /* | |
4269 | * Invalid "urf-supported" value... | |
4270 | */ | |
4271 | ||
d4259b45 | 4272 | goto bad_ppd; |
fb2d5470 MS |
4273 | } |
4274 | else | |
4275 | { | |
4276 | /* | |
4277 | * Generate print qualities based on low and high DPIs... | |
4278 | */ | |
4279 | ||
4280 | cupsFilePrintf(fp, "*DefaultResolution: %ddpi\n", lowdpi); | |
4281 | ||
c96cc7c0 MS |
4282 | cupsFilePrintf(fp, "*OpenUI *cupsPrintQuality: PickOne\n" |
4283 | "*OrderDependency: 10 AnySetup *cupsPrintQuality\n" | |
4284 | "*%s.Translation cupsPrintQuality/%s: \"\"\n" | |
4285 | "*DefaultcupsPrintQuality: Normal\n", lang->language, _cupsLangString(lang, _("Print Quality"))); | |
fb2d5470 | 4286 | if ((lowdpi & 1) == 0) |
c96cc7c0 | 4287 | cupsFilePrintf(fp, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi, lowdpi / 2, lang->language, _cupsLangString(lang, _("Draft"))); |
3b6c3c8e | 4288 | else if (ippContainsInteger(quality, IPP_QUALITY_DRAFT)) |
c96cc7c0 MS |
4289 | cupsFilePrintf(fp, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", lowdpi, lowdpi, lang->language, _cupsLangString(lang, _("Draft"))); |
4290 | ||
4291 | cupsFilePrintf(fp, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", lowdpi, lowdpi, lang->language, _cupsLangString(lang, _("Normal"))); | |
4292 | ||
3b6c3c8e | 4293 | if (hidpi > lowdpi || ippContainsInteger(quality, IPP_QUALITY_HIGH)) |
c96cc7c0 | 4294 | cupsFilePrintf(fp, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", hidpi, hidpi, lang->language, _cupsLangString(lang, _("High"))); |
fb2d5470 MS |
4295 | cupsFilePuts(fp, "*CloseUI: *cupsPrintQuality\n"); |
4296 | } | |
4297 | } | |
fa76bc3d MS |
4298 | else if ((attr = ippFindAttribute(response, "pwg-raster-document-resolution-supported", IPP_TAG_RESOLUTION)) != NULL) |
4299 | { | |
4300 | /* | |
4301 | * Make a sorted list of resolutions. | |
4302 | */ | |
4303 | ||
4304 | count = ippGetCount(attr); | |
4305 | if (count > (int)(sizeof(resolutions) / sizeof(resolutions[0]))) | |
4306 | count = (int)(sizeof(resolutions) / sizeof(resolutions[0])); | |
4307 | ||
25140c63 MS |
4308 | resolutions[0] = 0; /* Not in loop to silence Clang static analyzer... */ |
4309 | for (i = 1; i < count; i ++) | |
fa76bc3d MS |
4310 | resolutions[i] = i; |
4311 | ||
4312 | for (i = 0; i < (count - 1); i ++) | |
4313 | { | |
91d748b9 | 4314 | for (j = i + 1; j < count; j ++) |
fa76bc3d MS |
4315 | { |
4316 | int ix, iy, /* First X and Y resolution */ | |
4317 | jx, jy, /* Second X and Y resolution */ | |
4318 | temp; /* Swap variable */ | |
4319 | ipp_res_t units; /* Resolution units */ | |
4320 | ||
4321 | ix = ippGetResolution(attr, resolutions[i], &iy, &units); | |
4322 | jx = ippGetResolution(attr, resolutions[j], &jy, &units); | |
4323 | ||
4324 | if (ix > jx || (ix == jx && iy > jy)) | |
4325 | { | |
4326 | /* | |
4327 | * Swap these two resolutions... | |
4328 | */ | |
4329 | ||
4330 | temp = resolutions[i]; | |
4331 | resolutions[i] = resolutions[j]; | |
4332 | resolutions[j] = temp; | |
4333 | } | |
4334 | } | |
4335 | } | |
4336 | ||
4337 | /* | |
4338 | * Generate print quality options... | |
4339 | */ | |
4340 | ||
4341 | pwg_ppdize_resolution(attr, resolutions[count / 2], &xres, &yres, ppdname, sizeof(ppdname)); | |
4342 | cupsFilePrintf(fp, "*DefaultResolution: %s\n", ppdname); | |
4343 | ||
c96cc7c0 MS |
4344 | cupsFilePrintf(fp, "*OpenUI *cupsPrintQuality: PickOne\n" |
4345 | "*OrderDependency: 10 AnySetup *cupsPrintQuality\n" | |
4346 | "*%s.Translation cupsPrintQuality/%s: \"\"\n" | |
4347 | "*DefaultcupsPrintQuality: Normal\n", lang->language, _cupsLangString(lang, _("Print Quality"))); | |
fa76bc3d MS |
4348 | if (count > 2 || ippContainsInteger(quality, IPP_QUALITY_DRAFT)) |
4349 | { | |
4350 | pwg_ppdize_resolution(attr, resolutions[0], &xres, &yres, NULL, 0); | |
c96cc7c0 MS |
4351 | cupsFilePrintf(fp, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres, yres); |
4352 | cupsFilePrintf(fp, "*%s.cupsPrintQuality Draft/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Draft"))); | |
fa76bc3d | 4353 | } |
c96cc7c0 | 4354 | |
fa76bc3d | 4355 | pwg_ppdize_resolution(attr, resolutions[count / 2], &xres, &yres, NULL, 0); |
c96cc7c0 MS |
4356 | cupsFilePrintf(fp, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres, yres); |
4357 | cupsFilePrintf(fp, "*%s.cupsPrintQuality Normal/%s: \"\"\n", lang->language, _cupsLangString(lang, _("Normal"))); | |
4358 | ||
fa76bc3d MS |
4359 | if (count > 1 || ippContainsInteger(quality, IPP_QUALITY_HIGH)) |
4360 | { | |
4361 | pwg_ppdize_resolution(attr, resolutions[count - 1], &xres, &yres, NULL, 0); | |
c96cc7c0 MS |
4362 | cupsFilePrintf(fp, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n", xres, yres); |
4363 | cupsFilePrintf(fp, "*%s.cupsPrintQuality High/%s: \"\"\n", lang->language, _cupsLangString(lang, _("High"))); | |
fa76bc3d MS |
4364 | } |
4365 | ||
4366 | cupsFilePuts(fp, "*CloseUI: *cupsPrintQuality\n"); | |
4367 | } | |
d4259b45 MS |
4368 | else if (is_apple || is_pwg) |
4369 | goto bad_ppd; | |
3b6c3c8e | 4370 | else |
d9fc71e4 | 4371 | { |
3b6c3c8e MS |
4372 | if ((attr = ippFindAttribute(response, "printer-resolution-default", IPP_TAG_RESOLUTION)) != NULL) |
4373 | { | |
4374 | pwg_ppdize_resolution(attr, 0, &xres, &yres, ppdname, sizeof(ppdname)); | |
4375 | } | |
4376 | else | |
4377 | { | |
4378 | xres = yres = 300; | |
4379 | strlcpy(ppdname, "300dpi", sizeof(ppdname)); | |
4380 | } | |
4381 | ||
d9fc71e4 | 4382 | cupsFilePrintf(fp, "*DefaultResolution: %s\n", ppdname); |
3b6c3c8e | 4383 | |
c96cc7c0 | 4384 | cupsFilePrintf(fp, "*OpenUI *cupsPrintQuality: PickOne\n" |
3b6c3c8e | 4385 | "*OrderDependency: 10 AnySetup *cupsPrintQuality\n" |
c96cc7c0 MS |
4386 | "*%s.Translation cupsPrintQuality/%s: \"\"\n" |
4387 | "*DefaultcupsPrintQuality: Normal\n", lang->language, _cupsLangString(lang, _("Print Quality"))); | |
3b6c3c8e | 4388 | if (ippContainsInteger(quality, IPP_QUALITY_DRAFT)) |
c96cc7c0 MS |
4389 | cupsFilePrintf(fp, "*cupsPrintQuality Draft: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Draft/%s: \"\"\n", xres, yres, lang->language, _cupsLangString(lang, _("Draft"))); |
4390 | ||
4391 | cupsFilePrintf(fp, "*cupsPrintQuality Normal: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality Normal/%s: \"\"\n", xres, yres, lang->language, _cupsLangString(lang, _("Normal"))); | |
4392 | ||
3b6c3c8e | 4393 | if (ippContainsInteger(quality, IPP_QUALITY_HIGH)) |
c96cc7c0 | 4394 | cupsFilePrintf(fp, "*cupsPrintQuality High: \"<</HWResolution[%d %d]>>setpagedevice\"\n*%s.cupsPrintQuality High/%s: \"\"\n", xres, yres, lang->language, _cupsLangString(lang, _("High"))); |
3b6c3c8e | 4395 | cupsFilePuts(fp, "*CloseUI: *cupsPrintQuality\n"); |
d9fc71e4 | 4396 | } |
d9fc71e4 | 4397 | |
cfa8aa69 MS |
4398 | /* |
4399 | * Presets... | |
4400 | */ | |
4401 | ||
4402 | if ((attr = ippFindAttribute(response, "job-presets-supported", IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
4403 | { | |
4404 | for (i = 0, count = ippGetCount(attr); i < count; i ++) | |
4405 | { | |
4406 | ipp_t *preset = ippGetCollection(attr, i); | |
4407 | /* Preset collection */ | |
4408 | const char *preset_name = ippGetString(ippFindAttribute(preset, "preset-name", IPP_TAG_ZERO), 0, NULL), | |
4409 | /* Preset name */ | |
4410 | *localized_name; /* Localized preset name */ | |
4411 | ipp_attribute_t *member; /* Member attribute in preset */ | |
4412 | const char *member_name; /* Member attribute name */ | |
4413 | char member_value[256]; /* Member attribute value */ | |
4414 | ||
4415 | if (!preset || !preset_name) | |
4416 | continue; | |
4417 | ||
c96cc7c0 | 4418 | cupsFilePrintf(fp, "*APPrinterPreset %s: \"\n", preset_name); |
cfa8aa69 MS |
4419 | for (member = ippFirstAttribute(preset); member; member = ippNextAttribute(preset)) |
4420 | { | |
4421 | member_name = ippGetName(member); | |
4422 | ||
4423 | if (!member_name || !strcmp(member_name, "preset-name")) | |
4424 | continue; | |
4425 | ||
4426 | if (!strcmp(member_name, "finishings")) | |
4427 | { | |
4428 | for (i = 0, count = ippGetCount(member); i < count; i ++) | |
4429 | { | |
4430 | const char *option = NULL; /* PPD option name */ | |
4431 | ||
4432 | keyword = ippEnumString("finishings", ippGetInteger(member, i)); | |
4433 | ||
4434 | if (!strcmp(keyword, "booklet-maker")) | |
4435 | { | |
4436 | option = "Booklet"; | |
4437 | keyword = "True"; | |
4438 | } | |
4439 | else if (!strncmp(keyword, "fold-", 5)) | |
4440 | option = "FoldType"; | |
4441 | else if (!strncmp(keyword, "punch-", 6)) | |
4442 | option = "PunchMedia"; | |
4443 | else if (!strncmp(keyword, "bind-", 5) || !strncmp(keyword, "edge-stitch-", 12) || !strcmp(keyword, "saddle-stitch") || !strncmp(keyword, "staple-", 7)) | |
4444 | option = "StapleLocation"; | |
4445 | ||
4446 | if (option && keyword) | |
4447 | cupsFilePrintf(fp, "*%s %s\n", option, keyword); | |
4448 | } | |
4449 | } | |
4450 | else if (!strcmp(member_name, "finishings-col")) | |
4451 | { | |
4452 | ipp_t *fin_col; /* finishings-col value */ | |
4453 | ||
4454 | for (i = 0, count = ippGetCount(member); i < count; i ++) | |
4455 | { | |
4456 | fin_col = ippGetCollection(member, i); | |
4457 | ||
4458 | if ((keyword = ippGetString(ippFindAttribute(fin_col, "finishing-template", IPP_TAG_ZERO), 0, NULL)) != NULL) | |
4459 | cupsFilePrintf(fp, "*cupsFinishingTemplate %s\n", keyword); | |
4460 | } | |
4461 | } | |
4462 | else if (!strcmp(member_name, "media")) | |
4463 | { | |
4464 | /* | |
4465 | * Map media to PageSize... | |
4466 | */ | |
4467 | ||
4468 | if ((pwg = pwgMediaForPWG(ippGetString(member, 0, NULL))) != NULL && pwg->ppd) | |
4469 | cupsFilePrintf(fp, "*PageSize %s\n", pwg->ppd); | |
4470 | } | |
4471 | else if (!strcmp(member_name, "media-col")) | |
4472 | { | |
4473 | media_col = ippGetCollection(member, 0); | |
4474 | ||
4475 | if ((media_size = ippGetCollection(ippFindAttribute(media_col, "media-size", IPP_TAG_BEGIN_COLLECTION), 0)) != NULL) | |
4476 | { | |
4477 | x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_INTEGER); | |
4478 | y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_INTEGER); | |
4479 | if ((pwg = pwgMediaForSize(ippGetInteger(x_dim, 0), ippGetInteger(y_dim, 0))) != NULL && pwg->ppd) | |
4480 | cupsFilePrintf(fp, "*PageSize %s\n", pwg->ppd); | |
4481 | } | |
4482 | ||
4483 | if ((keyword = ippGetString(ippFindAttribute(media_col, "media-source", IPP_TAG_ZERO), 0, NULL)) != NULL) | |
4484 | { | |
4485 | pwg_ppdize_name(keyword, ppdname, sizeof(ppdname)); | |
4486 | cupsFilePrintf(fp, "*InputSlot %s\n", keyword); | |
4487 | } | |
4488 | ||
4489 | if ((keyword = ippGetString(ippFindAttribute(media_col, "media-type", IPP_TAG_ZERO), 0, NULL)) != NULL) | |
4490 | { | |
4491 | pwg_ppdize_name(keyword, ppdname, sizeof(ppdname)); | |
4492 | cupsFilePrintf(fp, "*MediaType %s\n", keyword); | |
4493 | } | |
4494 | } | |
4495 | else if (!strcmp(member_name, "print-quality")) | |
4496 | { | |
4497 | /* | |
4498 | * Map print-quality to cupsPrintQuality... | |
4499 | */ | |
4500 | ||
4501 | int qval = ippGetInteger(member, 0); | |
4502 | /* print-quality value */ | |
4503 | static const char * const qualities[] = { "Draft", "Normal", "High" }; | |
4504 | /* cupsPrintQuality values */ | |
4505 | ||
4506 | if (qval >= IPP_QUALITY_DRAFT && qval <= IPP_QUALITY_HIGH) | |
4507 | cupsFilePrintf(fp, "*cupsPrintQuality %s\n", qualities[qval - IPP_QUALITY_DRAFT]); | |
4508 | } | |
4509 | else if (!strcmp(member_name, "output-bin")) | |
4510 | { | |
4511 | pwg_ppdize_name(ippGetString(member, 0, NULL), ppdname, sizeof(ppdname)); | |
4512 | cupsFilePrintf(fp, "*OutputBin %s\n", ppdname); | |
4513 | } | |
4514 | else if (!strcmp(member_name, "sides")) | |
4515 | { | |
4516 | keyword = ippGetString(member, 0, NULL); | |
4517 | if (keyword && !strcmp(keyword, "one-sided")) | |
4518 | cupsFilePuts(fp, "*Duplex None\n"); | |
4519 | else if (keyword && !strcmp(keyword, "two-sided-long-edge")) | |
4520 | cupsFilePuts(fp, "*Duplex DuplexNoTumble\n"); | |
4521 | else if (keyword && !strcmp(keyword, "two-sided-short-edge")) | |
4522 | cupsFilePuts(fp, "*Duplex DuplexTumble\n"); | |
4523 | } | |
4524 | else | |
4525 | { | |
4526 | /* | |
4527 | * Add attribute name and value as-is... | |
4528 | */ | |
4529 | ||
4530 | ippAttributeString(member, member_value, sizeof(member_value)); | |
4531 | cupsFilePrintf(fp, "*%s %s\n", member_name, member_value); | |
4532 | } | |
4533 | } | |
4534 | ||
4535 | cupsFilePuts(fp, "\"\n*End\n"); | |
c96cc7c0 MS |
4536 | |
4537 | if ((localized_name = _cupsMessageLookup(strings, preset_name)) != preset_name) | |
4538 | cupsFilePrintf(fp, "*%s.APPrinterPreset %s/%s: \"\"\n", lang->language, preset_name, localized_name); | |
cfa8aa69 MS |
4539 | } |
4540 | } | |
4541 | ||
d9fc71e4 MS |
4542 | /* |
4543 | * Close up and return... | |
4544 | */ | |
4545 | ||
4546 | cupsFileClose(fp); | |
4547 | ||
4548 | return (buffer); | |
d4259b45 MS |
4549 | |
4550 | /* | |
4551 | * If we get here then there was a problem creating the PPD... | |
4552 | */ | |
4553 | ||
4554 | bad_ppd: | |
4555 | ||
4556 | cupsFileClose(fp); | |
4557 | unlink(buffer); | |
4558 | *buffer = '\0'; | |
4559 | ||
a946858f MS |
4560 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Printer does not support required IPP attributes or document formats."), 1); |
4561 | ||
d4259b45 | 4562 | return (NULL); |
d9fc71e4 MS |
4563 | } |
4564 | ||
4565 | ||
f14324a7 MS |
4566 | /* |
4567 | * '_pwgInputSlotForSource()' - Get the InputSlot name for the given PWG | |
4568 | * media-source. | |
4569 | */ | |
4570 | ||
4571 | const char * /* O - InputSlot name */ | |
4572 | _pwgInputSlotForSource( | |
4573 | const char *media_source, /* I - PWG media-source */ | |
4574 | char *name, /* I - Name buffer */ | |
4575 | size_t namesize) /* I - Size of name buffer */ | |
4576 | { | |
4577 | /* | |
4578 | * Range check input... | |
4579 | */ | |
4580 | ||
4581 | if (!media_source || !name || namesize < PPD_MAX_NAME) | |
4582 | return (NULL); | |
4583 | ||
88f9aafc | 4584 | if (_cups_strcasecmp(media_source, "main")) |
f14324a7 | 4585 | strlcpy(name, "Cassette", namesize); |
88f9aafc | 4586 | else if (_cups_strcasecmp(media_source, "alternate")) |
f14324a7 | 4587 | strlcpy(name, "Multipurpose", namesize); |
88f9aafc | 4588 | else if (_cups_strcasecmp(media_source, "large-capacity")) |
f14324a7 | 4589 | strlcpy(name, "LargeCapacity", namesize); |
88f9aafc | 4590 | else if (_cups_strcasecmp(media_source, "bottom")) |
f14324a7 | 4591 | strlcpy(name, "Lower", namesize); |
88f9aafc | 4592 | else if (_cups_strcasecmp(media_source, "middle")) |
f14324a7 | 4593 | strlcpy(name, "Middle", namesize); |
88f9aafc | 4594 | else if (_cups_strcasecmp(media_source, "top")) |
f14324a7 | 4595 | strlcpy(name, "Upper", namesize); |
88f9aafc | 4596 | else if (_cups_strcasecmp(media_source, "rear")) |
f14324a7 | 4597 | strlcpy(name, "Rear", namesize); |
88f9aafc | 4598 | else if (_cups_strcasecmp(media_source, "side")) |
f14324a7 | 4599 | strlcpy(name, "Side", namesize); |
88f9aafc | 4600 | else if (_cups_strcasecmp(media_source, "envelope")) |
f14324a7 | 4601 | strlcpy(name, "Envelope", namesize); |
88f9aafc | 4602 | else if (_cups_strcasecmp(media_source, "main-roll")) |
f14324a7 | 4603 | strlcpy(name, "Roll", namesize); |
88f9aafc | 4604 | else if (_cups_strcasecmp(media_source, "alternate-roll")) |
f14324a7 MS |
4605 | strlcpy(name, "Roll2", namesize); |
4606 | else | |
4607 | pwg_ppdize_name(media_source, name, namesize); | |
4608 | ||
4609 | return (name); | |
4610 | } | |
4611 | ||
4612 | ||
4613 | /* | |
4614 | * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG | |
4615 | * media-type. | |
4616 | */ | |
4617 | ||
4618 | const char * /* O - MediaType name */ | |
4619 | _pwgMediaTypeForType( | |
4620 | const char *media_type, /* I - PWG media-type */ | |
4621 | char *name, /* I - Name buffer */ | |
4622 | size_t namesize) /* I - Size of name buffer */ | |
4623 | { | |
4624 | /* | |
4625 | * Range check input... | |
4626 | */ | |
4627 | ||
4628 | if (!media_type || !name || namesize < PPD_MAX_NAME) | |
4629 | return (NULL); | |
4630 | ||
88f9aafc | 4631 | if (_cups_strcasecmp(media_type, "auto")) |
f14324a7 | 4632 | strlcpy(name, "Auto", namesize); |
88f9aafc | 4633 | else if (_cups_strcasecmp(media_type, "cardstock")) |
f14324a7 | 4634 | strlcpy(name, "Cardstock", namesize); |
88f9aafc | 4635 | else if (_cups_strcasecmp(media_type, "envelope")) |
f14324a7 | 4636 | strlcpy(name, "Envelope", namesize); |
88f9aafc | 4637 | else if (_cups_strcasecmp(media_type, "photographic-glossy")) |
f14324a7 | 4638 | strlcpy(name, "Glossy", namesize); |
88f9aafc | 4639 | else if (_cups_strcasecmp(media_type, "photographic-high-gloss")) |
f14324a7 | 4640 | strlcpy(name, "HighGloss", namesize); |
88f9aafc | 4641 | else if (_cups_strcasecmp(media_type, "photographic-matte")) |
f14324a7 | 4642 | strlcpy(name, "Matte", namesize); |
88f9aafc | 4643 | else if (_cups_strcasecmp(media_type, "stationery")) |
f14324a7 | 4644 | strlcpy(name, "Plain", namesize); |
88f9aafc | 4645 | else if (_cups_strcasecmp(media_type, "stationery-coated")) |
f14324a7 | 4646 | strlcpy(name, "Coated", namesize); |
88f9aafc | 4647 | else if (_cups_strcasecmp(media_type, "stationery-inkjet")) |
f14324a7 | 4648 | strlcpy(name, "Inkjet", namesize); |
88f9aafc | 4649 | else if (_cups_strcasecmp(media_type, "stationery-letterhead")) |
f14324a7 | 4650 | strlcpy(name, "Letterhead", namesize); |
88f9aafc | 4651 | else if (_cups_strcasecmp(media_type, "stationery-preprinted")) |
f14324a7 | 4652 | strlcpy(name, "Preprinted", namesize); |
88f9aafc | 4653 | else if (_cups_strcasecmp(media_type, "transparency")) |
f14324a7 MS |
4654 | strlcpy(name, "Transparency", namesize); |
4655 | else | |
4656 | pwg_ppdize_name(media_type, name, namesize); | |
4657 | ||
4658 | return (name); | |
4659 | } | |
4660 | ||
4661 | ||
4662 | /* | |
4663 | * '_pwgPageSizeForMedia()' - Get the PageSize name for the given media. | |
4664 | */ | |
4665 | ||
4666 | const char * /* O - PageSize name */ | |
4667 | _pwgPageSizeForMedia( | |
982be458 MS |
4668 | pwg_media_t *media, /* I - Media */ |
4669 | char *name, /* I - PageSize name buffer */ | |
4670 | size_t namesize) /* I - Size of name buffer */ | |
f14324a7 MS |
4671 | { |
4672 | const char *sizeptr, /* Pointer to size in PWG name */ | |
4673 | *dimptr; /* Pointer to dimensions in PWG name */ | |
4674 | ||
4675 | ||
4676 | /* | |
4677 | * Range check input... | |
4678 | */ | |
4679 | ||
4680 | if (!media || !name || namesize < PPD_MAX_NAME) | |
4681 | return (NULL); | |
4682 | ||
4683 | /* | |
4684 | * Copy or generate a PageSize name... | |
4685 | */ | |
4686 | ||
4687 | if (media->ppd) | |
4688 | { | |
4689 | /* | |
4690 | * Use a standard Adobe name... | |
4691 | */ | |
4692 | ||
4693 | strlcpy(name, media->ppd, namesize); | |
4694 | } | |
4695 | else if (!media->pwg || !strncmp(media->pwg, "custom_", 7) || | |
4696 | (sizeptr = strchr(media->pwg, '_')) == NULL || | |
4697 | (dimptr = strchr(sizeptr + 1, '_')) == NULL || | |
4698 | (size_t)(dimptr - sizeptr) > namesize) | |
4699 | { | |
4700 | /* | |
4701 | * Use a name of the form "wNNNhNNN"... | |
4702 | */ | |
4703 | ||
6961465f MS |
4704 | snprintf(name, namesize, "w%dh%d", (int)PWG_TO_POINTS(media->width), |
4705 | (int)PWG_TO_POINTS(media->length)); | |
f14324a7 MS |
4706 | } |
4707 | else | |
4708 | { | |
4709 | /* | |
4710 | * Copy the size name from class_sizename_dimensions... | |
4711 | */ | |
4712 | ||
07623986 | 4713 | memcpy(name, sizeptr + 1, (size_t)(dimptr - sizeptr - 1)); |
f14324a7 MS |
4714 | name[dimptr - sizeptr - 1] = '\0'; |
4715 | } | |
4716 | ||
4717 | return (name); | |
4718 | } | |
4719 | ||
4720 | ||
89550f3f MS |
4721 | /* |
4722 | * 'cups_get_url()' - Get a copy of the file at the given URL. | |
4723 | */ | |
4724 | ||
4725 | static int /* O - 1 on success, 0 on failure */ | |
4726 | cups_get_url(http_t **http, /* IO - Current HTTP connection */ | |
4727 | const char *url, /* I - URL to get */ | |
4728 | char *name, /* I - Temporary filename */ | |
4729 | size_t namesize) /* I - Size of temporary filename buffer */ | |
4730 | { | |
4731 | char scheme[32], /* URL scheme */ | |
4732 | userpass[256], /* URL username:password */ | |
4733 | host[256], /* URL host */ | |
4734 | curhost[256], /* Current host */ | |
4735 | resource[256]; /* URL resource */ | |
4736 | int port; /* URL port */ | |
4737 | http_encryption_t encryption; /* Type of encryption to use */ | |
4738 | http_status_t status; /* Status of GET request */ | |
4739 | int fd; /* Temporary file */ | |
4740 | ||
4741 | ||
4742 | if (httpSeparateURI(HTTP_URI_CODING_ALL, url, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK) | |
4743 | return (0); | |
4744 | ||
4745 | if (port == 443 || !strcmp(scheme, "https")) | |
4746 | encryption = HTTP_ENCRYPTION_ALWAYS; | |
4747 | else | |
4748 | encryption = HTTP_ENCRYPTION_IF_REQUESTED; | |
4749 | ||
4750 | if (!*http || strcasecmp(host, httpGetHostname(*http, curhost, sizeof(curhost))) || httpAddrPort(httpGetAddress(*http)) != port) | |
4751 | { | |
4752 | httpClose(*http); | |
4753 | *http = httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 5000, NULL); | |
4754 | } | |
4755 | ||
4756 | if (!*http) | |
4757 | return (0); | |
4758 | ||
4759 | if ((fd = cupsTempFd(name, (int)namesize)) < 0) | |
4760 | return (0); | |
4761 | ||
4762 | status = cupsGetFd(*http, resource, fd); | |
4763 | ||
4764 | close(fd); | |
4765 | ||
4766 | if (status != HTTP_STATUS_OK) | |
4767 | { | |
4768 | unlink(name); | |
4769 | *name = '\0'; | |
4770 | return (0); | |
4771 | } | |
4772 | ||
4773 | return (1); | |
4774 | } | |
4775 | ||
4776 | ||
1fbd0cab MS |
4777 | /* |
4778 | * 'pwg_add_finishing()' - Add a finishings value. | |
4779 | */ | |
4780 | ||
4781 | static void | |
4782 | pwg_add_finishing( | |
4783 | cups_array_t *finishings, /* I - Finishings array */ | |
4784 | ipp_finishings_t template, /* I - Finishing template */ | |
4785 | const char *name, /* I - PPD option */ | |
4786 | const char *value) /* I - PPD choice */ | |
4787 | { | |
4788 | _pwg_finishings_t *f; /* New finishings value */ | |
4789 | ||
4790 | ||
4791 | if ((f = (_pwg_finishings_t *)calloc(1, sizeof(_pwg_finishings_t))) != NULL) | |
4792 | { | |
4793 | f->value = template; | |
4794 | f->num_options = cupsAddOption(name, value, 0, &f->options); | |
4795 | ||
4796 | cupsArrayAdd(finishings, f); | |
4797 | } | |
4798 | } | |
4799 | ||
4800 | ||
2fa1ba3c MS |
4801 | /* |
4802 | * 'pwg_add_message()' - Add a message to the PPD cached strings. | |
4803 | */ | |
4804 | ||
4805 | static void | |
4806 | pwg_add_message(cups_array_t *a, /* I - Message catalog */ | |
4807 | const char *msg, /* I - Message identifier */ | |
4808 | const char *str) /* I - Localized string */ | |
4809 | { | |
4810 | _cups_message_t *m; /* New message */ | |
4811 | ||
4812 | ||
4813 | if ((m = calloc(1, sizeof(_cups_message_t))) != NULL) | |
4814 | { | |
4815 | m->msg = strdup(msg); | |
4816 | m->str = strdup(str); | |
4817 | cupsArrayAdd(a, m); | |
4818 | } | |
4819 | } | |
4820 | ||
4821 | ||
dcb445bc MS |
4822 | /* |
4823 | * 'pwg_compare_finishings()' - Compare two finishings values. | |
4824 | */ | |
4825 | ||
1fbd0cab | 4826 | static int /* O - Result of comparison */ |
dcb445bc MS |
4827 | pwg_compare_finishings( |
4828 | _pwg_finishings_t *a, /* I - First finishings value */ | |
4829 | _pwg_finishings_t *b) /* I - Second finishings value */ | |
4830 | { | |
7d5824d6 | 4831 | return ((int)b->value - (int)a->value); |
dcb445bc MS |
4832 | } |
4833 | ||
4834 | ||
982be458 MS |
4835 | /* |
4836 | * 'pwg_compare_sizes()' - Compare two media sizes... | |
4837 | */ | |
4838 | ||
4839 | static int /* O - Result of comparison */ | |
4840 | pwg_compare_sizes(cups_size_t *a, /* I - First media size */ | |
4841 | cups_size_t *b) /* I - Second media size */ | |
4842 | { | |
4843 | return (strcmp(a->media, b->media)); | |
4844 | } | |
4845 | ||
4846 | ||
4847 | /* | |
4848 | * 'pwg_copy_size()' - Copy a media size. | |
4849 | */ | |
4850 | ||
4851 | static cups_size_t * /* O - New media size */ | |
4852 | pwg_copy_size(cups_size_t *size) /* I - Media size to copy */ | |
4853 | { | |
4854 | cups_size_t *newsize = (cups_size_t *)calloc(1, sizeof(cups_size_t)); | |
4855 | /* New media size */ | |
4856 | ||
4857 | if (newsize) | |
4858 | memcpy(newsize, size, sizeof(cups_size_t)); | |
4859 | ||
4860 | return (newsize); | |
4861 | } | |
4862 | ||
4863 | ||
dcb445bc MS |
4864 | /* |
4865 | * 'pwg_free_finishings()' - Free a finishings value. | |
4866 | */ | |
4867 | ||
4868 | static void | |
4869 | pwg_free_finishings( | |
4870 | _pwg_finishings_t *f) /* I - Finishings value */ | |
4871 | { | |
4872 | cupsFreeOptions(f->num_options, f->options); | |
4873 | free(f); | |
4874 | } | |
4875 | ||
4876 | ||
f14324a7 MS |
4877 | /* |
4878 | * 'pwg_ppdize_name()' - Convert an IPP keyword to a PPD keyword. | |
4879 | */ | |
4880 | ||
4881 | static void | |
4882 | pwg_ppdize_name(const char *ipp, /* I - IPP keyword */ | |
4883 | char *name, /* I - Name buffer */ | |
4884 | size_t namesize) /* I - Size of name buffer */ | |
4885 | { | |
4886 | char *ptr, /* Pointer into name buffer */ | |
4887 | *end; /* End of name buffer */ | |
4888 | ||
4889 | ||
670172ea MS |
4890 | if (!ipp) |
4891 | { | |
4892 | *name = '\0'; | |
4893 | return; | |
4894 | } | |
4895 | ||
7e86f2f6 | 4896 | *name = (char)toupper(*ipp++); |
f14324a7 MS |
4897 | |
4898 | for (ptr = name + 1, end = name + namesize - 1; *ipp && ptr < end;) | |
4899 | { | |
2a8afc20 | 4900 | if (*ipp == '-' && _cups_isalnum(ipp[1])) |
f14324a7 MS |
4901 | { |
4902 | ipp ++; | |
7e86f2f6 | 4903 | *ptr++ = (char)toupper(*ipp++ & 255); |
f14324a7 MS |
4904 | } |
4905 | else | |
4906 | *ptr++ = *ipp++; | |
4907 | } | |
4908 | ||
4909 | *ptr = '\0'; | |
4910 | } | |
4911 | ||
4912 | ||
d9fc71e4 MS |
4913 | /* |
4914 | * 'pwg_ppdize_resolution()' - Convert PWG resolution values to PPD values. | |
4915 | */ | |
4916 | ||
4917 | static void | |
4918 | pwg_ppdize_resolution( | |
4919 | ipp_attribute_t *attr, /* I - Attribute to convert */ | |
4920 | int element, /* I - Element to convert */ | |
4921 | int *xres, /* O - X resolution in DPI */ | |
4922 | int *yres, /* O - Y resolution in DPI */ | |
4923 | char *name, /* I - Name buffer */ | |
4924 | size_t namesize) /* I - Size of name buffer */ | |
4925 | { | |
4926 | ipp_res_t units; /* Units for resolution */ | |
4927 | ||
4928 | ||
4929 | *xres = ippGetResolution(attr, element, yres, &units); | |
4930 | ||
4931 | if (units == IPP_RES_PER_CM) | |
4932 | { | |
4933 | *xres = (int)(*xres * 2.54); | |
4934 | *yres = (int)(*yres * 2.54); | |
4935 | } | |
4936 | ||
4937 | if (name && namesize > 4) | |
4938 | { | |
4939 | if (*xres == *yres) | |
4940 | snprintf(name, namesize, "%ddpi", *xres); | |
4941 | else | |
4942 | snprintf(name, namesize, "%dx%ddpi", *xres, *yres); | |
4943 | } | |
4944 | } | |
4945 | ||
4946 | ||
f14324a7 MS |
4947 | /* |
4948 | * 'pwg_unppdize_name()' - Convert a PPD keyword to a lowercase IPP keyword. | |
4949 | */ | |
4950 | ||
4951 | static void | |
4952 | pwg_unppdize_name(const char *ppd, /* I - PPD keyword */ | |
4953 | char *name, /* I - Name buffer */ | |
c1420c87 MS |
4954 | size_t namesize, /* I - Size of name buffer */ |
4955 | const char *dashchars)/* I - Characters to be replaced by dashes */ | |
f14324a7 MS |
4956 | { |
4957 | char *ptr, /* Pointer into name buffer */ | |
4958 | *end; /* End of name buffer */ | |
4959 | ||
4960 | ||
79d7d84a MS |
4961 | if (_cups_islower(*ppd)) |
4962 | { | |
4963 | /* | |
4964 | * Already lowercase name, use as-is? | |
4965 | */ | |
4966 | ||
4967 | const char *ppdptr; /* Pointer into PPD keyword */ | |
4968 | ||
4969 | for (ppdptr = ppd + 1; *ppdptr; ppdptr ++) | |
4970 | if (_cups_isupper(*ppdptr) || strchr(dashchars, *ppdptr)) | |
4971 | break; | |
4972 | ||
4973 | if (!*ppdptr) | |
4974 | { | |
4975 | strlcpy(name, ppd, namesize); | |
4976 | return; | |
4977 | } | |
4978 | } | |
4979 | ||
f14324a7 MS |
4980 | for (ptr = name, end = name + namesize - 1; *ppd && ptr < end; ppd ++) |
4981 | { | |
4982 | if (_cups_isalnum(*ppd) || *ppd == '-') | |
7e86f2f6 | 4983 | *ptr++ = (char)tolower(*ppd & 255); |
c1420c87 | 4984 | else if (strchr(dashchars, *ppd)) |
f14324a7 | 4985 | *ptr++ = '-'; |
c1420c87 MS |
4986 | else |
4987 | *ptr++ = *ppd; | |
f14324a7 MS |
4988 | |
4989 | if (!_cups_isupper(*ppd) && _cups_isalnum(*ppd) && | |
4990 | _cups_isupper(ppd[1]) && ptr < end) | |
4991 | *ptr++ = '-'; | |
d489df6a MS |
4992 | else if (!isdigit(*ppd & 255) && isdigit(ppd[1] & 255)) |
4993 | *ptr++ = '-'; | |
f14324a7 MS |
4994 | } |
4995 | ||
4996 | *ptr = '\0'; | |
4997 | } |