]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | <!-- |
bc44d920 | 2 | "$Id: api-ppd.shtml 6649 2007-07-11 21:46:42Z mike $" |
ef416fc2 | 3 | |
4 | PPD API introduction for the Common UNIX Printing System (CUPS). | |
5 | ||
bc44d920 | 6 | Copyright 2007 by Apple Inc. |
7 | Copyright 1997-2006 by Easy Software Products, all rights reserved. | |
ef416fc2 | 8 | |
9 | These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 14 | --> |
15 | ||
5a738aea | 16 | <h2 class='title'><a name='OVERVIEW'>Overview</a></h2> |
ef416fc2 | 17 | |
5a738aea MS |
18 | <p>The CUPS PPD API provides read-only access the data in PostScript Printer |
19 | Description ("PPD") files which are used for all printers with a driver. With | |
20 | it you can display printer options to users, mark option choices and check for | |
21 | conflicting choices, and output marked choices in PostScript output. The | |
22 | <a href="#ppd_file_t"><code>ppd_file_t</code></a> structure contains all of | |
23 | the information in a PPD file.</p> | |
ef416fc2 | 24 | |
5a738aea | 25 | <h3><a name="LOADING">Loading a PPD File</a></h3> |
ef416fc2 | 26 | |
5a738aea MS |
27 | <p>The <a href="#ppdOpenFile"><code>ppdOpenFile</code></a> function "opens" a |
28 | PPD file and loads it into memory. For example, the following code opens the | |
29 | current printer's PPD file in a CUPS filter:</p> | |
ef416fc2 | 30 | |
5a738aea MS |
31 | <pre class="example"> |
32 | #include <cups/ppd.h> | |
ef416fc2 | 33 | |
5a738aea | 34 | <a href="#ppd_file_t">ppd_file_t</a> *ppd = <a href="#ppdOpenFile">ppdOpenFile</a>(getenv("PPD")); |
ef416fc2 | 35 | </pre> |
36 | ||
5a738aea MS |
37 | <p>The return value is a pointer to a new |
38 | <a href="#ppd_file_t"><code>ppd_file_t</code></a> structure or <code>NULL</code> | |
39 | if the PPD file does not exist or cannot be loaded. The | |
40 | <a href="#ppdClose"><code>ppdClose</code></a> function frees the memory used | |
41 | by the structure:</p> | |
ef416fc2 | 42 | |
5a738aea MS |
43 | <pre class="example"> |
44 | #include <cups/ppd.h> | |
45 | ||
46 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
47 | ||
48 | <a href="#ppdClose">ppdClose</a>(ppd); | |
49 | </pre> | |
50 | ||
51 | <h3><a name="OPTIONS_AND_GROUPS">Options and Groups</a></h3> | |
52 | ||
53 | <p>PPD files support multiple options, which are stored in arrays of | |
54 | <a href="#ppd_option_t"><code>ppd_option_t</code></a> and | |
55 | <a href="#ppd_choice_t"><code>ppd_choice_t</code></a> structures.</p> | |
56 | ||
57 | <p>Each option in turn is associated with a group stored in a | |
58 | <a href="#ppd_group_t"><code>ppd_group_t</code></a> structure. Groups can be | |
59 | specified in the PPD file; if an option is not associated with a group | |
60 | then it is put in an automatically-generated "General" group. Groups can also | |
61 | have sub-groups, however CUPS currently ignores sub-groups because of past | |
62 | abuses of this functionality.</p> | |
63 | ||
64 | <p>Options are selected by marking them using one of three functions. The | |
65 | first is <a href="#ppdMarkDefaults"><code>ppdMarkDefaults</code></a> which | |
66 | selects all of the default options in the PPD file:</p> | |
67 | ||
68 | <pre class="example"> | |
69 | #include <cups/ppd.h> | |
70 | ||
71 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
72 | ||
73 | <a href="#ppdMarkDefaults">ppdMarkDefaults</a>(ppd); | |
74 | </pre> | |
75 | ||
76 | <p>The second is <a href="#ppdMarkOption"><code>ppdMarkOption</code></a> | |
77 | which selects a single option choice in the PPD file. For example, the following | |
78 | code selects the manual feed media source:</p> | |
79 | ||
80 | <pre class="example"> | |
81 | #include <cups/ppd.h> | |
82 | ||
83 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
84 | ||
85 | <a href="#ppdMarkOption">ppdMarkOption</a>(ppd, "InputSlot", "ManualFeed"); | |
86 | </pre> | |
87 | ||
88 | <p>The last function is | |
89 | <a href="#cupsMarkOptions"><code>cupsMarkOptions</code></a> which selects | |
90 | multiple option choices in the PPD file from an array of CUPS options, mapping | |
91 | IPP attributes like "media" and "sides" to their corresponding PPD options. You | |
92 | typically use this function in a print filter with | |
93 | <code>cupsParseOptions</code> and | |
94 | <a href="#ppdMarkDefaults"><code>ppdMarkDefaults</code></a> to select all of | |
95 | the option choices needed for the job, for example:</p> | |
96 | ||
97 | <pre class="example"> | |
98 | #include <cups/ppd.h> | |
99 | ||
100 | <a href="#ppd_file_t">ppd_file_t</a> *ppd = <a href="#ppdOpenFile">ppdOpenFile</a>(getenv("PPD")); | |
101 | cups_option_t *options = NULL; | |
102 | int num_options = cupsParseOptions(argv[5], 0, &options); | |
103 | ||
104 | <a href="#ppdMarkDefaults">ppdMarkDefaults</a>(ppd); | |
105 | <a href="#cupsMarkOptions">cupsMarkOptions</a>(ppd, num_options, options); | |
106 | </pre> | |
107 | ||
108 | <h3><a name="CONSTRAINTS">Constraints</a></h3> | |
109 | ||
110 | <p>PPD files support specification of conflict conditions, called | |
111 | constraints, between different options. Constraints are stored in an array of | |
112 | <a href="#ppd_const_t"><code>ppd_const_t</code></a> structures which specify | |
113 | the options and choices that conflict with each other. The | |
114 | <a href="#ppdConflicts"><code>ppdConflicts</code></a> function tells you | |
115 | how many of the selected options are incompatible.</p> | |
116 | ||
117 | <h3><a name="PAGE_SIZES">Page Sizes</a></h3> | |
118 | ||
119 | <p>Page sizes are special options which have physical dimensions and margins | |
120 | associated with them. The size information is stored in | |
121 | <a href="#ppd_size_t"><code>ppd_size_t</code></a> structures and is available | |
122 | by looking up the named size with the | |
123 | <a href="#ppdPageSize"><code>ppdPageSize</code></a> function. The page size and | |
124 | margins are returned in units called points; there are 72 points per inch. If | |
125 | you pass <code>NULL</code> for the size, the currently selected size is | |
126 | returned:</p> | |
127 | ||
128 | <pre class="example"> | |
129 | #include <cups/ppd.h> | |
130 | ||
131 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
132 | <a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, NULL); | |
133 | </pre> | |
134 | ||
135 | <p>Besides the standard page sizes listed in a PPD file, some printers | |
136 | support variable or custom page sizes. Custom page sizes are supported if the | |
137 | <code>variables_sizes</code> member of the | |
138 | <a href="#ppd_file_t"><code>ppd_file_t</code></a> structure is non-zero. | |
139 | The <code>custom_min</code>, <code>custom_max</code>, and | |
140 | <code>custom_margins</code> members of the | |
141 | <a href="#ppd_file_t"><code>ppd_file_t</code></a> structure define the limits | |
142 | of the printable area. To get the resulting media size, use a page size string | |
143 | of the form "Custom.<I>width</I>x<I>length</I>", where "width" and "length" are | |
144 | in points. Custom page size names can also be specified in inches | |
145 | ("Custom.<i>width</i>x<i>height</i>in"), centimeters | |
146 | ("Custom.<i>width</i>x<i>height</i>cm"), or millimeters | |
147 | ("Custom.<i>width</i>x<i>height</i>mm"):</p> | |
148 | ||
149 | <pre class="example"> | |
150 | #include <cups/ppd.h> | |
151 | ||
152 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
153 | ||
154 | /* Get an 576x720 point custom page size */ | |
155 | <a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.576x720"); | |
156 | ||
157 | /* Get an 8x10 inch custom page size */ | |
158 | <a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.8x10in"); | |
159 | ||
160 | /* Get a 100x200 millimeter custom page size */ | |
161 | <a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.100x200mm"); | |
162 | ||
163 | /* Get a 12.7x34.5 centimeter custom page size */ | |
164 | <a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.12.7x34.5cm"); | |
165 | </pre> | |
166 | ||
167 | <h3><a name="ATTRIBUTES">Attributes</a></h3> | |
168 | ||
169 | <p>Every PPD file is composed of one or more attributes. Most of these | |
170 | attributes are used to define groups, options, choices, and page sizes, | |
171 | however several informations attributes are available which you may need | |
172 | to access in your program or filter. Attributes normally look like one of | |
173 | the following examples in a PPD file:</p> | |
174 | ||
175 | <pre class="example"> | |
176 | *name: "value" | |
177 | *name spec: "value" | |
178 | *name spec/text: "value" | |
179 | </pre> | |
180 | ||
181 | <p>The <a href="#ppdFindAttr"><code>ppdFindAttr</code></a> and | |
182 | <a href="#ppdFindNextAttr"><code>ppdFindNextAttr</code></a> functions find the | |
183 | first and next instances, respectively, of the named attribute with the given | |
184 | "spec" string and return a <a href="#ppd_attr_t"><code>ppd_attr_t</code></a> | |
185 | structure. If you provide a NULL specifier string, all attributes with the | |
186 | given name will be returned. For example, the following code lists all of the | |
187 | <code>Product</code> attributes in a PPD file:</p> | |
188 | ||
189 | <pre class="example"> | |
190 | #include <cups/ppd.h> | |
191 | ||
192 | <a href="#ppd_file_t">ppd_file_t</a> *ppd; | |
193 | <a href="#ppd_attr_t">ppd_attr_t</a> *attr; | |
194 | ||
195 | for (attr = <a href="#ppdFindAttr">ppdFindAttr</a>(ppd, "Product", NULL); | |
196 | attr != NULL; | |
197 | attr = <a href="#ppdFindNextAttr">ppdFindNextAttr</a>(ppd, "Product", NULL)) | |
198 | puts(attr->value); | |
199 | </pre> |