]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-driver.cxx
4 // PPD file compiler definitions for the CUPS PPD Compiler.
6 // Copyright 2007-2008 by Apple Inc.
7 // Copyright 2002-2006 by Easy Software Products.
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/".
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.
23 // ppdcDriver::set_file_name() - Set the full filename.
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...
32 // Include necessary headers...
36 #include <cups/cups.h>
40 // 'ppdcDriver::ppdcDriver()' - Create a new printer driver.
43 ppdcDriver::ppdcDriver(ppdcDriver
*d
) // I - Printer driver template
45 ppdcGroup
*g
; // Current group
50 // Bump the use count of any strings we inherit...
52 d
->manufacturer
->get();
56 d
->default_font
->get();
58 d
->default_size
->get();
59 if (d
->custom_size_code
)
60 d
->custom_size_code
->get();
62 // Copy all of the data from the driver template...
63 copyright
= new ppdcArray(d
->copyright
);
64 manufacturer
= d
->manufacturer
;
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
;
93 // Then copy the groups manually, since we want separate copies
94 // of the groups and options...
95 groups
= new ppdcArray();
97 for (g
= (ppdcGroup
*)d
->groups
->first(); g
; g
= (ppdcGroup
*)d
->groups
->next())
98 groups
->add(new ppdcGroup(g
));
102 // Zero all of the data in the driver...
103 copyright
= new ppdcArray();
109 type
= PPDC_DRIVER_CUSTOM
;
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();
123 variable_paper_size
= 0;
124 custom_size_code
= 0;
138 // 'ppdcDriver::~ppdcDriver()' - Destroy a printer driver.
141 ppdcDriver::~ppdcDriver()
146 manufacturer
->release();
148 model_name
->release();
150 file_name
->release();
152 pc_file_name
->release();
156 default_font
->release();
158 default_size
->release();
159 if (custom_size_code
)
160 custom_size_code
->release();
173 // 'ppdcDriver::find_attr()' - Find an attribute.
176 ppdcAttr
* // O - Attribute or NULL
177 ppdcDriver::find_attr(const char *k
, // I - Keyword string
178 const char *s
) // I - Spec string
180 ppdcAttr
*a
; // Current attribute
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
))))
194 // 'ppdcDriver::find_group()' - Find a group.
197 ppdcGroup
* // O - Matching group or NULL
198 ppdcDriver::find_group(const char *n
) // I - Group name
200 ppdcGroup
*g
; // Current group
203 for (g
= (ppdcGroup
*)groups
->first(); g
; g
= (ppdcGroup
*)groups
->next())
204 if (!strcasecmp(n
, g
->name
->value
))
212 // 'ppdcDriver::find_option()' - Find an option.
215 ppdcOption
* // O - Matching option or NULL
216 ppdcDriver::find_option(const char *n
) // I - Option name
218 ppdcGroup
*g
; // Current group
219 ppdcOption
*o
; // Current option
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
))
232 // 'ppdcDriver::set_custom_size_code()' - Set the custom page size code.
236 ppdcDriver::set_custom_size_code(
237 const char *c
) // I - CustomPageSize code
239 if (custom_size_code
)
240 custom_size_code
->release();
242 custom_size_code
= new ppdcString(c
);
247 // 'ppdcDriver::set_default_font()' - Set the default font name.
251 ppdcDriver::set_default_font(
252 ppdcFont
*f
) // I - Font
255 default_font
->release();
260 default_font
= f
->name
;
268 // 'ppdcDriver::set_default_size()' - Set the default size name.
272 ppdcDriver::set_default_size(
273 ppdcMediaSize
*m
) // I - Media size
276 default_size
->release();
281 default_size
= m
->name
;
289 // 'ppdcDriver::set_file_name()' - Set the full filename.
293 ppdcDriver::set_file_name(const char *f
)// I - Filename
296 file_name
->release();
298 file_name
= new ppdcString(f
);
303 // 'ppdcDriver::set_manufacturer()' - Set the manufacturer name.
307 ppdcDriver::set_manufacturer(
308 const char *m
) // I - Model name
311 manufacturer
->release();
313 manufacturer
= new ppdcString(m
);
318 // 'ppdcDriver::set_model_name()' - Set the model name.
322 ppdcDriver::set_model_name(
323 const char *m
) // I - Model name
326 model_name
->release();
328 model_name
= new ppdcString(m
);
333 // 'ppdcDriver::set_pc_file_name()' - Set the PC filename.
337 ppdcDriver::set_pc_file_name(
338 const char *f
) // I - Filename
341 pc_file_name
->release();
343 pc_file_name
= new ppdcString(f
);
348 // 'ppdcDriver::set_version()' - Set the version string.
352 ppdcDriver::set_version(const char *v
) // I - Version
357 version
= new ppdcString(v
);
362 // 'ppdcDriver::write_ppd_file()' - Write a PPD file...
365 int // O - 0 on success, -1 on failure
366 ppdcDriver::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
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
389 // If we don't have a message catalog, use an empty (English) one...
392 catalog
= new ppdcCatalog("en");
398 // Figure out the end-of-line string...
399 if (le
== PPDC_LFONLY
)
401 else if (le
== PPDC_CRONLY
)
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
);
410 "*%% Created by the CUPS PPD Compiler " CUPS_SVERSION
".%s",
412 for (s
= (ppdcString
*)copyright
->first();
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
);
419 a
= find_attr("LanguageVersion", NULL
);
420 cupsFilePrintf(fp
, "*LanguageVersion: %s%s",
421 catalog
->find_message(a
? a
->value
->value
: "English"), lf
);
423 a
= find_attr("LanguageEncoding", NULL
);
424 cupsFilePrintf(fp
, "*LanguageEncoding: %s%s",
425 catalog
->find_message(a
? a
->value
->value
: "ISOLatin1"), lf
);
427 cupsFilePrintf(fp
, "*PCFileName: \"%s\"%s", pc_file_name
->value
, lf
);
429 for (a
= (ppdcAttr
*)attrs
->first(); a
; a
= (ppdcAttr
*)attrs
->next())
430 if (!strcmp(a
->name
->value
, "Product"))
435 for (; a
; a
= (ppdcAttr
*)attrs
->next())
436 if (!strcmp(a
->name
->value
, "Product"))
437 cupsFilePrintf(fp
, "*Product: \"%s\"%s", a
->value
->value
, lf
);
440 cupsFilePrintf(fp
, "*Product: \"(%s)\"%s", model_name
->value
, lf
);
442 cupsFilePrintf(fp
, "*Manufacturer: \"%s\"%s",
443 catalog
->find_message(manufacturer
->value
), lf
);
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
);
454 cupsFilePrintf(fp
, "*ModelName: \"%s\"%s",
455 catalog
->find_message(model_name
->value
), lf
);
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
);
466 cupsFilePrintf(fp
, "*ShortNickName: \"%s\"%s",
467 catalog
->find_message(model_name
->value
), lf
);
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
,
479 cupsFilePrintf(fp
, "*NickName: \"%s, %s\"%s",
480 catalog
->find_message(model_name
->value
), version
->value
,
483 for (a
= (ppdcAttr
*)attrs
->first(); a
; a
= (ppdcAttr
*)attrs
->next())
484 if (!strcmp(a
->name
->value
, "PSVersion"))
489 for (; a
; a
= (ppdcAttr
*)attrs
->next())
490 if (!strcmp(a
->name
->value
, "PSVersion"))
491 cupsFilePrintf(fp
, "*PSVersion: \"%s\"%s", a
->value
->value
, lf
);
494 cupsFilePrintf(fp
, "*PSVersion: \"(3010.000) 0\"%s", lf
);
496 if ((a
= find_attr("LanguageLevel", NULL
)) != NULL
)
497 cupsFilePrintf(fp
, "*LanguageLevel: \"%s\"%s", a
->value
->value
, lf
);
499 cupsFilePrintf(fp
, "*LanguageLevel: \"3\"%s", lf
);
501 cupsFilePrintf(fp
, "*ColorDevice: %s%s", color_device
? "True" : "False", lf
);
503 if ((a
= find_attr("DefaultColorSpace", NULL
)) != NULL
)
504 cupsFilePrintf(fp
, "*DefaultColorSpace: %s%s", a
->value
->value
, lf
);
506 cupsFilePrintf(fp
, "*DefaultColorSpace: %s%s",
507 color_device
? "RGB" : "Gray", lf
);
509 if ((a
= find_attr("FileSystem", NULL
)) != NULL
)
510 cupsFilePrintf(fp
, "*FileSystem: %s%s", a
->value
->value
, lf
);
512 cupsFilePrintf(fp
, "*FileSystem: False%s", lf
);
514 cupsFilePrintf(fp
, "*Throughput: \"%d\"%s", throughput
, lf
);
516 if ((a
= find_attr("LandscapeOrientation", NULL
)) != NULL
)
517 cupsFilePrintf(fp
, "*LandscapeOrientation: %s%s", a
->value
->value
, lf
);
519 cupsFilePrintf(fp
, "*LandscapeOrientation: Plus90%s", lf
);
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
);
528 // Write driver-defined attributes...
529 cupsFilePrintf(fp
, "*%% Driver-defined attributes...%s", lf
);
530 for (a
= (ppdcAttr
*)attrs
->first(); a
; a
= (ppdcAttr
*)attrs
->next())
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") ||
544 !strcmp(a
->name
->value
, "cupsVersion") ||
545 a
->name
->value
[0] == '?')
548 if (!a
->selector
->value
|| !a
->selector
->value
[0])
549 cupsFilePrintf(fp
, "*%s", a
->name
->value
);
550 else if (!a
->text
->value
|| !a
->text
->value
[0])
551 cupsFilePrintf(fp
, "*%s %s", a
->name
->value
, a
->selector
->value
);
553 cupsFilePrintf(fp
, "*%s %s/%s", a
->name
->value
, a
->selector
->value
,
556 if (strcmp(a
->value
->value
, "False") &&
557 strcmp(a
->value
->value
, "True") &&
558 strcmp(a
->name
->value
, "1284Modes") &&
559 strcmp(a
->name
->value
, "InkName") &&
560 strcmp(a
->name
->value
, "PageStackOrder") &&
561 strncmp(a
->name
->value
, "ParamCustom", 11) &&
562 strcmp(a
->name
->value
, "Protocols") &&
563 strcmp(a
->name
->value
, "ReferencePunch") &&
564 strncmp(a
->name
->value
, "Default", 7))
566 cupsFilePrintf(fp
, ": \"%s\"%s", a
->value
->value
, lf
);
568 if (strchr(a
->value
->value
, '\n'))
569 cupsFilePrintf(fp
, "*End%s", lf
);
572 cupsFilePrintf(fp
, ": %s%s", a
->value
->value
, lf
);
576 if (type
!= PPDC_DRIVER_PS
|| filters
->count
)
578 if ((a
= find_attr("cupsVersion", NULL
)) != NULL
)
579 cupsFilePrintf(fp
, "*cupsVersion: %s%s", a
->value
->value
, lf
);
581 cupsFilePrintf(fp
, "*cupsVersion: %d.%d%s", CUPS_VERSION_MAJOR
,
582 CUPS_VERSION_MINOR
, lf
);
583 cupsFilePrintf(fp
, "*cupsModelNumber: %d%s", model_number
, lf
);
584 cupsFilePrintf(fp
, "*cupsManualCopies: %s%s",
585 manual_copies
? "True" : "False", lf
);
589 for (f
= (ppdcFilter
*)filters
->first();
591 f
= (ppdcFilter
*)filters
->next())
592 cupsFilePrintf(fp
, "*cupsFilter: \"%s %d %s\"%s", f
->mime_type
->value
,
593 f
->cost
, f
->program
->value
, lf
);
599 case PPDC_DRIVER_LABEL
:
600 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-raster 50 "
601 "rastertolabel\"%s", lf
);
604 case PPDC_DRIVER_EPSON
:
605 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-raster 50 "
606 "rastertoepson\"%s", lf
);
609 case PPDC_DRIVER_ESCP
:
610 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-command 50 "
611 "commandtoescpx\"%s", lf
);
612 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-raster 50 "
613 "rastertoescpx\"%s", lf
);
616 case PPDC_DRIVER_HP
:
617 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-raster 50 "
618 "rastertohp\"%s", lf
);
621 case PPDC_DRIVER_PCL
:
622 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-command 50 "
623 "commandtopclx\"%s", lf
);
624 cupsFilePrintf(fp
, "*cupsFilter: \"application/vnd.cups-raster 50 "
625 "rastertopclx\"%s", lf
);
633 for (p
= (ppdcProfile
*)profiles
->first();
635 p
= (ppdcProfile
*)profiles
->next())
637 "*cupsColorProfile %s/%s: \"%.3f %.3f %.3f %.3f %.3f %.3f "
638 "%.3f %.3f %.3f %.3f %.3f\"%s",
639 p
->resolution
->value
, p
->media_type
->value
,
640 p
->density
, p
->gamma
,
641 p
->profile
[0], p
->profile
[1],
642 p
->profile
[2], p
->profile
[3],
643 p
->profile
[4], p
->profile
[5],
644 p
->profile
[6], p
->profile
[7],
650 // Add localizations for additional languages...
651 ppdcString
*locale
; // Locale name
652 ppdcCatalog
*locatalog
; // Message catalog for locale
655 // Write the list of languages...
656 cupsFilePrintf(fp
, "*cupsLanguages: \"en");
658 for (locale
= (ppdcString
*)locales
->first();
660 locale
= (ppdcString
*)locales
->next())
662 // Skip (US) English...
663 if (!strcmp(locale
->value
, "en") || !strcmp(locale
->value
, "en_US"))
666 // See if we have a po file for this language...
667 if (!src
->find_po(locale
->value
))
669 // No, see if we can use the base file?
670 locatalog
= new ppdcCatalog(locale
->value
);
672 if (locatalog
->messages
->count
== 0)
674 // No, skip this one...
675 fprintf(stderr
, "ppdc: No message catalog provided for locale %s!\n",
680 // Add the base file to the list...
681 src
->po_files
->add(locatalog
);
684 cupsFilePrintf(fp
, " %s", locale
->value
);
687 cupsFilePrintf(fp
, "\"%s", lf
);
690 for (cn
= (ppdcConstraint
*)constraints
->first();
692 cn
= (ppdcConstraint
*)constraints
->next())
694 // First constrain 1 against 2...
695 if (!strncmp(cn
->option1
->value
, "*Custom", 7) ||
696 !strncmp(cn
->option2
->value
, "*Custom", 7))
697 cupsFilePrintf(fp
, "*NonUIConstraints: ");
699 cupsFilePrintf(fp
, "*UIConstraints: ");
701 if (cn
->option1
->value
[0] != '*')
702 cupsFilePutChar(fp
, '*');
704 cupsFilePrintf(fp
, cn
->option1
->value
);
706 if (cn
->choice1
->value
)
707 cupsFilePrintf(fp
, " %s", cn
->choice1
->value
);
709 cupsFilePutChar(fp
, ' ');
711 if (cn
->option2
->value
[0] != '*')
712 cupsFilePutChar(fp
, '*');
714 cupsFilePrintf(fp
, cn
->option2
->value
);
716 if (cn
->choice2
->value
)
717 cupsFilePrintf(fp
, " %s", cn
->choice2
->value
);
719 cupsFilePrintf(fp
, "%s", lf
);
721 // Then constrain 2 against 1...
722 if (!strncmp(cn
->option1
->value
, "*Custom", 7) ||
723 !strncmp(cn
->option2
->value
, "*Custom", 7))
724 cupsFilePrintf(fp
, "*NonUIConstraints: ");
726 cupsFilePrintf(fp
, "*UIConstraints: ");
728 if (cn
->option2
->value
[0] != '*')
729 cupsFilePutChar(fp
, '*');
731 cupsFilePrintf(fp
, cn
->option2
->value
);
733 if (cn
->choice2
->value
)
734 cupsFilePrintf(fp
, " %s", cn
->choice2
->value
);
736 cupsFilePutChar(fp
, ' ');
738 if (cn
->option1
->value
[0] != '*')
739 cupsFilePutChar(fp
, '*');
741 cupsFilePrintf(fp
, cn
->option1
->value
);
743 if (cn
->choice1
->value
)
744 cupsFilePrintf(fp
, " %s", cn
->choice1
->value
);
746 cupsFilePuts(fp
, lf
);
749 // PageSize option...
750 cupsFilePrintf(fp
, "*OpenUI *PageSize/Media Size: PickOne%s", lf
);
751 cupsFilePrintf(fp
, "*OrderDependency: 10 AnySetup *PageSize%s", lf
);
752 cupsFilePrintf(fp
, "*DefaultPageSize: %s%s",
753 default_size
? default_size
->value
: "Letter", lf
);
755 for (m
= (ppdcMediaSize
*)sizes
->first();
757 m
= (ppdcMediaSize
*)sizes
->next())
758 if (m
->size_code
->value
)
760 cupsFilePrintf(fp
, "*PageSize %s/%s: \"%s\"%s",
761 m
->name
->value
, catalog
->find_message(m
->text
->value
),
762 m
->size_code
->value
, lf
);
764 if (strchr(m
->size_code
->value
, '\n') ||
765 strchr(m
->size_code
->value
, '\r'))
766 cupsFilePrintf(fp
, "*End%s", lf
);
770 "*PageSize %s/%s: \"<</PageSize[%.0f %.0f]"
771 "/ImagingBBox null>>setpagedevice\"%s",
772 m
->name
->value
, catalog
->find_message(m
->text
->value
),
773 m
->width
, m
->length
, lf
);
775 if ((a
= find_attr("?PageSize", NULL
)) != NULL
)
777 cupsFilePrintf(fp
, "*?PageSize: \"%s\"%s", a
->value
->value
, lf
);
779 if (strchr(a
->value
->value
, '\n') ||
780 strchr(a
->value
->value
, '\r'))
781 cupsFilePrintf(fp
, "*End%s", lf
);
784 cupsFilePrintf(fp
, "*CloseUI: *PageSize%s", lf
);
786 // PageRegion option...
787 cupsFilePrintf(fp
, "*OpenUI *PageRegion/Media Size: PickOne%s", lf
);
788 cupsFilePrintf(fp
, "*OrderDependency: 10 AnySetup *PageRegion%s", lf
);
789 cupsFilePrintf(fp
, "*DefaultPageRegion: %s%s",
790 default_size
? default_size
->value
: "Letter", lf
);
792 for (m
= (ppdcMediaSize
*)sizes
->first();
794 m
= (ppdcMediaSize
*)sizes
->next())
795 if (m
->region_code
->value
)
797 cupsFilePrintf(fp
, "*PageRegion %s/%s: \"%s\"%s",
798 m
->name
->value
, catalog
->find_message(m
->text
->value
),
799 m
->region_code
->value
, lf
);
801 if (strchr(m
->region_code
->value
, '\n') ||
802 strchr(m
->region_code
->value
, '\r'))
803 cupsFilePrintf(fp
, "*End%s", lf
);
807 "*PageRegion %s/%s: \"<</PageSize[%.0f %.0f]"
808 "/ImagingBBox null>>setpagedevice\"%s",
809 m
->name
->value
, catalog
->find_message(m
->text
->value
),
810 m
->width
, m
->length
, lf
);
812 if ((a
= find_attr("?PageRegion", NULL
)) != NULL
)
814 cupsFilePrintf(fp
, "*?PageRegion: \"%s\"%s", a
->value
->value
, lf
);
816 if (strchr(a
->value
->value
, '\n') ||
817 strchr(a
->value
->value
, '\r'))
818 cupsFilePrintf(fp
, "*End%s", lf
);
821 cupsFilePrintf(fp
, "*CloseUI: *PageRegion%s", lf
);
823 // ImageableArea info...
824 cupsFilePrintf(fp
, "*DefaultImageableArea: %s%s",
825 default_size
? default_size
->value
: "Letter", lf
);
827 for (m
= (ppdcMediaSize
*)sizes
->first();
829 m
= (ppdcMediaSize
*)sizes
->next())
830 cupsFilePrintf(fp
, "*ImageableArea %s/%s: \"%.2f %.2f %.2f %.2f\"%s",
831 m
->name
->value
, catalog
->find_message(m
->text
->value
),
832 m
->left
, m
->bottom
, m
->width
- m
->right
, m
->length
- m
->top
,
835 if ((a
= find_attr("?ImageableArea", NULL
)) != NULL
)
837 cupsFilePrintf(fp
, "*?ImageableArea: \"%s\"%s", a
->value
->value
, lf
);
839 if (strchr(a
->value
->value
, '\n') ||
840 strchr(a
->value
->value
, '\r'))
841 cupsFilePrintf(fp
, "*End%s", lf
);
844 // PaperDimension info...
845 cupsFilePrintf(fp
, "*DefaultPaperDimension: %s%s",
846 default_size
? default_size
->value
: "Letter", lf
);
848 for (m
= (ppdcMediaSize
*)sizes
->first();
850 m
= (ppdcMediaSize
*)sizes
->next())
851 cupsFilePrintf(fp
, "*PaperDimension %s/%s: \"%.2f %.2f\"%s",
852 m
->name
->value
, catalog
->find_message(m
->text
->value
),
853 m
->width
, m
->length
, lf
);
855 if ((a
= find_attr("?PaperDimension", NULL
)) != NULL
)
857 cupsFilePrintf(fp
, "*?PaperDimension: \"%s\"%s", a
->value
->value
, lf
);
859 if (strchr(a
->value
->value
, '\n') ||
860 strchr(a
->value
->value
, '\r'))
861 cupsFilePrintf(fp
, "*End%s", lf
);
864 // Custom size support...
865 if (variable_paper_size
)
867 cupsFilePrintf(fp
, "*MaxMediaWidth: \"%.2f\"%s", max_width
, lf
);
868 cupsFilePrintf(fp
, "*MaxMediaHeight: \"%.2f\"%s", max_length
, lf
);
869 cupsFilePrintf(fp
, "*HWMargins: %.2f %.2f %.2f %.2f\n",
870 left_margin
, bottom_margin
, right_margin
, top_margin
);
872 if (custom_size_code
&& custom_size_code
->value
)
874 cupsFilePrintf(fp
, "*CustomPageSize True: \"%s\"%s",
875 custom_size_code
->value
, lf
);
877 if (strchr(custom_size_code
->value
, '\n') ||
878 strchr(custom_size_code
->value
, '\r'))
879 cupsFilePrintf(fp
, "*End%s", lf
);
883 "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]"
884 "/ImagingBBox null>>setpagedevice\"%s", lf
);
886 if ((a
= find_attr("ParamCustomPageSize", "Width")) != NULL
)
887 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: %s%s", a
->value
->value
,
890 cupsFilePrintf(fp
, "*ParamCustomPageSize Width: 1 points %.2f %.2f%s",
891 min_width
, max_width
, lf
);
893 if ((a
= find_attr("ParamCustomPageSize", "Height")) != NULL
)
894 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: %s%s", a
->value
->value
,
897 cupsFilePrintf(fp
, "*ParamCustomPageSize Height: 2 points %.2f %.2f%s",
898 min_length
, max_length
, lf
);
900 if ((a
= find_attr("ParamCustomPageSize", "WidthOffset")) != NULL
)
901 cupsFilePrintf(fp
, "*ParamCustomPageSize WidthOffset: %s%s",
902 a
->value
->value
, lf
);
904 cupsFilePrintf(fp
, "*ParamCustomPageSize WidthOffset: 3 points 0 0%s", lf
);
906 if ((a
= find_attr("ParamCustomPageSize", "HeightOffset")) != NULL
)
907 cupsFilePrintf(fp
, "*ParamCustomPageSize HeightOffset: %s%s",
908 a
->value
->value
, lf
);
910 cupsFilePrintf(fp
, "*ParamCustomPageSize HeightOffset: 4 points 0 0%s", lf
);
912 if ((a
= find_attr("ParamCustomPageSize", "Orientation")) != NULL
)
913 cupsFilePrintf(fp
, "*ParamCustomPageSize Orientation: %s%s",
914 a
->value
->value
, lf
);
916 cupsFilePrintf(fp
, "*ParamCustomPageSize Orientation: 5 int 0 0%s", lf
);
919 if (type
!= PPDC_DRIVER_PS
&& !find_attr("RequiresPageRegion", NULL
))
920 cupsFilePrintf(fp
, "*RequiresPageRegion All: True%s", lf
);
922 // All other options...
923 for (g
= (ppdcGroup
*)groups
->first(); g
; g
= (ppdcGroup
*)groups
->next())
925 if (!g
->options
->count
)
928 if (strcasecmp(g
->name
->value
, "General"))
929 cupsFilePrintf(fp
, "*OpenGroup: %s/%s%s", g
->name
->value
,
930 catalog
->find_message(g
->text
->value
), lf
);
932 for (o
= (ppdcOption
*)g
->options
->first();
934 o
= (ppdcOption
*)g
->options
->next())
936 if (!o
->choices
->count
)
939 if (!o
->text
->value
|| !strcmp(o
->name
->value
, o
->text
->value
))
940 cupsFilePrintf(fp
, "*OpenUI *%s: ", o
->name
->value
);
942 cupsFilePrintf(fp
, "*OpenUI *%s/%s: ", o
->name
->value
,
943 catalog
->find_message(o
->text
->value
));
948 cupsFilePrintf(fp
, "Boolean%s", lf
);
951 cupsFilePrintf(fp
, "PickOne%s", lf
);
954 cupsFilePrintf(fp
, "PickMany%s", lf
);
958 cupsFilePrintf(fp
, "*OrderDependency: %.1f ", o
->order
);
962 cupsFilePrintf(fp
, "AnySetup");
964 case PPDC_SECTION_DOCUMENT
:
965 cupsFilePrintf(fp
, "DocumentSetup");
967 case PPDC_SECTION_EXIT
:
968 cupsFilePrintf(fp
, "ExitServer");
970 case PPDC_SECTION_JCL
:
971 cupsFilePrintf(fp
, "JCLSetup");
973 case PPDC_SECTION_PAGE
:
974 cupsFilePrintf(fp
, "PageSetup");
976 case PPDC_SECTION_PROLOG
:
977 cupsFilePrintf(fp
, "Prolog");
981 cupsFilePrintf(fp
, " *%s%s", o
->name
->value
, lf
);
985 // Use the programmer-supplied default...
986 cupsFilePrintf(fp
, "*Default%s: %s%s", o
->name
->value
,
987 o
->defchoice
->value
, lf
);
991 // Make the first choice the default...
992 c
= (ppdcChoice
*)o
->choices
->first();
993 cupsFilePrintf(fp
, "*Default%s: %s%s", o
->name
->value
, c
->name
->value
,
997 for (c
= (ppdcChoice
*)o
->choices
->first();
999 c
= (ppdcChoice
*)o
->choices
->next())
1001 // Write this choice...
1002 if (!c
->text
->value
|| !strcmp(c
->name
->value
, c
->text
->value
))
1003 cupsFilePrintf(fp
, "*%s %s: \"%s\"%s", o
->name
->value
, c
->name
->value
,
1004 c
->code
->value
, lf
);
1006 cupsFilePrintf(fp
, "*%s %s/%s: \"%s\"%s", o
->name
->value
,
1007 c
->name
->value
, catalog
->find_message(c
->text
->value
),
1008 c
->code
->value
, lf
);
1010 // Multi-line commands need a *End line to terminate them.
1011 if (strchr(c
->code
->value
, '\n') ||
1012 strchr(c
->code
->value
, '\r'))
1013 cupsFilePrintf(fp
, "*End%s", lf
);
1016 snprintf(query
, sizeof(query
), "?%s", o
->name
->value
);
1018 if ((a
= find_attr(query
, NULL
)) != NULL
)
1020 cupsFilePrintf(fp
, "*%s: \"%s\"\n", query
, a
->value
->value
);
1022 if (strchr(a
->value
->value
, '\n') ||
1023 strchr(a
->value
->value
, '\r'))
1024 cupsFilePrintf(fp
, "*End%s", lf
);
1027 cupsFilePrintf(fp
, "*CloseUI: *%s%s", o
->name
->value
, lf
);
1030 if (strcasecmp(g
->name
->value
, "General"))
1031 cupsFilePrintf(fp
, "*CloseGroup: %s%s", g
->name
->value
, lf
);
1036 // Add localizations for additional languages...
1037 ppdcString
*locale
; // Locale name
1038 ppdcCatalog
*locatalog
; // Message catalog for locale
1041 // Write the translation strings for each language...
1042 for (locale
= (ppdcString
*)locales
->first();
1044 locale
= (ppdcString
*)locales
->next())
1046 // Skip (US) English...
1047 if (!strcmp(locale
->value
, "en") || !strcmp(locale
->value
, "en_US"))
1050 // Skip missing languages...
1051 if ((locatalog
= src
->find_po(locale
->value
)) == NULL
)
1054 // Do the core stuff first...
1055 cupsFilePrintf(fp
, "*%s.Translation Manufacturer/%s: \"\"%s",
1057 locatalog
->find_message(manufacturer
->value
), lf
);
1059 if ((a
= find_attr("ModelName", NULL
)) != NULL
)
1060 cupsFilePrintf(fp
, "*%s.Translation ModelName/%s: \"\"%s",
1062 locatalog
->find_message(a
->value
->value
), lf
);
1063 else if (strncasecmp(model_name
->value
, manufacturer
->value
,
1064 strlen(manufacturer
->value
)))
1065 cupsFilePrintf(fp
, "*%s.Translation ModelName/%s %s: \"\"%s",
1067 locatalog
->find_message(manufacturer
->value
),
1068 locatalog
->find_message(model_name
->value
), lf
);
1070 cupsFilePrintf(fp
, "*%s.Translation ModelName/%s: \"\"%s",
1072 locatalog
->find_message(model_name
->value
), lf
);
1074 if ((a
= find_attr("ShortNickName", NULL
)) != NULL
)
1075 cupsFilePrintf(fp
, "*%s.Translation ShortNickName/%s: \"\"%s",
1077 locatalog
->find_message(a
->value
->value
), lf
);
1078 else if (strncasecmp(model_name
->value
, manufacturer
->value
,
1079 strlen(manufacturer
->value
)))
1080 cupsFilePrintf(fp
, "*%s.Translation ShortNickName/%s %s: \"\"%s",
1082 locatalog
->find_message(manufacturer
->value
),
1083 locatalog
->find_message(model_name
->value
), lf
);
1085 cupsFilePrintf(fp
, "*%s.Translation ShortNickName/%s: \"\"%s",
1087 locatalog
->find_message(model_name
->value
), lf
);
1089 if ((a
= find_attr("NickName", NULL
)) != NULL
)
1090 cupsFilePrintf(fp
, "*%s.Translation NickName/%s: \"\"%s",
1092 locatalog
->find_message(a
->value
->value
), lf
);
1093 else if (strncasecmp(model_name
->value
, manufacturer
->value
,
1094 strlen(manufacturer
->value
)))
1095 cupsFilePrintf(fp
, "*%s.Translation NickName/%s %s, %s: \"\"%s",
1097 locatalog
->find_message(manufacturer
->value
),
1098 locatalog
->find_message(model_name
->value
),
1099 version
->value
, lf
);
1101 cupsFilePrintf(fp
, "*%s.Translation NickName/%s, %s: \"\"%s",
1103 locatalog
->find_message(model_name
->value
),
1104 version
->value
, lf
);
1106 // Then the page sizes...
1107 cupsFilePrintf(fp
, "*%s.Translation PageSize/%s: \"\"%s", locale
->value
,
1108 locatalog
->find_message("Media Size"), lf
);
1110 for (m
= (ppdcMediaSize
*)sizes
->first();
1112 m
= (ppdcMediaSize
*)sizes
->next())
1114 cupsFilePrintf(fp
, "*%s.PageSize %s/%s: \"\"%s", locale
->value
,
1115 m
->name
->value
, locatalog
->find_message(m
->text
->value
),
1119 // Next the groups and options...
1120 for (g
= (ppdcGroup
*)groups
->first(); g
; g
= (ppdcGroup
*)groups
->next())
1122 if (!g
->options
->count
)
1125 if (strcasecmp(g
->name
->value
, "General"))
1126 cupsFilePrintf(fp
, "*%s.Translation %s/%s: \"\"%s", locale
->value
,
1128 locatalog
->find_message(g
->text
->value
), lf
);
1130 for (o
= (ppdcOption
*)g
->options
->first();
1132 o
= (ppdcOption
*)g
->options
->next())
1134 if (!o
->choices
->count
)
1137 cupsFilePrintf(fp
, "*%s.Translation %s/%s: \"\"%s", locale
->value
,
1139 locatalog
->find_message(o
->text
->value
?
1141 o
->name
->value
), lf
);
1143 for (c
= (ppdcChoice
*)o
->choices
->first();
1145 c
= (ppdcChoice
*)o
->choices
->next())
1147 // Write this choice...
1148 cupsFilePrintf(fp
, "*%s.%s %s/%s: \"\"%s", locale
->value
,
1149 o
->name
->value
, c
->name
->value
,
1150 locatalog
->find_message(c
->text
->value
?
1152 c
->name
->value
), lf
);
1157 // Finally the localizable attributes...
1158 for (a
= (ppdcAttr
*)attrs
->first(); a
; a
= (ppdcAttr
*)attrs
->next())
1160 if ((!a
->text
|| !a
->text
->value
|| !a
->text
->value
[0]) &&
1161 strncmp(a
->name
->value
, "Custom", 6) &&
1162 strncmp(a
->name
->value
, "ParamCustom", 11))
1165 if (!a
->localizable
&&
1166 strcmp(a
->name
->value
, "APCustomColorMatchingName") &&
1167 strcmp(a
->name
->value
, "APPrinterPreset") &&
1168 strcmp(a
->name
->value
, "cupsICCProfile") &&
1169 strcmp(a
->name
->value
, "cupsIPPReason") &&
1170 strcmp(a
->name
->value
, "cupsMarkerName") &&
1171 strncmp(a
->name
->value
, "Custom", 6) &&
1172 strncmp(a
->name
->value
, "ParamCustom", 11))
1175 cupsFilePrintf(fp
, "*%s.%s %s/%s: \"%s\"%s", locale
->value
,
1176 a
->name
->value
, a
->selector
->value
,
1177 locatalog
->find_message(a
->text
&& a
->text
->value
?
1178 a
->text
->value
: a
->name
->value
),
1179 ((a
->localizable
&& a
->value
->value
[0]) ||
1180 !strcmp(a
->name
->value
, "cupsIPPReason")) ?
1181 locatalog
->find_message(a
->value
->value
) : "",
1187 if (default_font
&& default_font
->value
)
1188 cupsFilePrintf(fp
, "*DefaultFont: %s%s", default_font
->value
, lf
);
1190 cupsFilePrintf(fp
, "*DefaultFont: Courier%s", lf
);
1192 for (fn
= (ppdcFont
*)fonts
->first(); fn
; fn
= (ppdcFont
*)fonts
->next())
1193 if (!strcmp(fn
->name
->value
, "*"))
1195 for (bfn
= (ppdcFont
*)src
->base_fonts
->first();
1197 bfn
= (ppdcFont
*)src
->base_fonts
->next())
1198 cupsFilePrintf(fp
, "*Font %s: %s \"%s\" %s %s%s",
1199 bfn
->name
->value
, bfn
->encoding
->value
,
1200 bfn
->version
->value
, bfn
->charset
->value
,
1201 bfn
->status
== PPDC_FONT_ROM
? "ROM" : "Disk", lf
);
1204 cupsFilePrintf(fp
, "*Font %s: %s \"%s\" %s %s%s",
1205 fn
->name
->value
, fn
->encoding
->value
, fn
->version
->value
,
1207 fn
->status
== PPDC_FONT_ROM
? "ROM" : "Disk", lf
);
1209 cupsFilePrintf(fp
, "*%% End of %s, %05d bytes.%s", pc_file_name
->value
,
1210 (int)(cupsFileTell(fp
) + 25 + strlen(pc_file_name
->value
)),