Debian Codegraph @

contrib/pcl3/eprn/mediasize.h

raw
1 /******************************************************************************
2 File: $Id: mediasize.h,v 1.11 2001/04/12 18:35:26 Martin Rel $
3 Contents: Header file for working with various media sizes
4 Author: Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,
5 Germany. E-mail: [email protected].
6
7 *******************************************************************************
8 * *
9 * Copyright (C) 1999, 2000 by Martin Lottermoser *
10 * All rights reserved *
11 * *
12 ******************************************************************************/
13
14 #ifndef _mediasize_h /* Inclusion protection */
15 #define _mediasize_h
16
17 /*****************************************************************************/
18
19 /* Macros for conversion between units.
20 All these macros resolve to floating point numbers. */
21
22 /* Millimetres per inch */
23 #define MM_PER_IN 25.4f
24
25 /* Big points (units in PostScript's default user space) per inch */
26 #define BP_PER_IN 72.0f
27
28 /* Big points per millimetre */
29 #define BP_PER_MM (BP_PER_IN/MM_PER_IN)
30
31 /******************************************************************************
32
33 Sizes
34 =====
35
36 The constants of type 'ms_Size' each represent a rectangular area ("sheet")
37 completely characterized by the lengths of its two edges. The orientation
38 of the sheet is unspecified but note that the 'ms_SizeDescription' entries
39 are guaranteed to return information such that dimen[0] <= dimen[1].
40
41 The names of the size constants are mostly identical to the values for the
42 "mediaOption" keywords in PPD files, prefixed with "ms_". The keywords are
43 documented in Appendix B, "Registered mediaOption Keywords", of:
44
45 Adobe Systems Incorporated
46 "PostScript Printer Description File Format Specification"
47 Version 4.3
48 9 February 1996
49 Document ID: PN LPS5003
50
51 It can be obtained from http://www.adobe.com.
52
53 The following list does not contain all sizes from PPD 4.3, but all
54 internationally standardized sizes are present.
55 */
56
57 typedef enum {
58 ms_none, /* no size; useful as a sentinel or default value */
59 ms_A10,
60 ms_EnvC10, /* Not a mediaOption keyword. */
61 ms_ISOB10,
62 ms_JISB10, /* PPD 4.3 calls this "B10" */
63 ms_A9,
64 ms_EnvC9, /* Not a mediaOption keyword. */
65 ms_ISOB9,
66 ms_JISB9, /* PPD 4.3 calls this "B9" */
67 ms_A8,
68 ms_EnvC8, /* Not a mediaOption keyword. */
69 ms_ISOB8,
70 ms_JISB8, /* PPD 4.3 calls this "B8" */
71 ms_A7,
72 ms_Index3x5in, /* US index card 3 x 5 in. Not a mediaOption keyword. */
73 ms_EnvC7,
74 ms_ISOB7,
75 ms_EnvChou4, /* Japanese */
76 ms_JISB7, /* PPD 4.3 calls this "B7" */
77 ms_EnvMonarch, /* US */
78 ms_Env9, /* US */
79 ms_Postcard, /* Japanese Hagaki postcard */
80 ms_Index4x6in, /* US index card 4 x 6 in. Not a mediaOption keyword. */
81 ms_Env10, /* US */
82 ms_A6,
83 ms_EnvDL,
84 ms_EnvUS_A2, /* US A2 envelope. Not a mediaOption keyword. */
85 ms_EnvC6,
86 ms_EnvChou3, /* Japanese */
87 ms_ISOB6,
88 ms_Index5x8in, /* US index card 5 x 8 in. Not a mediaOption keyword. */
89 ms_JISB6, /* PPD 4.3 calls this "B6" */
90 ms_Statement, /* US */
91 ms_DoublePostcard, /* double Japanese postcard */
92 ms_A5,
93 ms_EnvC5,
94 ms_ISOB5,
95 ms_JISB5, /* PPD 4.3 calls this "B5" */
96 ms_Executive, /* US */
97 ms_A4,
98 ms_Folio, /* US */
99 ms_Quarto, /* US */
100 ms_Letter, /* US */
101 ms_Legal, /* US */
102 ms_EnvKaku3, /* Japanese? */
103 ms_SuperA,
104 ms_ARCHA, /* US */
105 ms_EnvC4,
106 ms_EnvKaku2, /* Japanese? */
107 ms_ISOB4,
108 ms_JISB4, /* PPD 4.3 calls this "B4" */
109 ms_Tabloid, /* US */
110 ms_A3,
111 ms_ARCHB, /* US */
112 ms_SuperB,
113 ms_EnvC3,
114 ms_HPSuperB, /* what Hewlett-Packard calls "SuperB" (13x19 in).
115 Not a mediaOption keyword. */
116 ms_ISOB3,
117 ms_JISB3, /* PPD 4.3 calls this "B3" */
118 ms_A2,
119 ms_ARCHC, /* US */
120 ms_EnvC2,
121 ms_ISOB2,
122 ms_JISB2, /* PPD 4.3 calls this "B2" */
123 ms_A1,
124 ms_ARCHD, /* US */
125 ms_EnvC1,
126 ms_ISOB1,
127 ms_JISB1, /* PPD 4.3 calls this "B1" */
128 ms_A0,
129 ms_ARCHE, /* US */
130 ms_EnvC0,
131 ms_ISOB0,
132 ms_JISB0, /* PPD 4.3 calls this "B0" */
133 ms_2A0, /* Not a mediaOption keyword. */
134 ms_4A0, /* Not a mediaOption keyword. */
135 /* End of discrete sizes */
136 ms_CustomPageSize, /* no particular size. Not a mediaOption keyword. */
137 ms_MaxPage /* largest available size on a particular device */
138 } ms_Size;
139
140 typedef struct {
141 ms_Size size;
142 const char *name;
143 /* Names are identical to the name for the size constant after stripping the
144 "ms_" prefix, hence the map from size names to size codes (except
145 'ms_none') is bijective. There is no description for 'ms_none'. */
146 float dimen[2];
147 /* Given in bp and with 'dimen[0]' <= 'dimen[1]'. Both values are zero for
148 unspecified sizes like 'ms_CustomPageSize' and both are positive
149 otherwise.
150 */
151 } ms_SizeDescription;
152
153 #define MAX_MEDIASIZES 128
154
155 typedef struct {
156 int mediasize_list_inited;
157 const ms_SizeDescription *mediasize_list[MAX_MEDIASIZES];
158 } mediasize_table;
159
160 /******************************************************************************
161
162 Media codes
163 ===========
164
165 PPD 4.3 describes several standard qualifiers ("." followed by a string) and
166 substrings for mediaOption keywords. The type 'ms_MediaCode' is
167 intended for representing a combination of 'ms_Size' with a set of flags
168 holding additional information of this kind.
169
170 The additional information, as standardized by Adobe and as far as it is
171 supported here, consists of information concerning external conditions
172 ("Extra" and "Transverse") and information relating to the way the medium is
173 used ("Big"/"Small" and "Rotated"). I've also added two flags which the using
174 application can endow with any meaning it needs.
175
176 Use bitwise OR with the flag values to construct an 'ms_MediaCode' instance
177 from an 'ms_Size' instance.
178 Use ms_flags() and ms_without_flags() to split a value of type 'ms_MediaCode'
179 into its components.
180 */
181
182 typedef unsigned int ms_MediaCode;
183
184 /* Extraction of components */
185 #define MS_FLAG_MASK 0xFF00U
186 #define ms_flags(s) ((s) & MS_FLAG_MASK)
187 #define ms_without_flags(s) ((ms_Size)((s) & ~MS_FLAG_MASK))
188
189 /* The "Small" substring or qualifier describes a sheet of the same size as
190 without this modification but with a smaller imageable area (larger
191 hardware margins). */
192 #define MS_SMALL_STRING "Small"
193 #define MS_SMALL_FLAG 0x0400U
194
195 /* The "Big" substring or qualifier describes a sheet of the same size as
196 without this modification but with a larger imageable area (smaller
197 hardware margins).
198 This is not an Adobe-defined string, but note that there are sizes
199 "PRC32K" and "PRC32KBig" with identical dimensions in PPD 4.3. */
200 #define MS_BIG_STRING "Big"
201 #define MS_BIG_FLAG 0x0800U
202
203 /* The "Rotated" substring is used to distinguish between a sheet's two
204 different orientations with respect to the page contents. */
205 #define MS_ROTATED_STRING "Rotated"
206 #define MS_ROTATED_FLAG 0x1000U
207
208 /* The "Extra" substring or qualifier identifies a sheet which is actually a
209 bit larger than specified by the size code (in PPD 4.3 usually 1 inch in
210 each dimension). */
211 #define MS_EXTRA_STRING "Extra"
212 #define MS_EXTRA_FLAG 0x2000U
213
214 /* The "Transverse" qualifier is used to distinguish between a sheet's two
215 different orientations with respect to an external reference system, for
216 example the feeding direction. */
217 #define MS_TRANSVERSE_STRING "Transverse"
218 #define MS_TRANSVERSE_FLAG 0x4000U
219
220 /* Flags with user-definable interpretation */
221 #define MS_USER_FLAG_1 0x0200U
222 #define MS_USER_FLAG_2 0x0100U
223
224 /* Type for lists of flags and their names */
225 typedef struct {
226 ms_MediaCode code;
227 const char *name;
228 } ms_Flag;
229
230 /*****************************************************************************/
231
232 /* Find the size description for a media code. The flags in 'code' are
233 ignored. If the code is unknown, a NULL pointer will be returned.
234 */
235 extern const ms_SizeDescription *ms_find_size_from_code(ms_MediaCode code);
236
237 /*===========================================================================*/
238
239 /* Generate a media code for a name
240
241 Acceptable names are all size names and all size names extended with any
242 combination of the known substrings and qualifiers. The rules for forming a
243 name recognized by this function are:
244 - The order is: base name, substrings, qualifiers.
245 - No string may appear twice.
246 - At most one of "Big" and "Small" may be present.
247 Note that "Transverse" is only permitted as a qualifier and "Rotated" may
248 only appear as a substring. PPD 4.3 seems to prefer substrings to
249 qualifiers where possible.
250
251 The pointer 'user_flag_list', if non-NULL, must refer to a sequence of
252 entries associating user flags with names. The list is terminated by the
253 first entry having a zero 'code'. The names in this list will be recognized
254 as substrings in addition to the standard names. The list will be searched
255 linearly for a matching entry.
256
257 The function returns 'ms_none' if it cannot convert the name.
258
259 The function has the following restrictions:
260 - The flags returned do not distinguish between appearance as a substring
261 and appearance as a qualifier or consider the order of appearance.
262 - There is no support for serialization qualifiers.
263 */
264 extern ms_MediaCode ms_find_code_from_name(mediasize_table *tables,
265 const char *name,
266 const ms_Flag *user_flag_list);
267
268 /*===========================================================================*/
269
270 /* Construct a name for a media code
271
272 The pointer 'buffer' must be non-NULL and point to a storage area of at
273 least 'length' octets. The function will convert 'code' into a string
274 representation and write it to 'buffer', terminating it with NUL. The list
275 'user_flag_list', if non-NULL, is taken into account for the conversion of
276 user flags in 'code'. It is searched linearly until the first entry with a
277 zero 'code'. If an appropriate entry is found it is added as a substring
278 before all standard substrings.
279
280 The function returns zero on success and a non-zero value otherwise.
281 In the latter case, 'errno' will have been set to one of the following
282 values:
283 - EDOM: 'code' contains an unkown size or an unknown flag. The last case
284 includes the situation where a user flag is found in 'code' and
285 'user_flag_list' is NULL or does not contain a matching entry.
286 - EINVAL: 'buffer' is NULL or 'length' is zero.
287 - ERANGE: 'length' is insufficient to store the resulting string.
288 */
289 extern int ms_find_name_from_code(char *buffer, size_t length,
290 ms_MediaCode code, const ms_Flag *user_flag_list);
291
292 /*****************************************************************************/
293
294 #endif /* Inclusion protection */