]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/common.c
Merge changes from 1.1 tree.
[thirdparty/cups.git] / filter / common.c
CommitLineData
2d35d8ee 1/*
b5cb0608 2 * "$Id: common.c,v 1.15.2.1 2001/05/13 18:38:18 mike Exp $"
2d35d8ee 3 *
4 * Common filter routines for the Common UNIX Printing System (CUPS).
5 *
d2935a0f 6 * Copyright 1997-2001 by Easy Software Products.
2d35d8ee 7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
b5cb0608 26 * SetCommonOptions() - Set common filter options for media size,
27 * etc.
28 * UpdatePageVars() - Update the page variables for the
29 * orientation.
30 * WriteClassificationProlog() - Write the prolog with the classification
31 * and page label.
2d35d8ee 32 */
33
34/*
35 * Include necessary headers...
36 */
37
38#include "common.h"
39
40
41/*
42 * Globals...
43 */
44
45int Orientation = 0, /* 0 = portrait, 1 = landscape, etc. */
46 Duplex = 0, /* Duplexed? */
47 LanguageLevel = 1, /* Language level of printer */
a45537c4 48 ColorDevice = 1; /* Do color text? */
2d35d8ee 49float PageLeft = 18.0f, /* Left margin */
50 PageRight = 594.0f, /* Right margin */
51 PageBottom = 36.0f, /* Bottom margin */
52 PageTop = 756.0f, /* Top margin */
53 PageWidth = 612.0f, /* Total page width */
54 PageLength = 792.0f; /* Total page length */
55
56
57/*
58 * 'SetCommonOptions()' - Set common filter options for media size, etc.
59 */
60
ed19bd98 61ppd_file_t * /* O - PPD file */
62SetCommonOptions(int num_options, /* I - Number of options */
4e989042 63 cups_option_t *options, /* I - Options */
64 int change_size) /* I - Change page size? */
2d35d8ee 65{
2d35d8ee 66 ppd_file_t *ppd; /* PPD file */
67 ppd_size_t *pagesize; /* Current page size */
568d2c2f 68 const char *val; /* Option value */
2d35d8ee 69
70
71 ppd = ppdOpenFile(getenv("PPD"));
72
73 ppdMarkDefaults(ppd);
74 cupsMarkOptions(ppd, num_options, options);
75
76 if ((pagesize = ppdPageSize(ppd, NULL)) != NULL)
77 {
78 PageWidth = pagesize->width;
79 PageLength = pagesize->length;
80 PageTop = pagesize->top;
81 PageBottom = pagesize->bottom;
82 PageLeft = pagesize->left;
83 PageRight = pagesize->right;
81dec18a 84
85 fprintf(stderr, "DEBUG: Page = %.0fx%.0f; %.0f,%.0f to %.0f,%.0f\n",
86 PageWidth, PageLength, PageLeft, PageBottom, PageRight, PageTop);
2d35d8ee 87 }
88
89 if (ppd != NULL)
90 {
91 ColorDevice = ppd->color_device;
92 LanguageLevel = ppd->language_level;
93 }
94
2d35d8ee 95 if ((val = cupsGetOption("landscape", num_options, options)) != NULL)
96 Orientation = 1;
97
98 if ((val = cupsGetOption("orientation-requested", num_options, options)) != NULL)
99 {
100 /*
101 * Map IPP orientation values to 0 to 3:
102 *
103 * 3 = 0 degrees = 0
104 * 4 = 90 degrees = 1
105 * 5 = -90 degrees = 3
106 * 6 = 180 degrees = 2
107 */
108
109 Orientation = atoi(val) - 3;
110 if (Orientation >= 2)
111 Orientation ^= 1;
112 }
113
114 if ((val = cupsGetOption("page-left", num_options, options)) != NULL)
115 {
116 switch (Orientation)
117 {
118 case 0 :
119 PageLeft = (float)atof(val);
120 break;
121 case 1 :
122 PageBottom = (float)atof(val);
123 break;
124 case 2 :
125 PageRight = PageWidth - (float)atof(val);
126 break;
127 case 3 :
128 PageTop = PageLength - (float)atof(val);
129 break;
130 }
131 }
132
133 if ((val = cupsGetOption("page-right", num_options, options)) != NULL)
134 {
135 switch (Orientation)
136 {
137 case 0 :
138 PageRight = PageWidth - (float)atof(val);
139 break;
140 case 1 :
141 PageTop = PageLength - (float)atof(val);
142 break;
143 case 2 :
144 PageLeft = (float)atof(val);
145 break;
146 case 3 :
147 PageBottom = (float)atof(val);
148 break;
149 }
150 }
151
152 if ((val = cupsGetOption("page-bottom", num_options, options)) != NULL)
153 {
154 switch (Orientation)
155 {
156 case 0 :
157 PageBottom = (float)atof(val);
158 break;
159 case 1 :
71ec6979 160 PageLeft = (float)atof(val);
2d35d8ee 161 break;
162 case 2 :
163 PageTop = PageLength - (float)atof(val);
164 break;
165 case 3 :
71ec6979 166 PageRight = PageWidth - (float)atof(val);
2d35d8ee 167 break;
168 }
169 }
170
171 if ((val = cupsGetOption("page-top", num_options, options)) != NULL)
172 {
173 switch (Orientation)
174 {
175 case 0 :
176 PageTop = PageLength - (float)atof(val);
177 break;
178 case 1 :
71ec6979 179 PageRight = PageWidth - (float)atof(val);
2d35d8ee 180 break;
181 case 2 :
182 PageBottom = (float)atof(val);
183 break;
184 case 3 :
71ec6979 185 PageLeft = (float)atof(val);
2d35d8ee 186 break;
187 }
188 }
189
4e989042 190 if (change_size)
b5cb0608 191 UpdatePageVars();
2d35d8ee 192
193 if ((val = cupsGetOption("sides", num_options, options)) != NULL &&
a7b3e92e 194 strncasecmp(val, "two-", 4) == 0)
2d35d8ee 195 Duplex = 1;
c33207d6 196 else if ((val = cupsGetOption("Duplex", num_options, options)) != NULL &&
a7b3e92e 197 strncasecmp(val, "Duplex", 6) == 0)
c33207d6 198 Duplex = 1;
199 else if (ppdIsMarked(ppd, "Duplex", "DuplexNoTumble") ||
200 ppdIsMarked(ppd, "Duplex", "DuplexTumble"))
2d35d8ee 201 Duplex = 1;
ed19bd98 202
203 return (ppd);
2d35d8ee 204}
205
206
b5cb0608 207/*
208 * 'UpdatePageVars()' - Update the page variables for the orientation.
209 */
210
211void
212UpdatePageVars(void)
213{
214 float temp; /* Swapping variable */
215
216
217 switch (Orientation)
218 {
219 case 0 : /* Portait */
220 break;
221
222 case 1 : /* Landscape */
223 temp = PageLeft;
224 PageLeft = PageBottom;
225 PageBottom = temp;
226
227 temp = PageRight;
228 PageRight = PageTop;
229 PageTop = temp;
230
231 temp = PageWidth;
232 PageWidth = PageLength;
233 PageLength = temp;
234 break;
235
236 case 2 : /* Reverse Portrait */
237 temp = PageWidth - PageLeft;
238 PageLeft = PageWidth - PageRight;
239 PageRight = temp;
240
241 temp = PageLength - PageBottom;
242 PageBottom = PageLength - PageTop;
243 PageTop = temp;
244 break;
245
246 case 3 : /* Reverse Landscape */
247 temp = PageWidth - PageLeft;
248 PageLeft = PageWidth - PageRight;
249 PageRight = temp;
250
251 temp = PageLength - PageBottom;
252 PageBottom = PageLength - PageTop;
253 PageTop = temp;
254
255 temp = PageLeft;
256 PageLeft = PageBottom;
257 PageBottom = temp;
258
259 temp = PageRight;
260 PageRight = PageTop;
261 PageTop = temp;
262
263 temp = PageWidth;
264 PageWidth = PageLength;
265 PageLength = temp;
266 break;
267 }
268}
269
270
2d35d8ee 271/*
d11458ff 272 * 'WriteClassificationProlog()' - Write the prolog with the classification
273 * and page label.
274 */
275
276void
277WriteLabelProlog(const char *label) /* I - Page label */
278{
279 const char *classification; /* CLASSIFICATION environment variable */
280
281
282 /*
283 * First get the current classification...
284 */
285
286 if ((classification = getenv("CLASSIFICATION")) == NULL)
287 classification = "";
288 if (strcmp(classification, "none") == 0)
289 classification = "";
290
16566558 291 /*
292 * If there is nothing to show, bind an empty 'write labels' procedure
293 * and return...
294 */
295
41e45833 296 if (!classification[0] && (label == NULL || !label[0]))
16566558 297 {
298 puts("/espWL{}bind def");
299 return;
300 }
301
d11458ff 302 /*
303 * Set the classification + page label string...
304 */
305
306 if (strcmp(classification, "confidential") == 0)
307 printf("/espPL(CONFIDENTIAL");
308 else if (strcmp(classification, "classified") == 0)
309 printf("/espPL(CLASSIFIED");
310 else if (strcmp(classification, "secret") == 0)
311 printf("/espPL(SECRET");
312 else if (strcmp(classification, "topsecret") == 0)
313 printf("/espPL(TOP SECRET");
314 else if (strcmp(classification, "unclassified") == 0)
315 printf("/espPL(UNCLASSIFIED");
316 else
317 printf("/espPL(");
318
319 if (classification[0] && label)
320 printf(" - %s)def\n", label);
321 else if (label)
322 printf("%s)def\n", label);
323 else
324 puts(")def");
325
326 /*
327 * Then get a 14 point Helvetica-Bold font...
328 */
329
330 puts("/espPF /Helvetica-Bold findfont 14 scalefont def");
331
332 /*
333 * Finally, the procedure to write the labels on the page...
334 */
335
336 puts("/espWL{");
337 puts(" espPF setfont");
338 printf(" espPL stringwidth pop dup 12 add exch -0.5 mul %.0f add\n",
339 PageWidth * 0.5f);
340 puts(" 1 setgray");
341 printf(" dup 6 sub %.0f 3 index 20 rectfill\n", PageBottom - 2.0);
342 printf(" dup 6 sub %.0f 3 index 20 rectfill\n", PageTop - 18.0);
343 puts(" 0 setgray");
344 printf(" dup 6 sub %.0f 3 index 20 rectstroke\n", PageBottom - 2.0);
345 printf(" dup 6 sub %.0f 3 index 20 rectstroke\n", PageTop - 18.0);
346 printf(" dup %.0f moveto espPL show\n", PageBottom + 2.0);
347 printf(" %.0f moveto espPL show\n", PageTop - 14.0);
348 puts("pop");
349 puts("}bind def");
350}
351
352
353/*
b5cb0608 354 * End of "$Id: common.c,v 1.15.2.1 2001/05/13 18:38:18 mike Exp $".
2d35d8ee 355 */