Debian Codegraph @

src/cups/genppd.c

raw symbols SCIP
1 /*
2 * PPD file generation program for the CUPS drivers.
3 *
4 * Copyright 1993-2008 by Mike Sweet and Robert Krawitz.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Contents:
20 *
21 * main() - Process files on the command-line...
22 * cat_ppd() - Copy the named PPD to stdout.
23 * generate_ppd() - Generate a PPD file.
24 * getlangs() - Get a list of available translations.
25 * help() - Show detailed help.
26 * is_special_option() - Determine if an option should be grouped.
27 * list_ppds() - List the available drivers.
28 * print_group_close() - Close a UI group.
29 * print_group_open() - Open a new UI group.
30 * printlangs() - Print list of available translations.
31 * printmodels() - Print a list of available models.
32 * usage() - Show program usage.
33 * write_ppd() - Write a PPD file.
34 */
35
36 /*
37 * Include necessary headers...
38 */
39
40 #include "genppd.h"
41 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
42
43 #if defined(HAVE_VARARGS_H) && !defined(HAVE_STDARG_H)
44 #include <varargs.h>
45 #else
46 #include <stdarg.h>
47 #endif
48
49 const char *ppdext = ".ppd";
50 const char *cups_modeldir = CUPS_MODELDIR;
51 const char *gpext = "";
52
53 static int use_compression;
54
55 int use_base_version = 0;
56
57 /*
58 * Some applications use the XxYdpi tags rather than the actual
59 * hardware resolutions to decide what resolution to print at. Some
60 * applications get very unhappy if the vertical resolution exceeds
61 * a certain amount. Some of those applications even get very unhappy if
62 * the PPD file even contains a resolution that exceeds that limit.
63 * And they're not even free source applications.
64 * Feh.
65 */
66 #define MAXIMUM_SAFE_PPD_Y_RESOLUTION (720)
67 #define MAXIMUM_SAFE_PPD_X_RESOLUTION (1500)
68
69 /*
70 * Note:
71 *
72 * The current release of ESP Ghostscript is fully Level 3 compliant,
73 * so we can report Level 3 support by default...
74 */
75
76 int cups_ppd_ps_level = CUPS_PPD_PS_LEVEL;
77 int localize_numbers = 0;
78
79 /*
80 * File handling stuff...
81 */
82
83 typedef struct /**** Media size values ****/
84 {
85 const char *name, /* Media size name */
86 *text; /* Media size text */
87 stp_dimension_t width, /* Media width */
88 height, /* Media height */
89 left, /* Media left margin */
90 right, /* Media right margin */
91 bottom, /* Media bottom margin */
92 top; /* Media top margin */
93 } paper_t;
94
95 const char *special_options[] =
96 {
97 "PageSize",
98 "MediaType",
99 "InputSlot",
100 "Resolution",
101 "OutputOrder",
102 "Quality",
103 "Duplex",
104 "Collate",
105 NULL
106 };
107
108 /*
109 * TRANSLATORS:
110 * Please keep these translated names SHORT. The number of bytes in
111 * the parameter class name plus the number of bytes in the parameter
112 * name must not exceed 38 BYTES (not characters!)
113 */
114
115 const char *parameter_class_names[] =
116 {
117 _("Printer Features"),
118 _("Output Control")
119 };
120
121 const char *parameter_level_names[] =
122 {
123 _("Common"),
124 _("Extra 1"),
125 _("Extra 2"),
126 _("Extra 3"),
127 _("Extra 4"),
128 _("Extra 5")
129 };
130
131 /*
132 * Local functions...
133 */
134
135 static int gpputs(gpFile f, const char *s);
136 static int gpprintf(gpFile f, const char *format, ...)
137 __attribute__((format(__printf__, 2, 3)));
138 static int is_special_option(const char *name);
139 static void print_group_close(gpFile fp, stp_parameter_class_t p_class,
140 stp_parameter_level_t p_level,
141 const char *language,
142 const stp_string_list_t *po);
143 static void print_group_open(gpFile fp, stp_parameter_class_t p_class,
144 stp_parameter_level_t p_level,
145 const char *language,
146 const stp_string_list_t *po);
147
148
149 /*
150 * Global variables...
151 */
152
153
154 static int
155 gpputs(gpFile f, const char *s)
156 {
157 #ifdef HAVE_LIBZ
158 if (use_compression)
159 return gzputs(f->gzf, s);
160 else
161 return fputs(s, f->f);
162 #else
163 return fputs(s, f);
164 #endif
165 }
166
167 static int
168 gpprintf(gpFile f, const char *format, ...)
169 {
170 int status;
171 int current_allocation = 64;
172 char *result = stp_malloc(current_allocation);
173 while (1)
174 {
175 int bytes;
176 va_list args;
177 va_start(args, format);
178 bytes = vsnprintf(result, current_allocation, format, args);
179 va_end(args);
180 if (bytes >= 0 && bytes < current_allocation)
181 break;
182 else
183 {
184 stp_free(result);
185 if (bytes < 0)
186 current_allocation *= 2;
187 else
188 current_allocation = bytes + 1;
189 result = stp_malloc(current_allocation);
190 }
191 }
192 status = gpputs(f, result);
193 stp_free(result);
194 return status;
195 }
196
197 /*
198 * 'getlangs()' - Get a list of available translations.
199 */
200
201 char ** /* O - Array of languages */
202 getlangs(void)
203 {
204 int i; /* Looping var */
205 char *ptr; /* Pointer into string */
206 static char all_linguas[] = ALL_LINGUAS;
207 /* List of languages from configure.ac */
208 static char **langs = NULL; /* Array of languages */
209
210
211 if (!langs)
212 {
213 /*
214 * Create the langs array...
215 */
216
217 for (i = 1, ptr = strchr(all_linguas, ' '); ptr; ptr = strchr(ptr + 1, ' '))
218 i ++;
219
220 langs = calloc(i + 1, sizeof(char *));
221
222 langs[0] = all_linguas;
223 for (i = 1, ptr = strchr(all_linguas, ' '); ptr; ptr = strchr(ptr + 1, ' '))
224 {
225 *ptr = '\0';
226 langs[i] = ptr + 1;
227 i ++;
228 }
229 }
230
231 return (langs);
232 }
233
234
235 /*
236 * 'is_special_option()' - Determine if an option should be grouped.
237 */
238
239 static int /* O - 1 if non-grouped, 0 otherwise */
240 is_special_option(const char *name) /* I - Option name */
241 {
242 int i = 0;
243 while (special_options[i])
244 {
245 if (strcmp(name, special_options[i]) == 0)
246 return 1;
247 i++;
248 }
249 return 0;
250 }
251
252 /*
253 * strlen returns the number of characters. PPD file limitations are
254 * defined in bytes. So we need something to count bytes, not merely
255 * characters.
256 */
257
258 static size_t
259 bytelen(const char *buffer)
260 {
261 size_t answer = 0;
262 while (*buffer++ != '\0')
263 answer++;
264 return answer;
265 }
266
267 /*
268 * Use our localization routine to correctly do localization on all
269 * systems. The standard lookup routine has trouble creating multi-locale
270 * files on many systems, and on some systems there's not even a reliable
271 * way to use something other than the system locale.
272 */
273 #ifdef _
274 #undef _
275 #endif
276 #define _(x) stp_i18n_lookup(po, x)
277
278 #define PPD_MAX_SHORT_NICKNAME (31)
279
280 static void
281 print_ppd_header(gpFile fp, ppd_type_t ppd_type, int model, const char *driver,
282 const char *family, const char *long_name,
283 const char *manufacturer, const char *device_id,
284 const char *ppd_location,
285 const char *language, const stp_string_list_t *po,
286 char **all_langs)
287 {
288 (void)model;
289 (void)family;
290 (void)device_id;
291 (void)ppd_location;
292 (void)all_langs;
293
294 char short_long_name[(PPD_MAX_SHORT_NICKNAME) + 1];
295 /*
296 * Write a standard header...
297 */
298 gpputs(fp, "*PPD-Adobe: \"4.3\"\n");
299 gpputs(fp, "*% PPD file for CUPS/Gutenprint.\n");
300 gpputs(fp, "*% Copyright 1993-2008 by Mike Sweet and Robert Krawitz.\n");
301 gpputs(fp, "*% This program is free software; you can redistribute it and/or\n");
302 gpputs(fp, "*% modify it under the terms of the GNU General Public License,\n");
303 gpputs(fp, "*% either version 2, or (at your option) any later version,\n");
304 gpputs(fp, "*% as published by the Free Software Foundation.\n");
305 gpputs(fp, "*%\n");
306 gpputs(fp, "*% This program is distributed in the hope that it will be useful, but\n");
307 gpputs(fp, "*% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n");
308 gpputs(fp, "*% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n");
309 gpputs(fp, "*% for more details.\n");
310 gpputs(fp, "*%\n");
311 gpputs(fp, "*% You should have received a copy of the GNU General Public License\n");
312 gpputs(fp, "*% along with this program. If not, see <https://www.gnu.org/licenses/>.\n");
313 gpputs(fp, "*%\n");
314 gpputs(fp, "*FormatVersion: \"4.3\"\n");
315 if (use_base_version)
316 gpputs(fp, "*FileVersion: \"" BASE_VERSION "\"\n");
317 else
318 gpputs(fp, "*FileVersion: \"" VERSION "\"\n");
319 /* Specify language of PPD translation */
320 /* TRANSLATORS: Specify the language of the PPD translation.
321 * Use the English name of your language here, e.g. "Swedish" instead of
322 * "Svenska". */
323 gpprintf(fp, "*LanguageVersion: %s\n", _("English"));
324 if (language)
325 gpputs(fp, "*LanguageEncoding: UTF-8\n");
326 else
327 gpputs(fp, "*LanguageEncoding: ISOLatin1\n");
328 /*
329 * Strictly speaking, the PCFileName attribute should be a 12 character
330 * max (12345678.ppd) filename, as a requirement of the old PPD spec.
331 * The following code generates a (hopefully unique) 8.3 filename from
332 * the driver name, and makes the filename all UPPERCASE as well...
333 */
334
335 gpprintf(fp, "*PCFileName: \"STP%05d.PPD\"\n",
336 stp_get_printer_index_by_driver(driver) +
337 ((int) ppd_type * stp_printer_model_count()));
338 gpprintf(fp, "*Manufacturer: \"%s\"\n", manufacturer);
339
340 /*
341 * The Product attribute specifies the string returned by the PostScript
342 * interpreter. The last one will appear in the CUPS "product" field,
343 * while all instances are available as attributes. Rather than listing
344 * the PostScript interpreters we might encounter, we instead just list
345 * a single product line with the "long name" to be compatible with other
346 * CUPS-based drivers. (This is a change from Gutenprint 5.0 and earlier)
347 */
348
349 gpprintf(fp, "*Product: \"(%s)\"\n", long_name);
350
351 /*
352 * The ModelName attribute now provides the long name rather than the
353 * short driver name... The rastertoprinter driver looks up both...
354 */
355
356 gpprintf(fp, "*ModelName: \"%s\"\n", long_name);
357 strncpy(short_long_name, long_name, PPD_MAX_SHORT_NICKNAME);
358 short_long_name[PPD_MAX_SHORT_NICKNAME] = '\0';
359 gpprintf(fp, "*ShortNickName: \"%s\"\n", short_long_name);
360
361 /*
362 * NOTE - code in rastertoprinter looks for this version string.
363 * If this is changed, the corresponding change must be made in
364 * rastertoprinter.c. Look for "ppd->nickname"
365 */
366 gpprintf(fp, "*NickName: \"%s%s%s%s\"\n",
367 long_name, CUPS_PPD_NICKNAME_STRING, VERSION,
368 (ppd_type == PPD_SIMPLIFIED ? " Simplified" :
369 ppd_type == PPD_NO_COLOR_OPTS ? " No Color Options" : ""));
370 if (cups_ppd_ps_level == 2)
371 gpputs(fp, "*PSVersion: \"(2017.000) 550\"\n");
372 else
373 gpputs(fp, "*PSVersion: \"(3010.000) 0\"\n");
374 gpprintf(fp, "*LanguageLevel: \"%d\"\n", cups_ppd_ps_level);
375 }
376
377 static void
378 print_ppd_header_3(gpFile fp, ppd_type_t ppd_type, int model,
379 const char *driver,
380 const char *family, const char *long_name,
381 const char *manufacturer, const char *device_id,
382 const char *ppd_location,
383 const char *language, const stp_string_list_t *po,
384 char **all_langs)
385 {
386 (void)po;
387 (void)ppd_location;
388 (void)manufacturer;
389 (void)long_name;
390 (void)ppd_type;
391 (void)model;
392 (void)driver;
393 (void)family;
394
395 int i;
396 gpputs(fp, "*FileSystem: False\n");
397 gpputs(fp, "*LandscapeOrientation: Plus90\n");
398 gpputs(fp, "*TTRasterizer: Type42\n");
399
400 gpputs(fp, "*cupsVersion: 1.2\n");
401
402 gpprintf(fp, "*cupsFilter: \"application/vnd.cups-raster 100 rastertogutenprint.%s\"\n", GUTENPRINT_RELEASE_VERSION);
403
404 if (device_id)
405 {
406 if (strlen(device_id) > 200)
407 {
408 char buf[129];
409 int bytes_left = strlen(device_id);
410 int offset = 0;
411 gpputs(fp, "*1284DeviceID: \"");
412 while (bytes_left > 0)
413 {
414 memset(buf, 0, 129);
415 strncpy(buf, device_id + offset, 128);
416 gpputs(fp, buf);
417 if (bytes_left <= 128)
418 gpputs(fp, "\"");
419 gpputs(fp, "\n");
420 offset += 128;
421 bytes_left -= 128;
422 }
423 gpputs(fp, "*End\n");
424 }
425 else
426 gpprintf(fp, "*1284DeviceID: \"%s\"\n", device_id);
427 }
428 if (!language)
429 {
430 /*
431 * Generate globalized PPDs when POSIX language is requested...
432 */
433
434 const char *prefix = "*cupsLanguages: \"";
435
436 for (i = 0; all_langs[i]; i ++)
437 {
438 if (!strcmp(all_langs[i], "C") || !strcmp(all_langs[i], "en"))
439 continue;
440
441 gpprintf(fp, "%s%s", prefix, all_langs[i]);
442 prefix = " ";
443 }
444
445 if (!strcmp(prefix, " "))
446 gpputs(fp, "\"\n");
447 }
448 }
449
450 static void
451 print_ppd_header_2(gpFile fp, ppd_type_t ppd_type, int model, const char *driver,
452 const char *family, const char *long_name,
453 const char *manufacturer, const char *device_id,
454 const char *ppd_location,
455 const char *language, const stp_string_list_t *po,
456 char **all_langs)
457 {
458 (void)po;
459 (void)all_langs;
460 (void)device_id;
461 (void)manufacturer;
462 (void)long_name;
463 (void)ppd_type;
464
465 gpprintf(fp, "*StpDriverName: \"%s\"\n", driver);
466 gpprintf(fp, "*StpDriverModelFamily: \"%d_%s\"\n", model, family);
467 gpprintf(fp, "*StpPPDLocation: \"%s\"\n", ppd_location);
468 gpprintf(fp, "*StpLocale: \"%s\"\n", language ? language : "C");
469 }
470
471 static void
472 print_page_sizes(gpFile fp, stp_vars_t *v, int simplified,
473 const stp_string_list_t *po)
474 {
475 int variable_sizes = 0;
476 stp_parameter_t desc;
477 int num_opts;
478 paper_t *the_papers;
479 int i;
480 stp_dimension_t width, height, /* Page information */
481 bottom, left,
482 top, right;
483 stp_dimension_t min_width, /* Min/max custom size */
484 min_height,
485 max_width,
486 max_height;
487 const stp_param_string_t *opt;
488 int cur_opt = 0;
489
490 stp_describe_parameter(v, "PageSize", &desc);
491 num_opts = stp_string_list_count(desc.bounds.str);
492 the_papers = stp_malloc(sizeof(paper_t) * num_opts);
493 for (i = 0; i < num_opts; i++)
494 {
495 const stp_papersize_t *papersize;
496 opt = stp_string_list_param(desc.bounds.str, i);
497 if (strcmp(opt->name, "Custom") == 0)
498 {
499 variable_sizes = 1;
500 continue;
501 }
502
503 papersize = stp_describe_papersize(v, opt->name);
504
505 if (!papersize)
506 {
507 printf("Unable to lookup size %s!\n", opt->name);
508 continue;
509 }
510
511 if (simplified && num_opts >= 10 &&
512 (!desc.deflt.str || strcmp(opt->name, desc.deflt.str) != 0) &&
513 (papersize->paper_unit == PAPERSIZE_ENGLISH_EXTENDED ||
514 papersize->paper_unit == PAPERSIZE_METRIC_EXTENDED))
515 continue;
516
517 if (papersize->width <= 0 || papersize->height <= 0)
518 continue;
519
520 width = papersize->width;
521 height = papersize->height;
522
523 stp_set_string_parameter(v, "PageSize", opt->name);
524
525 stp_get_media_size(v, &width, &height);
526 stp_get_maximum_imageable_area(v, &left, &right, &bottom, &top);
527
528 if (left < 0)
529 left = 0;
530 if (right > width)
531 right = width;
532 if (bottom > height)
533 bottom = height;
534 if (top < 0)
535 top = 0;
536
537 the_papers[cur_opt].name = opt->name;
538 the_papers[cur_opt].text = stp_i18n_lookup(po, opt->text);
539 the_papers[cur_opt].width = width;
540 the_papers[cur_opt].height = height;
541 the_papers[cur_opt].left = left;
542 the_papers[cur_opt].right = right;
543 the_papers[cur_opt].bottom = height - bottom;
544 the_papers[cur_opt].top = height - top;
545
546 cur_opt++;
547 stp_clear_string_parameter(v, "PageSize");
548 }
549
550 /*
551 * The VariablePaperSize attribute is obsolete, however some popular
552 * applications still look for it to provide custom page size support.
553 */
554
555 gpprintf(fp, "*VariablePaperSize: %s\n\n", variable_sizes ? "true" : "false");
556
557 if (stp_parameter_has_category_value(v, &desc, "Color", "Yes"))
558 gpputs(fp, "*ColorKeyWords: \"PageSize\"\n");
559 gpprintf(fp, "*OpenUI *PageSize/%s: PickOne\n", _("Media Size"));
560 gpputs(fp, "*OPOptionHints PageSize: \"dropdown\"\n");
561 gpputs(fp, "*OrderDependency: 10 AnySetup *PageSize\n");
562 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
563 desc.name, desc.p_type, desc.is_mandatory,
564 desc.p_class, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
565 gpprintf(fp, "*DefaultPageSize: %s\n", desc.deflt.str);
566 gpprintf(fp, "*StpDefaultPageSize: %s\n", desc.deflt.str);
567 for (i = 0; i < cur_opt; i ++)
568 {
569 gpprintf(fp, "*PageSize %s", the_papers[i].name);
570 gpprintf(fp, "/%s:\t\"<</PageSize[%.3f %.3f]/ImagingBBox null>>setpagedevice\"\n",
571 the_papers[i].text, the_papers[i].width, the_papers[i].height);
572 }
573 gpputs(fp, "*CloseUI: *PageSize\n\n");
574
575 if (stp_parameter_has_category_value(v, &desc, "Color", "Yes"))
576 gpputs(fp, "*ColorKeyWords: \"PageRegion\"\n");
577 gpprintf(fp, "*OpenUI *PageRegion/%s: PickOne\n", _("Media Size"));
578 gpputs(fp, "*OPOptionHints PageRegion: \"dropdown\"\n");
579 gpputs(fp, "*OrderDependency: 10 AnySetup *PageRegion\n");
580 gpprintf(fp, "*DefaultPageRegion: %s\n", desc.deflt.str);
581 gpprintf(fp, "*StpDefaultPageRegion: %s\n", desc.deflt.str);
582 for (i = 0; i < cur_opt; i ++)
583 {
584 gpprintf(fp, "*PageRegion %s", the_papers[i].name);
585 gpprintf(fp, "/%s:\t\"<</PageSize[%.3f %.3f]/ImagingBBox null>>setpagedevice\"\n",
586 the_papers[i].text, the_papers[i].width, the_papers[i].height);
587 }
588 gpputs(fp, "*CloseUI: *PageRegion\n\n");
589
590 gpprintf(fp, "*DefaultImageableArea: %s\n", desc.deflt.str);
591 gpprintf(fp, "*StpDefaultImageableArea: %s\n", desc.deflt.str);
592 for (i = 0; i < cur_opt; i ++)
593 {
594 gpprintf(fp, "*ImageableArea %s", the_papers[i].name);
595 gpprintf(fp, "/%s:\t\"%.3f %.3f %.3f %.3f\"\n", the_papers[i].text,
596 the_papers[i].left, the_papers[i].bottom,
597 the_papers[i].right, the_papers[i].top);
598 }
599 gpputs(fp, "\n");
600
601 gpprintf(fp, "*DefaultPaperDimension: %s\n", desc.deflt.str);
602 gpprintf(fp, "*StpDefaultPaperDimension: %s\n", desc.deflt.str);
603
604 for (i = 0; i < cur_opt; i ++)
605 {
606 gpprintf(fp, "*PaperDimension %s", the_papers[i].name);
607 gpprintf(fp, "/%s:\t\"%.3f %.3f\"\n",
608 the_papers[i].text, the_papers[i].width, the_papers[i].height);
609 }
610 gpputs(fp, "\n");
611
612 if (variable_sizes)
613 {
614 stp_get_size_limit(v, &max_width, &max_height, &min_width, &min_height);
615 stp_set_string_parameter(v, "PageSize", "Custom");
616 stp_get_media_size(v, &width, &height);
617 stp_get_maximum_imageable_area(v, &left, &right, &bottom, &top);
618 if (left < 0)
619 left = 0;
620 if (top < 0)
621 top = 0;
622 if (bottom > height)
623 bottom = height;
624 if (right > width)
625 width = right;
626
627 gpprintf(fp, "*MaxMediaWidth: \"%.3f\"\n", max_width);
628 gpprintf(fp, "*MaxMediaHeight: \"%.3f\"\n", max_height);
629 gpprintf(fp, "*HWMargins: %.3f %.3f %.3f %.3f\n",
630 left, height - bottom, width - right, top);
631 gpputs(fp, "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\"\n");
632 gpprintf(fp, "*ParamCustomPageSize Width: 1 points %.3f %.3f\n",
633 min_width, max_width);
634 gpprintf(fp, "*ParamCustomPageSize Height: 2 points %.3f %.3f\n",
635 min_height, max_height);
636 gpputs(fp, "*ParamCustomPageSize WidthOffset: 3 points 0 0\n");
637 gpputs(fp, "*ParamCustomPageSize HeightOffset: 4 points 0 0\n");
638 gpputs(fp, "*ParamCustomPageSize Orientation: 5 int 0 0\n\n");
639 stp_clear_string_parameter(v, "PageSize");
640 }
641
642 stp_parameter_description_destroy(&desc);
643 if (the_papers)
644 stp_free(the_papers);
645 }
646
647 static void
648 print_color_setup(gpFile fp, int simplified, int printer_is_color,
649 const stp_string_list_t *po)
650 {
651 gpputs(fp, "*ColorKeyWords: \"ColorModel\"\n");
652 gpprintf(fp, "*OpenUI *ColorModel/%s: PickOne\n", _("Color Model"));
653 gpputs(fp, "*OPOptionHints ColorModel: \"radiobuttons\"\n");
654 gpputs(fp, "*OrderDependency: 2 AnySetup *ColorModel\n");
655
656 if (printer_is_color)
657 {
658 gpputs(fp, "*DefaultColorModel: RGB\n");
659 gpputs(fp, "*StpDefaultColorModel: RGB\n");
660 }
661 else
662 {
663 gpputs(fp, "*DefaultColorModel: Gray\n");
664 gpputs(fp, "*StpDefaultColorModel: Gray\n");
665 }
666
667 gpprintf(fp, "*ColorModel Gray/%s:\t\"<<"
668 "/cupsColorSpace %d"
669 "/cupsColorOrder %d"
670 "%s"
671 ">>setpagedevice\"\n",
672 _("Grayscale"), CUPS_CSPACE_W, CUPS_ORDER_CHUNKED,
673 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
674 gpprintf(fp, "*ColorModel Black/%s:\t\"<<"
675 "/cupsColorSpace %d"
676 "/cupsColorOrder %d"
677 "%s"
678 ">>setpagedevice\"\n",
679 _("Inverted Grayscale"), CUPS_CSPACE_K, CUPS_ORDER_CHUNKED,
680 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
681
682 if (printer_is_color)
683 {
684 gpprintf(fp, "*ColorModel RGB/%s:\t\"<<"
685 "/cupsColorSpace %d"
686 "/cupsColorOrder %d"
687 "%s"
688 ">>setpagedevice\"\n",
689 _("RGB Color"), CUPS_CSPACE_RGB, CUPS_ORDER_CHUNKED,
690 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
691 gpprintf(fp, "*ColorModel CMY/%s:\t\"<<"
692 "/cupsColorSpace %d"
693 "/cupsColorOrder %d"
694 "%s"
695 ">>setpagedevice\"\n",
696 _("CMY Color"), CUPS_CSPACE_CMY, CUPS_ORDER_CHUNKED,
697 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
698 gpprintf(fp, "*ColorModel CMYK/%s:\t\"<<"
699 "/cupsColorSpace %d"
700 "/cupsColorOrder %d"
701 "%s"
702 ">>setpagedevice\"\n",
703 _("CMYK"), CUPS_CSPACE_CMYK, CUPS_ORDER_CHUNKED,
704 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
705 gpprintf(fp, "*ColorModel KCMY/%s:\t\"<<"
706 "/cupsColorSpace %d"
707 "/cupsColorOrder %d"
708 "%s"
709 ">>setpagedevice\"\n",
710 _("KCMY"), CUPS_CSPACE_KCMY, CUPS_ORDER_CHUNKED,
711 simplified ? "/cupsBitsPerColor 8/cupsPreferredBitsPerColor 16" : "");
712 }
713
714 gpputs(fp, "*CloseUI: *ColorModel\n\n");
715 if (!simplified)
716 {
717 /*
718 * 8 or 16 bit color (16 bit is slower)
719 */
720 gpputs(fp, "*ColorKeyWords: \"StpColorPrecision\"\n");
721 gpprintf(fp, "*OpenUI *StpColorPrecision/%s: PickOne\n", _("Color Precision"));
722 gpputs(fp, "*OPOptionHints StpColorPrecision: \"radiobuttons\"\n");
723 gpputs(fp, "*OrderDependency: 1 AnySetup *StpColorPrecision\n");
724 gpputs(fp, "*DefaultStpColorPrecision: Normal\n");
725 gpputs(fp, "*StpDefaultStpColorPrecision: Normal\n");
726 gpprintf(fp, "*StpColorPrecision Normal/%s:\t\"<<"
727 "/cupsBitsPerColor 8>>setpagedevice\"\n", _("Normal"));
728 gpprintf(fp, "*StpColorPrecision Best/%s:\t\"<<"
729 "/cupsBitsPerColor 8"
730 "/cupsPreferredBitsPerColor 16>>setpagedevice\"\n", _("Best"));
731 gpputs(fp, "*CloseUI: *StpColorPrecision\n\n");
732 }
733 }
734
735 static int
736 fix_utf8(char *buf, size_t len)
737 {
738 char *b = NULL;
739
740 /* Might truncate up to 3 bytes*/
741 b = buf + len - 3;
742
743 /* Is the last byte part of multi-byte sequence? */
744 if (b[2] & 0x80)
745 {
746 /*Is the last byte in buffer the first byte in a new
747 * multi-byte sequence? */
748 if (b[2] & 0x40) return len - 1;
749 /* Is it a 3 byte sequence? */
750 else if ((b[1] & 0xe0) == 0xe0) return len - 2;
751 /* Is it a 4 byte sequence? */
752 else if ((b[0] & 0xf0) == 0xf0) return len - 3;
753 }
754 return len;
755 }
756
757 static void
758 print_group(
759 gpFile fp, /* I - File to write to */
760 const char *what,
761 stp_parameter_class_t p_class, /* I - Option class */
762 stp_parameter_level_t p_level, /* I - Option level */
763 const char *language, /* I - Language */
764 const stp_string_list_t *po) /* I - Message catalog */
765 {
766 char buf[64];
767 const char *class = stp_i18n_lookup(po, parameter_class_names[p_class]);
768 const char *level = stp_i18n_lookup(po, parameter_level_names[p_level]);
769 size_t bytes = bytelen(class) + bytelen(level);
770
771 snprintf(buf, 40, "%s%s%s", class, bytes < 39 ? " " : "", level);
772 buf[fix_utf8(buf, strlen(buf))] = 0;
773
774 gpprintf(fp, "*%sGroup: C%dL%d/%s\n", what, p_class, p_level, buf);
775 if (language && !strcmp(language, "C") && !strcmp(what, "Open"))
776 {
777 char **all_langs = getlangs();/* All languages */
778 const char *lang;
779 int langnum;
780
781 for (langnum = 0; all_langs[langnum]; langnum ++)
782 {
783 const stp_string_list_t *altpo;
784
785 lang = all_langs[langnum];
786
787 if (!strcmp(lang, "C") || !strcmp(lang, "en"))
788 continue;
789 if ((altpo = stp_i18n_load(lang)) != NULL)
790 {
791 class = stp_i18n_lookup(altpo, parameter_class_names[p_class]);
792 level = stp_i18n_lookup(altpo, parameter_level_names[p_level]);
793 bytes = bytelen(class) + bytelen(level);
794 snprintf(buf, 40, "%s%s%s", class, bytes < 39 ? " " : "", level);
795 buf[fix_utf8(buf, strlen(buf))] = 0;
796 gpprintf(fp, "*%s.Translation C%dL%d/%s: \"\"\n",
797 lang, p_class, p_level, buf);
798 }
799 }
800 }
801 gpputs(fp, "\n");
802 }
803
804 /*
805 * 'print_group_close()' - Close a UI group.
806 */
807
808 static void
809 print_group_close(
810 gpFile fp, /* I - File to write to */
811 stp_parameter_class_t p_class, /* I - Option class */
812 stp_parameter_level_t p_level, /* I - Option level */
813 const char *language, /* I - language */
814 const stp_string_list_t *po) /* I - Message catalog */
815 {
816 (void)po;
817 (void)language;
818 print_group(fp, "Close", p_class, p_level, NULL, NULL);
819 }
820
821
822 /*
823 * 'print_group_open()' - Open a new UI group.
824 */
825
826 static void
827 print_group_open(
828 gpFile fp, /* I - File to write to */
829 stp_parameter_class_t p_class, /* I - Option class */
830 stp_parameter_level_t p_level, /* I - Option level */
831 const char *language, /* I - language */
832 const stp_string_list_t *po) /* I - Message catalog */
833 {
834 print_group(fp, "Open", p_class, p_level, language ? language : "C", po);
835 }
836
837 static void
838 print_one_option(gpFile fp, stp_vars_t *v, const stp_string_list_t *po,
839 ppd_type_t ppd_type, const stp_parameter_t *lparam,
840 const stp_parameter_t *desc)
841 {
842 int num_opts;
843 int i;
844 const stp_param_string_t *opt;
845 int printed_default_value = 0;
846 int simplified = ppd_type == PPD_SIMPLIFIED;
847 char dimstr[255]; /* Dimension string */
848 int print_close_ui = 1;
849 int is_color_opt = stp_parameter_has_category_value(v, desc, "Color", "Yes");
850 int skip_color = (ppd_type == PPD_NO_COLOR_OPTS && is_color_opt);
851 if (is_color_opt)
852 gpprintf(fp, "*ColorKeyWords: \"Stp%s\"\n", desc->name);
853
854 #ifndef FULL_RAW
855 if (desc->p_type != STP_PARAMETER_TYPE_RAW)
856 {
857 #endif
858 gpprintf(fp, "*OpenUI *Stp%s/%s: PickOne\n",
859 desc->name, stp_i18n_lookup(po, desc->text));
860 gpprintf(fp, "*OrderDependency: 10 AnySetup *Stp%s\n", desc->name);
861 #ifndef FULL_RAW
862 }
863 #endif
864 switch (desc->p_type)
865 {
866 case STP_PARAMETER_TYPE_STRING_LIST:
867 num_opts = stp_string_list_count(desc->bounds.str);
868 if (! skip_color)
869 {
870 if (num_opts > 3)
871 gpprintf(fp, "*OPOptionHints Stp%s: \"dropdown\"\n", lparam->name);
872 else
873 gpprintf(fp, "*OPOptionHints Stp%s: \"radiobuttons\"\n", lparam->name);
874 }
875 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
876 desc->name, desc->p_type, desc->is_mandatory, desc->p_class,
877 desc->p_level, desc->channel, 0.0, 0.0, 0.0);
878 if (desc->is_mandatory)
879 {
880 gpprintf(fp, "*DefaultStp%s: %s\n", desc->name, desc->deflt.str);
881 gpprintf(fp, "*StpDefaultStp%s: %s\n", desc->name, desc->deflt.str);
882 }
883 else
884 {
885 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
886 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
887 gpprintf(fp, "*Stp%s %s/%s: \"\"\n", desc->name, "None", _("None"));
888 }
889 for (i = 0; i < num_opts; i++)
890 {
891 opt = stp_string_list_param(desc->bounds.str, i);
892 if (skip_color && strcmp(opt->name, desc->deflt.str) != 0)
893 gpprintf(fp, "*?Stp%s %s/%s: \"\"\n",
894 desc->name, opt->name, stp_i18n_lookup(po, opt->text));
895 else
896 gpprintf(fp, "*Stp%s %s/%s: \"\"\n",
897 desc->name, opt->name, stp_i18n_lookup(po, opt->text));
898 }
899 break;
900 case STP_PARAMETER_TYPE_RAW:
901 print_close_ui = 0;
902 #ifdef FULL_RAW /* XXX not sure if the standalone Custom... bit is sufficient */
903 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
904 desc->name, desc->p_type, desc->is_mandatory, desc->p_class,
905 desc->p_level, desc->channel, 0.0, 0.0, 0.0);
906 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
907 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
908 gpprintf(fp, "*Stp%s %s/%s: \"\"\n", desc->name, "None", _("None"));
909 gpprintf(fp, "*CloseUI: *Stp%s\n", desc->name);
910 #endif
911 gpprintf(fp, "*CustomStp%s True: \"pop\"\n", desc->name);
912 gpprintf(fp, "*ParamCustomStp%s Text/%s: 1 string %d %d\n\n",
913 desc->name, _("Text"), 0, 0);
914
915 break;
916 case STP_PARAMETER_TYPE_BOOLEAN:
917 gpprintf(fp, "*OPOptionHints Stp%s: \"checkbox\"\n", lparam->name);
918 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
919 desc->name, desc->p_type, desc->is_mandatory, desc->p_class,
920 desc->p_level, desc->channel, 0.0, 0.0,
921 desc->deflt.boolean ? 1.0 : 0.0);
922 if (desc->is_mandatory)
923 {
924 gpprintf(fp, "*DefaultStp%s: %s\n", desc->name,
925 desc->deflt.boolean ? "True" : "False");
926 gpprintf(fp, "*StpDefaultStp%s: %s\n", desc->name,
927 desc->deflt.boolean ? "True" : "False");
928 if (skip_color)
929 gpprintf(fp, "*Stp%s %s/%s: \"\"\n",
930 desc->name, desc->deflt.boolean ? "True" : "False",
931 desc->deflt.boolean ? _("Yes") : _("No"));
932 }
933 else
934 {
935 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
936 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
937 gpprintf(fp, "*Stp%s %s/%s: \"\"\n", desc->name, "None", _("None"));
938 }
939 gpprintf(fp, "*%sStp%s %s/%s: \"\"\n",
940 (skip_color ? "?" : ""), desc->name, "False", _("No"));
941 gpprintf(fp, "*%sStp%s %s/%s: \"\"\n",
942 (skip_color ? "?" : ""), desc->name, "True", _("Yes"));
943 break;
944 case STP_PARAMETER_TYPE_DOUBLE:
945 gpprintf(fp, "*OPOptionHints Stp%s: \"slider input spinbox\"\n",
946 lparam->name);
947 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
948 desc->name, desc->p_type, desc->is_mandatory, desc->p_class,
949 desc->p_level, desc->channel, desc->bounds.dbl.lower,
950 desc->bounds.dbl.upper, desc->deflt.dbl);
951 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
952 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
953 if (!skip_color)
954 {
955 for (i = desc->bounds.dbl.lower * 1000;
956 i <= desc->bounds.dbl.upper * 1000 ; i += 100)
957 {
958 if (desc->deflt.dbl * 1000 == i && desc->is_mandatory)
959 {
960 gpprintf(fp, "*Stp%s None/%.3f: \"\"\n",
961 desc->name, ((double) i) * .001);
962 printed_default_value = 1;
963 }
964 else
965 gpprintf(fp, "*Stp%s %d/%.3f: \"\"\n",
966 desc->name, i, ((double) i) * .001);
967 }
968 }
969 if (!desc->is_mandatory)
970 gpprintf(fp, "*Stp%s None/%s: \"\"\n", desc->name, _("None"));
971 else if (! printed_default_value)
972 gpprintf(fp, "*Stp%s None/%.3f: \"\"\n", desc->name, desc->deflt.dbl);
973 gpprintf(fp, "*CloseUI: *Stp%s\n\n", desc->name);
974
975 /*
976 * Add custom option code and value parameter...
977 */
978
979 gpprintf(fp, "*CustomStp%s True: \"pop\"\n", desc->name);
980 gpprintf(fp, "*ParamCustomStp%s Value/%s: 1 real %.3f %.3f\n\n",
981 desc->name, _("Value"), desc->bounds.dbl.lower,
982 desc->bounds.dbl.upper);
983 if (!simplified && !skip_color)
984 {
985 if (is_color_opt)
986 gpprintf(fp, "*ColorKeyWords: \"StpFine%s\"\n", desc->name);
987 gpprintf(fp, "*OpenUI *StpFine%s/%s %s: PickOne\n",
988 desc->name, stp_i18n_lookup(po, desc->text),
989 _("Fine Adjustment"));
990 gpprintf(fp, "*OPOptionHints StpFine%s: \"hide\"\n", lparam->name);
991 gpprintf(fp, "*StpStpFine%s: %d %d %d %d %d %.3f %.3f %.3f\n",
992 desc->name, STP_PARAMETER_TYPE_INVALID, 0,
993 0, 0, -1, 0.0, 0.0, 0.0);
994 gpprintf(fp, "*DefaultStpFine%s: None\n", desc->name);
995 gpprintf(fp, "*StpDefaultStpFine%s: None\n", desc->name);
996 gpprintf(fp, "*StpFine%s None/0.000: \"\"\n", desc->name);
997 for (i = 0; i < 100; i += 5)
998 gpprintf(fp, "*StpFine%s %d/%.3f: \"\"\n",
999 desc->name, i, ((double) i) * .001);
1000 gpprintf(fp, "*CloseUI: *StpFine%s\n\n", desc->name);
1001 }
1002 print_close_ui = 0;
1003
1004 break;
1005 case STP_PARAMETER_TYPE_DIMENSION:
1006 gpprintf(fp, "*OPOptionHints Stp%s: \"length slider input spinbox\"\n",
1007 lparam->name);
1008 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1009 desc->name, desc->p_type, desc->is_mandatory,
1010 desc->p_class, desc->p_level, desc->channel,
1011 desc->bounds.dimension.lower,
1012 desc->bounds.dimension.upper,
1013 desc->deflt.dimension);
1014 if (desc->is_mandatory)
1015 {
1016 gpprintf(fp, "*DefaultStp%s: %d\n",
1017 desc->name, (int) desc->deflt.dimension);
1018 gpprintf(fp, "*StpDefaultStp%s: %d\n",
1019 desc->name, (int) desc->deflt.dimension);
1020 }
1021 else
1022 {
1023 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
1024 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
1025 gpprintf(fp, "*Stp%s %s/%s: \"\"\n", desc->name, "None", _("None"));
1026 }
1027 if (!skip_color)
1028 {
1029 for (i = (int) desc->bounds.dimension.lower;
1030 i <= (int) desc->bounds.dimension.upper; i++)
1031 {
1032 snprintf(dimstr, sizeof(dimstr), _("%.1f mm"),
1033 (double)i * 25.4 / 72.0);
1034 gpprintf(fp, "*Stp%s %d/%s: \"\"\n", desc->name, i, dimstr);
1035 }
1036 }
1037
1038 print_close_ui = 0;
1039 gpprintf(fp, "*CloseUI: *Stp%s\n\n", desc->name);
1040
1041 #ifndef __APPLE__ /* This leads to outright _crashes_ on apple platforms */
1042 /*
1043 * Add custom option code and value parameter...
1044 */
1045
1046 gpprintf(fp, "*CustomStp%s True: \"pop\"\n", desc->name);
1047 gpprintf(fp, "*ParamCustomStp%s Value/%s: 1 points %d %d\n\n",
1048 desc->name, _("Value"), (int) desc->bounds.dimension.lower,
1049 (int) desc->bounds.dimension.upper);
1050 #endif
1051 break;
1052 case STP_PARAMETER_TYPE_INT:
1053 gpprintf(fp, "*OPOptionHints Stp%s: \"input spinbox\"\n", lparam->name);
1054 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1055 desc->name, desc->p_type, desc->is_mandatory, desc->p_class,
1056 desc->p_level, desc->channel,
1057 (double) desc->bounds.integer.lower,
1058 (double) desc->bounds.integer.upper,
1059 (double) desc->deflt.integer);
1060 if (desc->is_mandatory)
1061 {
1062 gpprintf(fp, "*DefaultStp%s: %d\n", desc->name, desc->deflt.integer);
1063 gpprintf(fp, "*StpDefaultStp%s: %d\n", desc->name, desc->deflt.integer);
1064 if (skip_color)
1065 gpprintf(fp, "*Stp%s %d/%d: \"\"\n", desc->name,
1066 desc->deflt.integer, desc->deflt.integer);
1067 }
1068 else
1069 {
1070 gpprintf(fp, "*DefaultStp%s: None\n", desc->name);
1071 gpprintf(fp, "*StpDefaultStp%s: None\n", desc->name);
1072 gpprintf(fp, "*Stp%s %s/%s: \"\"\n", desc->name, "None", _("None"));
1073 }
1074 for (i = desc->bounds.integer.lower; i <= desc->bounds.integer.upper; i++)
1075 {
1076 gpprintf(fp, "*%sStp%s %d/%d: \"\"\n",
1077 (skip_color ? "?" : ""), desc->name, i, i);
1078 }
1079
1080 print_close_ui = 0;
1081 gpprintf(fp, "*CloseUI: *Stp%s\n\n", desc->name);
1082
1083 break;
1084 default:
1085 break;
1086 }
1087 if (print_close_ui)
1088 gpprintf(fp, "*CloseUI: *Stp%s\n\n", desc->name);
1089 }
1090
1091 static void
1092 print_one_localization(gpFile fp, const stp_string_list_t *po,
1093 int simplified, const char *lang,
1094 const stp_parameter_t *lparam,
1095 const stp_parameter_t *desc)
1096 {
1097 int num_opts;
1098 int i;
1099 const stp_param_string_t *opt;
1100 char dimstr[255]; /* Dimension string */
1101 (void)lparam;
1102
1103 gpprintf(fp, "*%s.Translation Stp%s/%s: \"\"\n", lang,
1104 desc->name, stp_i18n_lookup(po, desc->text));
1105 switch (desc->p_type)
1106 {
1107 case STP_PARAMETER_TYPE_STRING_LIST:
1108 if (!desc->is_mandatory)
1109 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name,
1110 "None", _("None"));
1111 num_opts = stp_string_list_count(desc->bounds.str);
1112 for (i = 0; i < num_opts; i++)
1113 {
1114 opt = stp_string_list_param(desc->bounds.str, i);
1115 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang,
1116 desc->name, opt->name, stp_i18n_lookup(po, opt->text));
1117 }
1118 break;
1119
1120 case STP_PARAMETER_TYPE_BOOLEAN:
1121 if (!desc->is_mandatory)
1122 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name,
1123 "None", _("None"));
1124 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name, "False", _("No"));
1125 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name, "True", _("Yes"));
1126 break;
1127
1128 case STP_PARAMETER_TYPE_DOUBLE:
1129 if (localize_numbers)
1130 {
1131 for (i = desc->bounds.dbl.lower * 1000;
1132 i <= desc->bounds.dbl.upper * 1000; i += 100)
1133 {
1134 if (desc->deflt.dbl * 1000 == i && desc->is_mandatory)
1135 gpprintf(fp, "*%s.Stp%s None/%.3f: \"\"\n", lang,
1136 desc->name, ((double) i) * .001);
1137 else
1138 gpprintf(fp, "*%s.Stp%s %d/%.3f: \"\"\n", lang,
1139 desc->name, i, ((double) i) * .001);
1140 }
1141 }
1142 if (!desc->is_mandatory)
1143 gpprintf(fp, "*%s.Stp%s None/%s: \"\"\n", lang, desc->name, _("None"));
1144 gpprintf(fp, "*%s.ParamCustomStp%s Value/%s: \"\"\n", lang,
1145 desc->name, _("Value"));
1146 if (!simplified)
1147 {
1148 gpprintf(fp, "*%s.Translation StpFine%s/%s %s: \"\"\n", lang,
1149 desc->name, stp_i18n_lookup(po, desc->text),
1150 _("Fine Adjustment"));
1151 gpprintf(fp, "*%s.StpFine%s None/%.3f: \"\"\n", lang,
1152 desc->name, 0.0);
1153 if (localize_numbers)
1154 {
1155 for (i = 0; i < 100; i += 5)
1156 gpprintf(fp, "*%s.StpFine%s %d/%.3f: \"\"\n", lang,
1157 desc->name, i, ((double) i) * .001);
1158 }
1159 }
1160 break;
1161
1162 case STP_PARAMETER_TYPE_DIMENSION:
1163 if (!desc->is_mandatory)
1164 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name,
1165 "None", _("None"));
1166 /* Unlike the other fields, dimensions are not strictly numbers */
1167 for (i = (int) desc->bounds.dimension.lower;
1168 i <= (int) desc->bounds.dimension.upper; i++)
1169 {
1170 snprintf(dimstr, sizeof(dimstr), _("%.1f mm"),
1171 (double)i * 25.4 / 72.0);
1172 gpprintf(fp, "*%s.Stp%s %d/%s: \"\"\n", lang,
1173 desc->name, i, dimstr);
1174 }
1175 gpprintf(fp, "*%s.ParamCustomStp%s Value/%s: \"\"\n", lang,
1176 desc->name, _("Value"));
1177 break;
1178
1179 case STP_PARAMETER_TYPE_INT:
1180 if (!desc->is_mandatory)
1181 gpprintf(fp, "*%s.Stp%s %s/%s: \"\"\n", lang, desc->name,
1182 "None", _("None"));
1183 if (localize_numbers)
1184 {
1185 for (i = desc->bounds.integer.lower;
1186 i <= desc->bounds.integer.upper; i++)
1187 {
1188 gpprintf(fp, "*%s.Stp%s %d/%d: \"\"\n", lang, desc->name, i, i);
1189 }
1190 }
1191 break;
1192
1193 default:
1194 break;
1195 }
1196 }
1197
1198 static void
1199 print_standard_fonts(gpFile fp)
1200 {
1201 gpputs(fp, "\n*DefaultFont: Courier\n");
1202 gpputs(fp, "*Font AvantGarde-Book: Standard \"(001.006S)\" Standard ROM\n");
1203 gpputs(fp, "*Font AvantGarde-BookOblique: Standard \"(001.006S)\" Standard ROM\n");
1204 gpputs(fp, "*Font AvantGarde-Demi: Standard \"(001.007S)\" Standard ROM\n");
1205 gpputs(fp, "*Font AvantGarde-DemiOblique: Standard \"(001.007S)\" Standard ROM\n");
1206 gpputs(fp, "*Font Bookman-Demi: Standard \"(001.004S)\" Standard ROM\n");
1207 gpputs(fp, "*Font Bookman-DemiItalic: Standard \"(001.004S)\" Standard ROM\n");
1208 gpputs(fp, "*Font Bookman-Light: Standard \"(001.004S)\" Standard ROM\n");
1209 gpputs(fp, "*Font Bookman-LightItalic: Standard \"(001.004S)\" Standard ROM\n");
1210 gpputs(fp, "*Font Courier: Standard \"(002.004S)\" Standard ROM\n");
1211 gpputs(fp, "*Font Courier-Bold: Standard \"(002.004S)\" Standard ROM\n");
1212 gpputs(fp, "*Font Courier-BoldOblique: Standard \"(002.004S)\" Standard ROM\n");
1213 gpputs(fp, "*Font Courier-Oblique: Standard \"(002.004S)\" Standard ROM\n");
1214 gpputs(fp, "*Font Helvetica: Standard \"(001.006S)\" Standard ROM\n");
1215 gpputs(fp, "*Font Helvetica-Bold: Standard \"(001.007S)\" Standard ROM\n");
1216 gpputs(fp, "*Font Helvetica-BoldOblique: Standard \"(001.007S)\" Standard ROM\n");
1217 gpputs(fp, "*Font Helvetica-Narrow: Standard \"(001.006S)\" Standard ROM\n");
1218 gpputs(fp, "*Font Helvetica-Narrow-Bold: Standard \"(001.007S)\" Standard ROM\n");
1219 gpputs(fp, "*Font Helvetica-Narrow-BoldOblique: Standard \"(001.007S)\" Standard ROM\n");
1220 gpputs(fp, "*Font Helvetica-Narrow-Oblique: Standard \"(001.006S)\" Standard ROM\n");
1221 gpputs(fp, "*Font Helvetica-Oblique: Standard \"(001.006S)\" Standard ROM\n");
1222 gpputs(fp, "*Font NewCenturySchlbk-Bold: Standard \"(001.009S)\" Standard ROM\n");
1223 gpputs(fp, "*Font NewCenturySchlbk-BoldItalic: Standard \"(001.007S)\" Standard ROM\n");
1224 gpputs(fp, "*Font NewCenturySchlbk-Italic: Standard \"(001.006S)\" Standard ROM\n");
1225 gpputs(fp, "*Font NewCenturySchlbk-Roman: Standard \"(001.007S)\" Standard ROM\n");
1226 gpputs(fp, "*Font Palatino-Bold: Standard \"(001.005S)\" Standard ROM\n");
1227 gpputs(fp, "*Font Palatino-BoldItalic: Standard \"(001.005S)\" Standard ROM\n");
1228 gpputs(fp, "*Font Palatino-Italic: Standard \"(001.005S)\" Standard ROM\n");
1229 gpputs(fp, "*Font Palatino-Roman: Standard \"(001.005S)\" Standard ROM\n");
1230 gpputs(fp, "*Font Symbol: Special \"(001.007S)\" Special ROM\n");
1231 gpputs(fp, "*Font Times-Bold: Standard \"(001.007S)\" Standard ROM\n");
1232 gpputs(fp, "*Font Times-BoldItalic: Standard \"(001.009S)\" Standard ROM\n");
1233 gpputs(fp, "*Font Times-Italic: Standard \"(001.007S)\" Standard ROM\n");
1234 gpputs(fp, "*Font Times-Roman: Standard \"(001.007S)\" Standard ROM\n");
1235 gpputs(fp, "*Font ZapfChancery-MediumItalic: Standard \"(001.007S)\" Standard ROM\n");
1236 gpputs(fp, "*Font ZapfDingbats: Special \"(001.004S)\" Standard ROM\n");
1237 }
1238
1239 /*
1240 * 'write_ppd()' - Write a PPD file.
1241 */
1242
1243 int /* O - Exit status */
1244 write_ppd(
1245 gpFile fp, /* I - File to write to */
1246 const stp_printer_t *p, /* I - Printer driver */
1247 const char *language, /* I - Primary language */
1248 const char *ppd_location, /* I - Location of PPD file */
1249 ppd_type_t ppd_type, /* I - 1 = simplified options */
1250 const char *filename, /* I - input filename */
1251 int compress) /* I - compress output */
1252 {
1253 unsigned int i, j, k, l; /* Looping vars */
1254 unsigned int num_opts; /* Number of printer options */
1255 stp_resolution_t xdpi, ydpi; /* Resolution info */
1256 stp_vars_t *v; /* Variable info */
1257 const char *driver; /* Driver name */
1258 const char *family; /* Printer family */
1259 int model; /* Internal model ID */
1260 const char *long_name; /* Driver long name */
1261 const char *manufacturer; /* Manufacturer of printer */
1262 const char *device_id; /* IEEE1284 device ID */
1263 const stp_vars_t *printvars; /* Printer option names */
1264 int nativecopies = 0; /* Printer natively generates copies */
1265 stp_parameter_t desc;
1266 stp_parameter_list_t param_list;
1267 const stp_param_string_t *opt;
1268 int has_quality_parameter = 0;
1269 int printer_is_color = 0;
1270 int simplified = ppd_type == PPD_SIMPLIFIED;
1271 int skip_color = ppd_type == PPD_NO_COLOR_OPTS;
1272 unsigned int maximum_level = simplified ?
1273 STP_PARAMETER_LEVEL_BASIC : STP_PARAMETER_LEVEL_ADVANCED4;
1274 char *default_resolution = NULL; /* Default resolution mapped name */
1275 stp_string_list_t *resolutions = stp_string_list_create();
1276 char **all_langs = getlangs();/* All languages */
1277 const stp_string_list_t *po = stp_i18n_load(language);
1278 /* Message catalog */
1279
1280 /*
1281 * This is ugly. The right thing would be to pass this through, but
1282 * then all calls to gpputs, gpprintf, etc. and callers would need to
1283 * have this arg.
1284 */
1285 use_compression = compress;
1286 /*
1287 * Initialize driver-specific variables...
1288 */
1289
1290 driver = stp_printer_get_driver(p);
1291 family = stp_printer_get_family(p);
1292 model = stp_printer_get_model(p);
1293 long_name = stp_printer_get_long_name(p);
1294 manufacturer = stp_printer_get_manufacturer(p);
1295 device_id = stp_printer_get_device_id(p);
1296 printvars = stp_printer_get_defaults(p);
1297
1298 print_ppd_header(fp, ppd_type, model, driver, family, long_name,
1299 manufacturer, device_id, ppd_location, language, po,
1300 all_langs);
1301
1302
1303 /* Set Job Mode to "Job" as this enables the Duplex option */
1304 v = stp_vars_create_copy(printvars);
1305 stp_set_string_parameter(v, "JobMode", "Job");
1306
1307 /* Assume that color printers are inkjets and should have pages reversed */
1308 stp_describe_parameter(v, "PrintingMode", &desc);
1309 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1310 {
1311 if (stp_string_list_is_present(desc.bounds.str, "Color"))
1312 {
1313 printer_is_color = 1;
1314 gpputs(fp, "*ColorDevice: True\n");
1315 }
1316 else
1317 {
1318 printer_is_color = 0;
1319 gpputs(fp, "*ColorDevice: False\n");
1320 }
1321 if (strcmp(desc.deflt.str, "Color") == 0)
1322 gpputs(fp, "*DefaultColorSpace: RGB\n");
1323 else
1324 gpputs(fp, "*DefaultColorSpace: Gray\n");
1325 }
1326 stp_parameter_description_destroy(&desc);
1327
1328 stp_describe_parameter(v, "NativeCopies", &desc);
1329 if (desc.p_type == STP_PARAMETER_TYPE_BOOLEAN)
1330 nativecopies = desc.deflt.boolean;
1331 stp_parameter_description_destroy(&desc);
1332
1333 if (nativecopies)
1334 gpputs(fp, "*cupsManualCopies: False\n");
1335 else
1336 gpputs(fp, "*cupsManualCopies: True\n");
1337
1338 stp_describe_parameter(v, "CommandFilterName", &desc);
1339 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active)
1340 {
1341 opt = stp_string_list_param(desc.bounds.str, 0);
1342 gpprintf(fp, "*cupsFilter: \"application/vnd.cups-command 33 %s\"\n", opt->name);
1343 }
1344 stp_parameter_description_destroy(&desc);
1345
1346 stp_describe_parameter(v, "CommandFilterCommands", &desc);
1347 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active)
1348 {
1349 gpputs(fp, "*cupsCommands: \"");
1350 num_opts = stp_string_list_count(desc.bounds.str);
1351 for (i = 0 ; i < num_opts; i++)
1352 {
1353 opt = stp_string_list_param(desc.bounds.str, i);
1354 gpprintf(fp, "%s ", opt->name);
1355 }
1356 gpputs(fp, "\"\n");
1357 }
1358 stp_parameter_description_destroy(&desc);
1359
1360 print_ppd_header_3(fp, ppd_type, model,
1361 driver, family, long_name,
1362 manufacturer, device_id, ppd_location, language, po,
1363 all_langs);
1364
1365 /* Macintosh color management */
1366
1367 #ifdef __APPLE__
1368 gpputs(fp, "*cupsICCProfile Gray../Grayscale: \"/System/Library/ColorSync/Profiles/sRGB Profile.icc\"\n");
1369 gpputs(fp, "*cupsICCProfile RGB../Color: \"/System/Library/ColorSync/Profiles/sRGB Profile.icc\"\n");
1370 gpputs(fp, "*cupsICCProfile CMYK../Color: \"/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc\"\n");
1371 gpputs(fp, "*APSupportsCustomColorMatching: true\n");
1372 gpputs(fp, "*APDefaultCustomColorMatchingProfile: sRGB\n");
1373 gpputs(fp, "*APCustomColorMatchingProfile: sRGB\n");
1374 #endif
1375
1376 gpputs(fp, "\n");
1377
1378 print_ppd_header_2(fp, ppd_type, model, driver, family, long_name,
1379 manufacturer, device_id, ppd_location, language, po,
1380 all_langs);
1381
1382 /*
1383 * Get the page sizes from the driver...
1384 */
1385
1386 if (printer_is_color)
1387 stp_set_string_parameter(v, "PrintingMode", "Color");
1388 else
1389 stp_set_string_parameter(v, "PrintingMode", "BW");
1390 stp_set_string_parameter(v, "ChannelBitDepth", "8");
1391 print_page_sizes(fp, v, simplified, po);
1392
1393 /*
1394 * Do we support color?
1395 */
1396
1397 print_color_setup(fp, simplified, printer_is_color, po);
1398
1399 /*
1400 * Media types...
1401 */
1402
1403 stp_describe_parameter(v, "MediaType", &desc);
1404
1405 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active &&
1406 stp_string_list_count(desc.bounds.str) > 0)
1407 {
1408 int is_color_opt =
1409 stp_parameter_has_category_value(v, &desc, "Color", "Yes");
1410 int nocolor = skip_color && is_color_opt;
1411 num_opts = stp_string_list_count(desc.bounds.str);
1412 if (is_color_opt)
1413 gpprintf(fp, "*ColorKeyWords: \"MediaType\"\n");
1414 gpprintf(fp, "*OpenUI *MediaType/%s: PickOne\n", _("Media Type"));
1415 gpputs(fp, "*OPOptionHints MediaType: \"dropdown\"\n");
1416 gpputs(fp, "*OrderDependency: 10 AnySetup *MediaType\n");
1417 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1418 desc.name, desc.p_type, desc.is_mandatory,
1419 desc.p_class, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
1420 gpprintf(fp, "*DefaultMediaType: %s\n", desc.deflt.str);
1421 gpprintf(fp, "*StpDefaultMediaType: %s\n", desc.deflt.str);
1422
1423 for (i = 0; i < num_opts; i ++)
1424 {
1425 opt = stp_string_list_param(desc.bounds.str, i);
1426 gpprintf(fp, "*%sMediaType %s/%s:\t\"<</MediaType(%s)>>setpagedevice\"\n",
1427 nocolor && strcmp(opt->name, desc.deflt.str) != 0 ? "?" : "",
1428 opt->name, stp_i18n_lookup(po, opt->text), opt->name);
1429 }
1430
1431 gpputs(fp, "*CloseUI: *MediaType\n\n");
1432 }
1433 stp_parameter_description_destroy(&desc);
1434
1435 /*
1436 * Input slots...
1437 */
1438
1439 stp_describe_parameter(v, "InputSlot", &desc);
1440
1441 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active &&
1442 stp_string_list_count(desc.bounds.str) > 0)
1443 {
1444 int is_color_opt =
1445 stp_parameter_has_category_value(v, &desc, "Color", "Yes");
1446 int nocolor = skip_color && is_color_opt;
1447 num_opts = stp_string_list_count(desc.bounds.str);
1448 if (is_color_opt)
1449 gpprintf(fp, "*ColorKeyWords: \"InputSlot\"\n");
1450 gpprintf(fp, "*OpenUI *InputSlot/%s: PickOne\n", _("Media Source"));
1451 gpputs(fp, "*OPOptionHints InputSlot: \"dropdown\"\n");
1452 gpputs(fp, "*OrderDependency: 10 AnySetup *InputSlot\n");
1453 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1454 desc.name, desc.p_type, desc.is_mandatory,
1455 desc.p_class, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
1456 gpprintf(fp, "*DefaultInputSlot: %s\n", desc.deflt.str);
1457 gpprintf(fp, "*StpDefaultInputSlot: %s\n", desc.deflt.str);
1458
1459 for (i = 0; i < num_opts; i ++)
1460 {
1461 opt = stp_string_list_param(desc.bounds.str, i);
1462 gpprintf(fp, "*%sInputSlot %s/%s:\t\"<</MediaClass(%s)>>setpagedevice\"\n",
1463 nocolor && strcmp(opt->name, desc.deflt.str) != 0 ? "?" : "",
1464 opt->name, stp_i18n_lookup(po, opt->text), opt->name);
1465 }
1466
1467 gpputs(fp, "*CloseUI: *InputSlot\n\n");
1468 }
1469 stp_parameter_description_destroy(&desc);
1470
1471 /*
1472 * Quality settings
1473 */
1474
1475 stp_describe_parameter(v, "Quality", &desc);
1476 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active)
1477 {
1478 int is_color_opt =
1479 stp_parameter_has_category_value(v, &desc, "Color", "Yes");
1480 int nocolor = skip_color && is_color_opt;
1481 if (is_color_opt)
1482 gpprintf(fp, "*ColorKeyWords: \"Quality\"\n");
1483 stp_clear_string_parameter(v, "Resolution");
1484 has_quality_parameter = 1;
1485 num_opts = stp_string_list_count(desc.bounds.str);
1486 gpprintf(fp, "*OpenUI *StpQuality/%s: PickOne\n", stp_i18n_lookup(po, desc.text));
1487 if (num_opts > 3)
1488 gpputs(fp, "*OPOptionHints Quality: \"radiobuttons\"\n");
1489 else
1490 gpputs(fp, "*OPOptionHints Quality: \"dropdown\"\n");
1491 gpputs(fp, "*OrderDependency: 10 AnySetup *StpQuality\n");
1492 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1493 desc.name, desc.p_type, desc.is_mandatory,
1494 desc.p_type, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
1495 gpprintf(fp, "*DefaultStpQuality: %s\n", desc.deflt.str);
1496 gpprintf(fp, "*StpDefaultStpQuality: %s\n", desc.deflt.str);
1497 for (i = 0; i < num_opts; i++)
1498 {
1499 opt = stp_string_list_param(desc.bounds.str, i);
1500 stp_set_string_parameter(v, "Quality", opt->name);
1501 stp_describe_resolution(v, &xdpi, &ydpi);
1502 if (xdpi == -1 || ydpi == -1)
1503 {
1504 stp_parameter_t res_desc;
1505 stp_clear_string_parameter(v, "Quality");
1506 stp_describe_parameter(v, "Resolution", &res_desc);
1507 stp_set_string_parameter(v, "Resolution", res_desc.deflt.str);
1508 stp_describe_resolution(v, &xdpi, &ydpi);
1509 stp_clear_string_parameter(v, "Resolution");
1510 stp_parameter_description_destroy(&res_desc);
1511 }
1512 gpprintf(fp, "*%sStpQuality %s/%s:\t\"<</HWResolution[%d %d]/cupsRowFeed %d>>setpagedevice\"\n",
1513 nocolor && strcmp(opt->name, desc.deflt.str) != 0 ? "?" : "",
1514 opt->name, stp_i18n_lookup(po, opt->text), (int) xdpi, (int) ydpi, i + 1);
1515 }
1516 gpputs(fp, "*CloseUI: *StpQuality\n\n");
1517 }
1518 stp_parameter_description_destroy(&desc);
1519 stp_clear_string_parameter(v, "Quality");
1520
1521 /*
1522 * Resolutions...
1523 */
1524
1525 stp_describe_parameter(v, "Resolution", &desc);
1526
1527 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active)
1528 {
1529 num_opts = stp_string_list_count(desc.bounds.str);
1530 if (!simplified || desc.p_level == STP_PARAMETER_LEVEL_BASIC)
1531 {
1532 int is_color_opt =
1533 stp_parameter_has_category_value(v, &desc, "Color", "Yes");
1534 int nocolor = skip_color && is_color_opt;
1535 stp_string_list_t *res_list = stp_string_list_create();
1536 char res_name[64]; /* Plenty long enough for XXXxYYYdpi */
1537 int resolution_ok;
1538 stp_resolution_t tmp_xdpi, tmp_ydpi;
1539
1540 if (is_color_opt)
1541 gpprintf(fp, "*ColorKeyWords: \"Resolution\"\n");
1542 gpprintf(fp, "*OpenUI *Resolution/%s: PickOne\n", _("Resolution"));
1543 if (num_opts > 3)
1544 gpputs(fp, "*OPOptionHints Resolution: \"resolution radiobuttons\"\n");
1545 else
1546 gpputs(fp, "*OPOptionHints Resolution: \"resolution dropdown\"\n");
1547 gpputs(fp, "*OrderDependency: 10 AnySetup *Resolution\n");
1548 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1549 desc.name, desc.p_type, desc.is_mandatory,
1550 desc.p_class, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
1551 if (has_quality_parameter)
1552 {
1553 stp_parameter_t desc1;
1554 stp_clear_string_parameter(v, "Resolution");
1555 stp_describe_parameter(v, "Quality", &desc1);
1556 stp_set_string_parameter(v, "Quality", desc1.deflt.str);
1557 stp_parameter_description_destroy(&desc1);
1558 stp_describe_resolution(v, &xdpi, &ydpi);
1559 stp_clear_string_parameter(v, "Quality");
1560 tmp_xdpi = xdpi;
1561 while (tmp_xdpi > MAXIMUM_SAFE_PPD_X_RESOLUTION)
1562 tmp_xdpi /= 2;
1563 tmp_ydpi = ydpi;
1564 while (tmp_ydpi > MAXIMUM_SAFE_PPD_Y_RESOLUTION)
1565 tmp_ydpi /= 2;
1566 if (tmp_ydpi < tmp_xdpi)
1567 tmp_xdpi = tmp_ydpi;
1568 /*
1569 Make the default resolution look like an almost square resolution
1570 so that applications using it will be less likely to generate
1571 excess resolution. However, make the hardware resolution
1572 match the printer default.
1573 */
1574 (void) snprintf(res_name, 63, "%dx%ddpi", (int) tmp_xdpi + 1, (int) tmp_xdpi);
1575 default_resolution = stp_strdup(res_name);
1576 stp_string_list_add_string(res_list, res_name, res_name);
1577 gpprintf(fp, "*DefaultResolution: %s\n", res_name);
1578 gpprintf(fp, "*StpDefaultResolution: %s\n", res_name);
1579 gpprintf(fp, "*Resolution %s/%s:\t\"<</HWResolution[%d %d]>>setpagedevice\"\n",
1580 res_name, _("Automatic"), (int) xdpi, (int) ydpi);
1581 gpprintf(fp, "*StpResolutionMap: %s %s\n", res_name, "None");
1582 }
1583 else
1584 {
1585 stp_set_string_parameter(v, "Resolution", desc.deflt.str);
1586 stp_describe_resolution(v, &xdpi, &ydpi);
1587
1588 if (xdpi == ydpi)
1589 (void) snprintf(res_name, 63, "%ddpi", (int) xdpi);
1590 else
1591 (void) snprintf(res_name, 63, "%dx%ddpi", (int) xdpi, (int) ydpi);
1592 gpprintf(fp, "*DefaultResolution: %s\n", res_name);
1593 gpprintf(fp, "*StpDefaultResolution: %s\n", res_name);
1594 /*
1595 * We need to add this to the resolution list here so that
1596 * some non-default resolution won't wind up with the
1597 * default resolution name
1598 */
1599 stp_string_list_add_string(res_list, res_name, res_name);
1600 }
1601
1602 stp_clear_string_parameter(v, "Quality");
1603 for (i = 0; i < num_opts; i ++)
1604 {
1605 /*
1606 * Strip resolution name to its essentials...
1607 */
1608 opt = stp_string_list_param(desc.bounds.str, i);
1609 stp_set_string_parameter(v, "Resolution", opt->name);
1610 stp_describe_resolution(v, &xdpi, &ydpi);
1611
1612 /* This should only happen with a "None" resolution */
1613 if (xdpi == -1 || ydpi == -1)
1614 continue;
1615
1616 resolution_ok = 0;
1617 tmp_xdpi = xdpi;
1618 while (tmp_xdpi > MAXIMUM_SAFE_PPD_X_RESOLUTION)
1619 tmp_xdpi /= 2;
1620 tmp_ydpi = ydpi;
1621 while (tmp_ydpi > MAXIMUM_SAFE_PPD_Y_RESOLUTION)
1622 tmp_ydpi /= 2;
1623 do
1624 {
1625 if (tmp_xdpi == tmp_ydpi)
1626 (void) snprintf(res_name, 63, "%ddpi", (int) tmp_xdpi);
1627 else
1628 (void) snprintf(res_name, 63, "%dx%ddpi", (int) tmp_xdpi, (int) tmp_ydpi);
1629 if ((!has_quality_parameter &&
1630 strcmp(opt->name, desc.deflt.str) == 0) ||
1631 !stp_string_list_is_present(res_list, res_name))
1632 {
1633 resolution_ok = 1;
1634 stp_string_list_add_string(res_list, res_name, opt->text);
1635 }
1636 else if (tmp_ydpi > tmp_xdpi &&
1637 tmp_ydpi < MAXIMUM_SAFE_PPD_Y_RESOLUTION)
1638 /* Note that we're incrementing the *higher* resolution.
1639 This will generate less aliasing, and apps that convert
1640 down to a square resolution will do the right thing. */
1641 tmp_ydpi++;
1642 else if (tmp_xdpi < MAXIMUM_SAFE_PPD_X_RESOLUTION)
1643 tmp_xdpi++;
1644 else
1645 tmp_xdpi /= 2;
1646 } while (!resolution_ok);
1647 stp_string_list_add_string(resolutions, res_name, opt->text);
1648 gpprintf(fp, "*%sResolution %s/%s:\t\"<</HWResolution[%d %d]/cupsCompression %d>>setpagedevice\"\n",
1649 nocolor && strcmp(opt->name, desc.deflt.str) != 0 ? "?" : "",
1650 res_name, stp_i18n_lookup(po, opt->text), (int) xdpi, (int) ydpi, i + 1);
1651 if (strcmp(res_name, opt->name) != 0)
1652 gpprintf(fp, "*StpResolutionMap: %s %s\n", res_name, opt->name);
1653 }
1654
1655 stp_string_list_destroy(res_list);
1656 stp_clear_string_parameter(v, "Resolution");
1657 gpputs(fp, "*CloseUI: *Resolution\n\n");
1658 }
1659 }
1660
1661 stp_parameter_description_destroy(&desc);
1662
1663 stp_describe_parameter(v, "OutputOrder", &desc);
1664 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1665 {
1666 gpprintf(fp, "*OpenUI *OutputOrder/%s: PickOne\n", _("Output Order"));
1667 gpputs(fp, "*OPOptionHints OutputOrder: \"radiobuttons\"\n");
1668 gpputs(fp, "*OrderDependency: 10 AnySetup *OutputOrder\n");
1669 gpprintf(fp, "*DefaultOutputOrder: %s\n", desc.deflt.str);
1670 gpprintf(fp, "*StpDefaultOutputOrder: %s\n", desc.deflt.str);
1671 gpprintf(fp, "*OutputOrder Normal/%s: \"\"\n", _("Normal"));
1672 gpprintf(fp, "*OutputOrder Reverse/%s: \"\"\n", _("Reverse"));
1673 gpputs(fp, "*CloseUI: *OutputOrder\n\n");
1674 }
1675 stp_parameter_description_destroy(&desc);
1676
1677 /*
1678 * Duplex
1679 * Note that the opt->name strings MUST match those in the printer driver(s)
1680 * else the PPD files will not be generated correctly
1681 */
1682
1683 stp_describe_parameter(v, "Duplex", &desc);
1684 if (desc.is_active && desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1685 {
1686 num_opts = stp_string_list_count(desc.bounds.str);
1687 if (num_opts > 0)
1688 {
1689 int is_color_opt =
1690 stp_parameter_has_category_value(v, &desc, "Color", "Yes");
1691 if (is_color_opt)
1692 gpprintf(fp, "*ColorKeyWords: \"InputSlot\"\n");
1693 gpprintf(fp, "*OpenUI *Duplex/%s: PickOne\n", _("2-Sided Printing"));
1694 gpputs(fp, "*OPOptionHints Duplex: \"radiobuttons\"\n");
1695 gpputs(fp, "*OrderDependency: 10 AnySetup *Duplex\n");
1696 gpprintf(fp, "*StpStp%s: %d %d %d %d %d %.3f %.3f %.3f\n",
1697 desc.name, desc.p_type, desc.is_mandatory,
1698 desc.p_class, desc.p_level, desc.channel, 0.0, 0.0, 0.0);
1699 gpprintf(fp, "*DefaultDuplex: %s\n", desc.deflt.str);
1700 gpprintf(fp, "*StpDefaultDuplex: %s\n", desc.deflt.str);
1701
1702 for (i = 0; i < num_opts; i++)
1703 {
1704 opt = stp_string_list_param(desc.bounds.str, i);
1705 if (strcmp(opt->name, "None") == 0)
1706 gpprintf(fp, "*Duplex %s/%s: \"<</Duplex false>>setpagedevice\"\n", opt->name, stp_i18n_lookup(po, opt->text));
1707 else if (strcmp(opt->name, "DuplexNoTumble") == 0)
1708 gpprintf(fp, "*Duplex %s/%s: \"<</Duplex true/Tumble false>>setpagedevice\"\n", opt->name, stp_i18n_lookup(po, opt->text));
1709 else if (strcmp(opt->name, "DuplexTumble") == 0)
1710 gpprintf(fp, "*Duplex %s/%s: \"<</Duplex true/Tumble true>>setpagedevice\"\n", opt->name, stp_i18n_lookup(po, opt->text));
1711 }
1712 gpputs(fp, "*CloseUI: *Duplex\n\n");
1713 }
1714 }
1715 stp_parameter_description_destroy(&desc);
1716
1717 /* Collation */
1718 stp_describe_parameter(v, "Collate", &desc);
1719 if (desc.is_active)
1720 {
1721 gpprintf(fp, "*OpenUI *%s/%s: PickOne\n",
1722 desc.name, stp_i18n_lookup(po, desc.text));
1723 gpprintf(fp, "*OrderDependency: 10 AnySetup *%s\n", desc.name);
1724 gpprintf(fp, "*OPOptionHints %s: \"checkbox\"\n", desc.name);
1725 gpprintf(fp, "*Default%s: %s\n", desc.name,
1726 desc.deflt.boolean ? "True" : "False");
1727 gpprintf(fp, "*StpDefault%s: %s\n", desc.name,
1728 desc.deflt.boolean ? "True" : "False");
1729 gpprintf(fp, "*%s %s/%s: \"\"\n",
1730 desc.name, "False", _("No"));
1731 gpprintf(fp, "*%s %s/%s: \"\"\n",
1732 desc.name, "True", _("Yes"));
1733 gpprintf(fp, "*CloseUI: *%s\n\n", desc.name);
1734 }
1735 stp_parameter_description_destroy(&desc);
1736
1737 gpprintf(fp, "*OpenUI *StpiShrinkOutput/%s: PickOne\n",
1738 _("Shrink Page If Necessary to Fit Borders"));
1739 gpputs(fp, "*OPOptionHints StpiShrinkOutput: \"radiobuttons\"\n");
1740 gpputs(fp, "*OrderDependency: 10 AnySetup *StpiShrinkOutput\n");
1741 gpputs(fp, "*DefaultStpiShrinkOutput: Shrink\n");
1742 gpputs(fp, "*StpDefaultStpiShrinkOutput: Shrink\n");
1743 gpprintf(fp, "*StpiShrinkOutput %s/%s: \"\"\n", "Shrink", _("Shrink (print the whole page)"));
1744 gpprintf(fp, "*StpiShrinkOutput %s/%s: \"\"\n", "Crop", _("Crop (preserve dimensions)"));
1745 gpprintf(fp, "*StpiShrinkOutput %s/%s: \"\"\n", "Expand", _("Expand (use maximum page area)"));
1746 gpputs(fp, "*CloseUI: *StpiShrinkOutput\n\n");
1747
1748 param_list = stp_get_parameter_list(v);
1749
1750 for (j = 0; j <= STP_PARAMETER_CLASS_OUTPUT; j++)
1751 {
1752 for (k = 0; k <= maximum_level; k++)
1753 {
1754 int printed_open_group = 0;
1755 size_t param_count = stp_parameter_list_count(param_list);
1756 for (l = 0; l < param_count; l++)
1757 {
1758 const stp_parameter_t *lparam =
1759 stp_parameter_list_param(param_list, l);
1760 if (lparam->p_class != j || lparam->p_level != k ||
1761 is_special_option(lparam->name) || lparam->read_only ||
1762 (lparam->p_type != STP_PARAMETER_TYPE_STRING_LIST &&
1763 lparam->p_type != STP_PARAMETER_TYPE_RAW &&
1764 lparam->p_type != STP_PARAMETER_TYPE_BOOLEAN &&
1765 lparam->p_type != STP_PARAMETER_TYPE_DIMENSION &&
1766 lparam->p_type != STP_PARAMETER_TYPE_INT &&
1767 lparam->p_type != STP_PARAMETER_TYPE_DOUBLE))
1768 continue;
1769 stp_describe_parameter(v, lparam->name, &desc);
1770 if (desc.is_active)
1771 {
1772 if (!printed_open_group)
1773 {
1774 print_group_open(fp, j, k, language, po);
1775 printed_open_group = 1;
1776 }
1777 print_one_option(fp, v, po, ppd_type, lparam, &desc);
1778 }
1779 stp_parameter_description_destroy(&desc);
1780 }
1781 if (printed_open_group)
1782 print_group_close(fp, j, k, language, po);
1783 }
1784 }
1785 stp_describe_parameter(v, "ImageType", &desc);
1786 if (desc.is_active && desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1787 {
1788 num_opts = stp_string_list_count(desc.bounds.str);
1789 if (num_opts > 0)
1790 {
1791 for (i = 0; i < num_opts; i++)
1792 {
1793 opt = stp_string_list_param(desc.bounds.str, i);
1794 if (strcmp(opt->name, "None") != 0)
1795 gpprintf(fp, "*APPrinterPreset %s/%s: \"*StpImageType %s\"\n",
1796 opt->name, stp_i18n_lookup(po, opt->text), opt->name);
1797 }
1798 gpputs(fp, "\n");
1799 }
1800 }
1801 stp_parameter_description_destroy(&desc);
1802
1803 if (!language)
1804 {
1805 /*
1806 * Generate globalized PPDs when POSIX language is requested...
1807 */
1808
1809 const char *lang;
1810 const stp_string_list_t *savepo = po;
1811 int langnum;
1812
1813 for (langnum = 0; all_langs[langnum]; langnum ++)
1814 {
1815 lang = all_langs[langnum];
1816
1817 if (!strcmp(lang, "C") || !strcmp(lang, "en"))
1818 continue;
1819
1820 if ((po = stp_i18n_load(lang)) == NULL)
1821 continue;
1822
1823 /*
1824 * Get the page sizes from the driver...
1825 */
1826
1827 if (printer_is_color)
1828 stp_set_string_parameter(v, "PrintingMode", "Color");
1829 else
1830 stp_set_string_parameter(v, "PrintingMode", "BW");
1831 stp_set_string_parameter(v, "ChannelBitDepth", "8");
1832 stp_describe_parameter(v, "PageSize", &desc);
1833 num_opts = stp_string_list_count(desc.bounds.str);
1834
1835 gpprintf(fp, "*%s.Translation PageSize/%s: \"\"\n", lang, _("Media Size"));
1836 gpprintf(fp, "*%s.Translation PageRegion/%s: \"\"\n", lang, _("Media Size"));
1837
1838 for (i = 0; i < num_opts; i++)
1839 {
1840 const stp_papersize_t *papersize;
1841 opt = stp_string_list_param(desc.bounds.str, i);
1842 papersize = stp_describe_papersize(v, opt->name);
1843
1844 if (!papersize)
1845 continue;
1846
1847 /*
1848 if (strcmp(opt->name, "Custom") == 0)
1849 continue;
1850 */
1851
1852 if (simplified && num_opts >= 10 &&
1853 (!desc.deflt.str || strcmp(opt->name, desc.deflt.str) != 0) &&
1854 (papersize->paper_unit == PAPERSIZE_ENGLISH_EXTENDED ||
1855 papersize->paper_unit == PAPERSIZE_METRIC_EXTENDED ||
1856 ((papersize->width <= 0 || papersize->height <= 0) &&
1857 strcmp(opt->name, "Custom") != 0)))
1858 continue;
1859
1860 gpprintf(fp, "*%s.PageSize %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
1861 gpprintf(fp, "*%s.PageRegion %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
1862 }
1863
1864 stp_parameter_description_destroy(&desc);
1865
1866 /*
1867 * Do we support color?
1868 */
1869
1870 gpprintf(fp, "*%s.Translation ColorModel/%s: \"\"\n", lang, _("Color Model"));
1871 gpprintf(fp, "*%s.ColorModel Gray/%s: \"\"\n", lang, _("Grayscale"));
1872 gpprintf(fp, "*%s.ColorModel Black/%s: \"\"\n", lang, _("Inverted Grayscale"));
1873
1874 if (printer_is_color)
1875 {
1876 gpprintf(fp, "*%s.ColorModel RGB/%s: \"\"\n", lang, _("RGB Color"));
1877 gpprintf(fp, "*%s.ColorModel CMY/%s: \"\"\n", lang, _("CMY Color"));
1878 gpprintf(fp, "*%s.ColorModel CMYK/%s: \"\"\n", lang, _("CMYK"));
1879 gpprintf(fp, "*%s.ColorModel KCMY/%s: \"\"\n", lang, _("KCMY"));
1880 }
1881
1882 if (!simplified)
1883 {
1884 /*
1885 * 8 or 16 bit color (16 bit is slower)
1886 */
1887 gpprintf(fp, "*%s.Translation StpColorPrecision/%s: \"\"\n", lang, _("Color Precision"));
1888 gpprintf(fp, "*%s.StpColorPrecision Normal/%s: \"\"\n", lang, _("Normal"));
1889 gpprintf(fp, "*%s.StpColorPrecision Best/%s: \"\"\n", lang, _("Best"));
1890 }
1891
1892 /*
1893 * Media types...
1894 */
1895
1896 stp_describe_parameter(v, "MediaType", &desc);
1897 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active &&
1898 stp_string_list_count(desc.bounds.str) > 0)
1899 {
1900 num_opts = stp_string_list_count(desc.bounds.str);
1901 gpprintf(fp, "*%s.Translation MediaType/%s: \"\"\n", lang, _("Media Type"));
1902
1903 for (i = 0; i < num_opts; i ++)
1904 {
1905 opt = stp_string_list_param(desc.bounds.str, i);
1906 gpprintf(fp, "*%s.MediaType %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
1907 }
1908 }
1909 stp_parameter_description_destroy(&desc);
1910
1911 /*
1912 * Input slots...
1913 */
1914
1915 stp_describe_parameter(v, "InputSlot", &desc);
1916
1917 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active &&
1918 stp_string_list_count(desc.bounds.str) > 0)
1919 {
1920 num_opts = stp_string_list_count(desc.bounds.str);
1921 gpprintf(fp, "*%s.Translation InputSlot/%s: \"\"\n", lang, _("Media Source"));
1922
1923 for (i = 0; i < num_opts; i ++)
1924 {
1925 opt = stp_string_list_param(desc.bounds.str, i);
1926 gpprintf(fp, "*%s.InputSlot %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
1927 }
1928 }
1929 stp_parameter_description_destroy(&desc);
1930
1931 /*
1932 * Quality settings
1933 */
1934
1935 stp_describe_parameter(v, "Quality", &desc);
1936 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active)
1937 {
1938 gpprintf(fp, "*%s.Translation StpQuality/%s: \"\"\n", lang, stp_i18n_lookup(po, desc.text));
1939 num_opts = stp_string_list_count(desc.bounds.str);
1940 for (i = 0; i < num_opts; i++)
1941 {
1942 opt = stp_string_list_param(desc.bounds.str, i);
1943 gpprintf(fp, "*%s.StpQuality %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
1944 }
1945 }
1946 stp_parameter_description_destroy(&desc);
1947
1948 /*
1949 * Resolution
1950 */
1951
1952 stp_describe_parameter(v, "Resolution", &desc);
1953
1954 if (!simplified || desc.p_level == STP_PARAMETER_LEVEL_BASIC)
1955 {
1956 gpprintf(fp, "*%s.Translation Resolution/%s: \"\"\n", lang, _("Resolution"));
1957 if (has_quality_parameter)
1958 gpprintf(fp, "*%s.Resolution %s/%s: \"\"\n", lang,
1959 default_resolution, _("Automatic"));
1960
1961 num_opts = stp_string_list_count(resolutions);
1962 for (i = 0; i < num_opts; i ++)
1963 {
1964 opt = stp_string_list_param(resolutions, i);
1965 gpprintf(fp, "*%s.Resolution %s/%s: \"\"\n", lang,
1966 opt->name, stp_i18n_lookup(po, opt->text));
1967 }
1968 }
1969
1970 stp_parameter_description_destroy(&desc);
1971
1972 /*
1973 * OutputOrder
1974 */
1975
1976 stp_describe_parameter(v, "OutputOrder", &desc);
1977 if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1978 {
1979 gpprintf(fp, "*%s.Translation OutputOrder/%s: \"\"\n", lang, _("Output Order"));
1980 gpprintf(fp, "*%s.OutputOrder Normal/%s: \"\"\n", lang, _("Normal"));
1981 gpprintf(fp, "*%s.OutputOrder Reverse/%s: \"\"\n", lang, _("Reverse"));
1982 }
1983 stp_parameter_description_destroy(&desc);
1984
1985 /*
1986 * Duplex
1987 * Note that the opt->name strings MUST match those in the printer driver(s)
1988 * else the PPD files will not be generated correctly
1989 */
1990
1991 stp_describe_parameter(v, "Duplex", &desc);
1992 if (desc.is_active && desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
1993 {
1994 num_opts = stp_string_list_count(desc.bounds.str);
1995 if (num_opts > 0)
1996 {
1997 gpprintf(fp, "*%s.Translation Duplex/%s: \"\"\n", lang, _("2-Sided Printing"));
1998
1999 for (i = 0; i < num_opts; i++)
2000 {
2001 opt = stp_string_list_param(desc.bounds.str, i);
2002 if (strcmp(opt->name, "None") == 0)
2003 gpprintf(fp, "*%s.Duplex %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
2004 else if (strcmp(opt->name, "DuplexNoTumble") == 0)
2005 gpprintf(fp, "*%s.Duplex %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
2006 else if (strcmp(opt->name, "DuplexTumble") == 0)
2007 gpprintf(fp, "*%s.Duplex %s/%s: \"\"\n", lang, opt->name, stp_i18n_lookup(po, opt->text));
2008 }
2009 }
2010 }
2011 stp_parameter_description_destroy(&desc);
2012
2013 /* Collation */
2014 stp_describe_parameter(v, "Collate", &desc);
2015 if (desc.is_active)
2016 {
2017 gpprintf(fp, "*%s.Translation Collate/%s: \"\"\n", lang, _("Collate the Job"));
2018 gpprintf(fp, "*%s.Collate %s/%s: \"\"\n", lang, "True", _("Yes"));
2019 gpprintf(fp, "*%s.Collate %s/%s: \"\"\n", lang, "False", _("No"));
2020 }
2021
2022 gpprintf(fp, "*%s.Translation StpiShrinkOutput/%s: \"\"\n", lang,
2023 _("Shrink Page If Necessary to Fit Borders"));
2024 gpprintf(fp, "*%s.StpiShrinkOutput %s/%s: \"\"\n", lang, "Shrink", _("Shrink (print the whole page)"));
2025 gpprintf(fp, "*%s.StpiShrinkOutput %s/%s: \"\"\n", lang, "Crop", _("Crop (preserve dimensions)"));
2026 gpprintf(fp, "*%s.StpiShrinkOutput %s/%s: \"\"\n", lang, "Expand", _("Expand (use maximum page area)"));
2027
2028 for (j = 0; j <= STP_PARAMETER_CLASS_OUTPUT; j++)
2029 {
2030 for (k = 0; k <= maximum_level; k++)
2031 {
2032 size_t param_count = stp_parameter_list_count(param_list);
2033 for (l = 0; l < param_count; l++)
2034 {
2035 const stp_parameter_t *lparam =
2036 stp_parameter_list_param(param_list, l);
2037 if (lparam->p_class != j || lparam->p_level != k ||
2038 is_special_option(lparam->name) || lparam->read_only ||
2039 (lparam->p_type != STP_PARAMETER_TYPE_STRING_LIST &&
2040 lparam->p_type != STP_PARAMETER_TYPE_BOOLEAN &&
2041 lparam->p_type != STP_PARAMETER_TYPE_DIMENSION &&
2042 lparam->p_type != STP_PARAMETER_TYPE_INT &&
2043 lparam->p_type != STP_PARAMETER_TYPE_DOUBLE))
2044 continue;
2045 stp_describe_parameter(v, lparam->name, &desc);
2046 if (desc.is_active)
2047 print_one_localization(fp, po, simplified, lang,
2048 lparam, &desc);
2049 stp_parameter_description_destroy(&desc);
2050 }
2051 }
2052 }
2053 stp_describe_parameter(v, "ImageType", &desc);
2054 if (desc.is_active && desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
2055 {
2056 num_opts = stp_string_list_count(desc.bounds.str);
2057 if (num_opts > 0)
2058 {
2059 for (i = 0; i < num_opts; i++)
2060 {
2061 opt = stp_string_list_param(desc.bounds.str, i);
2062 if (strcmp(opt->name, "None") != 0)
2063 gpprintf(fp, "*%s.APPrinterPreset %s/%s: \"*StpImageType %s\"\n",
2064 lang, opt->name, opt->text, opt->name);
2065 }
2066 }
2067 }
2068 stp_parameter_description_destroy(&desc);
2069 }
2070 po = savepo;
2071 }
2072 stp_parameter_list_destroy(param_list);
2073 if (has_quality_parameter)
2074 stp_free(default_resolution);
2075 stp_string_list_destroy(resolutions);
2076
2077 /*
2078 * Fonts...
2079 */
2080
2081 print_standard_fonts(fp);
2082 gpprintf(fp, "\n*%% End of %s\n", filename);
2083
2084 stp_vars_destroy(v);
2085
2086 return (0);
2087 }