]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/common.c
2 * "$Id: common.c,v 1.31 2004/02/25 20:14:51 mike Exp $"
4 * Common filter routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2004 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * SetCommonOptions() - Set common filter options for media size,
30 * UpdatePageVars() - Update the page variables for the orientation.
31 * WriteCommon() - Write common procedures...
32 * WriteLabelProlog() - Write the prolog with the classification
34 * WriteLabels() - Write the actual page labels.
38 * Include necessary headers...
49 int Orientation
= 0, /* 0 = portrait, 1 = landscape, etc. */
50 Duplex
= 0, /* Duplexed? */
51 LanguageLevel
= 1, /* Language level of printer */
52 ColorDevice
= 1; /* Do color text? */
53 float PageLeft
= 18.0f
, /* Left margin */
54 PageRight
= 594.0f
, /* Right margin */
55 PageBottom
= 36.0f
, /* Bottom margin */
56 PageTop
= 756.0f
, /* Top margin */
57 PageWidth
= 612.0f
, /* Total page width */
58 PageLength
= 792.0f
; /* Total page length */
62 * 'SetCommonOptions()' - Set common filter options for media size, etc.
65 ppd_file_t
* /* O - PPD file */
66 SetCommonOptions(int num_options
, /* I - Number of options */
67 cups_option_t
*options
, /* I - Options */
68 int change_size
) /* I - Change page size? */
70 ppd_file_t
*ppd
; /* PPD file */
71 ppd_size_t
*pagesize
; /* Current page size */
72 const char *val
; /* Option value */
76 setlocale(LC_TIME
, "");
79 ppd
= ppdOpenFile(getenv("PPD"));
82 cupsMarkOptions(ppd
, num_options
, options
);
84 if ((pagesize
= ppdPageSize(ppd
, NULL
)) != NULL
)
86 PageWidth
= pagesize
->width
;
87 PageLength
= pagesize
->length
;
88 PageTop
= pagesize
->top
;
89 PageBottom
= pagesize
->bottom
;
90 PageLeft
= pagesize
->left
;
91 PageRight
= pagesize
->right
;
93 fprintf(stderr
, "DEBUG: Page = %.0fx%.0f; %.0f,%.0f to %.0f,%.0f\n",
94 PageWidth
, PageLength
, PageLeft
, PageBottom
, PageRight
, PageTop
);
99 ColorDevice
= ppd
->color_device
;
100 LanguageLevel
= ppd
->language_level
;
103 if ((val
= cupsGetOption("landscape", num_options
, options
)) != NULL
)
105 if (strcasecmp(val
, "no") != 0 && strcasecmp(val
, "off") != 0 &&
106 strcasecmp(val
, "false") != 0)
108 if (ppd
&& ppd
->landscape
> 0)
114 else if ((val
= cupsGetOption("orientation-requested", num_options
, options
)) != NULL
)
117 * Map IPP orientation values to 0 to 3:
121 * 5 = -90 degrees = 3
122 * 6 = 180 degrees = 2
125 Orientation
= atoi(val
) - 3;
126 if (Orientation
>= 2)
130 if ((val
= cupsGetOption("page-left", num_options
, options
)) != NULL
)
132 switch (Orientation
& 3)
135 PageLeft
= (float)atof(val
);
138 PageBottom
= (float)atof(val
);
141 PageRight
= PageWidth
- (float)atof(val
);
144 PageTop
= PageLength
- (float)atof(val
);
149 if ((val
= cupsGetOption("page-right", num_options
, options
)) != NULL
)
151 switch (Orientation
& 3)
154 PageRight
= PageWidth
- (float)atof(val
);
157 PageTop
= PageLength
- (float)atof(val
);
160 PageLeft
= (float)atof(val
);
163 PageBottom
= (float)atof(val
);
168 if ((val
= cupsGetOption("page-bottom", num_options
, options
)) != NULL
)
170 switch (Orientation
& 3)
173 PageBottom
= (float)atof(val
);
176 PageLeft
= (float)atof(val
);
179 PageTop
= PageLength
- (float)atof(val
);
182 PageRight
= PageWidth
- (float)atof(val
);
187 if ((val
= cupsGetOption("page-top", num_options
, options
)) != NULL
)
189 switch (Orientation
& 3)
192 PageTop
= PageLength
- (float)atof(val
);
195 PageRight
= PageWidth
- (float)atof(val
);
198 PageBottom
= (float)atof(val
);
201 PageLeft
= (float)atof(val
);
209 if (ppdIsMarked(ppd
, "Duplex", "DuplexNoTumble") ||
210 ppdIsMarked(ppd
, "Duplex", "DuplexTumble") ||
211 ppdIsMarked(ppd
, "JCLDuplex", "DuplexNoTumble") ||
212 ppdIsMarked(ppd
, "JCLDuplex", "DuplexTumble") ||
213 ppdIsMarked(ppd
, "EFDuplex", "DuplexNoTumble") ||
214 ppdIsMarked(ppd
, "EFDuplex", "DuplexTumble") ||
215 ppdIsMarked(ppd
, "KD03Duplex", "DuplexNoTumble") ||
216 ppdIsMarked(ppd
, "KD03Duplex", "DuplexTumble"))
224 * 'UpdatePageVars()' - Update the page variables for the orientation.
230 float temp
; /* Swapping variable */
233 switch (Orientation
& 3)
235 case 0 : /* Portait */
238 case 1 : /* Landscape */
240 PageLeft
= PageBottom
;
248 PageWidth
= PageLength
;
252 case 2 : /* Reverse Portrait */
253 temp
= PageWidth
- PageLeft
;
254 PageLeft
= PageWidth
- PageRight
;
257 temp
= PageLength
- PageBottom
;
258 PageBottom
= PageLength
- PageTop
;
262 case 3 : /* Reverse Landscape */
263 temp
= PageWidth
- PageLeft
;
264 PageLeft
= PageWidth
- PageRight
;
267 temp
= PageLength
- PageBottom
;
268 PageBottom
= PageLength
- PageTop
;
272 PageLeft
= PageBottom
;
280 PageWidth
= PageLength
;
288 * 'WriteCommon()' - Write common procedures...
294 puts("% x y w h ESPrc - Clip to a rectangle.\n"
295 "userdict/ESPrc/rectclip where{pop/rectclip load}\n"
296 "{{newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
297 "neg 0 rlineto closepath clip newpath}bind}ifelse put");
298 puts("% x y w h ESPrf - Fill a rectangle.\n"
299 "userdict/ESPrf/rectfill where{pop/rectfill load}\n"
300 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
301 "neg 0 rlineto closepath fill grestore}bind}ifelse put");
302 puts("% x y w h ESPrs - Stroke a rectangle.\n"
303 "userdict/ESPrs/rectstroke where{pop/rectstroke load}\n"
304 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
305 "neg 0 rlineto closepath stroke grestore}bind}ifelse put");
310 * 'WriteLabelProlog()' - Write the prolog with the classification
315 WriteLabelProlog(const char *label
, /* I - Page label */
316 float bottom
, /* I - Bottom position in points */
317 float top
, /* I - Top position in points */
318 float width
) /* I - Width in points */
320 const char *classification
; /* CLASSIFICATION environment variable */
321 const char *ptr
; /* Temporary string pointer */
325 * First get the current classification...
328 if ((classification
= getenv("CLASSIFICATION")) == NULL
)
330 if (strcmp(classification
, "none") == 0)
334 * If there is nothing to show, bind an empty 'write labels' procedure
338 if (!classification
[0] && (label
== NULL
|| !label
[0]))
340 puts("userdict/ESPwl{}bind put");
345 * Set the classification + page label string...
349 if (strcmp(classification
, "confidential") == 0)
350 printf("/ESPpl(CONFIDENTIAL");
351 else if (strcmp(classification
, "classified") == 0)
352 printf("/ESPpl(CLASSIFIED");
353 else if (strcmp(classification
, "secret") == 0)
354 printf("/ESPpl(SECRET");
355 else if (strcmp(classification
, "topsecret") == 0)
356 printf("/ESPpl(TOP SECRET");
357 else if (strcmp(classification
, "unclassified") == 0)
358 printf("/ESPpl(UNCLASSIFIED");
363 for (ptr
= classification
; *ptr
; ptr
++)
364 if (*ptr
< 32 || *ptr
> 126)
365 printf("\\%03o", *ptr
);
366 else if (*ptr
== '_')
370 if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
379 if (classification
[0])
383 * Quote the label string as needed...
386 for (ptr
= label
; *ptr
; ptr
++)
387 if (*ptr
< 32 || *ptr
> 126)
388 printf("\\%03o", *ptr
);
391 if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
401 * Then get a 14 point Helvetica-Bold font...
404 puts("userdict/ESPpf /Helvetica-Bold findfont 14 scalefont put");
407 * Finally, the procedure to write the labels on the page...
410 puts("userdict/ESPwl{");
411 puts(" ESPpf setfont");
412 printf(" ESPpl stringwidth pop dup 12 add exch -0.5 mul %.0f add\n",
415 printf(" dup 6 sub %.0f 3 index 20 ESPrf\n", bottom
- 2.0);
416 printf(" dup 6 sub %.0f 3 index 20 ESPrf\n", top
- 18.0);
418 printf(" dup 6 sub %.0f 3 index 20 ESPrs\n", bottom
- 2.0);
419 printf(" dup 6 sub %.0f 3 index 20 ESPrs\n", top
- 18.0);
420 printf(" dup %.0f moveto ESPpl show\n", bottom
+ 2.0);
421 printf(" %.0f moveto ESPpl show\n", top
- 14.0);
428 * 'WriteLabels()' - Write the actual page labels.
432 WriteLabels(int orient
) /* I - Orientation of the page */
434 float width
, /* Width of page */
435 length
; /* Length of page */
440 if ((orient
^ Orientation
) & 1)
453 case 1 : /* Landscape */
454 printf("%.1f 0.0 translate 90 rotate\n", length
);
456 case 2 : /* Reverse Portrait */
457 printf("%.1f %.1f translate 180 rotate\n", width
, length
);
459 case 3 : /* Reverse Landscape */
460 printf("0.0 %.1f translate -90 rotate\n", width
);
470 * End of "$Id: common.c,v 1.31 2004/02/25 20:14:51 mike Exp $".