]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdc-driver.cxx
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / ppdc / ppdc-driver.cxx
CommitLineData
ac884b6a
MS
1//
2// "$Id$"
3//
4// PPD file compiler definitions for the CUPS PPD Compiler.
5//
bdd6c45b 6// Copyright 2007-2008 by Apple Inc.
ac884b6a
MS
7// Copyright 2002-2006 by Easy Software Products.
8//
9// These coded instructions, statements, and computer programs are the
10// property of Apple Inc. and are protected by Federal copyright
11// law. Distribution and use rights are outlined in the file "LICENSE.txt"
12// which should have been included with this file. If this file is
13// file is missing or damaged, see the license at "http://www.cups.org/".
14//
15// Contents:
16//
17// ppdcDriver::ppdcDriver() - Create a new printer driver.
18// ppdcDriver::~ppdcDriver() - Destroy a printer driver.
19// ppdcDriver::find_attr() - Find an attribute.
20// ppdcDriver::find_group() - Find a group.
21// ppdcDriver::find_option() - Find an option.
22// ppdcDriver::set_default_size() - Set the default size name.
bdd6c45b 23// ppdcDriver::set_file_name() - Set the full filename.
ac884b6a
MS
24// ppdcDriver::set_manufacturer() - Set the manufacturer name.
25// ppdcDriver::set_model_name() - Set the model name.
26// ppdcDriver::set_pc_file_name() - Set the PC filename.
27// ppdcDriver::set_version() - Set the version string.
28// ppdcDriver::write_ppd_file() - Write a PPD file...
29//
30
31//
32// Include necessary headers...
33//
34
35#include "ppdc.h"
36#include <cups/cups.h>
37
38
39//
40// 'ppdcDriver::ppdcDriver()' - Create a new printer driver.
41//
42
43ppdcDriver::ppdcDriver(ppdcDriver *d) // I - Printer driver template
44{
45 ppdcGroup *g; // Current group
46
47
48 if (d)
49 {
50 // Bump the use count of any strings we inherit...
51 if (d->manufacturer)
52 d->manufacturer->get();
53 if (d->version)
54 d->version->get();
55 if (d->default_font)
56 d->default_font->get();
57 if (d->default_size)
58 d->default_size->get();
59 if (d->custom_size_code)
60 d->custom_size_code->get();
61
62 // Copy all of the data from the driver template...
63 copyright = new ppdcArray(d->copyright);
64 manufacturer = d->manufacturer;
65 model_name = 0;
bdd6c45b 66 file_name = 0;
ac884b6a
MS
67 pc_file_name = 0;
68 type = d->type;
69 version = d->version;
70 model_number = d->model_number;
71 manual_copies = d->manual_copies;
72 color_device = d->color_device;
73 throughput = d->throughput;
74 attrs = new ppdcArray(d->attrs);
75 constraints = new ppdcArray(d->constraints);
76 filters = new ppdcArray(d->filters);
77 fonts = new ppdcArray(d->fonts);
78 profiles = new ppdcArray(d->profiles);
79 sizes = new ppdcArray(d->sizes);
80 default_font = d->default_font;
81 default_size = d->default_size;
82 variable_paper_size = d->variable_paper_size;
83 custom_size_code = d->custom_size_code;
84 left_margin = d->left_margin;
85 bottom_margin = d->bottom_margin;
86 right_margin = d->right_margin;
87 top_margin = d->top_margin;
88 max_width = d->max_width;
89 max_length = d->max_length;
90 min_width = d->min_width;
91 min_length = d->min_length;
92
93 // Then copy the groups manually, since we want separate copies
94 // of the groups and options...
95 groups = new ppdcArray();
96
97 for (g = (ppdcGroup *)d->groups->first(); g; g = (ppdcGroup *)d->groups->next())
98 groups->add(new ppdcGroup(g));
99 }
100 else
101 {
102 // Zero all of the data in the driver...
103 copyright = new ppdcArray();
104 manufacturer = 0;
105 model_name = 0;
bdd6c45b 106 file_name = 0;
ac884b6a
MS
107 pc_file_name = 0;
108 version = 0;
109 type = PPDC_DRIVER_CUSTOM;
110 model_number = 0;
111 manual_copies = 0;
112 color_device = 0;
113 throughput = 1;
114 attrs = new ppdcArray();
115 constraints = new ppdcArray();
116 fonts = new ppdcArray();
117 filters = new ppdcArray();
118 groups = new ppdcArray();
119 profiles = new ppdcArray();
120 sizes = new ppdcArray();
121 default_font = 0;
122 default_size = 0;
123 variable_paper_size = 0;
124 custom_size_code = 0;
125 left_margin = 0;
126 bottom_margin = 0;
127 right_margin = 0;
128 top_margin = 0;
129 max_width = 0;
130 max_length = 0;
131 min_width = 0;
132 min_length = 0;
133 }
134}
135
136
137//
138// 'ppdcDriver::~ppdcDriver()' - Destroy a printer driver.
139//
140
141ppdcDriver::~ppdcDriver()
142{
143 delete copyright;
144
145 if (manufacturer)
146 manufacturer->release();
147 if (model_name)
148 model_name->release();
bdd6c45b
MS
149 if (file_name)
150 file_name->release();
ac884b6a
MS
151 if (pc_file_name)
152 pc_file_name->release();
153 if (version)
154 version->release();
155 if (default_font)
156 default_font->release();
157 if (default_size)
158 default_size->release();
159 if (custom_size_code)
160 custom_size_code->release();
161
162 delete attrs;
163 delete constraints;
164 delete filters;
165 delete fonts;
166 delete groups;
167 delete profiles;
168 delete sizes;
169}
170
171
172//
173// 'ppdcDriver::find_attr()' - Find an attribute.
174//
175
176ppdcAttr * // O - Attribute or NULL
177ppdcDriver::find_attr(const char *k, // I - Keyword string
178 const char *s) // I - Spec string
179{
180 ppdcAttr *a; // Current attribute
181
182
183 for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next())
184 if (!strcmp(a->name->value, k) &&
185 ((!s && (!a->selector->value || !a->selector->value[0])) ||
186 (!s && !a->selector->value && !strcmp(a->selector->value, s))))
187 return (a);
188
189 return (NULL);
190}
191
192
193//
194// 'ppdcDriver::find_group()' - Find a group.
195//
196
197ppdcGroup * // O - Matching group or NULL
198ppdcDriver::find_group(const char *n) // I - Group name
199{
200 ppdcGroup *g; // Current group
201
202
203 for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next())
204 if (!strcasecmp(n, g->name->value))
205 return (g);
206
207 return (0);
208}
209
210
211//
212// 'ppdcDriver::find_option()' - Find an option.
213//
214
215ppdcOption * // O - Matching option or NULL
216ppdcDriver::find_option(const char *n) // I - Option name
217{
218 ppdcGroup *g; // Current group
219 ppdcOption *o; // Current option
220
221
222 for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next())
223 for (o = (ppdcOption *)g->options->first(); o; o = (ppdcOption *)g->options->next())
224 if (!strcasecmp(n, o->name->value))
225 return (o);
226
227 return (0);
228}
229
230
231//
232// 'ppdcDriver::set_custom_size_code()' - Set the custom page size code.
233//
234
235void
bdd6c45b
MS
236ppdcDriver::set_custom_size_code(
237 const char *c) // I - CustomPageSize code
ac884b6a
MS
238{
239 if (custom_size_code)
240 custom_size_code->release();
241
242 custom_size_code = new ppdcString(c);
243}
244
245
246//
247// 'ppdcDriver::set_default_font()' - Set the default font name.
248//
249
250void
bdd6c45b
MS
251ppdcDriver::set_default_font(
252 ppdcFont *f) // I - Font
ac884b6a
MS
253{
254 if (default_font)
255 default_font->release();
256
257 if (f)
258 {
259 f->name->get();
260 default_font = f->name;
261 }
262 else
263 default_font = 0;
264}
265
266
267//
268// 'ppdcDriver::set_default_size()' - Set the default size name.
269//
270
271void
bdd6c45b
MS
272ppdcDriver::set_default_size(
273 ppdcMediaSize *m) // I - Media size
ac884b6a
MS
274{
275 if (default_size)
276 default_size->release();
277
278 if (m)
279 {
280 m->name->get();
281 default_size = m->name;
282 }
283 else
284 default_size = 0;
285}
286
287
bdd6c45b
MS
288//
289// 'ppdcDriver::set_file_name()' - Set the full filename.
290//
291
292void
293ppdcDriver::set_file_name(const char *f)// I - Filename
294{
295 if (file_name)
296 file_name->release();
297
298 file_name = new ppdcString(f);
299}
300
301
ac884b6a
MS
302//
303// 'ppdcDriver::set_manufacturer()' - Set the manufacturer name.
304//
305
306void
bdd6c45b
MS
307ppdcDriver::set_manufacturer(
308 const char *m) // I - Model name
ac884b6a
MS
309{
310 if (manufacturer)
311 manufacturer->release();
312
313 manufacturer = new ppdcString(m);
314}
315
316
317//
318// 'ppdcDriver::set_model_name()' - Set the model name.
319//
320
321void
bdd6c45b
MS
322ppdcDriver::set_model_name(
323 const char *m) // I - Model name
ac884b6a
MS
324{
325 if (model_name)
326 model_name->release();
327
328 model_name = new ppdcString(m);
329}
330
331
332//
333// 'ppdcDriver::set_pc_file_name()' - Set the PC filename.
334//
335
336void
bdd6c45b
MS
337ppdcDriver::set_pc_file_name(
338 const char *f) // I - Filename
ac884b6a
MS
339{
340 if (pc_file_name)
341 pc_file_name->release();
342
343 pc_file_name = new ppdcString(f);
344}
345
346
347//
348// 'ppdcDriver::set_version()' - Set the version string.
349//
350
351void
352ppdcDriver::set_version(const char *v) // I - Version
353{
354 if (version)
355 version->release();
356
357 version = new ppdcString(v);
358}
359
360
361//
362// 'ppdcDriver::write_ppd_file()' - Write a PPD file...
363//
364
365int // O - 0 on success, -1 on failure
366ppdcDriver::write_ppd_file(
367 cups_file_t *fp, // I - PPD file
368 ppdcCatalog *catalog, // I - Message catalog
369 ppdcArray *locales, // I - Additional languages to add
370 ppdcSource *src, // I - Driver source
371 ppdcLineEnding le) // I - Line endings to use
372{
373 bool delete_cat; // Delete the catalog when we are done?
374 char query[42]; // Query attribute
375 ppdcString *s; // Copyright string
376 ppdcGroup *g; // Current group
377 ppdcOption *o; // Current option
378 ppdcChoice *c; // Current choice
379 ppdcMediaSize *m; // Current media size
380 ppdcProfile *p; // Current color profile
381 ppdcFilter *f; // Current filter
382 ppdcFont *fn, // Current font
383 *bfn; // Current base font
384 ppdcConstraint *cn; // Current constraint
385 ppdcAttr *a; // Current attribute
386 const char *lf; // Linefeed character to use
387
388
389 // If we don't have a message catalog, use an empty (English) one...
390 if (!catalog)
391 {
392 catalog = new ppdcCatalog("en");
393 delete_cat = true;
394 }
395 else
396 delete_cat = false;
397
398 // Figure out the end-of-line string...
399 if (le == PPDC_LFONLY)
400 lf = "\n";
401 else if (le == PPDC_CRONLY)
402 lf = "\r";
403 else
404 lf = "\r\n";
405
406 // Write the standard header stuff...
407 cupsFilePrintf(fp, "*PPD-Adobe: \"4.3\"%s", lf);
408 cupsFilePrintf(fp, "*%% PPD file for %s with CUPS.%s", model_name->value, lf);
409 cupsFilePrintf(fp,
410 "*%% Created by the CUPS PPD Compiler " CUPS_SVERSION ".%s",
411 lf);
412 for (s = (ppdcString *)copyright->first();
413 s;
414 s = (ppdcString *)copyright->next())
415 cupsFilePrintf(fp, "*%% %s%s", catalog->find_message(s->value), lf);
416 cupsFilePrintf(fp, "*FormatVersion: \"4.3\"%s", lf);
417 cupsFilePrintf(fp, "*FileVersion: \"%s\"%s", version->value, lf);
418
419 a = find_attr("LanguageVersion", NULL);
420 cupsFilePrintf(fp, "*LanguageVersion: %s%s",
421 catalog->find_message(a ? a->value->value : "English"), lf);
422
423 a = find_attr("LanguageEncoding", NULL);
424 cupsFilePrintf(fp, "*LanguageEncoding: %s%s",
425 catalog->find_message(a ? a->value->value : "ISOLatin1"), lf);
426
427 cupsFilePrintf(fp, "*PCFileName: \"%s\"%s", pc_file_name->value, lf);
428
429 for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next())
430 if (!strcmp(a->name->value, "Product"))
431 break;
432
433 if (a)
434 {
435 for (; a; a = (ppdcAttr *)attrs->next())
436 if (!strcmp(a->name->value, "Product"))
437 cupsFilePrintf(fp, "*Product: \"%s\"%s", a->value->value, lf);
438 }
439 else
bdd6c45b 440 cupsFilePrintf(fp, "*Product: \"(%s)\"%s", model_name->value, lf);
ac884b6a
MS
441
442 cupsFilePrintf(fp, "*Manufacturer: \"%s\"%s",
443 catalog->find_message(manufacturer->value), lf);
444
445 if ((a = find_attr("ModelName", NULL)) != NULL)
446 cupsFilePrintf(fp, "*ModelName: \"%s\"%s",
447 catalog->find_message(a->value->value), lf);
448 else if (strncasecmp(model_name->value, manufacturer->value,
449 strlen(manufacturer->value)))
450 cupsFilePrintf(fp, "*ModelName: \"%s %s\"%s",
451 catalog->find_message(manufacturer->value),
452 catalog->find_message(model_name->value), lf);
453 else
454 cupsFilePrintf(fp, "*ModelName: \"%s\"%s",
455 catalog->find_message(model_name->value), lf);
456
457 if ((a = find_attr("ShortNickName", NULL)) != NULL)
458 cupsFilePrintf(fp, "*ShortNickName: \"%s\"%s",
459 catalog->find_message(a->value->value), lf);
460 else if (strncasecmp(model_name->value, manufacturer->value,
461 strlen(manufacturer->value)))
462 cupsFilePrintf(fp, "*ShortNickName: \"%s %s\"%s",
463 catalog->find_message(manufacturer->value),
464 catalog->find_message(model_name->value), lf);
465 else
466 cupsFilePrintf(fp, "*ShortNickName: \"%s\"%s",
467 catalog->find_message(model_name->value), lf);
468
469 if ((a = find_attr("NickName", NULL)) != NULL)
470 cupsFilePrintf(fp, "*NickName: \"%s\"%s",
471 catalog->find_message(a->value->value), lf);
472 else if (strncasecmp(model_name->value, manufacturer->value,
473 strlen(manufacturer->value)))
474 cupsFilePrintf(fp, "*NickName: \"%s %s, %s\"%s",
475 catalog->find_message(manufacturer->value),
476 catalog->find_message(model_name->value), version->value,
477 lf);
478 else
479 cupsFilePrintf(fp, "*NickName: \"%s, %s\"%s",
480 catalog->find_message(model_name->value), version->value,
481 lf);
482
483 for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next())
484 if (!strcmp(a->name->value, "PSVersion"))
485 break;
486
487 if (a)
488 {
489 for (; a; a = (ppdcAttr *)attrs->next())
490 if (!strcmp(a->name->value, "PSVersion"))
491 cupsFilePrintf(fp, "*PSVersion: \"%s\"%s", a->value->value, lf);
492 }
493 else
bdd6c45b 494 cupsFilePrintf(fp, "*PSVersion: \"(3010.000) 0\"%s", lf);
ac884b6a
MS
495
496 if ((a = find_attr("LanguageLevel", NULL)) != NULL)
497 cupsFilePrintf(fp, "*LanguageLevel: \"%s\"%s", a->value->value, lf);
498 else
499 cupsFilePrintf(fp, "*LanguageLevel: \"3\"%s", lf);
500
501 cupsFilePrintf(fp, "*ColorDevice: %s%s", color_device ? "True" : "False", lf);
502
503 if ((a = find_attr("DefaultColorSpace", NULL)) != NULL)
504 cupsFilePrintf(fp, "*DefaultColorSpace: %s%s", a->value->value, lf);
505 else
506 cupsFilePrintf(fp, "*DefaultColorSpace: %s%s",
507 color_device ? "RGB" : "Gray", lf);
508
509 if ((a = find_attr("FileSystem", NULL)) != NULL)
510 cupsFilePrintf(fp, "*FileSystem: %s%s", a->value->value, lf);
511 else
512 cupsFilePrintf(fp, "*FileSystem: False%s", lf);
513
514 cupsFilePrintf(fp, "*Throughput: \"%d\"%s", throughput, lf);
515
516 if ((a = find_attr("LandscapeOrientation", NULL)) != NULL)
517 cupsFilePrintf(fp, "*LandscapeOrientation: %s%s", a->value->value, lf);
518 else
519 cupsFilePrintf(fp, "*LandscapeOrientation: Plus90%s", lf);
520
521 if ((a = find_attr("TTRasterizer", NULL)) != NULL)
522 cupsFilePrintf(fp, "*TTRasterizer: %s%s", a->value->value, lf);
523 else if (type != PPDC_DRIVER_PS)
524 cupsFilePrintf(fp, "*TTRasterizer: Type42%s", lf);
525
526 if (attrs->count)
527 {
528 // Write driver-defined attributes...
529 cupsFilePrintf(fp, "*%% Driver-defined attributes...%s", lf);
530 for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next())
531 {
532 if (!strcmp(a->name->value, "Product") ||
533 !strcmp(a->name->value, "PSVersion") ||
534 !strcmp(a->name->value, "LanguageLevel") ||
535 !strcmp(a->name->value, "DefaultColorSpace") ||
536 !strcmp(a->name->value, "FileSystem") ||
537 !strcmp(a->name->value, "LandscapeOrientation") ||
538 !strcmp(a->name->value, "TTRasterizer") ||
539 !strcmp(a->name->value, "LanguageVersion") ||
540 !strcmp(a->name->value, "LanguageEncoding") ||
541 !strcmp(a->name->value, "ModelName") ||
542 !strcmp(a->name->value, "NickName") ||
543 !strcmp(a->name->value, "ShortNickName") ||
4509bb49 544 !strcmp(a->name->value, "cupsVersion"))
ac884b6a
MS
545 continue;
546
4509bb49
MS
547 if (a->name->value[0] == '?' &&
548 (find_option(a->name->value + 1) ||
549 !strcmp(a->name->value, "?ImageableArea") ||
550 !strcmp(a->name->value, "?PageRegion") ||
551 !strcmp(a->name->value, "?PageSize") ||
552 !strcmp(a->name->value, "?PaperDimension")))
553 continue;
554
ac884b6a
MS
555 if (!a->selector->value || !a->selector->value[0])
556 cupsFilePrintf(fp, "*%s", a->name->value);
557 else if (!a->text->value || !a->text->value[0])
558 cupsFilePrintf(fp, "*%s %s", a->name->value, a->selector->value);
559 else
560 cupsFilePrintf(fp, "*%s %s/%s", a->name->value, a->selector->value,
561 a->text->value);
562
563 if (strcmp(a->value->value, "False") &&
564 strcmp(a->value->value, "True") &&
565 strcmp(a->name->value, "1284Modes") &&
566 strcmp(a->name->value, "InkName") &&
567 strcmp(a->name->value, "PageStackOrder") &&
568 strncmp(a->name->value, "ParamCustom", 11) &&
569 strcmp(a->name->value, "Protocols") &&
570 strcmp(a->name->value, "ReferencePunch") &&
571 strncmp(a->name->value, "Default", 7))
572 {
573 cupsFilePrintf(fp, ": \"%s\"%s", a->value->value, lf);
574
575 if (strchr(a->value->value, '\n'))
576 cupsFilePrintf(fp, "*End%s", lf);
577 }
578 else
579 cupsFilePrintf(fp, ": %s%s", a->value->value, lf);
580 }
581 }
582
583 if (type != PPDC_DRIVER_PS || filters->count)
584 {
585 if ((a = find_attr("cupsVersion", NULL)) != NULL)
586 cupsFilePrintf(fp, "*cupsVersion: %s%s", a->value->value, lf);
587 else
588 cupsFilePrintf(fp, "*cupsVersion: %d.%d%s", CUPS_VERSION_MAJOR,
589 CUPS_VERSION_MINOR, lf);
590 cupsFilePrintf(fp, "*cupsModelNumber: %d%s", model_number, lf);
591 cupsFilePrintf(fp, "*cupsManualCopies: %s%s",
592 manual_copies ? "True" : "False", lf);
593
594 if (filters->count)
595 {
596 for (f = (ppdcFilter *)filters->first();
597 f;
598 f = (ppdcFilter *)filters->next())
599 cupsFilePrintf(fp, "*cupsFilter: \"%s %d %s\"%s", f->mime_type->value,
600 f->cost, f->program->value, lf);
601 }
602 else
603 {
604 switch (type)
605 {
606 case PPDC_DRIVER_LABEL :
607 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 "
608 "rastertolabel\"%s", lf);
609 break;
610
611 case PPDC_DRIVER_EPSON :
612 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 "
613 "rastertoepson\"%s", lf);
614 break;
615
616 case PPDC_DRIVER_ESCP :
617 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-command 50 "
618 "commandtoescpx\"%s", lf);
619 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 "
620 "rastertoescpx\"%s", lf);
621 break;
622
623 case PPDC_DRIVER_HP :
624 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 "
625 "rastertohp\"%s", lf);
626 break;
627
628 case PPDC_DRIVER_PCL :
629 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-command 50 "
630 "commandtopclx\"%s", lf);
631 cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 "
632 "rastertopclx\"%s", lf);
633 break;
634
635 default :
636 break;
637 }
638 }
639
640 for (p = (ppdcProfile *)profiles->first();
641 p;
642 p = (ppdcProfile *)profiles->next())
643 cupsFilePrintf(fp,
644 "*cupsColorProfile %s/%s: \"%.3f %.3f %.3f %.3f %.3f %.3f "
645 "%.3f %.3f %.3f %.3f %.3f\"%s",
646 p->resolution->value, p->media_type->value,
647 p->density, p->gamma,
648 p->profile[0], p->profile[1],
649 p->profile[2], p->profile[3],
650 p->profile[4], p->profile[5],
651 p->profile[6], p->profile[7],
652 p->profile[8], lf);
653 }
654
655 if (locales)
656 {
657 // Add localizations for additional languages...
658 ppdcString *locale; // Locale name
659 ppdcCatalog *locatalog; // Message catalog for locale
660
661
662 // Write the list of languages...
663 cupsFilePrintf(fp, "*cupsLanguages: \"en");
664
665 for (locale = (ppdcString *)locales->first();
666 locale;
667 locale = (ppdcString *)locales->next())
668 {
669 // Skip (US) English...
670 if (!strcmp(locale->value, "en") || !strcmp(locale->value, "en_US"))
671 continue;
672
673 // See if we have a po file for this language...
674 if (!src->find_po(locale->value))
675 {
676 // No, see if we can use the base file?
677 locatalog = new ppdcCatalog(locale->value);
678
679 if (locatalog->messages->count == 0)
680 {
681 // No, skip this one...
682 fprintf(stderr, "ppdc: No message catalog provided for locale %s!\n",
683 locale->value);
684 continue;
685 }
686
687 // Add the base file to the list...
688 src->po_files->add(locatalog);
689 }
690
691 cupsFilePrintf(fp, " %s", locale->value);
692 }
693
694 cupsFilePrintf(fp, "\"%s", lf);
695 }
696
697 for (cn = (ppdcConstraint *)constraints->first();
698 cn;
699 cn = (ppdcConstraint *)constraints->next())
700 {
701 // First constrain 1 against 2...
702 if (!strncmp(cn->option1->value, "*Custom", 7) ||
703 !strncmp(cn->option2->value, "*Custom", 7))
704 cupsFilePrintf(fp, "*NonUIConstraints: ");
705 else
706 cupsFilePrintf(fp, "*UIConstraints: ");
707
708 if (cn->option1->value[0] != '*')
709 cupsFilePutChar(fp, '*');
710
711 cupsFilePrintf(fp, cn->option1->value);
712
713 if (cn->choice1->value)
714 cupsFilePrintf(fp, " %s", cn->choice1->value);
715
716 cupsFilePutChar(fp, ' ');
717
718 if (cn->option2->value[0] != '*')
719 cupsFilePutChar(fp, '*');
720
721 cupsFilePrintf(fp, cn->option2->value);
722
723 if (cn->choice2->value)
724 cupsFilePrintf(fp, " %s", cn->choice2->value);
725
726 cupsFilePrintf(fp, "%s", lf);
727
728 // Then constrain 2 against 1...
729 if (!strncmp(cn->option1->value, "*Custom", 7) ||
730 !strncmp(cn->option2->value, "*Custom", 7))
731 cupsFilePrintf(fp, "*NonUIConstraints: ");
732 else
733 cupsFilePrintf(fp, "*UIConstraints: ");
734
735 if (cn->option2->value[0] != '*')
736 cupsFilePutChar(fp, '*');
737
738 cupsFilePrintf(fp, cn->option2->value);
739
740 if (cn->choice2->value)
741 cupsFilePrintf(fp, " %s", cn->choice2->value);
742
743 cupsFilePutChar(fp, ' ');
744
745 if (cn->option1->value[0] != '*')
746 cupsFilePutChar(fp, '*');
747
748 cupsFilePrintf(fp, cn->option1->value);
749
750 if (cn->choice1->value)
751 cupsFilePrintf(fp, " %s", cn->choice1->value);
752
753 cupsFilePuts(fp, lf);
754 }
755
756 // PageSize option...
757 cupsFilePrintf(fp, "*OpenUI *PageSize/Media Size: PickOne%s", lf);
758 cupsFilePrintf(fp, "*OrderDependency: 10 AnySetup *PageSize%s", lf);
759 cupsFilePrintf(fp, "*DefaultPageSize: %s%s",
760 default_size ? default_size->value : "Letter", lf);
761
762 for (m = (ppdcMediaSize *)sizes->first();
763 m;
764 m = (ppdcMediaSize *)sizes->next())
765 if (m->size_code->value)
766 {
767 cupsFilePrintf(fp, "*PageSize %s/%s: \"%s\"%s",
768 m->name->value, catalog->find_message(m->text->value),
769 m->size_code->value, lf);
770
771 if (strchr(m->size_code->value, '\n') ||
772 strchr(m->size_code->value, '\r'))
773 cupsFilePrintf(fp, "*End%s", lf);
774 }
775 else
776 cupsFilePrintf(fp,
777 "*PageSize %s/%s: \"<</PageSize[%.0f %.0f]"
778 "/ImagingBBox null>>setpagedevice\"%s",
779 m->name->value, catalog->find_message(m->text->value),
780 m->width, m->length, lf);
781
782 if ((a = find_attr("?PageSize", NULL)) != NULL)
783 {
784 cupsFilePrintf(fp, "*?PageSize: \"%s\"%s", a->value->value, lf);
785
786 if (strchr(a->value->value, '\n') ||
787 strchr(a->value->value, '\r'))
788 cupsFilePrintf(fp, "*End%s", lf);
789 }
790
791 cupsFilePrintf(fp, "*CloseUI: *PageSize%s", lf);
792
793 // PageRegion option...
794 cupsFilePrintf(fp, "*OpenUI *PageRegion/Media Size: PickOne%s", lf);
795 cupsFilePrintf(fp, "*OrderDependency: 10 AnySetup *PageRegion%s", lf);
796 cupsFilePrintf(fp, "*DefaultPageRegion: %s%s",
797 default_size ? default_size->value : "Letter", lf);
798
799 for (m = (ppdcMediaSize *)sizes->first();
800 m;
801 m = (ppdcMediaSize *)sizes->next())
802 if (m->region_code->value)
803 {
804 cupsFilePrintf(fp, "*PageRegion %s/%s: \"%s\"%s",
805 m->name->value, catalog->find_message(m->text->value),
806 m->region_code->value, lf);
807
808 if (strchr(m->region_code->value, '\n') ||
809 strchr(m->region_code->value, '\r'))
810 cupsFilePrintf(fp, "*End%s", lf);
811 }
812 else
813 cupsFilePrintf(fp,
814 "*PageRegion %s/%s: \"<</PageSize[%.0f %.0f]"
815 "/ImagingBBox null>>setpagedevice\"%s",
816 m->name->value, catalog->find_message(m->text->value),
817 m->width, m->length, lf);
818
819 if ((a = find_attr("?PageRegion", NULL)) != NULL)
820 {
821 cupsFilePrintf(fp, "*?PageRegion: \"%s\"%s", a->value->value, lf);
822
823 if (strchr(a->value->value, '\n') ||
824 strchr(a->value->value, '\r'))
825 cupsFilePrintf(fp, "*End%s", lf);
826 }
827
828 cupsFilePrintf(fp, "*CloseUI: *PageRegion%s", lf);
829
830 // ImageableArea info...
831 cupsFilePrintf(fp, "*DefaultImageableArea: %s%s",
832 default_size ? default_size->value : "Letter", lf);
833
834 for (m = (ppdcMediaSize *)sizes->first();
835 m;
836 m = (ppdcMediaSize *)sizes->next())
837 cupsFilePrintf(fp, "*ImageableArea %s/%s: \"%.2f %.2f %.2f %.2f\"%s",
838 m->name->value, catalog->find_message(m->text->value),
839 m->left, m->bottom, m->width - m->right, m->length - m->top,
840 lf);
841
842 if ((a = find_attr("?ImageableArea", NULL)) != NULL)
843 {
844 cupsFilePrintf(fp, "*?ImageableArea: \"%s\"%s", a->value->value, lf);
845
846 if (strchr(a->value->value, '\n') ||
847 strchr(a->value->value, '\r'))
848 cupsFilePrintf(fp, "*End%s", lf);
849 }
850
851 // PaperDimension info...
852 cupsFilePrintf(fp, "*DefaultPaperDimension: %s%s",
853 default_size ? default_size->value : "Letter", lf);
854
855 for (m = (ppdcMediaSize *)sizes->first();
856 m;
857 m = (ppdcMediaSize *)sizes->next())
858 cupsFilePrintf(fp, "*PaperDimension %s/%s: \"%.2f %.2f\"%s",
859 m->name->value, catalog->find_message(m->text->value),
860 m->width, m->length, lf);
861
862 if ((a = find_attr("?PaperDimension", NULL)) != NULL)
863 {
864 cupsFilePrintf(fp, "*?PaperDimension: \"%s\"%s", a->value->value, lf);
865
866 if (strchr(a->value->value, '\n') ||
867 strchr(a->value->value, '\r'))
868 cupsFilePrintf(fp, "*End%s", lf);
869 }
870
871 // Custom size support...
872 if (variable_paper_size)
873 {
874 cupsFilePrintf(fp, "*MaxMediaWidth: \"%.2f\"%s", max_width, lf);
875 cupsFilePrintf(fp, "*MaxMediaHeight: \"%.2f\"%s", max_length, lf);
876 cupsFilePrintf(fp, "*HWMargins: %.2f %.2f %.2f %.2f\n",
877 left_margin, bottom_margin, right_margin, top_margin);
878
879 if (custom_size_code && custom_size_code->value)
880 {
881 cupsFilePrintf(fp, "*CustomPageSize True: \"%s\"%s",
882 custom_size_code->value, lf);
883
884 if (strchr(custom_size_code->value, '\n') ||
885 strchr(custom_size_code->value, '\r'))
886 cupsFilePrintf(fp, "*End%s", lf);
887 }
888 else
889 cupsFilePrintf(fp,
890 "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]"
891 "/ImagingBBox null>>setpagedevice\"%s", lf);
892
893 if ((a = find_attr("ParamCustomPageSize", "Width")) != NULL)
894 cupsFilePrintf(fp, "*ParamCustomPageSize Width: %s%s", a->value->value,
895 lf);
896 else
897 cupsFilePrintf(fp, "*ParamCustomPageSize Width: 1 points %.2f %.2f%s",
898 min_width, max_width, lf);
899
900 if ((a = find_attr("ParamCustomPageSize", "Height")) != NULL)
901 cupsFilePrintf(fp, "*ParamCustomPageSize Height: %s%s", a->value->value,
902 lf);
903 else
904 cupsFilePrintf(fp, "*ParamCustomPageSize Height: 2 points %.2f %.2f%s",
905 min_length, max_length, lf);
906
907 if ((a = find_attr("ParamCustomPageSize", "WidthOffset")) != NULL)
908 cupsFilePrintf(fp, "*ParamCustomPageSize WidthOffset: %s%s",
909 a->value->value, lf);
910 else
911 cupsFilePrintf(fp, "*ParamCustomPageSize WidthOffset: 3 points 0 0%s", lf);
912
913 if ((a = find_attr("ParamCustomPageSize", "HeightOffset")) != NULL)
914 cupsFilePrintf(fp, "*ParamCustomPageSize HeightOffset: %s%s",
915 a->value->value, lf);
916 else
917 cupsFilePrintf(fp, "*ParamCustomPageSize HeightOffset: 4 points 0 0%s", lf);
918
919 if ((a = find_attr("ParamCustomPageSize", "Orientation")) != NULL)
920 cupsFilePrintf(fp, "*ParamCustomPageSize Orientation: %s%s",
921 a->value->value, lf);
922 else
923 cupsFilePrintf(fp, "*ParamCustomPageSize Orientation: 5 int 0 0%s", lf);
924 }
925
926 if (type != PPDC_DRIVER_PS && !find_attr("RequiresPageRegion", NULL))
927 cupsFilePrintf(fp, "*RequiresPageRegion All: True%s", lf);
928
929 // All other options...
930 for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next())
931 {
932 if (!g->options->count)
933 continue;
934
935 if (strcasecmp(g->name->value, "General"))
936 cupsFilePrintf(fp, "*OpenGroup: %s/%s%s", g->name->value,
937 catalog->find_message(g->text->value), lf);
938
939 for (o = (ppdcOption *)g->options->first();
940 o;
941 o = (ppdcOption *)g->options->next())
942 {
943 if (!o->choices->count)
944 continue;
945
946 if (!o->text->value || !strcmp(o->name->value, o->text->value))
947 cupsFilePrintf(fp, "*OpenUI *%s: ", o->name->value);
948 else
949 cupsFilePrintf(fp, "*OpenUI *%s/%s: ", o->name->value,
950 catalog->find_message(o->text->value));
951
952 switch (o->type)
953 {
954 case PPDC_BOOLEAN :
955 cupsFilePrintf(fp, "Boolean%s", lf);
956 break;
957 default :
958 cupsFilePrintf(fp, "PickOne%s", lf);
959 break;
960 case PPDC_PICKMANY :
961 cupsFilePrintf(fp, "PickMany%s", lf);
962 break;
963 }
964
965 cupsFilePrintf(fp, "*OrderDependency: %.1f ", o->order);
966 switch (o->section)
967 {
968 default :
969 cupsFilePrintf(fp, "AnySetup");
970 break;
971 case PPDC_SECTION_DOCUMENT :
972 cupsFilePrintf(fp, "DocumentSetup");
973 break;
974 case PPDC_SECTION_EXIT :
975 cupsFilePrintf(fp, "ExitServer");
976 break;
977 case PPDC_SECTION_JCL :
978 cupsFilePrintf(fp, "JCLSetup");
979 break;
980 case PPDC_SECTION_PAGE :
981 cupsFilePrintf(fp, "PageSetup");
982 break;
983 case PPDC_SECTION_PROLOG :
984 cupsFilePrintf(fp, "Prolog");
985 break;
986 }
987
988 cupsFilePrintf(fp, " *%s%s", o->name->value, lf);
989
990 if (o->defchoice)
991 {
992 // Use the programmer-supplied default...
993 cupsFilePrintf(fp, "*Default%s: %s%s", o->name->value,
994 o->defchoice->value, lf);
995 }
996 else
997 {
998 // Make the first choice the default...
999 c = (ppdcChoice *)o->choices->first();
1000 cupsFilePrintf(fp, "*Default%s: %s%s", o->name->value, c->name->value,
1001 lf);
1002 }
1003
1004 for (c = (ppdcChoice *)o->choices->first();
1005 c;
1006 c = (ppdcChoice *)o->choices->next())
1007 {
1008 // Write this choice...
1009 if (!c->text->value || !strcmp(c->name->value, c->text->value))
1010 cupsFilePrintf(fp, "*%s %s: \"%s\"%s", o->name->value, c->name->value,
1011 c->code->value, lf);
1012 else
1013 cupsFilePrintf(fp, "*%s %s/%s: \"%s\"%s", o->name->value,
1014 c->name->value, catalog->find_message(c->text->value),
1015 c->code->value, lf);
1016
1017 // Multi-line commands need a *End line to terminate them.
1018 if (strchr(c->code->value, '\n') ||
1019 strchr(c->code->value, '\r'))
1020 cupsFilePrintf(fp, "*End%s", lf);
1021 }
1022
1023 snprintf(query, sizeof(query), "?%s", o->name->value);
1024
1025 if ((a = find_attr(query, NULL)) != NULL)
1026 {
1027 cupsFilePrintf(fp, "*%s: \"%s\"\n", query, a->value->value);
1028
1029 if (strchr(a->value->value, '\n') ||
1030 strchr(a->value->value, '\r'))
1031 cupsFilePrintf(fp, "*End%s", lf);
1032 }
1033
1034 cupsFilePrintf(fp, "*CloseUI: *%s%s", o->name->value, lf);
1035 }
1036
1037 if (strcasecmp(g->name->value, "General"))
1038 cupsFilePrintf(fp, "*CloseGroup: %s%s", g->name->value, lf);
1039 }
1040
1041 if (locales)
1042 {
1043 // Add localizations for additional languages...
1044 ppdcString *locale; // Locale name
1045 ppdcCatalog *locatalog; // Message catalog for locale
1046
1047
1048 // Write the translation strings for each language...
1049 for (locale = (ppdcString *)locales->first();
1050 locale;
1051 locale = (ppdcString *)locales->next())
1052 {
1053 // Skip (US) English...
1054 if (!strcmp(locale->value, "en") || !strcmp(locale->value, "en_US"))
1055 continue;
1056
1057 // Skip missing languages...
1058 if ((locatalog = src->find_po(locale->value)) == NULL)
1059 continue;
1060
1061 // Do the core stuff first...
1062 cupsFilePrintf(fp, "*%s.Translation Manufacturer/%s: \"\"%s",
1063 locale->value,
1064 locatalog->find_message(manufacturer->value), lf);
1065
1066 if ((a = find_attr("ModelName", NULL)) != NULL)
1067 cupsFilePrintf(fp, "*%s.Translation ModelName/%s: \"\"%s",
1068 locale->value,
1069 locatalog->find_message(a->value->value), lf);
1070 else if (strncasecmp(model_name->value, manufacturer->value,
1071 strlen(manufacturer->value)))
1072 cupsFilePrintf(fp, "*%s.Translation ModelName/%s %s: \"\"%s",
1073 locale->value,
1074 locatalog->find_message(manufacturer->value),
1075 locatalog->find_message(model_name->value), lf);
1076 else
1077 cupsFilePrintf(fp, "*%s.Translation ModelName/%s: \"\"%s",
1078 locale->value,
1079 locatalog->find_message(model_name->value), lf);
1080
1081 if ((a = find_attr("ShortNickName", NULL)) != NULL)
1082 cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s: \"\"%s",
1083 locale->value,
1084 locatalog->find_message(a->value->value), lf);
1085 else if (strncasecmp(model_name->value, manufacturer->value,
1086 strlen(manufacturer->value)))
1087 cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s %s: \"\"%s",
1088 locale->value,
1089 locatalog->find_message(manufacturer->value),
1090 locatalog->find_message(model_name->value), lf);
1091 else
1092 cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s: \"\"%s",
1093 locale->value,
1094 locatalog->find_message(model_name->value), lf);
1095
1096 if ((a = find_attr("NickName", NULL)) != NULL)
1097 cupsFilePrintf(fp, "*%s.Translation NickName/%s: \"\"%s",
1098 locale->value,
1099 locatalog->find_message(a->value->value), lf);
1100 else if (strncasecmp(model_name->value, manufacturer->value,
1101 strlen(manufacturer->value)))
1102 cupsFilePrintf(fp, "*%s.Translation NickName/%s %s, %s: \"\"%s",
1103 locale->value,
1104 locatalog->find_message(manufacturer->value),
1105 locatalog->find_message(model_name->value),
1106 version->value, lf);
1107 else
1108 cupsFilePrintf(fp, "*%s.Translation NickName/%s, %s: \"\"%s",
1109 locale->value,
1110 locatalog->find_message(model_name->value),
1111 version->value, lf);
1112
1113 // Then the page sizes...
1114 cupsFilePrintf(fp, "*%s.Translation PageSize/%s: \"\"%s", locale->value,
1115 locatalog->find_message("Media Size"), lf);
1116
1117 for (m = (ppdcMediaSize *)sizes->first();
1118 m;
1119 m = (ppdcMediaSize *)sizes->next())
1120 {
1121 cupsFilePrintf(fp, "*%s.PageSize %s/%s: \"\"%s", locale->value,
1122 m->name->value, locatalog->find_message(m->text->value),
1123 lf);
1124 }
1125
1126 // Next the groups and options...
1127 for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next())
1128 {
1129 if (!g->options->count)
1130 continue;
1131
1132 if (strcasecmp(g->name->value, "General"))
1133 cupsFilePrintf(fp, "*%s.Translation %s/%s: \"\"%s", locale->value,
1134 g->name->value,
1135 locatalog->find_message(g->text->value), lf);
1136
1137 for (o = (ppdcOption *)g->options->first();
1138 o;
1139 o = (ppdcOption *)g->options->next())
1140 {
1141 if (!o->choices->count)
1142 continue;
1143
1144 cupsFilePrintf(fp, "*%s.Translation %s/%s: \"\"%s", locale->value,
1145 o->name->value,
1146 locatalog->find_message(o->text->value ?
1147 o->text->value :
1148 o->name->value), lf);
1149
1150 for (c = (ppdcChoice *)o->choices->first();
1151 c;
1152 c = (ppdcChoice *)o->choices->next())
1153 {
1154 // Write this choice...
1155 cupsFilePrintf(fp, "*%s.%s %s/%s: \"\"%s", locale->value,
1156 o->name->value, c->name->value,
1157 locatalog->find_message(c->text->value ?
1158 c->text->value :
1159 c->name->value), lf);
1160 }
1161 }
1162 }
1163
1164 // Finally the localizable attributes...
1165 for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next())
1166 {
1167 if ((!a->text || !a->text->value || !a->text->value[0]) &&
1168 strncmp(a->name->value, "Custom", 6) &&
1169 strncmp(a->name->value, "ParamCustom", 11))
1170 continue;
1171
bdd6c45b
MS
1172 if (!a->localizable &&
1173 strcmp(a->name->value, "APCustomColorMatchingName") &&
ac884b6a
MS
1174 strcmp(a->name->value, "APPrinterPreset") &&
1175 strcmp(a->name->value, "cupsICCProfile") &&
1176 strcmp(a->name->value, "cupsIPPReason") &&
bdd6c45b 1177 strcmp(a->name->value, "cupsMarkerName") &&
ac884b6a
MS
1178 strncmp(a->name->value, "Custom", 6) &&
1179 strncmp(a->name->value, "ParamCustom", 11))
1180 continue;
1181
1182 cupsFilePrintf(fp, "*%s.%s %s/%s: \"%s\"%s", locale->value,
1183 a->name->value, a->selector->value,
1184 locatalog->find_message(a->text && a->text->value ?
1185 a->text->value : a->name->value),
bdd6c45b
MS
1186 ((a->localizable && a->value->value[0]) ||
1187 !strcmp(a->name->value, "cupsIPPReason")) ?
ac884b6a
MS
1188 locatalog->find_message(a->value->value) : "",
1189 lf);
1190 }
1191 }
1192 }
1193
1194 if (default_font && default_font->value)
1195 cupsFilePrintf(fp, "*DefaultFont: %s%s", default_font->value, lf);
1196 else
1197 cupsFilePrintf(fp, "*DefaultFont: Courier%s", lf);
1198
1199 for (fn = (ppdcFont *)fonts->first(); fn; fn = (ppdcFont *)fonts->next())
1200 if (!strcmp(fn->name->value, "*"))
1201 {
1202 for (bfn = (ppdcFont *)src->base_fonts->first();
1203 bfn;
1204 bfn = (ppdcFont *)src->base_fonts->next())
1205 cupsFilePrintf(fp, "*Font %s: %s \"%s\" %s %s%s",
1206 bfn->name->value, bfn->encoding->value,
1207 bfn->version->value, bfn->charset->value,
1208 bfn->status == PPDC_FONT_ROM ? "ROM" : "Disk", lf);
1209 }
1210 else
1211 cupsFilePrintf(fp, "*Font %s: %s \"%s\" %s %s%s",
1212 fn->name->value, fn->encoding->value, fn->version->value,
1213 fn->charset->value,
1214 fn->status == PPDC_FONT_ROM ? "ROM" : "Disk", lf);
1215
1216 cupsFilePrintf(fp, "*%% End of %s, %05d bytes.%s", pc_file_name->value,
1217 (int)(cupsFileTell(fp) + 25 + strlen(pc_file_name->value)),
1218 lf);
1219
1220 if (delete_cat)
1221 delete catalog;
1222
1223 return (0);
1224}
1225
1226
1227//
1228// End of "$Id$".
1229//