4 * Banner to PostScript filter for CUPS.
6 * Copyright 2008-2010 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * main() - Generate PostScript cover pages.
19 * load_banner() - Load the banner file.
20 * ps_ascii85() - Print binary data as a series of base-85 numbers.
21 * write_banner() - Write a banner page...
22 * write_epilogue() - Write the PostScript file epilogue.
23 * write_prolog() - Write the PostScript file prolog with options.
27 * Include necessary headers...
32 #include <cups/language-private.h>
39 #define SHOW_IMAGEABLE_AREA 1 /* Show imageable area */
40 #define SHOW_JOB_BILLING 2 /* Show billing string */
41 #define SHOW_JOB_ID 4 /* Show job ID */
42 #define SHOW_JOB_NAME 8 /* Show job title */
43 #define SHOW_JOB_ORIGINATING_USER_NAME 16 /* Show owner of job */
44 #define SHOW_JOB_ORIGINATING_HOST_NAME 32 /* Show submitting system */
45 #define SHOW_JOB_UUID 64 /* Show job UUID */
46 #define SHOW_OPTIONS 128 /* Show print options */
47 #define SHOW_PAPER_NAME 256 /* Show paper size name */
48 #define SHOW_PAPER_SIZE 512 /* Show paper dimensions */
49 #define SHOW_PRINTER_DRIVER_NAME 1024 /* Show printer driver name */
50 #define SHOW_PRINTER_DRIVER_VERSION 2048 /* Show printer driver version */
51 #define SHOW_PRINTER_INFO 4096 /* Show printer description */
52 #define SHOW_PRINTER_LOCATION 8192 /* Show printer location */
53 #define SHOW_PRINTER_MAKE_AND_MODEL 16384 /* Show printer make and model */
54 #define SHOW_PRINTER_NAME 32768 /* Show printer queue ID */
55 #define SHOW_TIME_AT_CREATION 65536 /* Show date/time when submitted */
56 #define SHOW_TIME_AT_PROCESSING 131072 /* Show date/time when printed */
63 typedef struct banner_file_s
/**** Banner file data ****/
65 int show
; /* What to show */
66 char *header
, /* Header text */
67 *footer
; /* Footer text */
68 cups_array_t
*notices
, /* Notices to show */
69 *images
; /* Images to show */
77 static banner_file_t
*load_banner(const char *filename
);
78 static int write_banner(banner_file_t
*banner
, ppd_file_t
*ppd
,
79 ps_text_t
*fonts
, int job_id
,
80 const char *title
, const char *username
,
81 int num_options
, cups_option_t
*options
);
82 static void write_epilogue(int num_pages
);
83 static ps_text_t
*write_prolog(const char *title
, const char *user
);
87 * 'main()' - Generate PostScript cover pages.
90 int /* O - Exit status */
91 main(int argc
, /* I - Number of command-line args */
92 char *argv
[]) /* I - Command-line arguments */
94 banner_file_t
*banner
; /* Banner file data */
95 int num_options
; /* Number of print options */
96 cups_option_t
*options
; /* Print options */
97 ppd_file_t
*ppd
; /* PPD file */
98 ps_text_t
*fonts
; /* Fonts for output */
99 int job_id
; /* Job ID from command-line */
100 const char *title
, /* Title from command-line */
101 *username
; /* Username from command-line */
102 int num_pages
; /* Number of pages printed */
106 * Make sure status messages are not buffered...
109 setbuf(stderr
, NULL
);
112 * Check command-line...
115 if (argc
< 6 || argc
> 7)
117 _cupsLangPrintf(stderr
,
118 _("Usage: %s job-id user title copies options file"),
124 * Get stuff from command-line...
127 job_id
= atoi(argv
[1]);
131 num_options
= cupsParseOptions(argv
[5], 0, &options
);
132 banner
= load_banner(argv
[6]);
135 * Set standard options and get the PPD file for this printer...
138 ppd
= SetCommonOptions(num_options
, options
, 1);
141 * Write a PostScript banner document and return...
144 fonts
= write_prolog(title
, username
);
145 num_pages
= write_banner(banner
, ppd
, fonts
, job_id
, title
, username
,
146 num_options
, options
);
148 write_epilogue(num_pages
);
155 * 'load_banner()' - Load the banner file.
158 static banner_file_t
* /* O - Banner file data */
159 load_banner(const char *filename
) /* I - Filename or NULL for stdin */
161 cups_file_t
*fp
; /* File */
162 char line
[2048], /* Line buffer */
163 *ptr
; /* Pointer into line */
164 int linenum
; /* Current line number */
165 banner_file_t
*banner
; /* Banner file data */
166 const char *cups_docroot
; /* CUPS_DOCROOT environment variable */
169 fprintf(stderr
, "DEBUG: load_banner(filename=\"%s\")\n",
170 filename
? filename
: "(stdin)");
173 * Open the banner file...
177 fp
= cupsFileOpen(filename
, "r");
179 fp
= cupsFileStdin();
183 _cupsLangPrintError("ERROR", _("Unable to open print file"));
188 * Read the banner file...
191 if ((cups_docroot
= getenv("CUPS_DOCROOT")) == NULL
)
192 cups_docroot
= CUPS_DOCROOT
;
194 banner
= calloc(1, sizeof(banner_file_t
));
197 while (cupsFileGets(fp
, line
, sizeof(line
)))
200 * Skip blank and comment lines...
205 if (line
[0] == '#' || !line
[0])
209 * Break the line into keyword and value parts...
212 for (ptr
= line
; *ptr
&& !isspace(*ptr
& 255); ptr
++);
214 while (isspace(*ptr
& 255))
219 _cupsLangPrintFilter(stderr
, "ERROR",
220 _("Missing value on line %d of banner file."),
226 * Save keyword values in the appropriate places...
229 if (!strcasecmp(line
, "Footer"))
232 fprintf(stderr
, "DEBUG: Extra \"Footer\" on line %d of banner file\n",
235 banner
->footer
= strdup(ptr
);
237 else if (!strcasecmp(line
, "Header"))
240 fprintf(stderr
, "DEBUG: Extra \"Header\" on line %d of banner file\n",
243 banner
->header
= strdup(ptr
);
245 else if (!strcasecmp(line
, "Image"))
247 char imagefile
[1024]; /* Image filename */
251 strlcpy(imagefile
, ptr
, sizeof(imagefile
));
253 snprintf(imagefile
, sizeof(imagefile
), "%s/%s", cups_docroot
, ptr
);
255 if (access(imagefile
, R_OK
))
257 fprintf(stderr
, "DEBUG: Image \"%s\" on line %d of banner file: %s\n",
258 ptr
, linenum
, strerror(errno
));
263 banner
->images
= cupsArrayNew(NULL
, NULL
);
265 cupsArrayAdd(banner
->images
, strdup(imagefile
));
268 else if (!strcasecmp(line
, "Notice"))
270 if (!banner
->notices
)
271 banner
->notices
= cupsArrayNew(NULL
, NULL
);
273 cupsArrayAdd(banner
->notices
, strdup(ptr
));
275 else if (!strcasecmp(line
, "Show"))
277 char *value
; /* Current value */
280 for (value
= ptr
; *value
; value
= ptr
)
283 * Find the end of the current value
286 while (*ptr
&& !isspace(*ptr
& 255))
289 while (*ptr
&& isspace(*ptr
& 255))
293 * Add the value to the show flags...
295 if (!strcasecmp(value
, "imageable-area"))
296 banner
->show
|= SHOW_IMAGEABLE_AREA
;
297 else if (!strcasecmp(value
, "job-billing"))
298 banner
->show
|= SHOW_JOB_BILLING
;
299 else if (!strcasecmp(value
, "job-id"))
300 banner
->show
|= SHOW_JOB_ID
;
301 else if (!strcasecmp(value
, "job-name"))
302 banner
->show
|= SHOW_JOB_NAME
;
303 else if (!strcasecmp(value
, "job-originating-host-name"))
304 banner
->show
|= SHOW_JOB_ORIGINATING_HOST_NAME
;
305 else if (!strcasecmp(value
, "job-originating-user-name"))
306 banner
->show
|= SHOW_JOB_ORIGINATING_USER_NAME
;
307 else if (!strcasecmp(value
, "job-uuid"))
308 banner
->show
|= SHOW_JOB_UUID
;
309 else if (!strcasecmp(value
, "options"))
310 banner
->show
|= SHOW_OPTIONS
;
311 else if (!strcasecmp(value
, "paper-name"))
312 banner
->show
|= SHOW_PAPER_NAME
;
313 else if (!strcasecmp(value
, "paper-size"))
314 banner
->show
|= SHOW_PAPER_SIZE
;
315 else if (!strcasecmp(value
, "printer-driver-name"))
316 banner
->show
|= SHOW_PRINTER_DRIVER_NAME
;
317 else if (!strcasecmp(value
, "printer-driver-version"))
318 banner
->show
|= SHOW_PRINTER_DRIVER_VERSION
;
319 else if (!strcasecmp(value
, "printer-info"))
320 banner
->show
|= SHOW_PRINTER_INFO
;
321 else if (!strcasecmp(value
, "printer-location"))
322 banner
->show
|= SHOW_PRINTER_LOCATION
;
323 else if (!strcasecmp(value
, "printer-make-and-model"))
324 banner
->show
|= SHOW_PRINTER_MAKE_AND_MODEL
;
325 else if (!strcasecmp(value
, "printer-name"))
326 banner
->show
|= SHOW_PRINTER_NAME
;
327 else if (!strcasecmp(value
, "time-at-creation"))
328 banner
->show
|= SHOW_TIME_AT_CREATION
;
329 else if (!strcasecmp(value
, "time-at-processing"))
330 banner
->show
|= SHOW_TIME_AT_PROCESSING
;
334 "DEBUG: Unknown \"Show\" value \"%s\" on line %d of banner "
335 "file\n", value
, linenum
);
340 fprintf(stderr
, "DEBUG: Unknown key \"%s\" on line %d of banner file\n",
352 * 'ps_ascii85()' - Print binary data as a series of base-85 numbers.
356 ps_ascii85(cups_ib_t
*data
, /* I - Data to print */
357 int length
, /* I - Number of bytes to print */
358 int last_line
) /* I - Last line of raster data? */
360 unsigned b
; /* Binary data word */
361 unsigned char c
[5]; /* ASCII85 encoded chars */
362 static int col
= 0; /* Current column */
367 b
= (((((data
[0] << 8) | data
[1]) << 8) | data
[2]) << 8) | data
[3];
376 c
[4] = (b
% 85) + '!';
378 c
[3] = (b
% 85) + '!';
380 c
[2] = (b
% 85) + '!';
382 c
[1] = (b
% 85) + '!';
386 fwrite(c
, 5, 1, stdout
);
404 memset(data
+ length
, 0, 4 - length
);
405 b
= (((((data
[0] << 8) | data
[1]) << 8) | data
[2]) << 8) | data
[3];
407 c
[4] = (b
% 85) + '!';
409 c
[3] = (b
% 85) + '!';
411 c
[2] = (b
% 85) + '!';
413 c
[1] = (b
% 85) + '!';
417 fwrite(c
, length
+ 1, 1, stdout
);
427 * 'write_banner()' - Write a banner page...
430 static int /* O - Number of pages */
431 write_banner(banner_file_t
*banner
, /* I - Banner file */
432 ppd_file_t
*ppd
, /* I - PPD file */
433 ps_text_t
*fonts
, /* I - Fonts */
434 int job_id
, /* I - Job ID */
435 const char *title
, /* I - Title of job */
436 const char *username
, /* I - Owner of job */
437 int num_options
, /* I - Number of options */
438 cups_option_t
*options
) /* I - Options */
440 char *notice
; /* Current notice */
441 char *imagefile
; /* Current image file */
442 cups_array_t
*images
; /* Images */
443 cups_image_t
*image
; /* Current image */
444 const char *option
; /* Option value */
445 int i
, j
; /* Looping vars */
446 float x
, /* Current X position */
447 y
; /* Current Y position */
448 cups_lang_t
*language
; /* Default language */
449 int showlines
; /* Number of lines to show */
450 float fontsize
; /* Font size to use */
451 int num_pages
; /* Number of pages */
452 float print_width
, /* Printable width of page */
453 print_height
, /* Printable height of page */
454 info_top
, /* Top of info fields */
455 info_height
, /* Height of info fields */
456 line_height
, /* Height of info lines */
457 notices_height
, /* Height of all notices */
458 images_width
, /* Width of all images */
459 images_height
, /* Height of all images */
460 total_height
; /* Height of all content */
461 char text
[1024]; /* Formatted field text */
465 * Figure out how many lines of text will be shown...
469 if (banner
->show
& SHOW_IMAGEABLE_AREA
)
471 if (banner
->show
& SHOW_JOB_BILLING
)
473 if (banner
->show
& SHOW_JOB_ID
)
475 if (banner
->show
& SHOW_JOB_NAME
)
477 if (banner
->show
& SHOW_JOB_ORIGINATING_USER_NAME
)
479 if (banner
->show
& SHOW_JOB_ORIGINATING_HOST_NAME
)
481 if (banner
->show
& SHOW_JOB_UUID
)
483 if (banner
->show
& SHOW_OPTIONS
)
485 for (j
= 0; j
< num_options
; j
++)
487 if (strcasecmp("media", options
[j
].name
) &&
488 strcasecmp("PageSize", options
[j
].name
) &&
489 strcasecmp("PageRegion", options
[j
].name
) &&
490 strcasecmp("InputSlot", options
[j
].name
) &&
491 strcasecmp("MediaType", options
[j
].name
) &&
492 strcasecmp("finishings", options
[j
].name
) &&
493 strcasecmp("sides", options
[j
].name
) &&
494 strcasecmp("Duplex", options
[j
].name
) &&
495 strcasecmp("orientation-requested", options
[j
].name
) &&
496 strcasecmp("landscape", options
[j
].name
) &&
497 strcasecmp("number-up", options
[j
].name
) &&
498 strcasecmp("OutputOrder", options
[j
].name
))
504 if (banner
->show
& SHOW_PAPER_NAME
)
506 if (banner
->show
& SHOW_PAPER_SIZE
)
508 if (banner
->show
& SHOW_PRINTER_DRIVER_NAME
)
510 if (banner
->show
& SHOW_PRINTER_DRIVER_VERSION
)
512 if (banner
->show
& SHOW_PRINTER_INFO
)
514 if (banner
->show
& SHOW_PRINTER_LOCATION
)
516 if (banner
->show
& SHOW_PRINTER_MAKE_AND_MODEL
)
518 if (banner
->show
& SHOW_PRINTER_NAME
)
520 if (banner
->show
& SHOW_TIME_AT_CREATION
)
522 if (banner
->show
& SHOW_TIME_AT_PROCESSING
)
526 * Figure out the dimensions and positions of everything...
529 print_width
= PageRight
- PageLeft
;
530 print_height
= PageTop
- PageBottom
;
531 fontsize
= print_height
/ 60; /* Nominally 12pts */
532 line_height
= 1.2 * fontsize
;
533 info_height
= showlines
* line_height
;
534 notices_height
= cupsArrayCount(banner
->notices
) * line_height
;
536 if (cupsArrayCount(banner
->images
))
538 images
= cupsArrayNew(NULL
, NULL
);
539 images_height
= print_height
/ 10; /* Nominally 1" */
541 for (imagefile
= (char *)cupsArrayFirst(banner
->images
), images_width
= 0.0;
543 imagefile
= (char *)cupsArrayNext(banner
->images
))
545 if ((image
= cupsImageOpen(imagefile
, ColorDevice
? CUPS_IMAGE_RGB_CMYK
:
547 CUPS_IMAGE_WHITE
, 100, 0, NULL
)) == NULL
)
549 fprintf(stderr
, "DEBUG: Unable to open image file \"%s\"\n",
554 images_width
+= cupsImageGetWidth(image
) * images_height
/
555 cupsImageGetHeight(image
);
556 cupsArrayAdd(images
, image
);
566 total_height
= info_height
+ notices_height
+ images_height
;
567 if (cupsArrayCount(banner
->notices
) && showlines
)
568 total_height
+= 2 * line_height
;
569 if (cupsArrayCount(banner
->images
) &&
570 (showlines
|| cupsArrayCount(banner
->notices
)))
571 total_height
+= 2 * line_height
;
573 info_top
= 0.5 * (print_height
+ total_height
);
576 * Write the page(s)...
579 language
= cupsLangDefault();
580 num_pages
= Duplex
? 2 : 1;
582 for (i
= 1; i
<= num_pages
; i
++)
588 printf("%%%%Page: %s %d\n", i
== 1 ? "coverpage" : "coverback", i
);
591 printf("%.1f %.1f translate\n", PageLeft
, PageBottom
);
593 printf("%.1f %.1f translate\n", PageWidth
- PageRight
,
594 PageLength
- PageTop
);
605 x
= 0.33 * print_width
;
607 if (banner
->show
& SHOW_PRINTER_NAME
)
609 printf("%.1f %.1f moveto", x
, y
);
611 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
612 _cupsLangString(language
, _("Printer Name: ")));
613 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, getenv("PRINTER"));
615 if (banner
->show
& SHOW_JOB_ID
)
617 snprintf(text
, sizeof(text
), "%s-%d", getenv("PRINTER"), job_id
);
618 printf("%.1f %.1f moveto", x
, y
);
620 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
621 _cupsLangString(language
, _("Job ID: ")));
622 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
624 if (banner
->show
& SHOW_JOB_UUID
)
626 printf("%.1f %.1f moveto", x
, y
);
628 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
629 _cupsLangString(language
, _("Job UUID: ")));
630 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
631 cupsGetOption("job-uuid", num_options
, options
));
633 if (banner
->show
& SHOW_JOB_NAME
)
635 printf("%.1f %.1f moveto", x
, y
);
637 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
638 _cupsLangString(language
, _("Title: ")));
639 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, title
);
641 if (banner
->show
& SHOW_JOB_ORIGINATING_USER_NAME
)
643 printf("%.1f %.1f moveto", x
, y
);
645 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
646 _cupsLangString(language
, _("Printed For: ")));
647 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, username
);
649 if (banner
->show
& SHOW_JOB_ORIGINATING_HOST_NAME
)
651 printf("%.1f %.1f moveto", x
, y
);
653 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
654 _cupsLangString(language
, _("Printed From: ")));
655 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
656 cupsGetOption("job-originating-host-name", num_options
,
659 if (banner
->show
& SHOW_JOB_BILLING
)
661 printf("%.1f %.1f moveto", x
, y
);
663 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
664 _cupsLangString(language
, _("Billing Information: ")));
665 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
666 cupsGetOption("job-billing", num_options
, options
));
668 if (banner
->show
& SHOW_OPTIONS
)
670 printf("%.1f %.1f moveto", x
, y
);
671 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
672 _cupsLangString(language
, _("Options: ")));
674 for (j
= 0; j
< num_options
; j
++)
676 if (strcasecmp("media", options
[j
].name
) &&
677 strcasecmp("PageSize", options
[j
].name
) &&
678 strcasecmp("PageRegion", options
[j
].name
) &&
679 strcasecmp("InputSlot", options
[j
].name
) &&
680 strcasecmp("MediaType", options
[j
].name
) &&
681 strcasecmp("finishings", options
[j
].name
) &&
682 strcasecmp("sides", options
[j
].name
) &&
683 strcasecmp("Duplex", options
[j
].name
) &&
684 strcasecmp("orientation-requested", options
[j
].name
) &&
685 strcasecmp("landscape", options
[j
].name
) &&
686 strcasecmp("number-up", options
[j
].name
) &&
687 strcasecmp("OutputOrder", options
[j
].name
))
690 if (!strcasecmp("landscape", options
[j
].name
))
691 strlcpy(text
, "orientation-requested=landscape", sizeof(text
));
692 else if (!strcasecmp("orientation-requested", options
[j
].name
))
694 switch (atoi(options
[j
].value
))
698 strlcpy(text
, "orientation-requested=portrait",
703 strlcpy(text
, "orientation-requested=landscape",
707 case IPP_REVERSE_PORTRAIT
:
708 strlcpy(text
, "orientation-requested=reverse-portrait",
712 case IPP_REVERSE_LANDSCAPE
:
713 strlcpy(text
, "orientation-requested=reverse-landscape",
719 snprintf(text
, sizeof(text
), "%s=%s", options
[j
].name
,
722 printf("%.1f %.1f moveto", x
, y
);
724 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
728 if (banner
->show
& SHOW_PRINTER_INFO
)
730 printf("%.1f %.1f moveto", x
, y
);
732 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
733 _cupsLangString(language
, _("Description: ")));
734 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
735 getenv("PRINTER_INFO"));
737 if (banner
->show
& SHOW_PRINTER_LOCATION
)
739 printf("%.1f %.1f moveto", x
, y
);
741 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
742 _cupsLangString(language
, _("Location: ")));
743 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
744 getenv("PRINTER_LOCATION"));
746 if (banner
->show
& SHOW_PRINTER_MAKE_AND_MODEL
)
748 printf("%.1f %.1f moveto", x
, y
);
750 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
751 _cupsLangString(language
, _("Make and Model: ")));
752 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
753 ppd
? ppd
->nickname
: NULL
);
756 if (banner
->show
& SHOW_PAPER_NAME
)
758 if ((option
= cupsGetOption("media", num_options
, options
)) == NULL
)
759 if ((option
= cupsGetOption("PageSize", num_options
, options
)) == NULL
)
760 if ((option
= cupsGetOption("PageRegion", num_options
,
764 printf("%.1f %.1f moveto", x
, y
);
766 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
767 _cupsLangString(language
, _("Media Name: ")));
768 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, option
);
770 if (banner
->show
& SHOW_PAPER_SIZE
)
772 snprintf(text
, sizeof(text
),
773 _cupsLangString(language
, _("%.2f x %.2f inches")),
774 PageWidth
/ 72.0, PageLength
/ 72.0);
775 printf("%.1f %.1f moveto", x
, y
);
777 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
778 _cupsLangString(language
, _("Media Dimensions: ")));
779 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
781 snprintf(text
, sizeof(text
),
782 _cupsLangString(language
, _("%.0f x %.0f millimeters")),
783 PageWidth
* 25.4 / 72.0, PageLength
* 25.4 / 72.0);
784 printf("%.1f %.1f moveto", x
, y
);
786 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
788 if (banner
->show
& SHOW_IMAGEABLE_AREA
)
790 snprintf(text
, sizeof(text
),
791 _cupsLangString(language
,
792 _("%.2f x %.2f to %.2f x %.2f inches")),
793 PageLeft
/ 72.0, PageBottom
/ 72.0,
794 PageRight
/ 72.0, PageTop
/ 72.0);
795 printf("%.1f %.1f moveto", x
, y
);
797 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
798 _cupsLangString(language
, _("Media Limits: ")));
799 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
801 snprintf(text
, sizeof(text
),
802 _cupsLangString(language
,
803 _("%.0f x %.0f to %.0f x %.0f millimeters")),
804 PageLeft
* 25.4 / 72.0, PageBottom
* 25.4 / 72.0,
805 PageRight
* 25.4 / 72.0, PageTop
* 25.4 / 72.0);
806 printf("%.1f %.1f moveto", x
, y
);
808 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
810 printf("gsave 2 setlinewidth 1 1 %.1f %.1f rectstroke grestore\n",
811 print_width
- 2.0, print_height
- 2.0);
813 if (banner
->show
& SHOW_PRINTER_DRIVER_NAME
)
815 printf("%.1f %.1f moveto", x
, y
);
817 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
818 _cupsLangString(language
, _("Driver Name: ")));
819 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
820 ppd
? ppd
->pcfilename
: NULL
);
822 if (banner
->show
& SHOW_PRINTER_DRIVER_VERSION
)
824 ppd_attr_t
*file_version
= ppdFindAttr(ppd
, "FileVersion", NULL
);
826 printf("%.1f %.1f moveto", x
, y
);
828 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
829 _cupsLangString(language
, _("Driver Version: ")));
830 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
,
831 file_version
? file_version
->value
: NULL
);
833 if (banner
->show
& SHOW_TIME_AT_CREATION
)
835 if ((option
= cupsGetOption("time-at-creation", num_options
,
838 time_t curtime
; /* Current time */
839 struct tm
*curdate
; /* Current date */
841 curtime
= (time_t)atoi(option
);
842 curdate
= localtime(&curtime
);
844 strftime(text
, sizeof(text
), "%c", curdate
);
847 strlcpy(text
, "?", sizeof(text
));
849 printf("%.1f %.1f moveto", x
, y
);
851 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
852 _cupsLangString(language
, _("Created On: ")));
853 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
855 if (banner
->show
& SHOW_TIME_AT_PROCESSING
)
857 if ((option
= cupsGetOption("time-at-processing", num_options
,
860 time_t curtime
; /* Current time */
861 struct tm
*curdate
; /* Current date */
863 curtime
= (time_t)atoi(option
);
864 curdate
= localtime(&curtime
);
866 strftime(text
, sizeof(text
), "%c", curdate
);
869 strlcpy(text
, "?", sizeof(text
));
871 printf("%.1f %.1f moveto", x
, y
);
873 psTextUTF8(fonts
, fontsize
, PS_BOLD
, PS_RIGHT
,
874 _cupsLangString(language
, _("Printed On: ")));
875 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_LEFT
, text
);
883 if (cupsArrayCount(banner
->notices
))
886 y
-= 2 * line_height
;
888 x
= 0.5 * print_width
;
890 for (notice
= (char *)cupsArrayFirst(banner
->notices
);
892 notice
= (char *)cupsArrayNext(banner
->notices
))
894 printf("%.1f %.1f moveto", x
, y
);
896 psTextUTF8(fonts
, fontsize
, PS_NORMAL
, PS_CENTER
, notice
);
904 if (cupsArrayCount(images
))
906 if (banner
->show
|| cupsArrayCount(banner
->notices
))
907 y
-= 2 * line_height
;
909 x
= 0.5 * (print_width
- images_width
);
911 for (image
= (cups_image_t
*)cupsArrayFirst(images
);
913 image
= (cups_image_t
*)cupsArrayNext(images
))
915 float temp_width
; /* Width of this image */
916 int depth
, /* Bytes per pixel */
917 num_cols
, /* Number of columns */
918 row
, /* Current row */
919 num_rows
, /* Number of rows */
920 out_length
, /* Length of data to write */
921 out_offset
; /* Offset in line buffer */
922 unsigned char *line
; /* Data for current row */
925 depth
= cupsImageGetDepth(image
);
926 num_cols
= cupsImageGetWidth(image
);
927 num_rows
= cupsImageGetHeight(image
);
928 line
= malloc(depth
* num_cols
+ 3);
929 temp_width
= num_cols
* images_height
/ num_rows
;
931 printf("gsave %.1f %.1f translate %.3f %.3f scale\n", x
, y
,
932 temp_width
/ num_cols
, images_height
/ num_rows
);
935 switch (cupsImageGetColorSpace(image
))
938 case CUPS_IMAGE_WHITE
:
939 printf("/DeviceGray setcolorspace"
944 "/BitsPerComponent 8"
949 case CUPS_IMAGE_RGB
:
950 printf("/DeviceRGB setcolorspace"
955 "/BitsPerComponent 8"
956 "/Decode[0 1 0 1 0 1]\n",
960 case CUPS_IMAGE_CMYK
:
961 printf("/DeviceCMYK setcolorspace"
966 "/BitsPerComponent 8"
967 "/Decode[0 1 0 1 0 1 0 1]\n",
972 puts("/DataSource currentfile"
973 "/ASCII85Decode filter"
974 "/ImageMatrix[1 0 0 -1 0 1]>>image");
976 for (row
= 0, out_offset
= 0; row
< num_rows
; row
++)
978 cupsImageGetRow(image
, 0, row
, num_cols
, line
+ out_offset
);
980 out_length
= num_cols
* depth
+ out_offset
;
981 out_offset
= out_length
& 3;
983 ps_ascii85(line
, out_length
, row
== (num_rows
- 1));
986 memcpy(line
, line
+ out_length
- out_offset
, out_offset
);
992 cupsImageClose(image
);
997 * Header and footer...
1000 x
= 0.5 * print_width
;
1004 printf("%.1f %.1f moveto", x
, print_height
- 2 * fontsize
);
1005 psTextUTF8(fonts
, 2 * fontsize
, PS_BOLD
, PS_CENTER
, banner
->header
);
1010 printf("%.1f %.1f moveto", x
, fontsize
);
1011 psTextUTF8(fonts
, 2 * fontsize
, PS_BOLD
, PS_CENTER
, banner
->footer
);
1027 * 'write_epilogue()' - Write the PostScript file epilogue.
1031 write_epilogue(int num_pages
) /* I - Number of pages */
1034 printf("%%%%Pages: %d\n", num_pages
);
1040 * 'write_prolog()' - Write the PostScript file prolog with options.
1043 ps_text_t
* /* O - Fonts */
1044 write_prolog(const char *title
, /* I - Title of job */
1045 const char *username
) /* I - Username */
1047 time_t curtime
; /* Current time */
1048 struct tm
*curtm
; /* Current date */
1049 char curdate
[255]; /* Current date (text format) */
1050 ps_text_t
*fonts
; /* Fonts */
1054 * Get the fonts we'll need...
1057 fonts
= psTextInitialize();
1060 * Output the DSC header...
1063 curtime
= time(NULL
);
1064 curtm
= localtime(&curtime
);
1065 strftime(curdate
, sizeof(curdate
), "%c", curtm
);
1067 puts("%!PS-Adobe-3.0");
1068 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
1069 PageRight
, PageTop
);
1070 printf("%%cupsRotation: %d\n", (Orientation
& 3) * 90);
1071 puts("%%Creator: bannertops/" CUPS_SVERSION
);
1072 printf("%%%%CreationDate: %s\n", curdate
);
1073 puts("%%LanguageLevel: 2");
1074 puts("%%DocumentData: Clean7Bit");
1075 WriteTextComment("Title", title
);
1076 WriteTextComment("For", username
);
1077 printf("%%%%Pages: %d\n", Duplex
? 2 : 1);
1078 psTextListFonts(fonts
);
1079 puts("%%EndComments");
1080 puts("%%BeginProlog");
1081 psTextEmbedFonts(fonts
);
1082 puts("%%EndProlog");