]>
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-2011 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 * Ignore broken pipe signals...
260 signal(SIGPIPE
, SIG_IGN
);
263 * Check command-line...
266 if (argc
< 6 || argc
> 7)
268 _cupsLangPrintf(stderr
,
269 _("Usage: %s job-id user title copies options file"),
275 * Register a signal handler to cleanly cancel a job.
278 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
279 sigset(SIGTERM
, cancel_job
);
280 #elif defined(HAVE_SIGACTION)
281 memset(&action
, 0, sizeof(action
));
283 sigemptyset(&action
.sa_mask
);
284 action
.sa_handler
= cancel_job
;
285 sigaction(SIGTERM
, &action
, NULL
);
287 signal(SIGTERM
, cancel_job
);
288 #endif /* HAVE_SIGSET */
291 * If we have 7 arguments, print the file named on the command-line.
292 * Otherwise, send stdin instead...
296 fp
= cupsFileStdin();
300 * Try to open the print file...
303 if ((fp
= cupsFileOpen(argv
[6], "r")) == NULL
)
305 _cupsLangPrintError("ERROR", _("Unable to open print file"));
311 * Read the first line to see if we have DSC comments...
314 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
316 fputs("DEBUG: The print file is empty.\n", stderr
);
321 * Process command-line options...
325 num_options
= cupsParseOptions(argv
[5], 0, &options
);
326 ppd
= SetCommonOptions(num_options
, options
, 1);
328 set_pstops_options(&doc
, ppd
, argv
, num_options
, options
);
331 * Write any "exit server" options that have been selected...
334 ppdEmit(ppd
, stdout
, PPD_ORDER_EXIT
);
337 * Write any JCL commands that are needed to print PostScript code...
341 ppdEmitJCL(ppd
, stdout
, doc
.job_id
, doc
.user
, doc
.title
);
344 * Start with a DSC header...
347 puts("%!PS-Adobe-3.0");
350 * Skip leading PJL in the document...
353 while (!strncmp(line
, "\033%-12345X", 9) || !strncmp(line
, "@PJL ", 5))
356 * Yup, we have leading PJL fun, so skip it until we hit the line
357 * with "ENTER LANGUAGE"...
360 fputs("DEBUG: Skipping PJL header...\n", stderr
);
362 while (strstr(line
, "ENTER LANGUAGE") == NULL
&& strncmp(line
, "%!", 2))
363 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
366 if (!strncmp(line
, "%!", 2))
369 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
374 * Now see if the document conforms to the Adobe Document Structuring
378 if (!strncmp(line
, "%!PS-Adobe-", 11))
381 * Yes, filter the document...
384 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
389 * No, display an error message and treat the file as if it contains
393 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
397 * Send %%EOF as needed...
404 * End the job with the appropriate JCL command or CTRL-D...
409 if (ppd
&& ppd
->jcl_end
)
410 ppdEmitJCLEnd(ppd
, stdout
);
416 * Close files and remove the temporary file if needed...
421 cupsFileClose(doc
.temp
);
422 unlink(doc
.tempfile
);
426 cupsFreeOptions(num_options
, options
);
435 * 'add_page()' - Add a page to the pages array.
438 static pstops_page_t
* /* O - New page info object */
439 add_page(pstops_doc_t
*doc
, /* I - Document information */
440 const char *label
) /* I - Page label */
442 pstops_page_t
*pageinfo
; /* New page info object */
446 doc
->pages
= cupsArrayNew(NULL
, NULL
);
450 _cupsLangPrintError("EMERG", _("Unable to allocate memory for pages array"));
454 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
456 _cupsLangPrintError("EMERG", _("Unable to allocate memory for page info"));
460 pageinfo
->label
= strdup(label
);
461 pageinfo
->offset
= cupsFileTell(doc
->temp
);
463 cupsArrayAdd(doc
->pages
, pageinfo
);
472 * 'cancel_job()' - Flag the job as canceled.
476 cancel_job(int sig
) /* I - Signal number (unused) */
485 * 'check_range()' - Check to see if the current page is selected for
489 static int /* O - 1 if selected, 0 otherwise */
490 check_range(pstops_doc_t
*doc
, /* I - Document information */
491 int page
) /* I - Page number */
493 const char *range
; /* Pointer into range string */
494 int lower
, upper
; /* Lower and upper page numbers */
500 * See if we only print even or odd pages...
503 if (!strcasecmp(doc
->page_set
, "even") && (page
& 1))
506 if (!strcasecmp(doc
->page_set
, "odd") && !(page
& 1))
510 if (!doc
->page_ranges
)
511 return (1); /* No range, print all pages... */
513 for (range
= doc
->page_ranges
; *range
!= '\0';)
519 upper
= strtol(range
, (char **)&range
, 10);
523 lower
= strtol(range
, (char **)&range
, 10);
528 if (!isdigit(*range
& 255))
531 upper
= strtol(range
, (char **)&range
, 10);
537 if (page
>= lower
&& page
<= upper
)
551 * 'copy_bytes()' - Copy bytes from the input file to stdout.
555 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
556 off_t offset
, /* I - Offset to page data */
557 size_t length
) /* I - Length of page data */
559 char buffer
[8192]; /* Data buffer */
560 ssize_t nbytes
; /* Number of bytes read */
561 size_t nleft
; /* Number of bytes left/remaining */
566 if (cupsFileSeek(fp
, offset
) < 0)
568 _cupsLangPrintError("ERROR", _("Unable to see in file"));
572 while (nleft
> 0 || length
== 0)
574 if (nleft
> sizeof(buffer
) || length
== 0)
575 nbytes
= sizeof(buffer
);
579 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
584 fwrite(buffer
, 1, nbytes
, stdout
);
590 * 'copy_comments()' - Copy all of the comments section.
592 * This function expects "line" to be filled with a comment line.
593 * On return, "line" will contain the next line in the file, if any.
596 static ssize_t
/* O - Length of next line */
597 copy_comments(cups_file_t
*fp
, /* I - File to read from */
598 pstops_doc_t
*doc
, /* I - Document info */
599 ppd_file_t
*ppd
, /* I - PPD file */
600 char *line
, /* I - Line buffer */
601 ssize_t linelen
, /* I - Length of initial line */
602 size_t linesize
) /* I - Size of line buffer */
604 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
605 saw_for
, /* Saw %%For: comment? */
606 saw_pages
, /* Saw %%Pages: comment? */
607 saw_title
; /* Saw %%Title: comment? */
611 * Loop until we see %%EndComments or a non-comment line...
614 saw_bounding_box
= 0;
619 while (line
[0] == '%')
622 * Strip trailing whitespace...
629 if (!isspace(line
[linelen
] & 255))
632 line
[linelen
] = '\0';
639 fprintf(stderr
, "DEBUG: %s\n", line
);
642 * Pull the headers out...
645 if (!strncmp(line
, "%%Pages:", 8))
647 int pages
; /* Number of pages */
650 fputs("DEBUG: A duplicate %%Pages: comment was seen.\n", stderr
);
654 if (Duplex
&& (pages
= atoi(line
+ 8)) > 0 && pages
<= doc
->number_up
)
657 * Since we will only be printing on a single page, disable duplexing.
661 doc
->slow_duplex
= 0;
663 if (cupsGetOption("sides", doc
->num_options
, doc
->options
))
664 doc
->num_options
= cupsAddOption("sides", "one-sided",
665 doc
->num_options
, &(doc
->options
));
667 if (cupsGetOption("Duplex", doc
->num_options
, doc
->options
))
668 doc
->num_options
= cupsAddOption("Duplex", "None",
669 doc
->num_options
, &(doc
->options
));
671 if (cupsGetOption("EFDuplex", doc
->num_options
, doc
->options
))
672 doc
->num_options
= cupsAddOption("EFDuplex", "None",
673 doc
->num_options
, &(doc
->options
));
675 if (cupsGetOption("EFDuplexing", doc
->num_options
, doc
->options
))
676 doc
->num_options
= cupsAddOption("EFDuplexing", "False",
677 doc
->num_options
, &(doc
->options
));
679 if (cupsGetOption("KD03Duplex", doc
->num_options
, doc
->options
))
680 doc
->num_options
= cupsAddOption("KD03Duplex", "None",
681 doc
->num_options
, &(doc
->options
));
683 if (cupsGetOption("JCLDuplex", doc
->num_options
, doc
->options
))
684 doc
->num_options
= cupsAddOption("JCLDuplex", "None",
685 doc
->num_options
, &(doc
->options
));
687 ppdMarkOption(ppd
, "Duplex", "None");
688 ppdMarkOption(ppd
, "EFDuplex", "None");
689 ppdMarkOption(ppd
, "EFDuplexing", "False");
690 ppdMarkOption(ppd
, "KD03Duplex", "None");
691 ppdMarkOption(ppd
, "JCLDuplex", "None");
694 else if (!strncmp(line
, "%%BoundingBox:", 14))
696 if (saw_bounding_box
)
697 fputs("DEBUG: A duplicate %%BoundingBox: comment was seen.\n", stderr
);
698 else if (strstr(line
+ 14, "(atend)"))
701 * Do nothing for now but use the default imageable area...
704 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
705 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
706 doc
->bounding_box
+ 3) != 4)
708 fputs("DEBUG: A bad %%BoundingBox: comment was seen.\n", stderr
);
710 doc
->bounding_box
[0] = (int)PageLeft
;
711 doc
->bounding_box
[1] = (int)PageBottom
;
712 doc
->bounding_box
[2] = (int)PageRight
;
713 doc
->bounding_box
[3] = (int)PageTop
;
716 saw_bounding_box
= 1;
718 else if (!strncmp(line
, "%%For:", 6))
721 doc_printf(doc
, "%s\n", line
);
723 else if (!strncmp(line
, "%%Title:", 8))
726 doc_printf(doc
, "%s\n", line
);
728 else if (!strncmp(line
, "%cupsRotation:", 14))
731 * Reset orientation of document?
734 int orient
= (atoi(line
+ 14) / 90) & 3;
736 if (orient
!= Orientation
)
739 * Yes, update things so that the pages come out right...
742 Orientation
= (4 - Orientation
+ orient
) & 3;
744 Orientation
= orient
;
747 else if (!strcmp(line
, "%%EndComments"))
749 linelen
= cupsFileGetLine(fp
, line
, linesize
);
752 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
753 doc_printf(doc
, "%s\n", line
);
755 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
759 if (!saw_bounding_box
)
760 fputs("DEBUG: There wasn't a %%BoundingBox: comment in the header.\n",
764 fputs("DEBUG: There wasn't a %%Pages: comment in the header.\n", stderr
);
767 WriteTextComment("For", doc
->user
);
770 WriteTextComment("Title", doc
->title
);
772 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
775 * Tell the document processor the copy and duplex options
776 * that are required...
779 doc_printf(doc
, "%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
780 doc
->collate
? " collate" : "",
781 Duplex
? " duplex" : "");
784 * Apple uses RBI comments for various non-PPD options...
787 doc_printf(doc
, "%%RBINumCopies: %d\n", doc
->copies
);
792 * Tell the document processor the duplex option that is required...
796 doc_puts(doc
, "%%Requirements: duplex\n");
799 * Apple uses RBI comments for various non-PPD options...
802 doc_puts(doc
, "%RBINumCopies: 1\n");
805 doc_puts(doc
, "%%Pages: (atend)\n");
806 doc_puts(doc
, "%%BoundingBox: (atend)\n");
807 doc_puts(doc
, "%%EndComments\n");
814 * 'copy_dsc()' - Copy a DSC-conforming document.
816 * This function expects "line" to be filled with the %!PS-Adobe comment line.
820 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
821 pstops_doc_t
*doc
, /* I - Document info */
822 ppd_file_t
*ppd
, /* I - PPD file */
823 char *line
, /* I - Line buffer */
824 ssize_t linelen
, /* I - Length of initial line */
825 size_t linesize
) /* I - Size of line buffer */
827 int number
; /* Page number */
828 pstops_page_t
*pageinfo
; /* Page information */
832 * Make sure we use ESPshowpage for EPS files...
835 if (strstr(line
, "EPSF"))
837 doc
->use_ESPshowpage
= 1;
842 * Start sending the document with any commands needed...
845 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
846 linelen
= copy_comments(fp
, doc
, ppd
, line
, linelen
, linesize
);
849 * Now find the prolog section, if any...
852 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
853 linelen
= copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
856 * Then the document setup section...
859 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
860 linelen
= copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
863 * Copy until we see %%Page:...
866 while (strncmp(line
, "%%Page:", 7) && strncmp(line
, "%%Trailer", 9))
868 doc_write(doc
, line
, linelen
);
870 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
875 * Then process pages until we have no more...
880 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
881 while (!strncmp(line
, "%%Page:", 7))
888 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
890 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
891 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
895 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
896 linelen
= skip_page(fp
, line
, linelen
, linesize
);
901 * Finish up the last page(s)...
904 if (number
&& is_not_last_page(number
) && cupsArrayLast(doc
->pages
) &&
905 check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
907 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
909 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
910 doc_puts(doc
, "showpage\n");
911 end_nup(doc
, doc
->number_up
);
913 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
916 if (doc
->slow_duplex
&& (doc
->page
& 1))
919 * Make sure we have an even number of pages...
922 pageinfo
= add_page(doc
, "(filler)");
924 if (!doc
->slow_order
)
926 if (!ppd
|| !ppd
->num_filters
)
927 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
928 doc
->slow_collate
? 1 : doc
->copies
);
930 printf("%%%%Page: (filler) %d\n", doc
->page
);
933 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
934 doc_puts(doc
, "showpage\n");
935 end_nup(doc
, doc
->number_up
);
937 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
941 * Make additional copies as necessary...
944 number
= doc
->slow_order
? 0 : doc
->page
;
946 if (doc
->temp
&& !JobCanceled
&& cupsArrayCount(doc
->pages
) > 0)
948 int copy
; /* Current copy */
952 * Reopen the temporary file for reading...
955 cupsFileClose(doc
->temp
);
957 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
963 if (doc
->slow_collate
)
964 copy
= !doc
->slow_order
;
966 copy
= doc
->copies
- 1;
968 for (; copy
< doc
->copies
; copy
++)
974 * Send end-of-job stuff followed by any start-of-job stuff required
975 * for the JCL options...
978 if (number
&& doc
->emit_jcl
&& ppd
&& ppd
->jcl_end
)
981 * Send the trailer...
985 printf("%%%%Pages: %d\n", cupsArrayCount(doc
->pages
));
986 if (doc
->number_up
> 1 || doc
->fitplot
)
987 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
988 PageLeft
, PageBottom
, PageRight
, PageTop
);
990 printf("%%%%BoundingBox: %d %d %d %d\n",
991 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
992 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
996 * Start a new document...
999 ppdEmitJCLEnd(ppd
, stdout
);
1000 ppdEmitJCL(ppd
, stdout
, doc
->job_id
, doc
->user
, doc
->title
);
1002 puts("%!PS-Adobe-3.0");
1008 * Copy the prolog as needed...
1013 pageinfo
= (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
1014 copy_bytes(doc
->temp
, 0, pageinfo
->offset
);
1018 * Then copy all of the pages...
1021 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
1022 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
1031 if (!ppd
|| !ppd
->num_filters
)
1032 fprintf(stderr
, "PAGE: %d %d\n", number
,
1033 doc
->slow_collate
? 1 : doc
->copies
);
1035 if (doc
->number_up
> 1)
1037 printf("%%%%Page: (%d) %d\n", number
, number
);
1038 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1039 PageLeft
, PageBottom
, PageRight
, PageTop
);
1043 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
1044 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1045 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1046 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1049 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
1051 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
1052 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
1058 * Restore the old showpage operator as needed...
1061 if (doc
->use_ESPshowpage
)
1062 puts("userdict/showpage/ESPshowpage load put\n");
1065 * Write/copy the trailer...
1069 copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
1074 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC.
1076 * This function expects "line" to be filled with the %! comment line.
1080 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
1081 pstops_doc_t
*doc
, /* I - Document info */
1082 ppd_file_t
*ppd
, /* I - PPD file */
1083 char *line
, /* I - Line buffer */
1084 ssize_t linelen
, /* I - Length of initial line */
1085 size_t linesize
) /* I - Size of line buffer */
1087 int copy
; /* Current copy */
1088 char buffer
[8192]; /* Copy buffer */
1089 int bytes
; /* Number of bytes copied */
1093 * First let the user know that they are attempting to print a file
1094 * that may not print correctly...
1097 fputs("DEBUG: This document does not conform to the Adobe Document "
1098 "Structuring Conventions and may not print correctly.\n", stderr
);
1101 * Then write a standard DSC comment section...
1104 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
1105 PageRight
, PageTop
);
1107 if (doc
->slow_collate
&& doc
->copies
> 1)
1108 printf("%%%%Pages: %d\n", doc
->copies
);
1112 WriteTextComment("For", doc
->user
);
1113 WriteTextComment("Title", doc
->title
);
1115 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1118 * Tell the document processor the copy and duplex options
1119 * that are required...
1122 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
1123 doc
->collate
? " collate" : "",
1124 Duplex
? " duplex" : "");
1127 * Apple uses RBI comments for various non-PPD options...
1130 printf("%%RBINumCopies: %d\n", doc
->copies
);
1135 * Tell the document processor the duplex option that is required...
1139 puts("%%Requirements: duplex");
1142 * Apple uses RBI comments for various non-PPD options...
1145 puts("%RBINumCopies: 1");
1148 puts("%%EndComments");
1151 * Then the prolog...
1154 puts("%%BeginProlog");
1156 do_prolog(doc
, ppd
);
1158 puts("%%EndProlog");
1161 * Then the setup section...
1164 puts("%%BeginSetup");
1171 * Finally, embed a copy of the file inside a %%Page...
1174 if (!ppd
|| !ppd
->num_filters
)
1175 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
1177 puts("%%Page: 1 1");
1178 puts("%%BeginPageSetup");
1179 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1180 puts("%%EndPageSetup");
1181 puts("%%BeginDocument: nondsc");
1183 fwrite(line
, linelen
, 1, stdout
);
1186 cupsFileWrite(doc
->temp
, line
, linelen
);
1188 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1190 fwrite(buffer
, 1, bytes
, stdout
);
1193 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1196 puts("%%EndDocument");
1198 if (doc
->use_ESPshowpage
)
1200 WriteLabels(Orientation
);
1201 puts("ESPshowpage");
1204 if (doc
->temp
&& !JobCanceled
)
1207 * Reopen the temporary file for reading...
1210 cupsFileClose(doc
->temp
);
1212 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1215 * Make the additional copies as needed...
1218 for (copy
= 1; copy
< doc
->copies
; copy
++)
1223 if (!ppd
|| !ppd
->num_filters
)
1224 fputs("PAGE: 1 1\n", stderr
);
1226 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1227 puts("%%BeginPageSetup");
1228 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1229 puts("%%EndPageSetup");
1230 puts("%%BeginDocument: nondsc");
1232 copy_bytes(doc
->temp
, 0, 0);
1234 puts("%%EndDocument");
1236 if (doc
->use_ESPshowpage
)
1238 WriteLabels(Orientation
);
1239 puts("ESPshowpage");
1245 * Restore the old showpage operator as needed...
1248 if (doc
->use_ESPshowpage
)
1249 puts("userdict/showpage/ESPshowpage load put\n");
1254 * 'copy_page()' - Copy a page description.
1256 * This function expects "line" to be filled with a %%Page comment line.
1257 * On return, "line" will contain the next line in the file, if any.
1260 static ssize_t
/* O - Length of next line */
1261 copy_page(cups_file_t
*fp
, /* I - File to read from */
1262 pstops_doc_t
*doc
, /* I - Document info */
1263 ppd_file_t
*ppd
, /* I - PPD file */
1264 int number
, /* I - Current page number */
1265 char *line
, /* I - Line buffer */
1266 ssize_t linelen
, /* I - Length of initial line */
1267 size_t linesize
) /* I - Size of line buffer */
1269 char label
[256], /* Page label string */
1270 *ptr
; /* Pointer into line */
1271 int level
; /* Embedded document level */
1272 pstops_page_t
*pageinfo
; /* Page information */
1273 int first_page
; /* First page on N-up output? */
1274 int has_page_setup
; /* Does the page have %%Begin/EndPageSetup? */
1275 int bounding_box
[4]; /* PageBoundingBox */
1279 * Get the page label for this page...
1282 first_page
= is_first_page(number
);
1284 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1286 fputs("DEBUG: There was a bad %%Page: comment in the file.\n", stderr
);
1290 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1292 fputs("DEBUG: There was a bad %%Page: comment in the file.\n", stderr
);
1297 * Create or update the current output page...
1301 pageinfo
= add_page(doc
, label
);
1303 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1306 * Handle first page override...
1309 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1314 * First page/sheet gets AP_FIRSTPAGE_* options...
1317 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1318 pageinfo
->num_options
,
1319 &(pageinfo
->options
));
1320 pageinfo
->num_options
= cupsAddOption("ManualFeed",
1321 doc
->ap_input_slot
? "False" :
1322 doc
->ap_manual_feed
,
1323 pageinfo
->num_options
,
1324 &(pageinfo
->options
));
1325 pageinfo
->num_options
= cupsAddOption("MediaColor", doc
->ap_media_color
,
1326 pageinfo
->num_options
,
1327 &(pageinfo
->options
));
1328 pageinfo
->num_options
= cupsAddOption("MediaType", doc
->ap_media_type
,
1329 pageinfo
->num_options
,
1330 &(pageinfo
->options
));
1331 pageinfo
->num_options
= cupsAddOption("PageRegion", doc
->ap_page_region
,
1332 pageinfo
->num_options
,
1333 &(pageinfo
->options
));
1334 pageinfo
->num_options
= cupsAddOption("PageSize", doc
->ap_page_size
,
1335 pageinfo
->num_options
,
1336 &(pageinfo
->options
));
1338 else if (doc
->page
== (Duplex
+ 2))
1341 * Second page/sheet gets default options...
1344 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1345 pageinfo
->num_options
,
1346 &(pageinfo
->options
));
1347 pageinfo
->num_options
= cupsAddOption("ManualFeed",
1348 doc
->input_slot
? "False" :
1350 pageinfo
->num_options
,
1351 &(pageinfo
->options
));
1352 pageinfo
->num_options
= cupsAddOption("MediaColor", doc
->media_color
,
1353 pageinfo
->num_options
,
1354 &(pageinfo
->options
));
1355 pageinfo
->num_options
= cupsAddOption("MediaType", doc
->media_type
,
1356 pageinfo
->num_options
,
1357 &(pageinfo
->options
));
1358 pageinfo
->num_options
= cupsAddOption("PageRegion", doc
->page_region
,
1359 pageinfo
->num_options
,
1360 &(pageinfo
->options
));
1361 pageinfo
->num_options
= cupsAddOption("PageSize", doc
->page_size
,
1362 pageinfo
->num_options
,
1363 &(pageinfo
->options
));
1368 * Scan comments until we see something other than %%Page*: or
1372 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1374 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1376 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1379 * %%PageBoundingBox: llx lly urx ury
1382 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1383 bounding_box
+ 1, bounding_box
+ 2,
1384 bounding_box
+ 3) != 4)
1386 fputs("DEBUG: There was a bad %%PageBoundingBox: comment in the file.\n", stderr
);
1387 memcpy(bounding_box
, doc
->bounding_box
,
1388 sizeof(bounding_box
));
1390 else if (doc
->number_up
== 1 && !doc
->fitplot
&& Orientation
)
1392 int temp_bbox
[4]; /* Temporary bounding box */
1395 memcpy(temp_bbox
, bounding_box
, sizeof(temp_bbox
));
1397 fprintf(stderr
, "DEBUG: Orientation = %d\n", Orientation
);
1398 fprintf(stderr
, "DEBUG: original bounding_box = [ %d %d %d %d ]\n",
1399 bounding_box
[0], bounding_box
[1],
1400 bounding_box
[2], bounding_box
[3]);
1401 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
1402 PageWidth
, PageLength
);
1404 switch (Orientation
)
1406 case 1 : /* Landscape */
1407 bounding_box
[0] = PageLength
- temp_bbox
[3];
1408 bounding_box
[1] = temp_bbox
[0];
1409 bounding_box
[2] = PageLength
- temp_bbox
[1];
1410 bounding_box
[3] = temp_bbox
[2];
1413 case 2 : /* Reverse Portrait */
1414 bounding_box
[0] = PageWidth
- temp_bbox
[2];
1415 bounding_box
[1] = PageLength
- temp_bbox
[3];
1416 bounding_box
[2] = PageWidth
- temp_bbox
[0];
1417 bounding_box
[3] = PageLength
- temp_bbox
[1];
1420 case 3 : /* Reverse Landscape */
1421 bounding_box
[0] = temp_bbox
[1];
1422 bounding_box
[1] = PageWidth
- temp_bbox
[2];
1423 bounding_box
[2] = temp_bbox
[3];
1424 bounding_box
[3] = PageWidth
- temp_bbox
[0];
1428 fprintf(stderr
, "DEBUG: updated bounding_box = [ %d %d %d %d ]\n",
1429 bounding_box
[0], bounding_box
[1],
1430 bounding_box
[2], bounding_box
[3]);
1434 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1435 !strncmp(line
, "%%PageMedia:", 12) ||
1436 !strncmp(line
, "%%PageOrientation:", 18) ||
1437 !strncmp(line
, "%%PageProcessColors:", 20) ||
1438 !strncmp(line
, "%%PageRequirements:", 18) ||
1439 !strncmp(line
, "%%PageResources:", 16))
1446 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1449 * %%PageCustomColors: ...
1452 else if (!strncmp(line
, "%%PageMedia:", 12))
1458 else if (!strncmp(line
, "%%PageOrientation:", 18))
1461 * %%PageOrientation: ...
1464 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1467 * %%PageProcessColors: ...
1470 else if (!strncmp(line
, "%%PageRequirements:", 18))
1473 * %%PageRequirements: ...
1476 else if (!strncmp(line
, "%%PageResources:", 16))
1479 * %%PageResources: ...
1482 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1485 * %%IncludeFeature: *MainKeyword OptionKeyword
1488 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1489 pageinfo
->num_options
= include_feature(ppd
, line
,
1490 pageinfo
->num_options
,
1491 &(pageinfo
->options
));
1493 else if (strncmp(line
, "%%Include", 9))
1497 if (doc
->number_up
== 1)
1500 * Update the document's composite and page bounding box...
1503 memcpy(pageinfo
->bounding_box
, bounding_box
,
1504 sizeof(pageinfo
->bounding_box
));
1506 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1507 doc
->new_bounding_box
[0] = bounding_box
[0];
1508 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1509 doc
->new_bounding_box
[1] = bounding_box
[1];
1510 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1511 doc
->new_bounding_box
[2] = bounding_box
[2];
1512 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1513 doc
->new_bounding_box
[3] = bounding_box
[3];
1517 * Output the page header as needed...
1520 if (!doc
->slow_order
&& first_page
)
1522 if (!ppd
|| !ppd
->num_filters
)
1523 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1524 doc
->slow_collate
? 1 : doc
->copies
);
1526 if (doc
->number_up
> 1)
1528 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1529 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1530 PageLeft
, PageBottom
, PageRight
, PageTop
);
1534 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1535 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1536 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1537 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1542 * Copy any page setup commands...
1546 doc_puts(doc
, "%%BeginPageSetup\n");
1548 if ((has_page_setup
= !strncmp(line
, "%%BeginPageSetup", 16)) != 0)
1550 int feature
= 0; /* In a Begin/EndFeature block? */
1552 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1554 if (!strncmp(line
, "%%EndPageSetup", 14))
1556 else if (!strncmp(line
, "%%BeginFeature:", 15))
1560 if (doc
->number_up
> 1 || doc
->fitplot
)
1563 else if (!strncmp(line
, "%%EndFeature", 12))
1567 if (doc
->number_up
> 1 || doc
->fitplot
)
1570 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1572 pageinfo
->num_options
= include_feature(ppd
, line
,
1573 pageinfo
->num_options
,
1574 &(pageinfo
->options
));
1577 else if (!strncmp(line
, "%%Include", 9))
1580 if (line
[0] != '%' && !feature
)
1583 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1584 doc_write(doc
, line
, linelen
);
1588 * Skip %%EndPageSetup...
1591 if (linelen
> 0 && !strncmp(line
, "%%EndPageSetup", 14))
1593 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1600 char *page_setup
; /* PageSetup commands to send */
1603 if (pageinfo
->num_options
> 0)
1604 write_options(doc
, ppd
, pageinfo
->num_options
, pageinfo
->options
);
1607 * Output commands for the current page...
1610 page_setup
= ppdEmitString(ppd
, PPD_ORDER_PAGE
, 0);
1614 doc_puts(doc
, page_setup
);
1620 * Prep for the start of the page description...
1623 start_nup(doc
, number
, 1, bounding_box
);
1626 * Finish the PageSetup section as needed...
1631 int feature
= 0; /* In a Begin/EndFeature block? */
1633 doc_write(doc
, line
, linelen
);
1635 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1637 if (!strncmp(line
, "%%EndPageSetup", 14))
1639 else if (!strncmp(line
, "%%BeginFeature:", 15))
1643 if (doc
->number_up
> 1 || doc
->fitplot
)
1646 else if (!strncmp(line
, "%%EndFeature", 12))
1650 if (doc
->number_up
> 1 || doc
->fitplot
)
1653 else if (!strncmp(line
, "%%Include", 9))
1656 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1657 doc_write(doc
, line
, linelen
);
1661 * Skip %%EndPageSetup...
1664 if (linelen
> 0 && !strncmp(line
, "%%EndPageSetup", 14))
1665 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1669 doc_puts(doc
, "%%EndPageSetup\n");
1672 * Read the rest of the page description...
1680 (!strncmp(line
, "%%Page:", 7) ||
1681 !strncmp(line
, "%%Trailer", 9) ||
1682 !strncmp(line
, "%%EOF", 5)))
1684 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1685 !strncmp(line
, "%ADO_BeginApplication", 21))
1687 doc_write(doc
, line
, linelen
);
1691 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1692 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1694 doc_write(doc
, line
, linelen
);
1698 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1699 (!strncmp(line
, "%%BeginData:", 12) &&
1700 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1703 * Copy binary data...
1706 int bytes
; /* Bytes of data */
1709 doc_write(doc
, line
, linelen
);
1711 bytes
= atoi(strchr(line
, ':') + 1);
1715 if (bytes
> linesize
)
1716 linelen
= cupsFileRead(fp
, line
, linesize
);
1718 linelen
= cupsFileRead(fp
, line
, bytes
);
1723 perror("ERROR: Early end-of-file while reading binary data");
1727 doc_write(doc
, line
, linelen
);
1733 doc_write(doc
, line
, linelen
);
1735 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1738 * Finish up this page and return...
1741 end_nup(doc
, number
);
1743 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1750 * 'copy_prolog()' - Copy the document prolog section.
1752 * This function expects "line" to be filled with a %%BeginProlog comment line.
1753 * On return, "line" will contain the next line in the file, if any.
1756 static ssize_t
/* O - Length of next line */
1757 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1758 pstops_doc_t
*doc
, /* I - Document info */
1759 ppd_file_t
*ppd
, /* I - PPD file */
1760 char *line
, /* I - Line buffer */
1761 ssize_t linelen
, /* I - Length of initial line */
1762 size_t linesize
) /* I - Size of line buffer */
1764 while (strncmp(line
, "%%BeginProlog", 13))
1766 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1769 doc_write(doc
, line
, linelen
);
1771 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1775 doc_puts(doc
, "%%BeginProlog\n");
1777 do_prolog(doc
, ppd
);
1779 if (!strncmp(line
, "%%BeginProlog", 13))
1781 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1783 if (!strncmp(line
, "%%EndProlog", 11) ||
1784 !strncmp(line
, "%%BeginSetup", 12) ||
1785 !strncmp(line
, "%%Page:", 7))
1788 doc_write(doc
, line
, linelen
);
1791 if (!strncmp(line
, "%%EndProlog", 11))
1792 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1794 fputs("DEBUG: The %%EndProlog comment is missing.\n", stderr
);
1797 doc_puts(doc
, "%%EndProlog\n");
1804 * 'copy_setup()' - Copy the document setup section.
1806 * This function expects "line" to be filled with a %%BeginSetup comment line.
1807 * On return, "line" will contain the next line in the file, if any.
1810 static ssize_t
/* O - Length of next line */
1811 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1812 pstops_doc_t
*doc
, /* I - Document info */
1813 ppd_file_t
*ppd
, /* I - PPD file */
1814 char *line
, /* I - Line buffer */
1815 ssize_t linelen
, /* I - Length of initial line */
1816 size_t linesize
) /* I - Size of line buffer */
1818 int num_options
; /* Number of options */
1819 cups_option_t
*options
; /* Options */
1822 while (strncmp(line
, "%%BeginSetup", 12))
1824 if (!strncmp(line
, "%%Page:", 7))
1827 doc_write(doc
, line
, linelen
);
1829 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1833 doc_puts(doc
, "%%BeginSetup\n");
1840 if (!strncmp(line
, "%%BeginSetup", 12))
1842 while (strncmp(line
, "%%EndSetup", 10))
1844 if (!strncmp(line
, "%%Page:", 7))
1846 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1849 * %%IncludeFeature: *MainKeyword OptionKeyword
1852 if (doc
->number_up
== 1 && !doc
->fitplot
)
1853 num_options
= include_feature(ppd
, line
, num_options
, &options
);
1855 else if (strncmp(line
, "%%BeginSetup", 12))
1856 doc_write(doc
, line
, linelen
);
1858 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1862 if (!strncmp(line
, "%%EndSetup", 10))
1863 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1865 fputs("DEBUG: The %%EndSetup comment is missing.\n", stderr
);
1868 if (num_options
> 0)
1870 write_options(doc
, ppd
, num_options
, options
);
1871 cupsFreeOptions(num_options
, options
);
1874 doc_puts(doc
, "%%EndSetup\n");
1881 * 'copy_trailer()' - Copy the document trailer.
1883 * This function expects "line" to be filled with a %%Trailer comment line.
1884 * On return, "line" will contain the next line in the file, if any.
1887 static ssize_t
/* O - Length of next line */
1888 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1889 pstops_doc_t
*doc
, /* I - Document info */
1890 ppd_file_t
*ppd
, /* I - PPD file */
1891 int number
, /* I - Number of pages */
1892 char *line
, /* I - Line buffer */
1893 ssize_t linelen
, /* I - Length of initial line */
1894 size_t linesize
) /* I - Size of line buffer */
1897 * Write the trailer comments...
1904 if (!strncmp(line
, "%%EOF", 5))
1906 else if (strncmp(line
, "%%Trailer", 9) &&
1907 strncmp(line
, "%%Pages:", 8) &&
1908 strncmp(line
, "%%BoundingBox:", 14))
1909 fwrite(line
, 1, linelen
, stdout
);
1911 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1914 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1916 printf("%%%%Pages: %d\n", number
);
1917 if (doc
->number_up
> 1 || doc
->fitplot
)
1918 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1919 PageLeft
, PageBottom
, PageRight
, PageTop
);
1921 printf("%%%%BoundingBox: %d %d %d %d\n",
1922 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1923 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1930 * 'do_prolog()' - Send the necessary document prolog commands.
1934 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1935 ppd_file_t
*ppd
) /* I - PPD file */
1937 char *ps
; /* PS commands */
1941 * Send the document prolog commands...
1944 if (ppd
&& ppd
->patches
)
1946 doc_puts(doc
, "%%BeginFeature: *JobPatchFile 1\n");
1947 doc_puts(doc
, ppd
->patches
);
1948 doc_puts(doc
, "\n%%EndFeature\n");
1951 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_PROLOG
, 0.0)) != NULL
)
1958 * Define ESPshowpage here so that applications that define their
1959 * own procedure to do a showpage pick it up...
1962 if (doc
->use_ESPshowpage
)
1963 doc_puts(doc
, "userdict/ESPshowpage/showpage load put\n"
1964 "userdict/showpage{}put\n");
1969 * 'do_setup()' - Send the necessary document setup commands.
1973 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1974 ppd_file_t
*ppd
) /* I - PPD file */
1976 char *ps
; /* PS commands */
1980 * Disable CTRL-D so that embedded files don't cause printing
1984 doc_puts(doc
, "% Disable CTRL-D as an end-of-file marker...\n");
1985 doc_puts(doc
, "userdict dup(\\004)cvn{}put (\\004\\004)cvn{}put\n");
1988 * Mark job options...
1991 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
1994 * Send all the printer-specific setup commands...
1997 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, 0.0)) != NULL
)
2003 if ((ps
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
)
2010 * Set the number of copies for the job...
2013 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
2015 doc_printf(doc
, "%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
2017 "%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
2018 "{1 dict begin/NumCopies exch def currentdict end "
2020 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
2021 doc_puts(doc
, "%RBIEndNonPPDFeature\n");
2025 * If we are doing N-up printing, disable setpagedevice...
2028 if (doc
->number_up
> 1)
2030 doc_puts(doc
, "userdict/CUPSsetpagedevice/setpagedevice load put\n");
2031 doc_puts(doc
, "userdict/setpagedevice{pop}bind put\n");
2035 * Changes to the transfer function must be made AFTER any
2036 * setpagedevice code...
2039 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
2040 doc_printf(doc
, "{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
2041 "ifelse %.3f mul } bind settransfer\n",
2042 doc
->gamma
, doc
->brightness
);
2045 * Make sure we have rectclip and rectstroke procedures of some sort...
2049 "% x y w h ESPrc - Clip to a rectangle.\n"
2050 "userdict/ESPrc/rectclip where{pop/rectclip load}\n"
2051 "{{newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2052 "neg 0 rlineto closepath clip newpath}bind}ifelse put\n");
2055 "% x y w h ESPrf - Fill a rectangle.\n"
2056 "userdict/ESPrf/rectfill where{pop/rectfill load}\n"
2057 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2058 "neg 0 rlineto closepath fill grestore}bind}ifelse put\n");
2061 "% x y w h ESPrs - Stroke a rectangle.\n"
2062 "userdict/ESPrs/rectstroke where{pop/rectstroke load}\n"
2063 "{{gsave newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto\n"
2064 "neg 0 rlineto closepath stroke grestore}bind}ifelse put\n");
2067 * Write the page and label prologs...
2070 if (doc
->number_up
== 2 || doc
->number_up
== 6)
2073 * For 2- and 6-up output, rotate the labels to match the orientation
2077 if (Orientation
& 1)
2078 write_label_prolog(doc
, doc
->page_label
, PageBottom
,
2079 PageWidth
- PageLength
+ PageTop
, PageLength
);
2081 write_label_prolog(doc
, doc
->page_label
, PageLeft
, PageRight
,
2085 write_label_prolog(doc
, doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
2090 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
2092 * This function should be used for all page-level output that is affected
2093 * by ordering, collation, etc.
2097 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
2098 const char *format
, /* I - Printf-style format string */
2099 ...) /* I - Additional arguments as needed */
2101 va_list ap
; /* Pointer to arguments */
2102 char buffer
[1024]; /* Output buffer */
2103 size_t bytes
; /* Number of bytes to write */
2106 va_start(ap
, format
);
2107 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
2110 if (bytes
> sizeof(buffer
))
2112 _cupsLangPrintFilter(stderr
, "ERROR",
2113 _("Buffer overflow detected, aborting."));
2117 doc_write(doc
, buffer
, bytes
);
2122 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
2124 * This function should be used for all page-level output that is affected
2125 * by ordering, collation, etc.
2129 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
2130 const char *s
) /* I - String to send */
2132 doc_write(doc
, s
, strlen(s
));
2137 * 'doc_write()' - Send data to stdout and/or the temp file.
2141 doc_write(pstops_doc_t
*doc
, /* I - Document information */
2142 const char *s
, /* I - Data to send */
2143 size_t len
) /* I - Number of bytes to send */
2145 if (!doc
->slow_order
)
2146 fwrite(s
, 1, len
, stdout
);
2149 cupsFileWrite(doc
->temp
, s
, len
);
2154 * 'end_nup()' - End processing for N-up printing.
2158 end_nup(pstops_doc_t
*doc
, /* I - Document information */
2159 int number
) /* I - Page number */
2161 if (doc
->number_up
> 1)
2162 doc_puts(doc
, "userdict/ESPsave get restore\n");
2164 switch (doc
->number_up
)
2167 if (doc
->use_ESPshowpage
)
2169 write_labels(doc
, Orientation
);
2170 doc_puts(doc
, "ESPshowpage\n");
2176 if (is_last_page(number
) && doc
->use_ESPshowpage
)
2178 if (Orientation
& 1)
2181 * Rotate the labels back to portrait...
2184 write_labels(doc
, Orientation
- 1);
2186 else if (Orientation
== 0)
2189 * Rotate the labels to landscape...
2192 write_labels(doc
, doc
->normal_landscape
? 1 : 3);
2197 * Rotate the labels to landscape...
2200 write_labels(doc
, doc
->normal_landscape
? 3 : 1);
2203 doc_puts(doc
, "ESPshowpage\n");
2208 if (is_last_page(number
) && doc
->use_ESPshowpage
)
2210 write_labels(doc
, Orientation
);
2211 doc_puts(doc
, "ESPshowpage\n");
2221 * 'include_feature()' - Include a printer option/feature command.
2224 static int /* O - New number of options */
2226 ppd_file_t
*ppd
, /* I - PPD file */
2227 const char *line
, /* I - DSC line */
2228 int num_options
, /* I - Number of options */
2229 cups_option_t
**options
) /* IO - Options */
2231 char name
[255], /* Option name */
2232 value
[255]; /* Option value */
2233 ppd_option_t
*option
; /* Option in file */
2237 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
2240 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
2242 fputs("DEBUG: The %%IncludeFeature: comment is not valid.\n", stderr
);
2243 return (num_options
);
2247 * Find the option and choice...
2250 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
2252 _cupsLangPrintFilter(stderr
, "WARNING", _("Unknown option \"%s\"."),
2254 return (num_options
);
2257 if (option
->section
== PPD_ORDER_EXIT
||
2258 option
->section
== PPD_ORDER_JCL
)
2260 _cupsLangPrintFilter(stderr
, "WARNING",
2261 _("Option \"%s\" cannot be included via "
2262 "%%%%IncludeFeature."), name
+ 1);
2263 return (num_options
);
2266 if (!ppdFindChoice(option
, value
))
2268 _cupsLangPrintFilter(stderr
, "WARNING",
2269 _("Unknown choice \"%s\" for option \"%s\"."),
2271 return (num_options
);
2275 * Add the option to the option array and return...
2278 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
2283 * 'parse_text()' - Parse a text value in a comment.
2285 * This function parses a DSC text value as defined on page 36 of the
2286 * DSC specification. Text values are either surrounded by parenthesis
2287 * or whitespace-delimited.
2289 * The value returned is the literal characters for the entire text
2290 * string, including any parenthesis and escape characters.
2293 static char * /* O - Value or NULL on error */
2294 parse_text(const char *start
, /* I - Start of text value */
2295 char **end
, /* O - End of text value */
2296 char *buffer
, /* I - Buffer */
2297 size_t bufsize
) /* I - Size of buffer */
2299 char *bufptr
, /* Pointer in buffer */
2300 *bufend
; /* End of buffer */
2301 int level
; /* Parenthesis level */
2305 * Skip leading whitespace...
2308 while (isspace(*start
& 255))
2312 * Then copy the value...
2317 bufend
= buffer
+ bufsize
- 1;
2319 while (bufptr
< bufend
)
2321 if (isspace(*start
& 255) && !level
)
2328 else if (*start
== ')')
2338 else if (*start
== '\\')
2341 * Copy escaped character...
2344 int i
; /* Looping var */
2348 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
2349 *bufptr
++ = start
[i
], i
++);
2358 * Return the value and new pointer into the line...
2362 *end
= (char *)start
;
2364 if (bufptr
== bufend
)
2372 * 'set_pstops_options()' - Set pstops options.
2377 pstops_doc_t
*doc
, /* I - Document information */
2378 ppd_file_t
*ppd
, /* I - PPD file */
2379 char *argv
[], /* I - Command-line arguments */
2380 int num_options
, /* I - Number of options */
2381 cups_option_t
*options
) /* I - Options */
2383 const char *val
; /* Option value */
2384 int intval
; /* Integer option value */
2385 ppd_attr_t
*attr
; /* PPD attribute */
2386 ppd_option_t
*option
; /* PPD option */
2387 ppd_choice_t
*choice
; /* PPD choice */
2388 const char *content_type
; /* Original content type */
2392 * Initialize document information structure...
2395 memset(doc
, 0, sizeof(pstops_doc_t
));
2397 doc
->job_id
= atoi(argv
[1]);
2398 doc
->user
= argv
[2];
2399 doc
->title
= argv
[3];
2400 doc
->copies
= atoi(argv
[4]);
2402 if (ppd
&& ppd
->landscape
> 0)
2403 doc
->normal_landscape
= 1;
2405 doc
->bounding_box
[0] = (int)PageLeft
;
2406 doc
->bounding_box
[1] = (int)PageBottom
;
2407 doc
->bounding_box
[2] = (int)PageRight
;
2408 doc
->bounding_box
[3] = (int)PageTop
;
2410 doc
->new_bounding_box
[0] = INT_MAX
;
2411 doc
->new_bounding_box
[1] = INT_MAX
;
2412 doc
->new_bounding_box
[2] = INT_MIN
;
2413 doc
->new_bounding_box
[3] = INT_MIN
;
2416 * AP_FIRSTPAGE_* and the corresponding non-first-page options.
2419 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2421 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2423 doc
->ap_media_color
= cupsGetOption("AP_FIRSTPAGE_MediaColor", num_options
,
2425 doc
->ap_media_type
= cupsGetOption("AP_FIRSTPAGE_MediaType", num_options
,
2427 doc
->ap_page_region
= cupsGetOption("AP_FIRSTPAGE_PageRegion", num_options
,
2429 doc
->ap_page_size
= cupsGetOption("AP_FIRSTPAGE_PageSize", num_options
,
2432 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2433 doc
->input_slot
= choice
->choice
;
2434 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2435 doc
->manual_feed
= choice
->choice
;
2436 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaColor")) != NULL
)
2437 doc
->media_color
= choice
->choice
;
2438 if ((choice
= ppdFindMarkedChoice(ppd
, "MediaType")) != NULL
)
2439 doc
->media_type
= choice
->choice
;
2440 if ((choice
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
2441 doc
->page_region
= choice
->choice
;
2442 if ((choice
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
2443 doc
->page_size
= choice
->choice
;
2449 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2452 * Get brightness value from 10 to 1000.
2457 if (intval
< 10 || intval
> 1000)
2459 _cupsLangPrintFilter(stderr
, "ERROR",
2460 _("Unsupported brightness value %s, using "
2461 "brightness=100."), val
);
2462 doc
->brightness
= 1.0f
;
2465 doc
->brightness
= intval
* 0.01f
;
2468 doc
->brightness
= 1.0f
;
2471 * collate, multiple-document-handling
2474 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2477 * This IPP attribute is unnecessarily complicated...
2479 * single-document, separate-documents-collated-copies, and
2480 * single-document-new-sheet all require collated copies.
2482 * separate-documents-uncollated-copies allows for uncollated copies.
2485 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2488 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2489 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2490 !strcasecmp(val
, "yes")))
2497 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2498 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2499 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2505 * fitplot/fit-to-page/ipp-attribute-fidelity
2507 * (Only for original PostScript content)
2510 if ((content_type
= getenv("CONTENT_TYPE")) == NULL
)
2511 content_type
= "application/postscript";
2513 if (!strcasecmp(content_type
, "application/postscript"))
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"))
2521 else if ((val
= cupsGetOption("ipp-attribute-fidelity", num_options
,
2522 options
)) != NULL
&&
2523 !strcasecmp(val
, "true"))
2531 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2534 * Get gamma value from 1 to 10000...
2539 if (intval
< 1 || intval
> 10000)
2541 _cupsLangPrintFilter(stderr
, "ERROR",
2542 _("Unsupported gamma value %s, using gamma=1000."),
2547 doc
->gamma
= intval
* 0.001f
;
2553 * mirror/MirrorPrint
2556 if ((choice
= ppdFindMarkedChoice(ppd
, "MirrorPrint")) != NULL
)
2558 val
= choice
->choice
;
2562 val
= cupsGetOption("mirror", num_options
, options
);
2564 if (val
&& (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2565 !strcasecmp(val
, "yes")))
2572 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2574 switch (intval
= atoi(val
))
2582 doc
->number_up
= intval
;
2585 _cupsLangPrintFilter(stderr
, "ERROR",
2586 _("Unsupported number-up value %d, using "
2587 "number-up=1."), intval
);
2599 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2601 if (!strcasecmp(val
, "lrtb"))
2602 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2603 else if (!strcasecmp(val
, "lrbt"))
2604 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2605 else if (!strcasecmp(val
, "rltb"))
2606 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2607 else if (!strcasecmp(val
, "rlbt"))
2608 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2609 else if (!strcasecmp(val
, "tblr"))
2610 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2611 else if (!strcasecmp(val
, "tbrl"))
2612 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2613 else if (!strcasecmp(val
, "btlr"))
2614 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2615 else if (!strcasecmp(val
, "btrl"))
2616 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2619 _cupsLangPrintFilter(stderr
, "ERROR",
2620 _("Unsupported number-up-layout value %s, using "
2621 "number-up-layout=lrtb."), val
);
2622 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2626 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2632 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2634 if (!strcasecmp(val
, "Reverse"))
2635 doc
->output_order
= 1;
2640 * Figure out the right default output order from the PPD file...
2643 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2644 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2646 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2647 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2649 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2656 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2658 if (!strcasecmp(val
, "none"))
2659 doc
->page_border
= PSTOPS_BORDERNONE
;
2660 else if (!strcasecmp(val
, "single"))
2661 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2662 else if (!strcasecmp(val
, "single-thick"))
2663 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2664 else if (!strcasecmp(val
, "double"))
2665 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2666 else if (!strcasecmp(val
, "double-thick"))
2667 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2670 _cupsLangPrintFilter(stderr
, "ERROR",
2671 _("Unsupported page-border value %s, using "
2672 "page-border=none."), val
);
2673 doc
->page_border
= PSTOPS_BORDERNONE
;
2677 doc
->page_border
= PSTOPS_BORDERNONE
;
2683 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2689 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2695 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2698 * Now figure out if we have to force collated copies, etc.
2701 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2704 * Force collated copies when printing a duplexed document to
2705 * a non-PS printer that doesn't do hardware copy generation.
2706 * Otherwise the copies will end up on the front/back side of
2714 * See if we have to filter the fast or slow way...
2717 if (doc
->collate
&& doc
->copies
> 1)
2720 * See if we need to manually collate the pages...
2723 doc
->slow_collate
= 1;
2725 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2726 !strcasecmp(choice
->choice
, "True"))
2729 * Hardware collate option is selected, see if the option is
2730 * conflicting - if not, collate in hardware. Otherwise,
2731 * turn the hardware collate option off...
2734 if ((option
= ppdFindOption(ppd
, "Collate")) != NULL
&&
2735 !option
->conflicted
)
2736 doc
->slow_collate
= 0;
2738 ppdMarkOption(ppd
, "Collate", "False");
2742 doc
->slow_collate
= 0;
2744 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2745 doc
->slow_order
= 1;
2747 doc
->slow_order
= 0;
2750 (doc
->slow_collate
|| doc
->slow_order
||
2751 ((attr
= ppdFindAttr(ppd
, "cupsEvenDuplex", NULL
)) != NULL
&&
2752 attr
->value
&& !strcasecmp(attr
->value
, "true"))))
2753 doc
->slow_duplex
= 1;
2755 doc
->slow_duplex
= 0;
2758 * Create a temporary file for page data if we need to filter slowly...
2761 if (doc
->slow_order
|| doc
->slow_collate
)
2763 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2764 sizeof(doc
->tempfile
))) == NULL
)
2766 perror("DEBUG: Unable to create temporary file");
2772 * Figure out if we should use ESPshowpage or not...
2775 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2779 * Yes, use ESPshowpage...
2782 doc
->use_ESPshowpage
= 1;
2785 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2786 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2791 * 'skip_page()' - Skip past a page that won't be printed.
2794 static ssize_t
/* O - Length of next line */
2795 skip_page(cups_file_t
*fp
, /* I - File to read from */
2796 char *line
, /* I - Line buffer */
2797 ssize_t linelen
, /* I - Length of initial line */
2798 size_t linesize
) /* I - Size of line buffer */
2800 int level
; /* Embedded document level */
2805 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2808 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer", 9)))
2810 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2811 !strncmp(line
, "%ADO_BeginApplication", 21))
2813 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2814 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2816 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2817 (!strncmp(line
, "%%BeginData:", 12) &&
2818 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2821 * Skip binary data...
2824 int bytes
; /* Bytes of data */
2827 bytes
= atoi(strchr(line
, ':') + 1);
2831 if (bytes
> linesize
)
2832 linelen
= cupsFileRead(fp
, line
, linesize
);
2834 linelen
= cupsFileRead(fp
, line
, bytes
);
2839 perror("ERROR: Early end-of-file while reading binary data");
2853 * 'start_nup()' - Start processing for N-up printing.
2857 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2858 int number
, /* I - Page number */
2859 int show_border
, /* I - Show the border? */
2860 const int *bounding_box
) /* I - BoundingBox value */
2862 int pos
; /* Position on page */
2863 int x
, y
; /* Relative position of subpage */
2864 float w
, l
, /* Width and length of subpage */
2865 tx
, ty
; /* Translation values for subpage */
2866 float pagew
, /* Printable width of page */
2867 pagel
; /* Printable height of page */
2868 int bboxx
, /* BoundingBox X origin */
2869 bboxy
, /* BoundingBox Y origin */
2870 bboxw
, /* BoundingBox width */
2871 bboxl
; /* BoundingBox height */
2872 float margin
= 0; /* Current margin for border */
2875 if (doc
->number_up
> 1)
2876 doc_puts(doc
, "userdict/ESPsave save put\n");
2878 pos
= (number
- 1) % doc
->number_up
;
2879 pagew
= PageRight
- PageLeft
;
2880 pagel
= PageTop
- PageBottom
;
2884 bboxx
= bounding_box
[0];
2885 bboxy
= bounding_box
[1];
2886 bboxw
= bounding_box
[2] - bounding_box
[0];
2887 bboxl
= bounding_box
[3] - bounding_box
[1];
2897 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2898 fprintf(stderr
, "DEBUG: bboxx = %d, bboxy = %d, bboxw = %d, bboxl = %d\n",
2899 bboxx
, bboxy
, bboxw
, bboxl
);
2900 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2901 PageLeft
, PageRight
);
2902 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2903 PageTop
, PageBottom
);
2904 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2905 PageWidth
, PageLength
);
2907 switch (Orientation
)
2909 case 1 : /* Landscape */
2910 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2912 case 2 : /* Reverse Portrait */
2913 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2916 case 3 : /* Reverse Landscape */
2917 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2921 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2922 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2923 else if (doc
->number_up
> 1 || doc
->fitplot
)
2924 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2926 switch (doc
->number_up
)
2932 l
= w
* bboxl
/ bboxw
;
2937 w
= l
* bboxw
/ bboxl
;
2940 tx
= 0.5 * (pagew
- w
);
2941 ty
= 0.5 * (pagel
- l
);
2943 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2944 w
/ bboxw
, l
/ bboxl
);
2951 if (Orientation
& 1)
2955 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2959 l
= w
* bboxl
/ bboxw
;
2961 if (l
> (pagew
* 0.5))
2964 w
= l
* bboxw
/ bboxl
;
2967 tx
= 0.5 * (pagew
* 0.5 - l
);
2968 ty
= 0.5 * (pagel
- w
);
2970 if (doc
->normal_landscape
)
2971 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2973 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2975 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2976 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2982 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2986 w
= l
* bboxw
/ bboxl
;
2988 if (w
> (pagel
* 0.5))
2991 l
= w
* bboxl
/ bboxw
;
2994 tx
= 0.5 * (pagel
* 0.5 - w
);
2995 ty
= 0.5 * (pagew
- l
);
2997 if (doc
->normal_landscape
)
2998 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
3000 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
3002 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3003 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
3008 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3019 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3022 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3026 l
= w
* bboxl
/ bboxw
;
3028 if (l
> (pagel
* 0.5))
3031 w
= l
* bboxw
/ bboxl
;
3034 tx
= 0.5 * (pagew
* 0.5 - w
);
3035 ty
= 0.5 * (pagel
* 0.5 - l
);
3037 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3038 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
3039 w
/ bboxw
, l
/ bboxl
);
3043 if (Orientation
& 1)
3045 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3050 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3053 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3061 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3064 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3069 l
= w
* bboxl
/ bboxw
;
3071 if (l
> (pagew
* 0.333))
3074 w
= l
* bboxw
/ bboxl
;
3077 tx
= 0.5 * (pagel
- 2 * w
);
3078 ty
= 0.5 * (pagew
- 3 * l
);
3080 if (doc
->normal_landscape
)
3081 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
3083 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
3085 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3086 tx
+ x
* w
, ty
+ y
* l
, l
/ bboxl
, w
/ bboxw
);
3090 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3095 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3098 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3106 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3109 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3114 w
= l
* bboxw
/ bboxl
;
3116 if (w
> (pagel
* 0.333))
3119 l
= w
* bboxl
/ bboxw
;
3122 tx
= 0.5 * (pagel
- 3 * w
);
3123 ty
= 0.5 * (pagew
- 2 * l
);
3125 if (doc
->normal_landscape
)
3126 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
3128 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
3130 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3131 tx
+ w
* x
, ty
+ l
* y
, w
/ bboxw
, l
/ bboxl
);
3137 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3148 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3151 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3155 l
= w
* bboxl
/ bboxw
;
3157 if (l
> (pagel
* 0.333))
3160 w
= l
* bboxw
/ bboxl
;
3163 tx
= 0.5 * (pagew
* 0.333 - w
);
3164 ty
= 0.5 * (pagel
* 0.333 - l
);
3166 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3167 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
3168 w
/ bboxw
, l
/ bboxl
);
3172 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
3183 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
3186 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
3190 l
= w
* bboxl
/ bboxw
;
3192 if (l
> (pagel
* 0.25))
3195 w
= l
* bboxw
/ bboxl
;
3198 tx
= 0.5 * (pagew
* 0.25 - w
);
3199 ty
= 0.5 * (pagel
* 0.25 - l
);
3201 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
3202 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
3203 w
/ bboxw
, l
/ bboxl
);
3208 * Draw borders as necessary...
3211 if (doc
->page_border
&& show_border
)
3213 int rects
; /* Number of border rectangles */
3214 float fscale
; /* Scaling value for points */
3217 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
3218 fscale
= PageWidth
/ w
;
3219 margin
= 2.25 * fscale
;
3222 * Set the line width and color...
3225 doc_puts(doc
, "gsave\n");
3226 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
3227 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
3231 * Draw border boxes...
3234 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
3235 if (doc
->number_up
> 1)
3236 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
3240 bboxl
- 2 * margin
);
3242 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
3244 PageBottom
+ margin
,
3245 PageRight
- PageLeft
- 2 * margin
,
3246 PageTop
- PageBottom
- 2 * margin
);
3249 * Restore pen settings...
3252 doc_puts(doc
, "grestore\n");
3258 * Offset the page by its bounding box...
3261 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
3265 if (doc
->fitplot
|| doc
->number_up
> 1)
3268 * Clip the page to the page's bounding box...
3271 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrc\n",
3272 bboxx
+ margin
, bboxy
+ margin
,
3273 bboxw
- 2 * margin
, bboxl
- 2 * margin
);
3277 * Mirror the page as needed...
3281 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
3286 * 'write_label_prolog()' - Write the prolog with the classification
3291 write_label_prolog(pstops_doc_t
*doc
, /* I - Document info */
3292 const char *label
, /* I - Page label */
3293 float bottom
, /* I - Bottom position in points */
3294 float top
, /* I - Top position in points */
3295 float width
) /* I - Width in points */
3297 const char *classification
; /* CLASSIFICATION environment variable */
3298 const char *ptr
; /* Temporary string pointer */
3302 * First get the current classification...
3305 if ((classification
= getenv("CLASSIFICATION")) == NULL
)
3306 classification
= "";
3307 if (strcmp(classification
, "none") == 0)
3308 classification
= "";
3311 * If there is nothing to show, bind an empty 'write labels' procedure
3315 if (!classification
[0] && (label
== NULL
|| !label
[0]))
3317 doc_puts(doc
, "userdict/ESPwl{}bind put\n");
3322 * Set the classification + page label string...
3325 doc_puts(doc
, "userdict");
3326 if (!strcmp(classification
, "confidential"))
3327 doc_puts(doc
, "/ESPpl(CONFIDENTIAL");
3328 else if (!strcmp(classification
, "classified"))
3329 doc_puts(doc
, "/ESPpl(CLASSIFIED");
3330 else if (!strcmp(classification
, "secret"))
3331 doc_puts(doc
, "/ESPpl(SECRET");
3332 else if (!strcmp(classification
, "topsecret"))
3333 doc_puts(doc
, "/ESPpl(TOP SECRET");
3334 else if (!strcmp(classification
, "unclassified"))
3335 doc_puts(doc
, "/ESPpl(UNCLASSIFIED");
3338 doc_puts(doc
, "/ESPpl(");
3340 for (ptr
= classification
; *ptr
; ptr
++)
3342 if (*ptr
< 32 || *ptr
> 126)
3343 doc_printf(doc
, "\\%03o", *ptr
);
3344 else if (*ptr
== '_')
3346 else if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
3347 doc_printf(doc
, "\\%c", *ptr
);
3349 doc_printf(doc
, "%c", *ptr
);
3355 if (classification
[0])
3356 doc_puts(doc
, " - ");
3359 * Quote the label string as needed...
3362 for (ptr
= label
; *ptr
; ptr
++)
3364 if (*ptr
< 32 || *ptr
> 126)
3365 doc_printf(doc
, "\\%03o", *ptr
);
3366 else if (*ptr
== '(' || *ptr
== ')' || *ptr
== '\\')
3367 doc_printf(doc
, "\\%c", *ptr
);
3369 doc_printf(doc
, "%c", *ptr
);
3373 doc_puts(doc
, ")put\n");
3376 * Then get a 14 point Helvetica-Bold font...
3379 doc_puts(doc
, "userdict/ESPpf /Helvetica-Bold findfont 14 scalefont put\n");
3382 * Finally, the procedure to write the labels on the page...
3385 doc_puts(doc
, "userdict/ESPwl{\n");
3386 doc_puts(doc
, " ESPpf setfont\n");
3387 doc_printf(doc
, " ESPpl stringwidth pop dup 12 add exch -0.5 mul %.0f add\n",
3389 doc_puts(doc
, " 1 setgray\n");
3390 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrf\n", bottom
- 2.0);
3391 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrf\n", top
- 18.0);
3392 doc_puts(doc
, " 0 setgray\n");
3393 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrs\n", bottom
- 2.0);
3394 doc_printf(doc
, " dup 6 sub %.0f 3 index 20 ESPrs\n", top
- 18.0);
3395 doc_printf(doc
, " dup %.0f moveto ESPpl show\n", bottom
+ 2.0);
3396 doc_printf(doc
, " %.0f moveto ESPpl show\n", top
- 14.0);
3397 doc_puts(doc
, "pop\n");
3398 doc_puts(doc
, "}bind put\n");
3403 * 'write_labels()' - Write the actual page labels.
3405 * This function is a copy of the one in common.c since we need to
3406 * use doc_puts/doc_printf instead of puts/printf...
3410 write_labels(pstops_doc_t
*doc
, /* I - Document information */
3411 int orient
) /* I - Orientation of the page */
3413 float width
, /* Width of page */
3414 length
; /* Length of page */
3417 doc_puts(doc
, "gsave\n");
3419 if ((orient
^ Orientation
) & 1)
3427 length
= PageLength
;
3432 case 1 : /* Landscape */
3433 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", length
);
3435 case 2 : /* Reverse Portrait */
3436 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", width
, length
);
3438 case 3 : /* Reverse Landscape */
3439 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", width
);
3443 doc_puts(doc
, "ESPwl\n");
3444 doc_puts(doc
, "grestore\n");
3449 * 'write_options()' - Write options provided via %%IncludeFeature.
3454 pstops_doc_t
*doc
, /* I - Document */
3455 ppd_file_t
*ppd
, /* I - PPD file */
3456 int num_options
, /* I - Number of options */
3457 cups_option_t
*options
) /* I - Options */
3459 int i
; /* Looping var */
3460 ppd_option_t
*option
; /* PPD option */
3461 int min_order
; /* Minimum OrderDependency value */
3462 char *doc_setup
, /* DocumentSetup commands to send */
3463 *any_setup
; /* AnySetup commands to send */
3467 * Figure out the minimum OrderDependency value...
3470 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
3471 min_order
= option
->order
;
3475 for (i
= 0; i
< num_options
; i
++)
3476 if ((option
= ppdFindOption(ppd
, options
[i
].name
)) != NULL
&&
3477 option
->order
< min_order
)
3478 min_order
= option
->order
;
3481 * Mark and extract them...
3484 cupsMarkOptions(ppd
, num_options
, options
);
3486 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
3487 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
3490 * Then send them out...
3493 if (doc
->number_up
> 1)
3496 * Temporarily restore setpagedevice so we can set the options...
3499 doc_puts(doc
, "userdict/setpagedevice/CUPSsetpagedevice load put\n");
3504 doc_puts(doc
, doc_setup
);
3510 doc_puts(doc
, any_setup
);
3514 if (doc
->number_up
> 1)
3517 * Disable setpagedevice again...
3520 doc_puts(doc
, "userdict/setpagedevice{pop}bind put\n");
3526 * End of "$Id: pstops.c 7977 2008-09-23 23:44:33Z mike $".