This chapter describes how to use the CUPS DDK and write PPD compiler source files.
The DDK provides the basis for creating printer drivers that work within the architecture defined by the Common UNIX Printing System. The DDK includes a PostScript Printer Description ("PPD") file compiler, two general-purpose raster printer drivers for printers that understand the Hewlett-Packard Page Control Language ("HP-PCL") or Epson Standard Code for Printers ("ESC/P") languages, and a raster printer driver library that provides general-purpose dithering and color management/separation functions.
All of the tools in the DDK are currently command-line only, however future releases of the DDK will include an integrated development environment which provides an intuitive GUI for creating and testing printer drivers.
Aside from this manual, the DDK also includes several man pages that can be used as a quick reference when developing your printer drivers. These pages are also available via the CUPS on-line help system and the man(1) command. For example, type the following command to display the man page for the ppdc(1) command:
man ppdc ENTER
The PPD compiler, ppdc, is a simple command-line tool that takes a single driver information file, which by convention uses the extension .drv, and produces one or more PPD files that may be distributed with your printer drivers for use with CUPS. For example, you would run the following command to create the English language PPD files defined by the driver information file mydrivers.drv:
ppdc mydrivers.drv ENTER
The PPD files are placed in a subdirectory called ppd. The -d option is used to put the PPD files in a different location, for example:
ppdc -d myppds mydrivers.drv ENTER
places the PPD files in a subdirectory named myppds. Finally, use the -l option to specify the language localization for the PPD files that are created, for example:
ppdc -d myppds/de -l de mydrivers.drv ENTER ppdc -d myppds/en -l en mydrivers.drv ENTER ppdc -d myppds/es -l es mydrivers.drv ENTER ppdc -d myppds/fr -l fr mydrivers.drv ENTER ppdc -d myppds/it -l it mydrivers.drv ENTER
creates PPD files in German (de), English (en), Spanish (es), French (fr), and Italian (it) in the corresponding subdirectories. Specify multiple languages (separated by commas) to produce "globalized" PPD files:
ppdc -d myppds -l de,en,es,fr,it mydrivers.drv ENTER
You'll learn more about localization in "Chapter 5, Localizing Printer Drivers".
The driver information files accepted by the PPD compiler are plain text files that define the various attributes and options that are included in the PPD files that are generated. A driver information file can define the information for one or more printers and their corresponding PPD files.
// Include standard font and media definitions #include <font.defs> #include <media.defs> // List the fonts that are supported, in this case all standard // fonts... Font * // Manufacturer, model name, and version Manufacturer "Foo" ModelName "FooJet 2000" Version 1.0 // Each filter provided by the driver... Filter application/vnd.cups-raster 100 rastertofoo // Supported page sizes *MediaSize Letter MediaSize A4 // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Specify the name of the PPD file we want to generate... PCFileName "foojet2k.ppd" |
The example in Listing 2-1 shows a driver information file which defines the minimum required attributes to provide a valid PPD file.
The first part of the file includes standard definition files for fonts and media sizes:
#include <font.defs> #include <media.defs>
The #include directive works just like the C/C++ include directive; files included using the angle brackets (<filename>) are found in any of the standard include directories and files included using quotes ("filename") are found in the same directory as the source or include file. The <font.defs> include file defines the standard fonts which are included with ESP Ghostscript and the Apple PDF RIP. The <media.defs> include file defines the standard media sizes listed in Appendix B of the Adobe PostScript Printer Description File Format Specification.
Other standard include files include:
Next we list all of the fonts that are available in the driver; for CUPS raster drivers, the following line is all that is usually supplied:
Font *
The Font directive specifies the name of a single font or the asterisk to specify all fonts. For example, you would use the following line to define an additional bar code font that you are supplying with your printer driver:
// name encoding version charset status Font Barcode-Foo Special "(1.0)" Special ROM
The name of the font is Barcode-Foo. Since it is not a standard text font, the encoding and charset name Special is used. The version number is 1.0 and the status (where the font is located) is ROM to indicate that the font does not need to be embedded in documents that use the font for this printer.
Third comes the manufacturer, model name, and version number information strings:
Manufacturer "Foo" ModelName "FooJet 2000" Version 1.0
These strings are used when the user (or auto-configuration program) selects the printer driver for a newly connected device.
The list of filters comes after the information strings; for the example in Listing 2-1, we have a single filter that takes CUPS raster data:
Filter application/vnd.cups-raster 100 rastertofoo
Each filter specified in the driver information file is the equivalent of a printer driver for that format; if a user submits a print job in a different format, CUPS figures out the sequence of commands that will produce a supported format for the least relative cost.
Once we have defined the driver information we specify the supported options. For the example driver we support a single resolution of 600 dots per inch and two media sizes, A4 and Letter:
*MediaSize Letter MediaSize A4 *Resolution k 8 0 0 0 "600dpi/600 DPI"
The asterisk in front of the MediaSize and Resolution directives specify that those option choices are the default. The MediaSize directive is followed by a media size name which is normally defined in the <media.defs> file and corresponds to a standard Adobe media size name. If the default media size is Letter, the PPD compiler will override it to be A4 for non-English localizations for you automatically.
The Resolution directive accepts several values after it as follows:
Finally, the PCFileName directive specifies that the named PPD file should be written for the current driver definitions:
PCFileName "foojet2k.ppd"
The filename follows the directive and must conform to the Adobe filename requirements in the Adobe Postscript Printer Description File Format Specification. Specifically, the filename may not exceed 8 characters followed by the extension .ppd.
The previous example created a single PPD file. Driver information files can also define multiple printers by using the PPD compiler grouping functionality. Directives are grouped using the curly braces ({ and }) and every group that uses the PCFileName directive produces a PPD file with that name. Listing 2-2 shows a variation of the original example that uses two groups to define two printers that share the same printer driver filter but provide two different resolution options.
The second example is essentially the same as the first, except that each printer model is defined inside of a pair of curly braces. For example, the first printer is defined using:
{ // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Specify the model name and filename... ModelName "FooJet 2000" PCFileName "foojet2k.ppd" }
The printer inherits all of the definitions from the parent group (the top part of the file) and adds the additional definitions inside the curly braces for that printer driver. When we define the second group, it also inherits the same definitions from the parent group but none of the definitions from the first driver. Groups can be nested to any number of levels to support variations of similar models without duplication of information.
Sometimes you will want to define constants for your drivers so that you can share values in different groups within the same driver information file, or to share values between different driver information files using the #include directive. The #define directive is used to define constants for use in your printer definitions:
#define NAME value
// Include standard font and media definitions #include <font.defs> #include <media.defs> // List the fonts that are supported, in this case all standard // fonts... Font * // Manufacturer and version Manufacturer "Foo" Version 1.0 // Each filter provided by the driver... Filter application/vnd.cups-raster 100 rastertofoo // Supported page sizes *MediaSize Letter MediaSize A4 { // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Specify the model name and filename... ModelName "FooJet 2000" PCFileName "foojet2k.ppd" } { // Supported resolutions *Resolution k 8 0 0 0 "1200dpi/1200 DPI" // Specify the model name and filename... ModelName "FooJet 2001" PCFileName "foojt2k1.ppd" } |
The NAME is any sequence of letters, numbers, and the underscore. The value is a number or string; if the value contains spaces you must put double quotes around it, for example:
#define FOO "My String Value"
Constants can also be defined on the command-line using the -D option:
ppdc -DNAME="value" filename.drv ENTER
Once defined, you use the notation $NAME to substitute the value of the constant in the file, for example:
#define MANUFACTURER "Foo" #define FOO_600 0 #define FOO_1200 1 { Manufacturer "$MANUFACTURER" ModelNumber $FOO_600 ModelName "FooJet 2000" ... } { Manufacturer "$MANUFACTURER" ModelNumber $FOO_1200 ModelName "FooJet 2001" ... }
Numeric constants can be bitwise OR'd together by placing the constants inside parenthesis, for example:
// ModelNumber capability bits #define DUPLEX 1 #define COLOR 2 ... { // Define a model number specifying the capabilities of // the printer... ModelNumber ($DUPLEX $COLOR) ... }
For printer drivers that support color printing, the ColorDevice and ColorModel directives must be used to tell the printing system that color output is desired and in what formats. Listing 2-3 shows a variation of the previous example which includes a color printer that supports printing at 300 and 600 DPI.
The key changes are the addition of the ColorDevice directive:
ColorDevice true
which tells the printing system that the printer supports color printing, and the ColorModel directives:
ColorModel Gray/Grayscale w chunky 0 *ColorModel RGB/Color rgb chunky 0
which tell the printing system which colorspaces are supported by the printer driver for color printing. Each of the ColorModel directives is followed by the option name and text (Gray/Grayscale and RGB/Color), the colorspace name (w and rgb), the color organization (chunky), and the compression mode number (0) to be passed to the driver. The option name can be any of the standard Adobe ColorModel names:
Custom names can be used, however it is recommended that you use your vendor prefix for any custom names, for example "fooName".
The colorspace name can be any of the following universally supported colorspaces:
Additional colorspaces are supported by the standard CUPS image RIP filter and by ESP Ghostscript. The full list can be found in Appendix B, PPD Compiler Source File Reference.
The color organization can be any of the following values:
The compression mode value is passed to the driver in the cupsCompression attribute. It is traditionally used to select an appropriate compression mode for the color model but can be used for any purpose, such as specifying a photo mode vs. standard mode.
// Include standard font and media definitions #include <font.defs> #include <media.defs> // List the fonts that are supported, in this case all standard // fonts... Font * // Manufacturer and version Manufacturer "Foo" Version 1.0 // Each filter provided by the driver... Filter application/vnd.cups-raster 100 rastertofoo // Supported page sizes *MediaSize Letter MediaSize A4 { // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Specify the model name and filename... ModelName "FooJet 2000" PCFileName "foojet2k.ppd" } { // Supports color printing ColorDevice true // Supported colorspaces ColorModel Gray/Grayscale w chunky 0 *ColorModel RGB/Color rgb chunky 0 // Supported resolutions *Resolution - 8 0 0 0 "300dpi/300 DPI" Resolution - 8 0 0 0 "600dpi/600 DPI" // Specify the model name and filename... ModelName "FooJet Color" PCFileName "foojetco.ppd" } |
The Group, Option, and Choice directives are used to define or select a group, option, or choice. Listing 2-4 shows a variation of the first example that provides two custom options in a group named "Footasm".
The custom group is introduced by the Group directive which is followed by the name and optionally text for the user:
Group "Footasm"
The group name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length. The groups General, Extra, and InstallableOptions are predefined by CUPS; the general and extra groups are filled by the UI options defined by the PPD specification. The InstallableOptions group is reserved for options that define whether accessories for the printer (duplexer unit, finisher, stapler, etc.) are installed.
Once the group is specified, the Option directive is used to introduce a new option:
Option "fooEnhance/Resolution Enhancement" Boolean AnySetup 10
The directive is followed by the name of the option and any optional user text, the option type, the PostScript document group, and the sort order number. The option name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length.
The option type can be Boolean for true/false selections, PickOne for picking one of many choices, or PickMany for picking zero or more choices. Boolean options can have at most two choices with the names False and True. Pick options can have any number of choices, although for Windows compatibility reasons the number of choices should not exceed 255.
The PostScript document group is typically AnySetup, meaning that the option can be introduced at any point in the PostScript document. Other values include PageSetup to include the option before each page and DocumentSetup to include the option once at the beginning of the document.
The sort order number is used to sort the printer commands associated with each option choice within the PostScript document. This allows you to setup certain options before others as required by the printer. For most CUPS raster printer drivers, the value 10 can be used for all options.
Once the option is specified, each option choice can be listed using the Choice directive:
*Choice True/Yes "<</cupsCompression 1>>setpagedevice" Choice False/No "<</cupsCompression 0>>setpagedevice"
// Include standard font and media definitions #include <font.defs> #include <media.defs> // List the fonts that are supported, in this case all standard // fonts... Font * // Manufacturer, model name, and version Manufacturer "Foo" ModelName "FooJet 2000" Version 1.0 // Each filter provided by the driver... Filter application/vnd.cups-raster 100 rastertofoo // Supported page sizes *MediaSize Letter MediaSize A4 // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Option Group Group "Footasm" // Boolean option Option "fooEnhance/Resolution Enhancement" Boolean AnySetup 10 *Choice True/Yes "<</cupsCompression 1>>setpagedevice" Choice False/No "<</cupsCompression 0>>setpagedevice" // Multiple choice option Option "fooOutputType/Output Quality" PickOne AnySetup 10 *Choice "Auto/Automatic Selection" "<</OutputType(Auto)>>setpagedevice"" Choice "Text/Optimize for Text" "<</OutputType(Text)>>setpagedevice"" Choice "Graph/Optimize for Graphics" "<</OutputType(Graph)>>setpagedevice"" Choice "Photo/Optimize for Photos" "<</OutputType(Photo)>>setpagedevice"" // Specify the name of the PPD file we want to generate... PCFileName "foojet2k.ppd" |
The directive is followed by the choice name and optionally user text, and the PostScript commands that should be inserted when printing a file to this printer. The option name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length.
The PostScript commands are also interpreted by any RIP filters, so these commands typically must be present for all option choices. Most commands take the form:
<</name value>>setpagedevice
where name is the name of the PostScript page device attribute and value is the numeric or string value for that attribute.
Constraints are strings that are used to specify that one or more option choices are incompatible, for example two-sided printing on transparency media. Constraints are also used to prevent the use of uninstalled features such as the duplexer unit, additional media trays, and so forth.
The UIConstraints directive is used to specify a constraint that is placed in the PPD file. The directive is followed by a string using one of the following formats:
UIConstraints "*Option1 *Option2" UIConstraints "*Option1 Choice1 *Option2" UIConstraints "*Option1 *Option2 Choice2" UIConstraints "*Option1 Choice1 *Option2 Choice2"
Each option name is preceded by the asterisk (*). If no choice is given for an option, then all choices except False and None will conflict with the other option and choice(s). Since the PPD compiler automatically adds reciprocal constraints (option A conflicts with option B, so therefore option B conflicts with option A), you need only specify the constraint once.
Listing 2-5 shows a variation of the first example with an added Duplex option and installable option for the duplexer, OptionDuplex. A constraint is added at the end to specify that any choice of the Duplex option that is not None is incompatible with the "Duplexer Installed" option set to "Not Installed" (False):
UIConstraints "*Duplex *OptionDuplexer False"
// Include standard font and media definitions #include <font.defs> #include <media.defs> // List the fonts that are supported, in this case all standard // fonts... Font * // Manufacturer, model name, and version Manufacturer "Foo" ModelName "FooJet 2000" Version 1.0 // Each filter provided by the driver... Filter application/vnd.cups-raster 100 rastertofoo // Supported page sizes *MediaSize Letter MediaSize A4 // Supported resolutions *Resolution k 8 0 0 0 "600dpi/600 DPI" // Installable Option Group Group "InstallableOptions/Options Installed" // Duplexing unit option Option "OptionDuplexer/Duplexing Unit" Boolean AnySetup 10 Choice True/Installed "" *Choice "False/Not Installed" "" // General Option Group Group General // Duplexing option Option "Duplex/Two-Sided Printing" PickOne AnySetup 10 *Choice "None/No" "<</Duplex false>>setpagedevice"" Choice "DuplexNoTumble/Long Edge Binding" "<</Duplex true/Tumble false>>setpagedevice"" Choice "DuplexTumble/Short Edge Binding" "<</Duplex true/Tumble true>>setpagedevice"" // Only allow duplexing if the duplexer is installed UIConstraints "*Duplex *OptionDuplexer False" // Specify the name of the PPD file we want to generate... PCFileName "foojet2k.ppd" |
The DDK includes a utility called ppdi(1) which allows you to import existing PPD files into the driver information file format. Once imported, you can modify, localize, and regenerate the PPD files easily. The PPD files can be for CUPS raster printer drivers or for PostScript printers - the DDK makes no distinction when managing driver information or PPD files.
Type the following command to import the PPD file mydevice.ppd into the driver information file mydevice.drv:
ppdi -o mydevice.drv mydevice.ppd ENTER
If you have a whole directory of PPD files that you would like to import, you can list multiple filenames or use shell wildcards to import more than one PPD file on the command-line:
ppdi -o mydevice.drv mydevice1.ppd mydevice2.ppd ENTER ppdi -o mydevice.drv *.ppd ENTER
If the driver information file already exists, the new PPD file entries are appended to the end of the file. Each PPD file is placed in its own group of curly braces within the driver information file.