]>
Commit | Line | Data |
---|---|---|
ac884b6a MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * Common PCL functions for CUPS. | |
5 | * | |
6 | * Copyright 2007 by Apple Inc. | |
7 | * Copyright 1993-2005 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 | * pcl_set_media_size() - Set media size using the page size command. | |
18 | * pjl_write() - Write a PJL command string, performing | |
19 | * substitutions as needed. | |
20 | */ | |
21 | ||
22 | /* | |
23 | * Include necessary headers... | |
24 | */ | |
25 | ||
26 | #include "driver.h" | |
27 | #include "pcl-common.h" | |
28 | #include <math.h> | |
29 | ||
30 | ||
31 | /* | |
32 | * 'pcl_set_media_size()' - Set media size using the page size command. | |
33 | */ | |
34 | ||
35 | void | |
36 | pcl_set_media_size(ppd_file_t *ppd, /* I - PPD file */ | |
37 | float width, /* I - Width of page */ | |
38 | float length) /* I - Length of page */ | |
39 | { | |
40 | (void)width; | |
41 | ||
42 | printf("\033&l0O"); /* Set portrait orientation */ | |
43 | ||
44 | if (ppd->model_number & PCL_PAPER_SIZE) | |
45 | switch ((int)(length + 0.5f)) | |
46 | { | |
47 | case 419 : /* Postcard */ | |
48 | printf("\033&l71A"); /* Set page size */ | |
49 | break; | |
50 | ||
51 | case 540 : /* Monarch Envelope */ | |
52 | printf("\033&l80A"); /* Set page size */ | |
53 | break; | |
54 | ||
55 | case 567 : /* Double Postcard */ | |
56 | printf("\033&l72A"); /* Set page size */ | |
57 | break; | |
58 | ||
59 | case 595 : /* A5 */ | |
60 | printf("\033&l25A"); /* Set page size */ | |
61 | break; | |
62 | ||
63 | case 612 : /* Statement */ | |
64 | printf("\033&l5A"); /* Set page size */ | |
65 | break; | |
66 | ||
67 | case 624 : /* DL Envelope */ | |
68 | printf("\033&l90A"); /* Set page size */ | |
69 | break; | |
70 | ||
71 | case 649 : /* C5 Envelope */ | |
72 | printf("\033&l91A"); /* Set page size */ | |
73 | break; | |
74 | ||
75 | case 684 : /* COM-10 Envelope */ | |
76 | printf("\033&l81A"); /* Set page size */ | |
77 | break; | |
78 | ||
79 | case 709 : /* B5 Envelope */ | |
80 | printf("\033&l100A"); /* Set page size */ | |
81 | break; | |
82 | ||
83 | case 729 : /* B5 */ | |
84 | printf("\033&l45A"); /* Set page size */ | |
85 | break; | |
86 | ||
87 | case 756 : /* Executive */ | |
88 | printf("\033&l1A"); /* Set page size */ | |
89 | break; | |
90 | ||
91 | case 792 : /* Letter */ | |
92 | printf("\033&l2A"); /* Set page size */ | |
93 | break; | |
94 | ||
95 | case 842 : /* A4 */ | |
96 | printf("\033&l26A"); /* Set page size */ | |
97 | break; | |
98 | ||
99 | case 936 : /* Foolscap */ | |
100 | printf("\033&l23A"); /* Set page size */ | |
101 | break; | |
102 | ||
103 | case 1008 : /* Legal */ | |
104 | printf("\033&l3A"); /* Set page size */ | |
105 | break; | |
106 | ||
107 | case 1032 : /* B4 */ | |
108 | printf("\033&l46A"); /* Set page size */ | |
109 | break; | |
110 | ||
111 | case 1191 : /* A3 */ | |
112 | printf("\033&l27A"); /* Set page size */ | |
113 | break; | |
114 | ||
115 | case 1224 : /* Tabloid */ | |
116 | printf("\033&l6A"); /* Set page size */ | |
117 | break; | |
118 | ||
119 | default : | |
120 | printf("\033&l101A"); /* Set page size */ | |
121 | printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */ | |
122 | printf("\033&l%.2fP", length / 12.0); | |
123 | /* Set page length */ | |
124 | printf("\033&l%.0fF", length / 12.0); | |
125 | /* Set text length to page */ | |
126 | break; | |
127 | } | |
128 | else | |
129 | { | |
130 | printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */ | |
131 | printf("\033&l%.2fP", length / 12.0); | |
132 | /* Set page length */ | |
133 | printf("\033&l%.0fF", length / 12.0); | |
134 | /* Set text length to page */ | |
135 | } | |
136 | ||
137 | printf("\033&l0L"); /* Turn off perforation skip */ | |
138 | printf("\033&l0E"); /* Reset top margin to 0 */ | |
139 | } | |
140 | ||
141 | ||
142 | /* | |
143 | * 'pjl_write()' - Write a PJL command string, performing substitutions as needed. | |
144 | */ | |
145 | ||
146 | void | |
147 | pjl_write(ppd_file_t *ppd, /* I - PPD file */ | |
148 | const char *format, /* I - Format string */ | |
149 | const char *value, /* I - Value for %s */ | |
150 | int job_id, /* I - Job ID */ | |
151 | const char *user, /* I - Username */ | |
152 | const char *title, /* I - Title */ | |
153 | int num_options, /* I - Number of options */ | |
154 | cups_option_t *options) /* I - Options */ | |
155 | { | |
156 | const char *optval; /* Option value */ | |
157 | char match[255], /* Match string */ | |
158 | *mptr; /* Pointer into match string */ | |
159 | ||
160 | ||
161 | if (!format) | |
162 | return; | |
163 | ||
164 | while (*format) | |
165 | { | |
166 | if (*format == '%') | |
167 | { | |
168 | /* | |
169 | * Perform substitution... | |
170 | */ | |
171 | ||
172 | format ++; | |
173 | switch (*format) | |
174 | { | |
175 | case 'b' : /* job-billing */ | |
176 | if ((optval = cupsGetOption("job-billing", num_options, | |
177 | options)) != NULL) | |
178 | fputs(optval, stdout); | |
179 | break; | |
180 | ||
181 | case 'h' : /* job-originating-host-name */ | |
182 | if ((optval = cupsGetOption("job-originating-host-name", | |
183 | num_options, options)) != NULL) | |
184 | fputs(optval, stdout); | |
185 | break; | |
186 | ||
187 | case 'j' : /* job-id */ | |
188 | printf("%d", job_id); | |
189 | break; | |
190 | ||
191 | case 'n' : /* CR + LF */ | |
192 | putchar('\r'); | |
193 | putchar('\n'); | |
194 | break; | |
195 | ||
196 | case 'q' : /* double quote (") */ | |
197 | putchar('\"'); | |
198 | break; | |
199 | ||
200 | case 's' : /* "value" */ | |
201 | if (value) | |
202 | fputs(value, stdout); | |
203 | break; | |
204 | ||
205 | case 't' : /* job-name */ | |
206 | fputs(title, stdout); | |
207 | break; | |
208 | ||
209 | case 'u' : /* job-originating-user-name */ | |
210 | fputs(user, stdout); | |
211 | break; | |
212 | ||
213 | case '?' : /* ?value:string; */ | |
214 | /* | |
215 | * Get the match value... | |
216 | */ | |
217 | ||
218 | for (format ++, mptr = match; *format && *format != ':'; format ++) | |
219 | if (mptr < (match + sizeof(match) - 1)) | |
220 | *mptr++ = *format; | |
221 | ||
222 | if (!*format) | |
223 | return; | |
224 | ||
225 | /* | |
226 | * See if we have a match... | |
227 | */ | |
228 | ||
229 | format ++; | |
230 | *mptr = '\0'; | |
231 | ||
232 | if (!value || strcmp(match, value)) | |
233 | { | |
234 | /* | |
235 | * Value doesn't match; skip the string that follows... | |
236 | */ | |
237 | ||
238 | while (*format && *format != ';') | |
239 | format ++; | |
240 | } | |
241 | else | |
242 | { | |
243 | /* | |
244 | * Value matches; copy the string that follows... | |
245 | */ | |
246 | ||
247 | while (*format && *format != ';') | |
248 | putchar(*format++); | |
249 | } | |
250 | ||
251 | if (!*format) | |
252 | return; | |
253 | break; | |
254 | ||
255 | default : /* Anything else */ | |
256 | putchar('%'); | |
257 | case '%' : /* %% = single % */ | |
258 | putchar(*format); | |
259 | break; | |
260 | } | |
261 | } | |
262 | else | |
263 | putchar(*format); | |
264 | ||
265 | format ++; | |
266 | } | |
267 | } | |
268 | ||
269 | ||
270 | /* | |
271 | * End of "$Id$". | |
272 | */ |