]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/pstops.c
2 * "$Id: pstops.c 7977 2008-09-23 23:44:33Z mike $"
4 * PostScript filter for CUPS.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1993-2007 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry.
20 * add_page() - Add a page to the pages array.
21 * cancel_job() - Flag the job as canceled.
22 * check_range() - Check to see if the current page is selected for
24 * copy_bytes() - Copy bytes from the input file to stdout.
25 * copy_comments() - Copy all of the comments section.
26 * copy_dsc() - Copy a DSC-conforming document.
27 * copy_non_dsc() - Copy a document that does not conform to the DSC.
28 * copy_page() - Copy a page description.
29 * copy_prolog() - Copy the document prolog section.
30 * copy_setup() - Copy the document setup section.
31 * copy_trailer() - Copy the document trailer.
32 * do_prolog() - Send the necessary document prolog commands.
33 * do_setup() - Send the necessary document setup commands.
34 * doc_printf() - Send a formatted string to stdout and/or the temp
36 * doc_puts() - Send a nul-terminated string to stdout and/or the
38 * doc_write() - Send data to stdout and/or the temp file.
39 * end_nup() - End processing for N-up printing.
40 * include_feature() - Include a printer option/feature command.
41 * parse_text() - Parse a text value in a comment.
42 * set_pstops_options() - Set pstops options.
43 * skip_page() - Skip past a page that won't be printed.
44 * start_nup() - Start processing for N-up printing.
45 * write_label_prolog() - Write the prolog with the classification and page
47 * write_labels() - Write the actual page labels.
48 * write_options() - Write options provided via %%IncludeFeature.
52 * Include necessary headers...
58 #include <cups/file.h>
59 #include <cups/array.h>
60 #include <cups/language-private.h>
68 #define PSTOPS_BORDERNONE 0 /* No border or hairline border */
69 #define PSTOPS_BORDERTHICK 1 /* Think border */
70 #define PSTOPS_BORDERSINGLE 2 /* Single-line hairline border */
71 #define PSTOPS_BORDERSINGLE2 3 /* Single-line thick border */
72 #define PSTOPS_BORDERDOUBLE 4 /* Double-line hairline border */
73 #define PSTOPS_BORDERDOUBLE2 5 /* Double-line thick border */
75 #define PSTOPS_LAYOUT_LRBT 0 /* Left to right, bottom to top */
76 #define PSTOPS_LAYOUT_LRTB 1 /* Left to right, top to bottom */
77 #define PSTOPS_LAYOUT_RLBT 2 /* Right to left, bottom to top */
78 #define PSTOPS_LAYOUT_RLTB 3 /* Right to left, top to bottom */
79 #define PSTOPS_LAYOUT_BTLR 4 /* Bottom to top, left to right */
80 #define PSTOPS_LAYOUT_TBLR 5 /* Top to bottom, left to right */
81 #define PSTOPS_LAYOUT_BTRL 6 /* Bottom to top, right to left */
82 #define PSTOPS_LAYOUT_TBRL 7 /* Top to bottom, right to left */
84 #define PSTOPS_LAYOUT_NEGATEY 1 /* The bits for the layout */
85 #define PSTOPS_LAYOUT_NEGATEX 2 /* definitions above... */
86 #define PSTOPS_LAYOUT_VERTICAL 4
93 typedef struct /**** Page information ****/
95 char *label
; /* Page label */
96 int bounding_box
[4]; /* PageBoundingBox */
97 off_t offset
; /* Offset to start of page */
98 ssize_t length
; /* Number of bytes for page */
99 int num_options
; /* Number of options for this page */
100 cups_option_t
*options
; /* Options for this page */
103 typedef struct /**** Document information ****/
105 int page
; /* Current page */
106 int bounding_box
[4]; /* BoundingBox from header */
107 int new_bounding_box
[4]; /* New composite bounding box */
108 int num_options
; /* Number of document-wide options */
109 cups_option_t
*options
; /* Document-wide options */
110 int normal_landscape
, /* Normal rotation for landscape? */
111 saw_eof
, /* Saw the %%EOF comment? */
112 slow_collate
, /* Collate copies by hand? */
113 slow_duplex
, /* Duplex pages slowly? */
114 slow_order
, /* Reverse pages slowly? */
115 use_ESPshowpage
; /* Use ESPshowpage? */
116 cups_array_t
*pages
; /* Pages in document */
117 cups_file_t
*temp
; /* Temporary file, if any */
118 char tempfile
[1024]; /* Temporary filename */
119 int job_id
; /* Job ID */
120 const char *user
, /* User name */
121 *title
; /* Job name */
122 int copies
; /* Number of copies */
123 const char *ap_input_slot
, /* AP_FIRSTPAGE_InputSlot value */
124 *ap_manual_feed
, /* AP_FIRSTPAGE_ManualFeed value */
125 *ap_media_color
, /* AP_FIRSTPAGE_MediaColor value */
126 *ap_media_type
, /* AP_FIRSTPAGE_MediaType value */
127 *ap_page_region
, /* AP_FIRSTPAGE_PageRegion value */
128 *ap_page_size
; /* AP_FIRSTPAGE_PageSize value */
129 float brightness
; /* brightness value */
130 int collate
, /* Collate copies? */
131 emit_jcl
, /* Emit JCL commands? */
132 fitplot
; /* Fit pages to media */
133 float gamma
; /* gamma value */
134 const char *input_slot
, /* InputSlot value */
135 *manual_feed
, /* ManualFeed value */
136 *media_color
, /* MediaColor value */
137 *media_type
, /* MediaType value */
138 *page_region
, /* PageRegion value */
139 *page_size
; /* PageSize value */
140 int mirror
, /* doc->mirror/mirror pages */
141 number_up
, /* Number of pages on each sheet */
142 number_up_layout
, /* doc->number_up_layout of N-up pages */
143 output_order
, /* Requested reverse output order? */
144 page_border
; /* doc->page_border around pages */
145 const char *page_label
, /* page-label option, if any */
146 *page_ranges
, /* page-ranges option, if any */
147 *page_set
; /* page-set option, if any */
152 * Convenience macros...
155 #define is_first_page(p) (doc->number_up == 1 || \
156 ((p) % doc->number_up) == 1)
157 #define is_last_page(p) (doc->number_up == 1 || \
158 ((p) % doc->number_up) == 0)
159 #define is_not_last_page(p) (doc->number_up > 1 && \
160 ((p) % doc->number_up) != 0)
167 static int JobCanceled
= 0;/* Set to 1 on SIGTERM */
174 static pstops_page_t
*add_page(pstops_doc_t
*doc
, const char *label
);
175 static void cancel_job(int sig
);
176 static int check_range(pstops_doc_t
*doc
, int page
);
177 static void copy_bytes(cups_file_t
*fp
, off_t offset
,
179 static ssize_t
copy_comments(cups_file_t
*fp
, pstops_doc_t
*doc
,
180 ppd_file_t
*ppd
, char *line
,
181 ssize_t linelen
, size_t linesize
);
182 static void copy_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
183 ppd_file_t
*ppd
, char *line
, ssize_t linelen
,
185 static void copy_non_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
186 ppd_file_t
*ppd
, char *line
,
187 ssize_t linelen
, size_t linesize
);
188 static ssize_t
copy_page(cups_file_t
*fp
, pstops_doc_t
*doc
,
189 ppd_file_t
*ppd
, int number
, char *line
,
190 ssize_t linelen
, size_t linesize
);
191 static ssize_t
copy_prolog(cups_file_t
*fp
, pstops_doc_t
*doc
,
192 ppd_file_t
*ppd
, char *line
,
193 ssize_t linelen
, size_t linesize
);
194 static ssize_t
copy_setup(cups_file_t
*fp
, pstops_doc_t
*doc
,
195 ppd_file_t
*ppd
, char *line
,
196 ssize_t linelen
, size_t linesize
);
197 static ssize_t
copy_trailer(cups_file_t
*fp
, pstops_doc_t
*doc
,
198 ppd_file_t
*ppd
, int number
, char *line
,
199 ssize_t linelen
, size_t linesize
);
200 static void do_prolog(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
201 static void do_setup(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
202 static void doc_printf(pstops_doc_t
*doc
, const char *format
, ...)
204 __attribute__ ((__format__ (__printf__
, 2, 3)))
205 #endif /* __GNUC__ */
207 static void doc_puts(pstops_doc_t
*doc
, const char *s
);
208 static void doc_write(pstops_doc_t
*doc
, const char *s
, size_t len
);
209 static void end_nup(pstops_doc_t
*doc
, int number
);
210 static int include_feature(ppd_file_t
*ppd
, const char *line
,
212 cups_option_t
**options
);
213 static char *parse_text(const char *start
, char **end
, char *buffer
,
215 static void set_pstops_options(pstops_doc_t
*doc
, ppd_file_t
*ppd
,
216 char *argv
[], int num_options
,
217 cups_option_t
*options
);
218 static ssize_t
skip_page(cups_file_t
*fp
, char *line
, ssize_t linelen
,
220 static void start_nup(pstops_doc_t
*doc
, int number
,
221 int show_border
, const int *bounding_box
);
222 static void write_label_prolog(pstops_doc_t
*doc
, const char *label
,
223 float bottom
, float top
,
225 static void write_labels(pstops_doc_t
*doc
, int orient
);
226 static void write_options(pstops_doc_t
*doc
, ppd_file_t
*ppd
,
227 int num_options
, cups_option_t
*options
);
231 * 'main()' - Main entry.
234 int /* O - Exit status */
235 main(int argc
, /* I - Number of command-line args */
236 char *argv
[]) /* I - Command-line arguments */
238 pstops_doc_t doc
; /* Document information */
239 cups_file_t
*fp
; /* Print file */
240 ppd_file_t
*ppd
; /* PPD file */
241 int num_options
; /* Number of print options */
242 cups_option_t
*options
; /* Print options */
243 char line
[8192]; /* Line buffer */
244 size_t len
; /* Length of line buffer */
245 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
246 struct sigaction action
; /* Actions for POSIX signals */
247 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
251 * Make sure status messages are not buffered...
254 setbuf(stderr
, NULL
);
257 * Check command-line...
260 if (argc
< 6 || argc
> 7)
262 _cupsLangPrintf(stderr
,
263 _("Usage: %s job-id user title copies options [file]\n"),
269 * Register a signal handler to cleanly cancel a job.
272 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
273 sigset(SIGTERM
, cancel_job
);
274 #elif defined(HAVE_SIGACTION)
275 memset(&action
, 0, sizeof(action
));
277 sigemptyset(&action
.sa_mask
);
278 action
.sa_handler
= cancel_job
;
279 sigaction(SIGTERM
, &action
, NULL
);
281 signal(SIGTERM
, cancel_job
);
282 #endif /* HAVE_SIGSET */
285 * If we have 7 arguments, print the file named on the command-line.
286 * Otherwise, send stdin instead...
290 fp
= cupsFileStdin();
294 * Try to open the print file...
297 if ((fp
= cupsFileOpen(argv
[6], "r")) == NULL
)
299 _cupsLangPrintf(stderr
, _("ERROR: Unable to open file \"%s\" - %s\n"),
300 argv
[6], strerror(errno
));
306 * Read the first line to see if we have DSC comments...
309 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
311 _cupsLangPuts(stderr
, _("ERROR: Empty print file\n"));
316 * Process command-line options...
320 num_options
= cupsParseOptions(argv
[5], 0, &options
);
321 ppd
= SetCommonOptions(num_options
, options
, 1);
323 set_pstops_options(&doc
, ppd
, argv
, num_options
, options
);
326 * Write any "exit server" options that have been selected...
329 ppdEmit(ppd
, stdout
, PPD_ORDER_EXIT
);
332 * Write any JCL commands that are needed to print PostScript code...
336 ppdEmitJCL(ppd
, stdout
, doc
.job_id
, doc
.user
, doc
.title
);
339 * Start with a DSC header...
342 puts("%!PS-Adobe-3.0");
345 * Skip leading PJL in the document...
348 while (!strncmp(line
, "\033%-12345X", 9) || !strncmp(line
, "@PJL ", 5))
351 * Yup, we have leading PJL fun, so skip it until we hit the line
352 * with "ENTER LANGUAGE"...
355 fputs("DEBUG: Skipping PJL header...\n", stderr
);
357 while (strstr(line
, "ENTER LANGUAGE") == NULL
&& strncmp(line
, "%!", 2))
358 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
361 if (!strncmp(line
, "%!", 2))
364 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
369 * Now see if the document conforms to the Adobe Document Structuring
373 if (!strncmp(line
, "%!PS-Adobe-", 11))
376 * Yes, filter the document...
379 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
384 * No, display an error message and treat the file as if it contains
388 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
392 * Send %%EOF as needed...
399 * End the job with the appropriate JCL command or CTRL-D...
404 if (ppd
&& ppd
->jcl_end
)
405 ppdEmitJCLEnd(ppd
, stdout
);
411 * Close files and remove the temporary file if needed...
416 cupsFileClose(doc
.temp
);
417 unlink(doc
.tempfile
);
421 cupsFreeOptions(num_options
, options
);
430 * 'add_page()' - Add a page to the pages array.
433 static pstops_page_t
* /* O - New page info object */
434 add_page(pstops_doc_t
*doc
, /* I - Document information */
435 const char *label
) /* I - Page label */
437 pstops_page_t
*pageinfo
; /* New page info object */
441 doc
->pages
= cupsArrayNew(NULL
, NULL
);
445 _cupsLangPrintf(stderr
,
446 _("EMERG: Unable to allocate memory for pages array: %s\n"),
451 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
453 _cupsLangPrintf(stderr
,
454 _("EMERG: Unable to allocate memory for page info: %s\n"),
459 pageinfo
->label
= strdup(label
);
460 pageinfo
->offset
= cupsFileTell(doc
->temp
);
462 cupsArrayAdd(doc
->pages
, pageinfo
);
471 * 'cancel_job()' - Flag the job as canceled.
475 cancel_job(int sig
) /* I - Signal number (unused) */
484 * 'check_range()' - Check to see if the current page is selected for
488 static int /* O - 1 if selected, 0 otherwise */
489 check_range(pstops_doc_t
*doc
, /* I - Document information */
490 int page
) /* I - Page number */
492 const char *range
; /* Pointer into range string */
493 int lower
, upper
; /* Lower and upper page numbers */
499 * See if we only print even or odd pages...
502 if (!strcasecmp(doc
->page_set
, "even") && (page
& 1))
505 if (!strcasecmp(doc
->page_set
, "odd") && !(page
& 1))
509 if (!doc
->page_ranges
)
510 return (1); /* No range, print all pages... */
512 for (range
= doc
->page_ranges
; *range
!= '\0';)
518 upper
= strtol(range
, (char **)&range
, 10);
522 lower
= strtol(range
, (char **)&range
, 10);
527 if (!isdigit(*range
& 255))
530 upper
= strtol(range
, (char **)&range
, 10);
536 if (page
>= lower
&& page
<= upper
)
550 * 'copy_bytes()' - Copy bytes from the input file to stdout.
554 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
555 off_t offset
, /* I - Offset to page data */
556 size_t length
) /* I - Length of page data */
558 char buffer
[8192]; /* Data buffer */
559 ssize_t nbytes
; /* Number of bytes read */
560 size_t nleft
; /* Number of bytes left/remaining */
565 if (cupsFileSeek(fp
, offset
) < 0)
567 _cupsLangPrintf(stderr
,
568 #ifdef HAVE_LONG_LONG
569 _("ERROR: Unable to seek to offset %lld in file - %s\n"),
571 _("ERROR: Unable to seek to offset %ld in file - %s\n"),
572 #endif /* HAVE_LONG_LONG */
573 CUPS_LLCAST offset
, strerror(errno
));
577 while (nleft
> 0 || length
== 0)
579 if (nleft
> sizeof(buffer
) || length
== 0)
580 nbytes
= sizeof(buffer
);
584 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
589 fwrite(buffer
, 1, nbytes
, stdout
);
595 * 'copy_comments()' - Copy all of the comments section.
597 * This function expects "line" to be filled with a comment line.
598 * On return, "line" will contain the next line in the file, if any.
601 static ssize_t
/* O - Length of next line */
602 copy_comments(cups_file_t
*fp
, /* I - File to read from */
603 pstops_doc_t
*doc
, /* I - Document info */
604 ppd_file_t
*ppd
, /* I - PPD file */
605 char *line
, /* I - Line buffer */
606 ssize_t linelen
, /* I - Length of initial line */
607 size_t linesize
) /* I - Size of line buffer */
609 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
610 saw_for
, /* Saw %%For: comment? */
611 saw_pages
, /* Saw %%Pages: comment? */
612 saw_title
; /* Saw %%Title: comment? */
616 * Loop until we see %%EndComments or a non-comment line...
619 saw_bounding_box
= 0;
624 while (line
[0] == '%')
627 * Strip trailing whitespace...
634 if (!isspace(line
[linelen
] & 255))
637 line
[linelen
] = '\0';
644 fprintf(stderr
, "DEBUG: %s\n", line
);
647 * Pull the headers out...
650 if (!strncmp(line
, "%%Pages:", 8))
652 int pages
; /* Number of pages */
656 _cupsLangPuts(stderr
, _("ERROR: Duplicate %%Pages: comment seen\n"));
660 if (Duplex
&& (pages
= atoi(line
+ 8)) > 0 && pages
<= doc
->number_up
)
663 * Since we will only be printing on a single page, disable duplexing.
667 doc
->slow_duplex
= 0;
669 if (cupsGetOption("sides", doc
->num_options
, doc
->options
))
670 doc
->num_options
= cupsAddOption("sides", "one-sided",
671 doc
->num_options
, &(doc
->options
));
673 if (cupsGetOption("Duplex", doc
->num_options
, doc
->options
))
674 doc
->num_options
= cupsAddOption("Duplex", "None",
675 doc
->num_options
, &(doc
->options
));
677 if (cupsGetOption("EFDuplex", doc
->num_options
, doc
->options
))
678 doc
->num_options
= cupsAddOption("EFDuplex", "None",
679 doc
->num_options
, &(doc
->options
));
681 if (cupsGetOption("EFDuplexing", doc
->num_options
, doc
->options
))
682 doc
->num_options
= cupsAddOption("EFDuplexing", "False",
683 doc
->num_options
, &(doc
->options
));
685 if (cupsGetOption("KD03Duplex", doc
->num_options
, doc
->options
))
686 doc
->num_options
= cupsAddOption("KD03Duplex", "None",
687 doc
->num_options
, &(doc
->options
));
689 if (cupsGetOption("JCLDuplex", doc
->num_options
, doc
->options
))
690 doc
->num_options
= cupsAddOption("JCLDuplex", "None",
691 doc
->num_options
, &(doc
->options
));
693 ppdMarkOption(ppd
, "Duplex", "None");
694 ppdMarkOption(ppd
, "EFDuplex", "None");
695 ppdMarkOption(ppd
, "EFDuplexing", "False");
696 ppdMarkOption(ppd
, "KD03Duplex", "None");
697 ppdMarkOption(ppd
, "JCLDuplex", "None");
700 else if (!strncmp(line
, "%%BoundingBox:", 14))
702 if (saw_bounding_box
)
703 _cupsLangPuts(stderr
,
704 _("ERROR: Duplicate %%BoundingBox: comment seen\n"));
705 else if (strstr(line
+ 14, "(atend)"))
708 * Do nothing for now but use the default imageable area...
711 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
712 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
713 doc
->bounding_box
+ 3) != 4)
715 _cupsLangPuts(stderr
, _("ERROR: Bad %%BoundingBox: comment seen\n"));
717 doc
->bounding_box
[0] = (int)PageLeft
;
718 doc
->bounding_box
[1] = (int)PageBottom
;
719 doc
->bounding_box
[2] = (int)PageRight
;
720 doc
->bounding_box
[3] = (int)PageTop
;
723 saw_bounding_box
= 1;
725 else if (!strncmp(line
, "%%For:", 6))
728 doc_printf(doc
, "%s\n", line
);
730 else if (!strncmp(line
, "%%Title:", 8))
733 doc_printf(doc
, "%s\n", line
);
735 else if (!strncmp(line
, "%cupsRotation:", 14))
738 * Reset orientation of document?
741 int orient
= (atoi(line
+ 14) / 90) & 3;
743 if (orient
!= Orientation
)
746 * Yes, update things so that the pages come out right...
749 Orientation
= (4 - Orientation
+ orient
) & 3;
751 Orientation
= orient
;
754 else if (!strcmp(line
, "%%EndComments"))
756 linelen
= cupsFileGetLine(fp
, line
, linesize
);
759 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
760 doc_printf(doc
, "%s\n", line
);
762 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
766 if (!saw_bounding_box
)
767 _cupsLangPuts(stderr
, _("ERROR: No %%BoundingBox: comment in header\n"));
770 _cupsLangPuts(stderr
, _("ERROR: No %%Pages: comment in header\n"));
773 WriteTextComment("For", doc
->user
);
776 WriteTextComment("Title", doc
->title
);
778 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
781 * Tell the document processor the copy and duplex options
782 * that are required...
785 doc_printf(doc
, "%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
786 doc
->collate
? " collate" : "",
787 Duplex
? " duplex" : "");
790 * Apple uses RBI comments for various non-PPD options...
793 doc_printf(doc
, "%%RBINumCopies: %d\n", doc
->copies
);
798 * Tell the document processor the duplex option that is required...
802 doc_puts(doc
, "%%Requirements: duplex\n");
805 * Apple uses RBI comments for various non-PPD options...
808 doc_puts(doc
, "%RBINumCopies: 1\n");
811 doc_puts(doc
, "%%Pages: (atend)\n");
812 doc_puts(doc
, "%%BoundingBox: (atend)\n");
813 doc_puts(doc
, "%%EndComments\n");
820 * 'copy_dsc()' - Copy a DSC-conforming document.
822 * This function expects "line" to be filled with the %!PS-Adobe comment line.
826 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
827 pstops_doc_t
*doc
, /* I - Document info */
828 ppd_file_t
*ppd
, /* I - PPD file */
829 char *line
, /* I - Line buffer */
830 ssize_t linelen
, /* I - Length of initial line */
831 size_t linesize
) /* I - Size of line buffer */
833 int number
; /* Page number */
834 pstops_page_t
*pageinfo
; /* Page information */
838 * Make sure we use ESPshowpage for EPS files...
841 if (strstr(line
, "EPSF"))
843 doc
->use_ESPshowpage
= 1;
848 * Start sending the document with any commands needed...
851 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
852 linelen
= copy_comments(fp
, doc
, ppd
, line
, linelen
, linesize
);
855 * Now find the prolog section, if any...
858 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
859 linelen
= copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
862 * Then the document setup section...
865 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
866 linelen
= copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
869 * Copy until we see %%Page:...
872 while (strncmp(line
, "%%Page:", 7) && strncmp(line
, "%%Trailer", 9))
874 doc_write(doc
, line
, linelen
);
876 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
881 * Then process pages until we have no more...
886 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
887 while (!strncmp(line
, "%%Page:", 7))
894 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
896 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
897 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
901 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
902 linelen
= skip_page(fp
, line
, linelen
, linesize
);
907 * Finish up the last page(s)...
910 if (number
&& is_not_last_page(number
) && cupsArrayLast(doc
->pages
) &&
911 check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
913 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
915 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
916 doc_puts(doc
, "showpage\n");
917 end_nup(doc
, doc
->number_up
);
919 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
922 if (doc
->slow_duplex
&& (doc
->page
& 1))
925 * Make sure we have an even number of pages...
928 pageinfo
= add_page(doc
, "(filler)");
930 if (!doc
->slow_order
)
932 if (!ppd
|| !ppd
->num_filters
)
933 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
934 doc
->slow_collate
? 1 : doc
->copies
);
936 printf("%%%%Page: (filler) %d\n", doc
->page
);
939 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
940 doc_puts(doc
, "showpage\n");
941 end_nup(doc
, doc
->number_up
);
943 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
947 * Make additional copies as necessary...
950 number
= doc
->slow_order
? 0 : doc
->page
;
952 if (doc
->temp
&& !JobCanceled
&& cupsArrayCount(doc
->pages
) > 0)
954 int copy
; /* Current copy */
958 * Reopen the temporary file for reading...
961 cupsFileClose(doc
->temp
);
963 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
969 if (doc
->slow_collate
)
970 copy
= !doc
->slow_order
;
972 copy
= doc
->copies
- 1;
974 for (; copy
< doc
->copies
; copy
++)
980 * Send end-of-job stuff followed by any start-of-job stuff required
981 * for the JCL options...
984 if (number
&& doc
->emit_jcl
&& ppd
&& ppd
->jcl_end
)
987 * Send the trailer...
991 printf("%%%%Pages: %d\n", cupsArrayCount(doc
->pages
));
992 if (doc
->number_up
> 1 || doc
->fitplot
)
993 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
994 PageLeft
, PageBottom
, PageRight
, PageTop
);
996 printf("%%%%BoundingBox: %d %d %d %d\n",
997 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
998 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1002 * Start a new document...
1005 ppdEmitJCLEnd(ppd
, stdout
);
1006 ppdEmitJCL(ppd
, stdout
, doc
->job_id
, doc
->user
, doc
->title
);
1008 puts("%!PS-Adobe-3.0");
1014 * Copy the prolog as needed...
1019 pageinfo
= (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
1020 copy_bytes(doc
->temp
, 0, pageinfo
->offset
);
1024 * Then copy all of the pages...
1027 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
1028 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
1037 if (!ppd
|| !ppd
->num_filters
)
1038 fprintf(stderr
, "PAGE: %d %d\n", number
,
1039 doc
->slow_collate
? 1 : doc
->copies
);
1041 if (doc
->number_up
> 1)
1043 printf("%%%%Page: (%d) %d\n", number
, number
);
1044 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1045 PageLeft
, PageBottom
, PageRight
, PageTop
);
1049 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
1050 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1051 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1052 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1055 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
1057 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
1058 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
1064 * Restore the old showpage operator as needed...
1067 if (doc
->use_ESPshowpage
)
1068 puts("userdict/showpage/ESPshowpage load put\n");
1071 * Write/copy the trailer...
1075 copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
1080 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC.
1082 * This function expects "line" to be filled with the %! comment line.
1086 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
1087 pstops_doc_t
*doc
, /* I - Document info */
1088 ppd_file_t
*ppd
, /* I - PPD file */
1089 char *line
, /* I - Line buffer */
1090 ssize_t linelen
, /* I - Length of initial line */
1091 size_t linesize
) /* I - Size of line buffer */
1093 int copy
; /* Current copy */
1094 char buffer
[8192]; /* Copy buffer */
1095 int bytes
; /* Number of bytes copied */
1099 * First let the user know that they are attempting to print a file
1100 * that may not print correctly...
1103 _cupsLangPuts(stderr
,
1104 _("WARNING: This document does not conform to the Adobe "
1105 "Document Structuring Conventions and may not print "
1109 * Then write a standard DSC comment section...
1112 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
1113 PageRight
, PageTop
);
1115 if (doc
->slow_collate
&& doc
->copies
> 1)
1116 printf("%%%%Pages: %d\n", doc
->copies
);
1120 WriteTextComment("For", doc
->user
);
1121 WriteTextComment("Title", doc
->title
);
1123 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1126 * Tell the document processor the copy and duplex options
1127 * that are required...
1130 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
1131 doc
->collate
? " collate" : "",
1132 Duplex
? " duplex" : "");
1135 * Apple uses RBI comments for various non-PPD options...
1138 printf("%%RBINumCopies: %d\n", doc
->copies
);
1143 * Tell the document processor the duplex option that is required...
1147 puts("%%Requirements: duplex");
1150 * Apple uses RBI comments for various non-PPD options...
1153 puts("%RBINumCopies: 1");
1156 puts("%%EndComments");
1159 * Then the prolog...
1162 puts("%%BeginProlog");
1164 do_prolog(doc
, ppd
);
1166 puts("%%EndProlog");
1169 * Then the setup section...
1172 puts("%%BeginSetup");
1179 * Finally, embed a copy of the file inside a %%Page...
1182 if (!ppd
|| !ppd
->num_filters
)
1183 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
1185 puts("%%Page: 1 1");
1186 puts("%%BeginPageSetup");
1187 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1188 puts("%%EndPageSetup");
1189 puts("%%BeginDocument: nondsc");
1191 fwrite(line
, linelen
, 1, stdout
);
1194 cupsFileWrite(doc
->temp
, line
, linelen
);
1196 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1198 fwrite(buffer
, 1, bytes
, stdout
);
1201 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1204 puts("%%EndDocument");
1206 if (doc
->use_ESPshowpage
)
1208 WriteLabels(Orientation
);
1209 puts("ESPshowpage");
1212 if (doc
->temp
&& !JobCanceled
)
1215 * Reopen the temporary file for reading...
1218 cupsFileClose(doc
->temp
);
1220 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1223 * Make the additional copies as needed...
1226 for (copy
= 1; copy
< doc
->copies
; copy
++)
1231 if (!ppd
|| !ppd
->num_filters
)
1232 fputs("PAGE: 1 1\n", stderr
);
1234 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1235 puts("%%BeginPageSetup");
1236 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1237 puts("%%EndPageSetup");
1238 puts("%%BeginDocument: nondsc");
1240 copy_bytes(doc
->temp
, 0, 0);
1242 puts("%%EndDocument");
1244 if (doc
->use_ESPshowpage
)
1246 WriteLabels(Orientation
);
1247 puts("ESPshowpage");
1253 * Restore the old showpage operator as needed...
1256 if (doc
->use_ESPshowpage
)
1257 puts("userdict/showpage/ESPshowpage load put\n");
1262 * 'copy_page()' - Copy a page description.
1264 * This function expects "line" to be filled with a %%Page comment line.
1265 * On return, "line" will contain the next line in the file, if any.
1268 static ssize_t
/* O - Length of next line */
1269 copy_page(cups_file_t
*fp
, /* I - File to read from */
1270 pstops_doc_t
*doc
, /* I - Document info */
1271 ppd_file_t
*ppd
, /* I - PPD file */
1272 int number
, /* I - Current page number */
1273 char *line
, /* I - Line buffer */
1274 ssize_t linelen
, /* I - Length of initial line */
1275 size_t linesize
) /* I - Size of line buffer */
1277 char label
[256], /* Page label string */
1278 *ptr
; /* Pointer into line */
1279 int level
; /* Embedded document level */
1280 pstops_page_t
*pageinfo
; /* Page information */
1281 int first_page
; /* First page on N-up output? */
1282 int has_page_setup
; /* Does the page have %%Begin/EndPageSetup? */
1283 int bounding_box
[4]; /* PageBoundingBox */
1287 * Get the page label for this page...
1290 first_page
= is_first_page(number
);
1292 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1294 _cupsLangPuts(stderr
, _("ERROR: Bad %%Page: comment in file\n"));
1298 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1300 _cupsLangPuts(stderr
, _("ERROR: Bad %%Page: comment in file\n"));
1305 * Create or update the current output page...
1309 pageinfo
= add_page(doc
, label
);
1311 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1314 * Handle first page override...
1317 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1322 * First page/sheet gets AP_FIRSTPAGE_* options...
1325 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1326 pageinfo
->num_options
,
1327 &(pageinfo
->options
));
1328 pageinfo
->num_options
= cupsAddOption("ManualFeed",
1329 doc
->ap_input_slot
? "False" :
1330 doc
->ap_manual_feed
,
1331 pageinfo
->num_options
,
1332 &(pageinfo
->options
));
1333 pageinfo
->num_options
= cupsAddOption("MediaColor", doc
->ap_media_color
,
1334 pageinfo
->num_options
,
1335 &(pageinfo
->options
));
1336 pageinfo
->num_options
= cupsAddOption("MediaType", doc
->ap_media_type
,
1337 pageinfo
->num_options
,
1338 &(pageinfo
->options
));
1339 pageinfo
->num_options
= cupsAddOption("PageRegion", doc
->ap_page_region
,
1340 pageinfo
->num_options
,
1341 &(pageinfo
->options
));
1342 pageinfo
->num_options
= cupsAddOption("PageSize", doc
->ap_page_size
,
1343 pageinfo
->num_options
,
1344 &(pageinfo
->options
));
1346 else if (doc
->page
== (Duplex
+ 2))
1349 * Second page/sheet gets default options...
1352 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1353 pageinfo
->num_options
,
1354 &(pageinfo
->options
));
1355 pageinfo
->num_options
= cupsAddOption("ManualFeed",
1356 doc
->input_slot
? "False" :
1358 pageinfo
->num_options
,
1359 &(pageinfo
->options
));
1360 pageinfo
->num_options
= cupsAddOption("MediaColor", doc
->media_color
,
1361 pageinfo
->num_options
,
1362 &(pageinfo
->options
));
1363 pageinfo
->num_options
= cupsAddOption("MediaType", doc
->media_type
,
1364 pageinfo
->num_options
,
1365 &(pageinfo
->options
));
1366 pageinfo
->num_options
= cupsAddOption("PageRegion", doc
->page_region
,
1367 pageinfo
->num_options
,
1368 &(pageinfo
->options
));
1369 pageinfo
->num_options
= cupsAddOption("PageSize", doc
->page_size
,
1370 pageinfo
->num_options
,
1371 &(pageinfo
->options
));
1376 * Scan comments until we see something other than %%Page*: or
1380 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1382 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1384 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1387 * %%PageBoundingBox: llx lly urx ury
1390 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1391 bounding_box
+ 1, bounding_box
+ 2,
1392 bounding_box
+ 3) != 4)
1394 _cupsLangPuts(stderr
,
1395 _("ERROR: Bad %%PageBoundingBox: comment in file\n"));
1396 memcpy(bounding_box
, doc
->bounding_box
,
1397 sizeof(bounding_box
));
1399 else if (doc
->number_up
== 1 && !doc
->fitplot
&& Orientation
)
1401 int temp_bbox
[4]; /* Temporary bounding box */
1404 memcpy(temp_bbox
, bounding_box
, sizeof(temp_bbox
));
1406 fprintf(stderr
, "DEBUG: Orientation = %d\n", Orientation
);
1407 fprintf(stderr
, "DEBUG: original bounding_box = [ %d %d %d %d ]\n",
1408 bounding_box
[0], bounding_box
[1],
1409 bounding_box
[2], bounding_box
[3]);
1410 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
1411 PageWidth
, PageLength
);
1413 switch (Orientation
)
1415 case 1 : /* Landscape */
1416 bounding_box
[0] = PageLength
- temp_bbox
[3];
1417 bounding_box
[1] = temp_bbox
[0];
1418 bounding_box
[2] = PageLength
- temp_bbox
[1];
1419 bounding_box
[3] = temp_bbox
[2];
1422 case 2 : /* Reverse Portrait */
1423 bounding_box
[0] = PageWidth
- temp_bbox
[2];
1424 bounding_box
[1] = PageLength
- temp_bbox
[3];
1425 bounding_box
[2] = PageWidth
- temp_bbox
[0];
1426 bounding_box
[3] = PageLength
- temp_bbox
[1];
1429 case 3 : /* Reverse Landscape */
1430 bounding_box
[0] = temp_bbox
[1];
1431 bounding_box
[1] = PageWidth
- temp_bbox
[2];
1432 bounding_box
[2] = temp_bbox
[3];
1433 bounding_box
[3] = PageWidth
- temp_bbox
[0];
1437 fprintf(stderr
, "DEBUG: updated bounding_box = [ %d %d %d %d ]\n",
1438 bounding_box
[0], bounding_box
[1],
1439 bounding_box
[2], bounding_box
[3]);
1443 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1444 !strncmp(line
, "%%PageMedia:", 12) ||
1445 !strncmp(line
, "%%PageOrientation:", 18) ||
1446 !strncmp(line
, "%%PageProcessColors:", 20) ||
1447 !strncmp(line
, "%%PageRequirements:", 18) ||
1448 !strncmp(line
, "%%PageResources:", 16))
1455 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1458 * %%PageCustomColors: ...
1461 else if (!strncmp(line
, "%%PageMedia:", 12))
1467 else if (!strncmp(line
, "%%PageOrientation:", 18))
1470 * %%PageOrientation: ...
1473 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1476 * %%PageProcessColors: ...
1479 else if (!strncmp(line
, "%%PageRequirements:", 18))
1482 * %%PageRequirements: ...
1485 else if (!strncmp(line
, "%%PageResources:", 16))
1488 * %%PageResources: ...
1491 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1494 * %%IncludeFeature: *MainKeyword OptionKeyword
1497 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1498 pageinfo
->num_options
= include_feature(ppd
, line
,
1499 pageinfo
->num_options
,
1500 &(pageinfo
->options
));
1502 else if (strncmp(line
, "%%Include", 9))
1506 if (doc
->number_up
== 1)
1509 * Update the document's composite and page bounding box...
1512 memcpy(pageinfo
->bounding_box
, bounding_box
,
1513 sizeof(pageinfo
->bounding_box
));
1515 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1516 doc
->new_bounding_box
[0] = bounding_box
[0];
1517 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1518 doc
->new_bounding_box
[1] = bounding_box
[1];
1519 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1520 doc
->new_bounding_box
[2] = bounding_box
[2];
1521 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1522 doc
->new_bounding_box
[3] = bounding_box
[3];
1526 * Output the page header as needed...
1529 if (!doc
->slow_order
&& first_page
)
1531 if (!ppd
|| !ppd
->num_filters
)
1532 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1533 doc
->slow_collate
? 1 : doc
->copies
);
1535 if (doc
->number_up
> 1)
1537 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1538 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1539 PageLeft
, PageBottom
, PageRight
, PageTop
);
1543 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1544 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1545 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1546 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1551 * Copy any page setup commands...
1555 doc_puts(doc
, "%%BeginPageSetup\n");
1557 if ((has_page_setup
= !strncmp(line
, "%%BeginPageSetup", 16)) != 0)
1559 int feature
= 0; /* In a Begin/EndFeature block? */
1561 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1563 if (!strncmp(line
, "%%EndPageSetup", 14))
1565 else if (!strncmp(line
, "%%BeginFeature:", 15))
1569 if (doc
->number_up
> 1 || doc
->fitplot
)
1572 else if (!strncmp(line
, "%%EndFeature", 12))
1576 if (doc
->number_up
> 1 || doc
->fitplot
)
1579 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1581 pageinfo
->num_options
= include_feature(ppd
, line
,
1582 pageinfo
->num_options
,
1583 &(pageinfo
->options
));
1586 else if (!strncmp(line
, "%%Include", 9))
1589 if (line
[0] != '%' && !feature
)
1592 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1593 doc_write(doc
, line
, linelen
);
1597 * Skip %%EndPageSetup...
1600 if (linelen
> 0 && !strncmp(line
, "%%EndPageSetup", 14))
1602 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1609 char *page_setup
; /* PageSetup commands to send */
1612 if (pageinfo
->num_options
> 0)
1613 write_options(doc
, ppd
, pageinfo
->num_options
, pageinfo
->options
);
1616 * Output commands for the current page...
1619 page_setup
= ppdEmitString(ppd
, PPD_ORDER_PAGE
, 0);
1623 doc_puts(doc
, page_setup
);
1629 * Prep for the start of the page description...
1632 start_nup(doc
, number
, 1, bounding_box
);
1635 * Finish the PageSetup section as needed...
1640 int feature
= 0; /* In a Begin/EndFeature block? */
1642 doc_write(doc
, line
, linelen
);
1644 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1646 if (!strncmp(line
, "%%EndPageSetup", 14))
1648 else if (!strncmp(line
, "%%BeginFeature:", 15))
1652 if (doc
->number_up
> 1 || doc
->fitplot
)
1655 else if (!strncmp(line
, "%%EndFeature", 12))
1659 if (doc
->number_up
> 1 || doc
->fitplot
)
1662 else if (!strncmp(line
, "%%Include", 9))
1665 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1666 doc_write(doc
, line
, linelen
);
1670 * Skip %%EndPageSetup...
1673 if (linelen
> 0 && !strncmp(line
, "%%EndPageSetup", 14))
1674 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1678 doc_puts(doc
, "%%EndPageSetup\n");
1681 * Read the rest of the page description...
1689 (!strncmp(line
, "%%Page:", 7) ||
1690 !strncmp(line
, "%%Trailer", 9) ||
1691 !strncmp(line
, "%%EOF", 5)))
1693 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1694 !strncmp(line
, "%ADO_BeginApplication", 21))
1696 doc_write(doc
, line
, linelen
);
1700 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1701 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1703 doc_write(doc
, line
, linelen
);
1707 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1708 (!strncmp(line
, "%%BeginData:", 12) &&
1709 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1712 * Copy binary data...
1715 int bytes
; /* Bytes of data */
1718 doc_write(doc
, line
, linelen
);
1720 bytes
= atoi(strchr(line
, ':') + 1);
1724 if (bytes
> linesize
)
1725 linelen
= cupsFileRead(fp
, line
, linesize
);
1727 linelen
= cupsFileRead(fp
, line
, bytes
);
1732 perror("ERROR: Early end-of-file while reading binary data");
1736 doc_write(doc
, line
, linelen
);
1742 doc_write(doc
, line
, linelen
);
1744 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1747 * Finish up this page and return...
1750 end_nup(doc
, number
);
1752 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1759 * 'copy_prolog()' - Copy the document prolog section.
1761 * This function expects "line" to be filled with a %%BeginProlog comment line.
1762 * On return, "line" will contain the next line in the file, if any.
1765 static ssize_t
/* O - Length of next line */
1766 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1767 pstops_doc_t
*doc
, /* I - Document info */
1768 ppd_file_t
*ppd
, /* I - PPD file */
1769 char *line
, /* I - Line buffer */
1770 ssize_t linelen
, /* I - Length of initial line */
1771 size_t linesize
) /* I - Size of line buffer */
1773 while (strncmp(line
, "%%BeginProlog", 13))
1775 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1778 doc_write(doc
, line
, linelen
);
1780 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1784 doc_puts(doc
, "%%BeginProlog\n");
1786 do_prolog(doc
, ppd
);
1788 if (!strncmp(line
, "%%BeginProlog", 13))
1790 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1792 if (!strncmp(line
, "%%EndProlog", 11) ||
1793 !strncmp(line
, "%%BeginSetup", 12) ||
1794 !strncmp(line
, "%%Page:", 7))
1797 doc_write(doc
, line
, linelen
);
1800 if (!strncmp(line
, "%%EndProlog", 11))
1801 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1803 _cupsLangPuts(stderr
, _("ERROR: Missing %%EndProlog\n"));
1806 doc_puts(doc
, "%%EndProlog\n");
1813 * 'copy_setup()' - Copy the document setup section.
1815 * This function expects "line" to be filled with a %%BeginSetup comment line.
1816 * On return, "line" will contain the next line in the file, if any.
1819 static ssize_t
/* O - Length of next line */
1820 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1821 pstops_doc_t
*doc
, /* I - Document info */
1822 ppd_file_t
*ppd
, /* I - PPD file */
1823 char *line
, /* I - Line buffer */
1824 ssize_t linelen
, /* I - Length of initial line */
1825 size_t linesize
) /* I - Size of line buffer */
1827 int num_options
; /* Number of options */
1828 cups_option_t
*options
; /* Options */
1831 while (strncmp(line
, "%%BeginSetup", 12))
1833 if (!strncmp(line
, "%%Page:", 7))
1836 doc_write(doc
, line
, linelen
);
1838 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1842 doc_puts(doc
, "%%BeginSetup\n");
1849 if (!strncmp(line
, "%%BeginSetup", 12))
1851 while (strncmp(line
, "%%EndSetup", 10))
1853 if (!strncmp(line
, "%%Page:", 7))
1855 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1858 * %%IncludeFeature: *MainKeyword OptionKeyword
1861 if (doc
->number_up
== 1 && !doc
->fitplot
)
1862 num_options
= include_feature(ppd
, line
, num_options
, &options
);
1864 else if (strncmp(line
, "%%BeginSetup", 12))
1865 doc_write(doc
, line
, linelen
);
1867 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1871 if (!strncmp(line
, "%%EndSetup", 10))
1872 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1874 _cupsLangPuts(stderr
, _("ERROR: Missing %%EndSetup\n"));
1877 if (num_options
> 0)
1879 write_options(doc
, ppd
, num_options
, options
);
1880 cupsFreeOptions(num_options
, options
);
1883 doc_puts(doc
, "%%EndSetup\n");
1890 * 'copy_trailer()' - Copy the document trailer.
1892 * This function expects "line" to be filled with a %%Trailer comment line.
1893 * On return, "line" will contain the next line in the file, if any.
1896 static ssize_t
/* O - Length of next line */
1897 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1898 pstops_doc_t
*doc
, /* I - Document info */
1899 ppd_file_t
*ppd
, /* I - PPD file */
1900 int number
, /* I - Number of pages */
1901 char *line
, /* I - Line buffer */
1902 ssize_t linelen
, /* I - Length of initial line */
1903 size_t linesize
) /* I - Size of line buffer */
1906 * Write the trailer comments...
1913 if (!strncmp(line
, "%%EOF", 5))
1915 else if (strncmp(line
, "%%Trailer", 9) &&
1916 strncmp(line
, "%%Pages:", 8) &&
1917 strncmp(line
, "%%BoundingBox:", 14))
1918 fwrite(line
, 1, linelen
, stdout
);
1920 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1923 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1925 printf("%%%%Pages: %d\n", number
);
1926 if (doc
->number_up
> 1 || doc
->fitplot
)
1927 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1928 PageLeft
, PageBottom
, PageRight
, PageTop
);
1930 printf("%%%%BoundingBox: %d %d %d %d\n",
1931 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1932 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1939 * 'do_prolog()' - Send the necessary document prolog commands.
1943 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1944 ppd_file_t
*ppd
) /* I - PPD file */
1946 char *ps
; /* PS commands */
1950 * Send the document prolog commands...
1953 if (ppd
&& ppd
->patches
)
1955 doc_puts(doc
, "%%BeginFeature: *JobPatchFile 1\n");
1956 doc_puts(doc
, ppd
->patches
);
1957 doc_puts(doc
, "\n%%EndFeature\n");
1960 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_PROLOG
, 0.0)) != NULL
)
1967 * Define ESPshowpage here so that applications that define their
1968 * own procedure to do a showpage pick it up...
1971 if (doc
->use_ESPshowpage
)
1972 doc_puts(doc
, "userdict/ESPshowpage/showpage load put\n"
1973 "userdict/showpage{}put\n");
1978 * 'do_setup()' - Send the necessary document setup commands.
1982 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1983 ppd_file_t
*ppd
) /* I - PPD file */
1985 char *ps
; /* PS commands */
1989 * Disable CTRL-D so that embedded files don't cause printing
1993 doc_puts(doc
, "% Disable CTRL-D as an end-of-file marker...\n");
1994 doc_puts(doc
, "userdict dup(\\004)cvn{}put (\\004\\004)cvn{}put\n");
1997 * Mark job options...
2000 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
2003 * Send all the printer-specific setup commands...
2006 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, 0.0)) != NULL
)
2012 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
)
2019 * Set the number of copies for the job...
2022 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
2024 doc_printf(doc
, "%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
2026 "%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
2027 "{1 dict begin/NumCopies exch def currentdict end "
2029 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
2030 doc_puts(doc
, "%RBIEndNonPPDFeature\n");
2034 * If we are doing N-up printing, disable setpagedevice...
2037 if (doc
->number_up
> 1)
2039 doc_puts(doc
, "userdict/CUPSsetpagedevice/setpagedevice load put\n");
2040 doc_puts(doc
, "userdict/setpagedevice{pop}bind put\n");
2044 * Changes to the transfer function must be made AFTER any
2045 * setpagedevice code...
2048 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
2049 doc_printf(doc
, "{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
2050 "ifelse %.3f mul } bind settransfer\n",
2051 doc
->gamma
, doc
->brightness
);
2054 * Make sure we have rectclip and rectstroke procedures of some sort...
2058 "% x y w h ESPrc - Clip to a rectangle.\n"
2059 "userdict/ESPrc/rectclip where{pop/rectclip load}\n"
2060 "{{newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2061 "neg 0 rlineto closepath clip newpath}bind}ifelse put\n");
2064 "% x y w h ESPrf - Fill a rectangle.\n"
2065 "userdict/ESPrf/rectfill where{pop/rectfill load}\n"
2066 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2067 "neg 0 rlineto closepath fill grestore}bind}ifelse put\n");
2070 "% x y w h ESPrs - Stroke a rectangle.\n"
2071 "userdict/ESPrs/rectstroke where{pop/rectstroke load}\n"
2072 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2073 "neg 0 rlineto closepath stroke grestore}bind}ifelse put\n");
2076 * Write the page and label prologs...
2079 if (doc
->number_up
== 2 || doc
->number_up
== 6)
2082 * For 2- and 6-up output, rotate the labels to match the orientation
2086 if (Orientation
& 1)
2087 write_label_prolog(doc
, doc
->page_label
, PageBottom
,
2088 PageWidth
- PageLength
+ PageTop
, PageLength
);
2090 write_label_prolog(doc
, doc
->page_label
, PageLeft
, PageRight
,
2094 write_label_prolog(doc
, doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
2099 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
2101 * This function should be used for all page-level output that is affected
2102 * by ordering, collation, etc.
2106 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
2107 const char *format
, /* I - Printf-style format string */
2108 ...) /* I - Additional arguments as needed */
2110 va_list ap
; /* Pointer to arguments */
2111 char buffer
[1024]; /* Output buffer */
2112 size_t bytes
; /* Number of bytes to write */
2115 va_start(ap
, format
);
2116 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
2119 if (bytes
> sizeof(buffer
))
2121 _cupsLangPrintf(stderr
,
2122 _("ERROR: doc_printf overflow (%d bytes) detected, "
2123 "aborting\n"), (int)bytes
);
2127 doc_write(doc
, buffer
, bytes
);
2132 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
2134 * This function should be used for all page-level output that is affected
2135 * by ordering, collation, etc.
2139 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
2140 const char *s
) /* I - String to send */
2142 doc_write(doc
, s
, strlen(s
));
2147 * 'doc_write()' - Send data to stdout and/or the temp file.
2151 doc_write(pstops_doc_t
*doc
, /* I - Document information */
2152 const char *s
, /* I - Data to send */
2153 size_t len
) /* I - Number of bytes to send */
2155 if (!doc
->slow_order
)
2156 fwrite(s
, 1, len
, stdout
);
2159 cupsFileWrite(doc
->temp
, s
, len
);
2164 * 'end_nup()' - End processing for N-up printing.
2168 end_nup(pstops_doc_t
*doc
, /* I - Document information */
2169 int number
) /* I - Page number */
2171 if (doc
->number_up
> 1)
2172 doc_puts(doc
, "userdict/ESPsave get restore\n");
2174 switch (doc
->number_up
)
2177 if (doc
->use_ESPshowpage
)
2179 write_labels(doc
, Orientation
);
2180 doc_puts(doc
, "ESPshowpage\n");
2186 if (is_last_page(number
) && doc
->use_ESPshowpage
)
2188 if (Orientation
& 1)
2191 * Rotate the labels back to portrait...
2194 write_labels(doc
, Orientation
- 1);
2196 else if (Orientation
== 0)
2199 * Rotate the labels to landscape...
2202 write_labels(doc
, doc
->normal_landscape
? 1 : 3);
2207 * Rotate the labels to landscape...
2210 write_labels(doc
, doc
->normal_landscape
? 3 : 1);
2213 doc_puts(doc
, "ESPshowpage\n");
2218 if (is_last_page(number
) && doc
->use_ESPshowpage
)
2220 write_labels(doc
, Orientation
);
2221 doc_puts(doc
, "ESPshowpage\n");
2231 * 'include_feature()' - Include a printer option/feature command.
2234 static int /* O - New number of options */
2236 ppd_file_t
*ppd
, /* I - PPD file */
2237 const char *line
, /* I - DSC line */
2238 int num_options
, /* I - Number of options */
2239 cups_option_t
**options
) /* IO - Options */
2241 char name
[255], /* Option name */
2242 value
[255]; /* Option value */
2243 ppd_option_t
*option
; /* Option in file */
2247 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
2250 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
2252 _cupsLangPuts(stderr
, _("ERROR: Bad %%IncludeFeature: comment\n"));
2253 return (num_options
);
2257 * Find the option and choice...
2260 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
2262 _cupsLangPrintf(stderr
, _("WARNING: Unknown option \"%s\"\n"), name
+ 1);
2263 return (num_options
);
2266 if (option
->section
== PPD_ORDER_EXIT
||
2267 option
->section
== PPD_ORDER_JCL
)
2269 _cupsLangPrintf(stderr
, _("WARNING: Option \"%s\" cannot be included via "
2270 "IncludeFeature\n"), name
+ 1);
2271 return (num_options
);
2274 if (!ppdFindChoice(option
, value
))
2276 _cupsLangPrintf(stderr
,
2277 _("WARNING: Unknown choice \"%s\" for option \"%s\"\n"),
2279 return (num_options
);
2283 * Add the option to the option array and return...
2286 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
2291 * 'parse_text()' - Parse a text value in a comment.
2293 * This function parses a DSC text value as defined on page 36 of the
2294 * DSC specification. Text values are either surrounded by parenthesis
2295 * or whitespace-delimited.
2297 * The value returned is the literal characters for the entire text
2298 * string, including any parenthesis and escape characters.
2301 static char * /* O - Value or NULL on error */
2302 parse_text(const char *start
, /* I - Start of text value */
2303 char **end
, /* O - End of text value */
2304 char *buffer
, /* I - Buffer */
2305 size_t bufsize
) /* I - Size of buffer */
2307 char *bufptr
, /* Pointer in buffer */
2308 *bufend
; /* End of buffer */
2309 int level
; /* Parenthesis level */
2313 * Skip leading whitespace...
2316 while (isspace(*start
& 255))
2320 * Then copy the value...
2325 bufend
= buffer
+ bufsize
- 1;
2327 while (bufptr
< bufend
)
2329 if (isspace(*start
& 255) && !level
)
2336 else if (*start
== ')')
2346 else if (*start
== '\\')
2349 * Copy escaped character...
2352 int i
; /* Looping var */
2356 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
2357 *bufptr
++ = start
[i
], i
++);
2366 * Return the value and new pointer into the line...
2370 *end
= (char *)start
;
2372 if (bufptr
== bufend
)
2380 * 'set_pstops_options()' - Set pstops options.
2385 pstops_doc_t
*doc
, /* I - Document information */
2386 ppd_file_t
*ppd
, /* I - PPD file */
2387 char *argv
[], /* I - Command-line arguments */
2388 int num_options
, /* I - Number of options */
2389 cups_option_t
*options
) /* I - Options */
2391 const char *val
; /* Option value */
2392 int intval
; /* Integer option value */
2393 ppd_attr_t
*attr
; /* PPD attribute */
2394 ppd_option_t
*option
; /* PPD option */
2395 ppd_choice_t
*choice
; /* PPD choice */
2399 * Initialize document information structure...
2402 memset(doc
, 0, sizeof(pstops_doc_t
));
2404 doc
->job_id
= atoi(argv
[1]);
2405 doc
->user
= argv
[2];
2406 doc
->title
= argv
[3];
2407 doc
->copies
= atoi(argv
[4]);
2409 if (ppd
&& ppd
->landscape
> 0)
2410 doc
->normal_landscape
= 1;
2412 doc
->bounding_box
[0] = (int)PageLeft
;
2413 doc
->bounding_box
[1] = (int)PageBottom
;
2414 doc
->bounding_box
[2] = (int)PageRight
;
2415 doc
->bounding_box
[3] = (int)PageTop
;
2417 doc
->new_bounding_box
[0] = INT_MAX
;
2418 doc
->new_bounding_box
[1] = INT_MAX
;
2419 doc
->new_bounding_box
[2] = INT_MIN
;
2420 doc
->new_bounding_box
[3] = INT_MIN
;
2423 * AP_FIRSTPAGE_* and the corresponding non-first-page options.
2426 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2428 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2430 doc
->ap_media_color
= cupsGetOption("AP_FIRSTPAGE_MediaColor", num_options
,
2432 doc
->ap_media_type
= cupsGetOption("AP_FIRSTPAGE_MediaType", num_options
,
2434 doc
->ap_page_region
= cupsGetOption("AP_FIRSTPAGE_PageRegion", num_options
,
2436 doc
->ap_page_size
= cupsGetOption("AP_FIRSTPAGE_PageSize", num_options
,
2439 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2440 doc
->input_slot
= choice
->choice
;
2441 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2442 doc
->manual_feed
= choice
->choice
;
2443 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaColor")) != NULL
)
2444 doc
->media_color
= choice
->choice
;
2445 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaType")) != NULL
)
2446 doc
->media_type
= choice
->choice
;
2447 if ((choice
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
2448 doc
->page_region
= choice
->choice
;
2449 if ((choice
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
2450 doc
->page_size
= choice
->choice
;
2457 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2460 * Get brightness value from 10 to 1000.
2465 if (intval
< 10 || intval
> 1000)
2467 _cupsLangPrintf(stderr
, _("ERROR: Unsupported brightness value %s, using "
2468 "brightness=100\n"), val
);
2469 doc
->brightness
= 1.0f
;
2472 doc
->brightness
= intval
* 0.01f
;
2475 doc
->brightness
= 1.0f
;
2478 * collate, multiple-document-handling
2481 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2484 * This IPP attribute is unnecessarily complicated...
2486 * single-document, separate-documents-collated-copies, and
2487 * single-document-new-sheet all require collated copies.
2489 * separate-documents-uncollated-copies allows for uncollated copies.
2492 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2495 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2496 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2497 !strcasecmp(val
, "yes")))
2504 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2505 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2506 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2512 * fitplot/fit-to-page
2515 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
2516 !strcasecmp(val
, "true"))
2518 else if ((val
= cupsGetOption("fit-to-page", num_options
, options
)) != NULL
&&
2519 !strcasecmp(val
, "true"))
2526 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2529 * Get gamma value from 1 to 10000...
2534 if (intval
< 1 || intval
> 10000)
2536 _cupsLangPrintf(stderr
, _("ERROR: Unsupported gamma value %s, using "
2537 "gamma=1000\n"), val
);
2541 doc
->gamma
= intval
* 0.001f
;
2547 * mirror/MirrorPrint
2550 if ((choice
= ppdFindMarkedChoice(ppd
, "MirrorPrint")) != NULL
)
2552 val
= choice
->choice
;
2556 val
= cupsGetOption("mirror", num_options
, options
);
2558 if (val
&& (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2559 !strcasecmp(val
, "yes")))
2566 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2568 switch (intval
= atoi(val
))
2576 doc
->number_up
= intval
;
2579 _cupsLangPrintf(stderr
,
2580 _("ERROR: Unsupported number-up value %d, using "
2581 "number-up=1\n"), intval
);
2593 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2595 if (!strcasecmp(val
, "lrtb"))
2596 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2597 else if (!strcasecmp(val
, "lrbt"))
2598 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2599 else if (!strcasecmp(val
, "rltb"))
2600 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2601 else if (!strcasecmp(val
, "rlbt"))
2602 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2603 else if (!strcasecmp(val
, "tblr"))
2604 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2605 else if (!strcasecmp(val
, "tbrl"))
2606 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2607 else if (!strcasecmp(val
, "btlr"))
2608 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2609 else if (!strcasecmp(val
, "btrl"))
2610 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2613 _cupsLangPrintf(stderr
, _("ERROR: Unsupported number-up-layout value %s, "
2614 "using number-up-layout=lrtb\n"), val
);
2615 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2619 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2625 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2627 if (!strcasecmp(val
, "Reverse"))
2628 doc
->output_order
= 1;
2633 * Figure out the right default output order from the PPD file...
2636 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2637 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2639 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2640 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2642 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2649 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2651 if (!strcasecmp(val
, "none"))
2652 doc
->page_border
= PSTOPS_BORDERNONE
;
2653 else if (!strcasecmp(val
, "single"))
2654 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2655 else if (!strcasecmp(val
, "single-thick"))
2656 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2657 else if (!strcasecmp(val
, "double"))
2658 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2659 else if (!strcasecmp(val
, "double-thick"))
2660 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2663 _cupsLangPrintf(stderr
, _("ERROR: Unsupported page-border value %s, "
2664 "using page-border=none\n"), val
);
2665 doc
->page_border
= PSTOPS_BORDERNONE
;
2669 doc
->page_border
= PSTOPS_BORDERNONE
;
2675 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2681 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2687 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2690 * Now figure out if we have to force collated copies, etc.
2693 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2696 * Force collated copies when printing a duplexed document to
2697 * a non-PS printer that doesn't do hardware copy generation.
2698 * Otherwise the copies will end up on the front/back side of
2706 * See if we have to filter the fast or slow way...
2709 if (doc
->collate
&& doc
->copies
> 1)
2712 * See if we need to manually collate the pages...
2715 doc
->slow_collate
= 1;
2717 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2718 !strcasecmp(choice
->choice
, "True"))
2721 * Hardware collate option is selected, see if the option is
2722 * conflicting - if not, collate in hardware. Otherwise,
2723 * turn the hardware collate option off...
2726 if ((option
= ppdFindOption(ppd
, "Collate")) != NULL
&&
2727 !option
->conflicted
)
2728 doc
->slow_collate
= 0;
2730 ppdMarkOption(ppd
, "Collate", "False");
2734 doc
->slow_collate
= 0;
2736 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2737 doc
->slow_order
= 1;
2739 doc
->slow_order
= 0;
2742 (doc
->slow_collate
|| doc
->slow_order
||
2743 ((attr
= ppdFindAttr(ppd
, "cupsEvenDuplex", NULL
)) != NULL
&&
2744 attr
->value
&& !strcasecmp(attr
->value
, "true"))))
2745 doc
->slow_duplex
= 1;
2747 doc
->slow_duplex
= 0;
2750 * Create a temporary file for page data if we need to filter slowly...
2753 if (doc
->slow_order
|| doc
->slow_collate
)
2755 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2756 sizeof(doc
->tempfile
))) == NULL
)
2758 _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
2764 * Figure out if we should use ESPshowpage or not...
2767 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2771 * Yes, use ESPshowpage...
2774 doc
->use_ESPshowpage
= 1;
2777 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2778 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2783 * 'skip_page()' - Skip past a page that won't be printed.
2786 static ssize_t
/* O - Length of next line */
2787 skip_page(cups_file_t
*fp
, /* I - File to read from */
2788 char *line
, /* I - Line buffer */
2789 ssize_t linelen
, /* I - Length of initial line */
2790 size_t linesize
) /* I - Size of line buffer */
2792 int level
; /* Embedded document level */
2797 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2800 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer", 9)))
2802 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2803 !strncmp(line
, "%ADO_BeginApplication", 21))
2805 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2806 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2808 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2809 (!strncmp(line
, "%%BeginData:", 12) &&
2810 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2813 * Skip binary data...
2816 int bytes
; /* Bytes of data */
2819 bytes
= atoi(strchr(line
, ':') + 1);
2823 if (bytes
> linesize
)
2824 linelen
= cupsFileRead(fp
, line
, linesize
);
2826 linelen
= cupsFileRead(fp
, line
, bytes
);
2831 perror("ERROR: Early end-of-file while reading binary data");
2845 * 'start_nup()' - Start processing for N-up printing.
2849 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2850 int number
, /* I - Page number */
2851 int show_border
, /* I - Show the border? */
2852 const int *bounding_box
) /* I - BoundingBox value */
2854 int pos
; /* Position on page */
2855 int x
, y
; /* Relative position of subpage */
2856 float w
, l
, /* Width and length of subpage */
2857 tx
, ty
; /* Translation values for subpage */
2858 float pagew
, /* Printable width of page */
2859 pagel
; /* Printable height of page */
2860 int bboxx
, /* BoundingBox X origin */
2861 bboxy
, /* BoundingBox Y origin */
2862 bboxw
, /* BoundingBox width */
2863 bboxl
; /* BoundingBox height */
2864 float margin
= 0; /* Current margin for border */
2867 if (doc
->number_up
> 1)
2868 doc_puts(doc
, "userdict/ESPsave save put\n");
2870 pos
= (number
- 1) % doc
->number_up
;
2871 pagew
= PageRight
- PageLeft
;
2872 pagel
= PageTop
- PageBottom
;
2876 bboxx
= bounding_box
[0];
2877 bboxy
= bounding_box
[1];
2878 bboxw
= bounding_box
[2] - bounding_box
[0];
2879 bboxl
= bounding_box
[3] - bounding_box
[1];
2889 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2890 fprintf(stderr
, "DEBUG: bboxx = %d, bboxy = %d, bboxw = %d, bboxl = %d\n",
2891 bboxx
, bboxy
, bboxw
, bboxl
);
2892 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2893 PageLeft
, PageRight
);
2894 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2895 PageTop
, PageBottom
);
2896 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2897 PageWidth
, PageLength
);
2899 switch (Orientation
)
2901 case 1 : /* Landscape */
2902 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2904 case 2 : /* Reverse Portrait */
2905 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2908 case 3 : /* Reverse Landscape */
2909 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2913 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2914 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2915 else if (doc
->number_up
> 1 || doc
->fitplot
)
2916 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2919 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
2921 switch (doc
->number_up
)
2927 l
= w
* bboxl
/ bboxw
;
2932 w
= l
* bboxw
/ bboxl
;
2935 tx
= 0.5 * (pagew
- w
);
2936 ty
= 0.5 * (pagel
- l
);
2938 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2939 w
/ bboxw
, l
/ bboxl
);
2946 if (Orientation
& 1)
2950 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2954 l
= w
* bboxl
/ bboxw
;
2956 if (l
> (pagew
* 0.5))
2959 w
= l
* bboxw
/ bboxl
;
2962 tx
= 0.5 * (pagew
* 0.5 - l
);
2963 ty
= 0.5 * (pagel
- w
);
2965 if (doc
->normal_landscape
)
2966 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2968 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2970 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2971 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2977 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2981 w
= l
* bboxw
/ bboxl
;
2983 if (w
> (pagel
* 0.5))
2986 l
= w
* bboxl
/ bboxw
;
2989 tx
= 0.5 * (pagel
* 0.5 - w
);
2990 ty
= 0.5 * (pagew
- l
);
2992 if (doc
->normal_landscape
)
2993 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2995 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2997 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2998 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
3003 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3014 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3017 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3021 l
= w
* bboxl
/ bboxw
;
3023 if (l
> (pagel
* 0.5))
3026 w
= l
* bboxw
/ bboxl
;
3029 tx
= 0.5 * (pagew
* 0.5 - w
);
3030 ty
= 0.5 * (pagel
* 0.5 - l
);
3032 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3033 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
3034 w
/ bboxw
, l
/ bboxl
);
3038 if (Orientation
& 1)
3040 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3045 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3048 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3056 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3059 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3064 l
= w
* bboxl
/ bboxw
;
3066 if (l
> (pagew
* 0.333))
3069 w
= l
* bboxw
/ bboxl
;
3072 tx
= 0.5 * (pagel
- 2 * w
);
3073 ty
= 0.5 * (pagew
- 3 * l
);
3075 if (doc
->normal_landscape
)
3076 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
3078 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
3080 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3081 tx
+ x
* w
, ty
+ y
* l
, l
/ bboxl
, w
/ bboxw
);
3085 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3090 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3093 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3101 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3104 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3109 w
= l
* bboxw
/ bboxl
;
3111 if (w
> (pagel
* 0.333))
3114 l
= w
* bboxl
/ bboxw
;
3117 tx
= 0.5 * (pagel
- 3 * w
);
3118 ty
= 0.5 * (pagew
- 2 * l
);
3120 if (doc
->normal_landscape
)
3121 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
3123 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
3125 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3126 tx
+ w
* x
, ty
+ l
* y
, w
/ bboxw
, l
/ bboxl
);
3132 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3143 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3146 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3150 l
= w
* bboxl
/ bboxw
;
3152 if (l
> (pagel
* 0.333))
3155 w
= l
* bboxw
/ bboxl
;
3158 tx
= 0.5 * (pagew
* 0.333 - w
);
3159 ty
= 0.5 * (pagel
* 0.333 - l
);
3161 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3162 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
3163 w
/ bboxw
, l
/ bboxl
);
3167 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3178 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3181 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3185 l
= w
* bboxl
/ bboxw
;
3187 if (l
> (pagel
* 0.25))
3190 w
= l
* bboxw
/ bboxl
;
3193 tx
= 0.5 * (pagew
* 0.25 - w
);
3194 ty
= 0.5 * (pagel
* 0.25 - l
);
3196 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3197 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
3198 w
/ bboxw
, l
/ bboxl
);
3203 * Draw borders as necessary...
3206 if (doc
->page_border
&& show_border
)
3208 int rects
; /* Number of border rectangles */
3209 float fscale
; /* Scaling value for points */
3212 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
3213 fscale
= PageWidth
/ w
;
3214 margin
= 2.25 * fscale
;
3217 * Set the line width and color...
3220 doc_puts(doc
, "gsave\n");
3221 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
3222 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
3226 * Draw border boxes...
3229 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
3230 if (doc
->number_up
> 1)
3231 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
3235 bboxl
- 2 * margin
);
3237 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
3239 PageBottom
+ margin
,
3240 PageRight
- PageLeft
- 2 * margin
,
3241 PageTop
- PageBottom
- 2 * margin
);
3244 * Restore pen settings...
3247 doc_puts(doc
, "grestore\n");
3253 * Offset the page by its bounding box...
3256 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
3260 if (doc
->fitplot
|| doc
->number_up
> 1)
3263 * Clip the page to the page's bounding box...
3266 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrc\n",
3267 bboxx
+ margin
, bboxy
+ margin
,
3268 bboxw
- 2 * margin
, bboxl
- 2 * margin
);
3274 * 'write_label_prolog()' - Write the prolog with the classification
3279 write_label_prolog(pstops_doc_t
*doc
, /* I - Document info */
3280 const char *label
, /* I - Page label */
3281 float bottom
, /* I - Bottom position in points */
3282 float top
, /* I - Top position in points */
3283 float width
) /* I - Width in points */
3285 const char *classification
; /* CLASSIFICATION environment variable */
3286 const char *ptr
; /* Temporary string pointer */
3290 * First get the current classification...
3293 if ((classification
= getenv("CLASSIFICATION")) == NULL
)
3294 classification
= "";
3295 if (strcmp(classification
, "none") == 0)
3296 classification
= "";
3299 * If there is nothing to show, bind an empty 'write labels' procedure
3303 if (!classification
[0] && (label
== NULL
|| !label
[0]))
3305 doc_puts(doc
, "userdict/ESPwl{}bind put\n");
3310 * Set the classification + page label string...
3313 doc_puts(doc
, "userdict");
3314 if (!strcmp(classification
, "confidential"))
3315 doc_puts(doc
, "/ESPpl(CONFIDENTIAL");
3316 else if (!strcmp(classification
, "classified"))
3317 doc_puts(doc
, "/ESPpl(CLASSIFIED");
3318 else if (!strcmp(classification
, "secret"))
3319 doc_puts(doc
, "/ESPpl(SECRET");
3320 else if (!strcmp(classification
, "topsecret"))
3321 doc_puts(doc
, "/ESPpl(TOP SECRET");
3322 else if (!strcmp(classification
, "unclassified"))
3323 doc_puts(doc
, "/ESPpl(UNCLASSIFIED");
3326 doc_puts(doc
, "/ESPpl(");
3328 for (ptr
= classification
; *ptr
; ptr
++)
3330 if (*ptr
< 32 || *ptr
> 126)
3331 doc_printf(doc
, "\\%03o", *ptr
);
3332 else if (*ptr
== '_')
3334 else if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
3335 doc_printf(doc
, "\\%c", *ptr
);
3337 doc_printf(doc
, "%c", *ptr
);
3343 if (classification
[0])
3344 doc_puts(doc
, " - ");
3347 * Quote the label string as needed...
3350 for (ptr
= label
; *ptr
; ptr
++)
3352 if (*ptr
< 32 || *ptr
> 126)
3353 doc_printf(doc
, "\\%03o", *ptr
);
3354 else if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
3355 doc_printf(doc
, "\\%c", *ptr
);
3357 doc_printf(doc
, "%c", *ptr
);
3361 doc_puts(doc
, ")put\n");
3364 * Then get a 14 point Helvetica-Bold font...
3367 doc_puts(doc
, "userdict/ESPpf /Helvetica-Bold findfont 14 scalefont put\n");
3370 * Finally, the procedure to write the labels on the page...
3373 doc_puts(doc
, "userdict/ESPwl{\n");
3374 doc_puts(doc
, " ESPpf setfont\n");
3375 doc_printf(doc
, " ESPpl stringwidth pop dup 12 add exch -0.5 mul %.0f add\n",
3377 doc_puts(doc
, " 1 setgray\n");
3378 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrf\n", bottom
- 2.0);
3379 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrf\n", top
- 18.0);
3380 doc_puts(doc
, " 0 setgray\n");
3381 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrs\n", bottom
- 2.0);
3382 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrs\n", top
- 18.0);
3383 doc_printf(doc
, " dup %.0f moveto ESPpl show\n", bottom
+ 2.0);
3384 doc_printf(doc
, " %.0f moveto ESPpl show\n", top
- 14.0);
3385 doc_puts(doc
, "pop\n");
3386 doc_puts(doc
, "}bind put\n");
3391 * 'write_labels()' - Write the actual page labels.
3393 * This function is a copy of the one in common.c since we need to
3394 * use doc_puts/doc_printf instead of puts/printf...
3398 write_labels(pstops_doc_t
*doc
, /* I - Document information */
3399 int orient
) /* I - Orientation of the page */
3401 float width
, /* Width of page */
3402 length
; /* Length of page */
3405 doc_puts(doc
, "gsave\n");
3407 if ((orient
^ Orientation
) & 1)
3415 length
= PageLength
;
3420 case 1 : /* Landscape */
3421 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", length
);
3423 case 2 : /* Reverse Portrait */
3424 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", width
, length
);
3426 case 3 : /* Reverse Landscape */
3427 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", width
);
3431 doc_puts(doc
, "ESPwl\n");
3432 doc_puts(doc
, "grestore\n");
3437 * 'write_options()' - Write options provided via %%IncludeFeature.
3442 pstops_doc_t
*doc
, /* I - Document */
3443 ppd_file_t
*ppd
, /* I - PPD file */
3444 int num_options
, /* I - Number of options */
3445 cups_option_t
*options
) /* I - Options */
3447 int i
; /* Looping var */
3448 ppd_option_t
*option
; /* PPD option */
3449 int min_order
; /* Minimum OrderDependency value */
3450 char *doc_setup
, /* DocumentSetup commands to send */
3451 *any_setup
; /* AnySetup commands to send */
3455 * Figure out the minimum OrderDependency value...
3458 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
3459 min_order
= option
->order
;
3463 for (i
= 0; i
< num_options
; i
++)
3464 if ((option
= ppdFindOption(ppd
, options
[i
].name
)) != NULL
&&
3465 option
->order
< min_order
)
3466 min_order
= option
->order
;
3469 * Mark and extract them...
3472 cupsMarkOptions(ppd
, num_options
, options
);
3474 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
3475 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
3478 * Then send them out...
3481 if (doc
->number_up
> 1)
3484 * Temporarily restore setpagedevice so we can set the options...
3487 doc_puts(doc
, "userdict/setpagedevice/CUPSsetpagedevice load put\n");
3492 doc_puts(doc
, doc_setup
);
3498 doc_puts(doc
, any_setup
);
3502 if (doc
->number_up
> 1)
3505 * Disable setpagedevice again...
3508 doc_puts(doc
, "userdict/setpagedevice{pop}bind put\n");
3514 * End of "$Id: pstops.c 7977 2008-09-23 23:44:33Z mike $".