]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/pstops.c
305c798d85421f29a0c83d099d678b234882b7da
2 * "$Id: pstops.c 5382 2006-04-07 14:58:44Z mike $"
4 * PostScript filter for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry...
29 * add_page() - Add a page to the pages array...
30 * check_range() - Check to see if the current page is selected for
31 * copy_bytes() - Copy bytes from the input file to stdout...
32 * copy_comments() - Copy all of the comments section...
33 * copy_dsc() - Copy a DSC-conforming document...
34 * copy_non_dsc() - Copy a document that does not conform to the DSC...
35 * copy_page() - Copy a page description...
36 * copy_prolog() - Copy the document prolog section...
37 * copy_setup() - Copy the document setup section...
38 * copy_trailer() - Copy the document trailer...
39 * do_prolog() - Send the necessary document prolog commands...
40 * do_setup() - Send the necessary document setup commands...
41 * doc_printf() - Send a formatted string to stdout and/or the temp
43 * doc_puts() - Send a nul-terminated string to stdout and/or the
45 * doc_write() - Send data to stdout and/or the temp file.
46 * end_nup() - End processing for N-up printing...
47 * include_feature() - Include a printer option/feature command.
48 * parse_text() - Parse a text value in a comment...
49 * set_pstops_options() - Set pstops options...
50 * skip_page() - Skip past a page that won't be printed...
51 * start_nup() - Start processing for N-up printing...
55 * Include necessary headers...
61 #include <cups/file.h>
62 #include <cups/array.h>
69 #define PSTOPS_BORDERNONE 0 /* No border or hairline border */
70 #define PSTOPS_BORDERTHICK 1 /* Think border */
71 #define PSTOPS_BORDERSINGLE 2 /* Single-line hairline border */
72 #define PSTOPS_BORDERSINGLE2 3 /* Single-line thick border */
73 #define PSTOPS_BORDERDOUBLE 4 /* Double-line hairline border */
74 #define PSTOPS_BORDERDOUBLE2 5 /* Double-line thick border */
76 #define PSTOPS_LAYOUT_LRBT 0 /* Left to right, bottom to top */
77 #define PSTOPS_LAYOUT_LRTB 1 /* Left to right, top to bottom */
78 #define PSTOPS_LAYOUT_RLBT 2 /* Right to left, bottom to top */
79 #define PSTOPS_LAYOUT_RLTB 3 /* Right to left, top to bottom */
80 #define PSTOPS_LAYOUT_BTLR 4 /* Bottom to top, left to right */
81 #define PSTOPS_LAYOUT_TBLR 5 /* Top to bottom, left to right */
82 #define PSTOPS_LAYOUT_BTRL 6 /* Bottom to top, right to left */
83 #define PSTOPS_LAYOUT_TBRL 7 /* Top to bottom, right to left */
85 #define PSTOPS_LAYOUT_NEGATEY 1 /* The bits for the layout */
86 #define PSTOPS_LAYOUT_NEGATEX 2 /* definitions above... */
87 #define PSTOPS_LAYOUT_VERTICAL 4
94 typedef struct /**** Page information ****/
96 char *label
; /* Page label */
97 int bounding_box
[4]; /* PageBoundingBox */
98 off_t offset
; /* Offset to start of page */
99 ssize_t length
; /* Number of bytes for page */
100 int num_options
; /* Number of options for this page */
101 cups_option_t
*options
; /* Options for this page */
104 typedef struct /**** Document information ****/
106 int page
; /* Current page */
107 int bounding_box
[4]; /* BoundingBox from header */
108 int new_bounding_box
[4]; /* New composite bounding box */
109 int num_options
; /* Number of document-wide options */
110 cups_option_t
*options
; /* Document-wide options */
111 int normal_landscape
, /* Normal rotation for landscape? */
112 saw_eof
, /* Saw the %%EOF comment? */
113 slow_collate
, /* Collate copies by hand? */
114 slow_duplex
, /* Duplex pages slowly? */
115 slow_order
, /* Reverse pages slowly? */
116 use_ESPshowpage
; /* Use ESPshowpage? */
117 cups_array_t
*pages
; /* Pages in document */
118 cups_file_t
*temp
; /* Temporary file, if any */
119 char tempfile
[1024]; /* Temporary filename */
120 int job_id
; /* Job ID */
121 const char *user
, /* User name */
122 *title
; /* Job name */
123 int copies
; /* Number of copies */
124 const char *ap_input_slot
, /* AP_FIRSTPAGE_InputSlot value */
125 *ap_manual_feed
; /* AP_FIRSTPAGE_ManualFeed value */
126 float brightness
; /* brightness value */
127 int collate
, /* Collate copies? */
128 emit_jcl
, /* Emit JCL commands? */
129 fitplot
; /* Fit pages to media */
130 float gamma
; /* gamma value */
131 const char *input_slot
, /* InputSlot value */
132 *manual_feed
; /* ManualFeed value */
133 int mirror
, /* doc->mirror/mirror pages */
134 number_up
, /* Number of pages on each sheet */
135 number_up_layout
, /* doc->number_up_layout of N-up pages */
136 output_order
, /* Requested reverse output order? */
137 page_border
; /* doc->page_border around pages */
138 const char *page_label
, /* page-label option, if any */
139 *page_ranges
, /* page-ranges option, if any */
140 *page_set
; /* page-set option, if any */
145 * Convenience macros...
148 #define is_first_page(p) (doc->number_up == 1 || \
149 ((p) % doc->number_up) == 1)
150 #define is_last_page(p) (doc->number_up == 1 || \
151 ((p) % doc->number_up) == 0)
152 #define is_not_last_page(p) (doc->number_up > 1 && \
153 ((p) % doc->number_up) != 0)
160 static pstops_page_t
*add_page(pstops_doc_t
*doc
, const char *label
);
161 static int check_range(pstops_doc_t
*doc
, int page
);
162 static void copy_bytes(cups_file_t
*fp
, off_t offset
,
164 static size_t copy_comments(cups_file_t
*fp
, pstops_doc_t
*doc
,
165 char *line
, size_t linelen
,
167 static void copy_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
168 ppd_file_t
*ppd
, char *line
, size_t linelen
,
170 static void copy_non_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
171 ppd_file_t
*ppd
, char *line
,
172 size_t linelen
, size_t linesize
);
173 static size_t copy_page(cups_file_t
*fp
, pstops_doc_t
*doc
,
174 ppd_file_t
*ppd
, int number
, char *line
,
175 size_t linelen
, size_t linesize
);
176 static size_t copy_prolog(cups_file_t
*fp
, pstops_doc_t
*doc
,
177 ppd_file_t
*ppd
, char *line
,
178 size_t linelen
, size_t linesize
);
179 static size_t copy_setup(cups_file_t
*fp
, pstops_doc_t
*doc
,
180 ppd_file_t
*ppd
, char *line
,
181 size_t linelen
, size_t linesize
);
182 static size_t copy_trailer(cups_file_t
*fp
, pstops_doc_t
*doc
,
183 ppd_file_t
*ppd
, int number
, char *line
,
184 size_t linelen
, size_t linesize
);
185 static void do_prolog(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
186 static void do_setup(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
187 static void doc_printf(pstops_doc_t
*doc
, const char *format
, ...);
188 static void doc_puts(pstops_doc_t
*doc
, const char *s
);
189 static void doc_write(pstops_doc_t
*doc
, const char *s
, size_t len
);
190 static void end_nup(pstops_doc_t
*doc
, int number
);
191 static int include_feature(ppd_file_t
*ppd
, const char *line
,
193 cups_option_t
**options
);
194 static char *parse_text(const char *start
, char **end
, char *buffer
,
196 static void set_pstops_options(pstops_doc_t
*doc
, ppd_file_t
*ppd
,
197 char *argv
[], int num_options
,
198 cups_option_t
*options
);
199 static size_t skip_page(cups_file_t
*fp
, char *line
, size_t linelen
,
201 static void start_nup(pstops_doc_t
*doc
, int number
,
202 int show_border
, const int *bounding_box
);
206 * 'main()' - Main entry...
209 int /* O - Exit status */
210 main(int argc
, /* I - Number of command-line args */
211 char *argv
[]) /* I - Command-line arguments */
213 pstops_doc_t doc
; /* Document information */
214 cups_file_t
*fp
; /* Print file */
215 ppd_file_t
*ppd
; /* PPD file */
216 int num_options
; /* Number of print options */
217 cups_option_t
*options
; /* Print options */
218 char line
[8192]; /* Line buffer */
219 size_t len
; /* Length of line buffer */
223 * Make sure status messages are not buffered...
226 setbuf(stderr
, NULL
);
229 * Check command-line...
232 if (argc
< 6 || argc
> 7)
234 fputs("ERROR: pstops job-id user title copies options [file]\n", stderr
);
239 * If we have 7 arguments, print the file named on the command-line.
240 * Otherwise, send stdin instead...
244 fp
= cupsFileStdin();
248 * Try to open the print file...
251 if ((fp
= cupsFileOpen(argv
[6], "r")) == NULL
)
253 fprintf(stderr
, "ERROR: Unable to open print file \"%s\" - %s\n",
254 argv
[6], strerror(errno
));
260 * Read the first line to see if we have DSC comments...
263 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
265 fputs("ERROR: Empty print file!\n", stderr
);
270 * Process command-line options...
274 num_options
= cupsParseOptions(argv
[5], 0, &options
);
275 ppd
= SetCommonOptions(num_options
, options
, 1);
277 set_pstops_options(&doc
, ppd
, argv
, num_options
, options
);
280 * Write any "exit server" options that have been selected...
283 ppdEmit(ppd
, stdout
, PPD_ORDER_EXIT
);
286 * Write any JCL commands that are needed to print PostScript code...
290 ppdEmitJCL(ppd
, stdout
, doc
.job_id
, doc
.user
, doc
.title
);
293 * Start with a DSC header...
296 puts("%!PS-Adobe-3.0");
299 * Skip leading PJL in the document...
302 while (!strncmp(line
, "\033%-12345X", 9) || !strncmp(line
, "@PJL ", 5))
305 * Yup, we have leading PJL fun, so skip it until we hit the line
306 * with "ENTER LANGUAGE"...
309 fputs("DEBUG: Skipping PJL header...\n", stderr
);
311 while (strstr(line
, "ENTER LANGUAGE") == NULL
&& strncmp(line
, "%!", 2))
312 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
315 if (!strncmp(line
, "%!", 2))
318 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
323 * Now see if the document conforms to the Adobe Document Structuring
327 if (!strncmp(line
, "%!PS-Adobe-", 11))
330 * Yes, filter the document...
333 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
338 * No, display an error message and treat the file as if it contains
342 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
346 * Send %%EOF as needed...
353 * End the job with the appropriate JCL command or CTRL-D...
358 if (ppd
&& ppd
->jcl_end
)
359 ppdEmitJCLEnd(ppd
, stdout
);
365 * Close files and remove the temporary file if needed...
370 cupsFileClose(doc
.temp
);
371 unlink(doc
.tempfile
);
375 cupsFreeOptions(num_options
, options
);
384 * 'add_page()' - Add a page to the pages array...
387 static pstops_page_t
* /* O - New page info object */
388 add_page(pstops_doc_t
*doc
, /* I - Document information */
389 const char *label
) /* I - Page label */
391 pstops_page_t
*pageinfo
; /* New page info object */
395 doc
->pages
= cupsArrayNew(NULL
, NULL
);
399 fprintf(stderr
, "EMERG: Unable to allocate memory for pages array: %s\n",
404 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
406 fprintf(stderr
, "EMERG: Unable to allocate memory for page info: %s\n",
411 pageinfo
->label
= strdup(label
);
412 pageinfo
->offset
= cupsFileTell(doc
->temp
);
414 cupsArrayAdd(doc
->pages
, pageinfo
);
423 * 'check_range()' - Check to see if the current page is selected for
427 static int /* O - 1 if selected, 0 otherwise */
428 check_range(pstops_doc_t
*doc
, /* I - Document information */
429 int page
) /* I - Page number */
431 const char *range
; /* Pointer into range string */
432 int lower
, upper
; /* Lower and upper page numbers */
438 * See if we only print even or odd pages...
441 if (!strcasecmp(doc
->page_set
, "even") && (page
& 1))
444 if (!strcasecmp(doc
->page_set
, "odd") && !(page
& 1))
448 if (!doc
->page_ranges
)
449 return (1); /* No range, print all pages... */
451 for (range
= doc
->page_ranges
; *range
!= '\0';)
457 upper
= strtol(range
, (char **)&range
, 10);
461 lower
= strtol(range
, (char **)&range
, 10);
466 if (!isdigit(*range
& 255))
469 upper
= strtol(range
, (char **)&range
, 10);
475 if (page
>= lower
&& page
<= upper
)
489 * 'copy_bytes()' - Copy bytes from the input file to stdout...
493 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
494 off_t offset
, /* I - Offset to page data */
495 size_t length
) /* I - Length of page data */
497 char buffer
[8192]; /* Data buffer */
498 ssize_t nbytes
; /* Number of bytes read */
499 size_t nleft
; /* Number of bytes left/remaining */
504 if (cupsFileSeek(fp
, offset
) < 0)
506 fprintf(stderr
, "ERROR: Unable to seek to offset " CUPS_LLFMT
508 CUPS_LLCAST offset
, strerror(errno
));
512 while (nleft
> 0 || length
== 0)
514 if (nleft
> sizeof(buffer
) || length
== 0)
515 nbytes
= sizeof(buffer
);
519 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
524 fwrite(buffer
, 1, nbytes
, stdout
);
530 * 'copy_comments()' - Copy all of the comments section...
532 * This function expects "line" to be filled with a comment line.
533 * On return, "line" will contain the next line in the file, if any.
536 static size_t /* O - Length of next line */
537 copy_comments(cups_file_t
*fp
, /* I - File to read from */
538 pstops_doc_t
*doc
, /* I - Document info */
539 char *line
, /* I - Line buffer */
540 size_t linelen
, /* I - Length of initial line */
541 size_t linesize
) /* I - Size of line buffer */
543 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
544 saw_for
, /* Saw %%For: comment? */
545 saw_pages
, /* Saw %%Pages: comment? */
546 saw_title
; /* Saw %%Title: comment? */
550 * Loop until we see %%EndComments or a non-comment line...
553 saw_bounding_box
= 0;
558 while (line
[0] == '%')
561 * Strip trailing whitespace...
568 if (!isspace(line
[linelen
] & 255))
571 line
[linelen
] = '\0';
578 fprintf(stderr
, "DEBUG: %s\n", line
);
581 * Pull the headers out...
584 if (!strncmp(line
, "%%Pages:", 8))
587 fputs("ERROR: Duplicate %%Pages: comment seen!\n", stderr
);
591 else if (!strncmp(line
, "%%BoundingBox:", 14))
593 if (saw_bounding_box
)
594 fputs("ERROR: Duplicate %%BoundingBox: comment seen!\n", stderr
);
595 else if (strstr(line
+ 14, "(atend)"))
598 * Do nothing for now but use the default imageable area...
601 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
602 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
603 doc
->bounding_box
+ 3) != 4)
605 fputs("ERROR: Bad %%BoundingBox: comment seen!\n", stderr
);
607 doc
->bounding_box
[0] = (int)PageLeft
;
608 doc
->bounding_box
[1] = (int)PageBottom
;
609 doc
->bounding_box
[2] = (int)PageRight
;
610 doc
->bounding_box
[3] = (int)PageTop
;
613 saw_bounding_box
= 1;
615 else if (!strncmp(line
, "%%For:", 6))
618 printf("%s\n", line
);
620 else if (!strncmp(line
, "%%Title:", 8))
623 printf("%s\n", line
);
625 else if (!strncmp(line
, "%cupsRotation:", 14))
628 * Reset orientation of document?
631 int orient
= (atoi(line
+ 14) / 90) & 3;
633 if (orient
!= Orientation
)
636 * Yes, update things so that the pages come out right...
639 Orientation
= (4 - Orientation
+ orient
) & 3;
641 Orientation
= orient
;
644 else if (!strcmp(line
, "%%EndComments"))
646 linelen
= cupsFileGetLine(fp
, line
, linesize
);
649 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
650 printf("%s\n", line
);
652 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
656 if (!saw_bounding_box
)
657 fputs("ERROR: No %%BoundingBox: comment in header!\n", stderr
);
660 fputs("ERROR: No %%Pages: comment in header!\n", stderr
);
663 printf("%%%%For: %s\n", doc
->user
);
666 printf("%%%%Title: %s\n", doc
->title
);
668 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
671 * Tell the document processor the copy and duplex options
672 * that are required...
675 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
676 doc
->collate
? " collate" : "",
677 Duplex
? " duplex" : "");
680 * Apple uses RBI comments for various non-PPD options...
683 printf("%%RBINumCopies: %d\n", doc
->copies
);
688 * Tell the document processor the duplex option that is required...
692 puts("%%Requirements: duplex");
695 * Apple uses RBI comments for various non-PPD options...
698 puts("%RBINumCopies: 1");
701 puts("%%Pages: (atend)");
702 puts("%%BoundingBox: (atend)");
703 puts("%%EndComments");
710 * 'copy_dsc()' - Copy a DSC-conforming document...
712 * This function expects "line" to be filled with the %!PS-Adobe comment line.
716 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
717 pstops_doc_t
*doc
, /* I - Document info */
718 ppd_file_t
*ppd
, /* I - PPD file */
719 char *line
, /* I - Line buffer */
720 size_t linelen
, /* I - Length of initial line */
721 size_t linesize
) /* I - Size of line buffer */
723 int number
; /* Page number */
724 pstops_page_t
*pageinfo
; /* Page information */
728 * Make sure we use ESPshowpage for EPS files...
731 if (strstr(line
, "EPSF"))
733 doc
->use_ESPshowpage
= 1;
738 * Start sending the document with any commands needed...
741 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
742 linelen
= copy_comments(fp
, doc
, line
, linelen
, linesize
);
745 * Now find the prolog section, if any...
748 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
749 linelen
= copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
752 * Then the document setup section...
755 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
756 linelen
= copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
759 * Copy until we see %%Page:...
762 while (strncmp(line
, "%%Page:", 7) && strncmp(line
, "%%Trailer", 9))
764 fwrite(line
, 1, linelen
, stdout
);
766 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
771 * Then process pages until we have no more...
776 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
777 while (!strncmp(line
, "%%Page:", 7))
781 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
783 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
784 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
788 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
789 linelen
= skip_page(fp
, line
, linelen
, linesize
);
794 * Finish up the last page(s)...
797 if (number
&& is_not_last_page(number
) && cupsArrayLast(doc
->pages
))
799 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
801 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
802 doc_puts(doc
, "showpage\n");
803 end_nup(doc
, doc
->number_up
);
805 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
808 if (doc
->slow_duplex
&& (doc
->page
& 1))
811 * Make sure we have an even number of pages...
814 pageinfo
= add_page(doc
, "(filler)");
816 if (!doc
->slow_order
)
818 if (!ppd
|| !ppd
->num_filters
)
819 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
820 doc
->slow_collate
? 1 : doc
->copies
);
822 printf("%%%%Page: (filler) %d\n", doc
->page
);
825 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
826 doc_puts(doc
, "showpage\n");
827 end_nup(doc
, doc
->number_up
);
829 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
833 * Make additional copies as necessary...
836 number
= doc
->slow_order
? 0 : doc
->page
;
840 int copy
; /* Current copy */
844 * Reopen the temporary file for reading...
847 cupsFileClose(doc
->temp
);
849 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
855 for (copy
= !doc
->slow_order
; copy
< doc
->copies
; copy
++)
857 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
858 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
864 if (!ppd
|| !ppd
->num_filters
)
865 fprintf(stderr
, "PAGE: %d 1\n", number
);
867 if (doc
->number_up
> 1)
869 printf("%%%%Page: (%d) %d\n", number
, number
);
870 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
871 PageLeft
, PageBottom
, PageRight
, PageTop
);
875 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
876 printf("%%%%PageBoundingBox: %d %d %d %d\n",
877 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
878 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
881 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
883 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
884 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
890 * Write/copy the trailer...
893 linelen
= copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
898 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC...
900 * This function expects "line" to be filled with the %! comment line.
904 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
905 pstops_doc_t
*doc
, /* I - Document info */
906 ppd_file_t
*ppd
, /* I - PPD file */
907 char *line
, /* I - Line buffer */
908 size_t linelen
, /* I - Length of initial line */
909 size_t linesize
) /* I - Size of line buffer */
911 int copy
; /* Current copy */
912 char buffer
[8192]; /* Copy buffer */
913 int bytes
; /* Number of bytes copied */
917 * First let the user know that they are attempting to print a file
918 * that may not print correctly...
921 fputs("WARNING: This document does not conform to the Adobe Document "
922 "Structuring Conventions and may not print correctly!\n", stderr
);
925 * Then write a standard DSC comment section...
928 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
931 if (doc
->slow_collate
&& doc
->copies
> 1)
932 printf("%%%%Pages: %d\n", doc
->copies
);
936 printf("%%%%For: %s\n", doc
->user
);
937 printf("%%%%Title: %s\n", doc
->title
);
939 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
942 * Tell the document processor the copy and duplex options
943 * that are required...
946 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
947 doc
->collate
? " collate" : "",
948 Duplex
? " duplex" : "");
951 * Apple uses RBI comments for various non-PPD options...
954 printf("%%RBINumCopies: %d\n", doc
->copies
);
959 * Tell the document processor the duplex option that is required...
963 puts("%%Requirements: duplex");
966 * Apple uses RBI comments for various non-PPD options...
969 puts("%RBINumCopies: 1");
972 puts("%%EndComments");
978 puts("%%BeginProlog");
985 * Then the setup section...
988 puts("%%BeginSetup");
995 * Finally, embed a copy of the file inside a %%Page...
998 if (!ppd
|| !ppd
->num_filters
)
999 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
1001 puts("%%Page: 1 1");
1002 puts("%%BeginPageSetup");
1003 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1004 puts("%%EndPageSetup");
1005 puts("%%BeginDocument: nondsc");
1007 fwrite(line
, linelen
, 1, stdout
);
1010 cupsFileWrite(doc
->temp
, line
, linelen
);
1012 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1014 fwrite(buffer
, 1, bytes
, stdout
);
1017 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1020 puts("%%EndDocument");
1022 if (doc
->use_ESPshowpage
)
1024 WriteLabels(Orientation
);
1025 puts("ESPshowpage");
1031 * Reopen the temporary file for reading...
1034 cupsFileClose(doc
->temp
);
1036 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1039 * Make the additional copies as needed...
1042 for (copy
= 1; copy
< doc
->copies
; copy
++)
1044 if (!ppd
|| !ppd
->num_filters
)
1045 fputs("PAGE: 1 1\n", stderr
);
1047 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1048 puts("%%BeginPageSetup");
1049 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1050 puts("%%EndPageSetup");
1051 puts("%%BeginDocument: nondsc");
1053 copy_bytes(doc
->temp
, 0, 0);
1055 puts("%%EndDocument");
1057 if (doc
->use_ESPshowpage
)
1059 WriteLabels(Orientation
);
1060 puts("ESPshowpage");
1068 * 'copy_page()' - Copy a page description...
1070 * This function expects "line" to be filled with a %%Page comment line.
1071 * On return, "line" will contain the next line in the file, if any.
1074 static size_t /* O - Length of next line */
1075 copy_page(cups_file_t
*fp
, /* I - File to read from */
1076 pstops_doc_t
*doc
, /* I - Document info */
1077 ppd_file_t
*ppd
, /* I - PPD file */
1078 int number
, /* I - Current page number */
1079 char *line
, /* I - Line buffer */
1080 size_t linelen
, /* I - Length of initial line */
1081 size_t linesize
) /* I - Size of line buffer */
1083 char label
[256], /* Page label string */
1084 *ptr
; /* Pointer into line */
1085 int level
; /* Embedded document level */
1086 pstops_page_t
*pageinfo
; /* Page information */
1087 int first_page
; /* First page on N-up output? */
1088 int bounding_box
[4]; /* PageBoundingBox */
1092 * Get the page label for this page...
1095 first_page
= is_first_page(number
);
1097 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1099 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1103 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1105 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1110 * Create or update the current output page...
1114 pageinfo
= add_page(doc
, label
);
1116 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1119 * Handle first page override...
1122 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1127 * First page/sheet gets AP_FIRSTPAGE_* options...
1130 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1131 pageinfo
->num_options
,
1132 &(pageinfo
->options
));
1133 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->ap_manual_feed
,
1134 pageinfo
->num_options
,
1135 &(pageinfo
->options
));
1137 else if (doc
->page
== (Duplex
+ 2))
1140 * Second page/sheet gets default options...
1143 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1144 pageinfo
->num_options
,
1145 &(pageinfo
->options
));
1146 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->manual_feed
,
1147 pageinfo
->num_options
,
1148 &(pageinfo
->options
));
1153 * Scan comments until we see something other than %%Page*: or
1157 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1159 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1161 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1164 * %%PageBoundingBox: llx lly urx ury
1167 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1168 bounding_box
+ 1, bounding_box
+ 2,
1169 bounding_box
+ 3) != 4)
1171 fputs("ERROR: Bad %%PageBoundingBox: comment in file!\n", stderr
);
1172 memcpy(bounding_box
, doc
->bounding_box
,
1173 sizeof(bounding_box
));
1177 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1178 !strncmp(line
, "%%PageMedia:", 12) ||
1179 !strncmp(line
, "%%PageOrientation:", 18) ||
1180 !strncmp(line
, "%%PageProcessColors:", 20) ||
1181 !strncmp(line
, "%%PageRequirements:", 18) ||
1182 !strncmp(line
, "%%PageResources:", 16))
1189 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1192 * %%PageCustomColors: ...
1195 else if (!strncmp(line
, "%%PageMedia:", 12))
1201 else if (!strncmp(line
, "%%PageOrientation:", 18))
1204 * %%PageOrientation: ...
1207 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1210 * %%PageProcessColors: ...
1213 else if (!strncmp(line
, "%%PageRequirements:", 18))
1216 * %%PageRequirements: ...
1219 else if (!strncmp(line
, "%%PageResources:", 16))
1222 * %%PageResources: ...
1225 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1228 * %%IncludeFeature: *MainKeyword OptionKeyword
1231 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1232 pageinfo
->num_options
= include_feature(ppd
, line
,
1233 pageinfo
->num_options
,
1234 &(pageinfo
->options
));
1236 else if (strncmp(line
, "%%Include", 9))
1240 if (doc
->number_up
== 1)
1243 * Update the document's composite and page bounding box...
1246 memcpy(pageinfo
->bounding_box
, bounding_box
,
1247 sizeof(pageinfo
->bounding_box
));
1249 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1250 doc
->new_bounding_box
[0] = bounding_box
[0];
1251 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1252 doc
->new_bounding_box
[1] = bounding_box
[1];
1253 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1254 doc
->new_bounding_box
[2] = bounding_box
[2];
1255 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1256 doc
->new_bounding_box
[3] = bounding_box
[3];
1260 * Output the page header as needed...
1263 if (!doc
->slow_order
&& first_page
)
1265 if (!ppd
|| !ppd
->num_filters
)
1266 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1267 doc
->slow_collate
? 1 : doc
->copies
);
1269 if (doc
->number_up
> 1)
1271 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1272 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1273 PageLeft
, PageBottom
, PageRight
, PageTop
);
1277 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1278 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1279 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1280 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1285 * Copy any page setup commands...
1290 doc_puts(doc
, "%%BeginPageSetup\n");
1292 if (pageinfo
->num_options
> 0)
1294 int i
; /* Looping var */
1295 ppd_option_t
*option
; /* PPD option */
1296 int min_order
; /* Minimum OrderDependency value */
1297 char *doc_setup
, /* DocumentSetup commands to send */
1298 *any_setup
; /* AnySetup commands to send */
1302 * Yes, figure out the minimum OrderDependency value...
1305 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1306 min_order
= option
->order
;
1310 for (i
= 0; i
< pageinfo
->num_options
; i
++)
1311 if ((option
= ppdFindOption(ppd
, pageinfo
->options
[i
].name
)) != NULL
&&
1312 option
->order
< min_order
)
1313 min_order
= option
->order
;
1316 * Mark and extract them...
1319 cupsMarkOptions(ppd
, pageinfo
->num_options
, pageinfo
->options
);
1321 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
1322 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
1325 * Then send them out...
1329 doc_puts(doc
, doc_setup
);
1332 doc_puts(doc
, any_setup
);
1335 * Free the command strings...
1347 * Prep for the start of the page description...
1350 start_nup(doc
, number
, 1, bounding_box
);
1353 * Copy page setup commands as needed...
1356 if (!strncmp(line
, "%%BeginPageSetup", 16))
1358 int feature
= 0; /* In a Begin/EndFeature block? */
1361 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1363 if (!strncmp(line
, "%%EndPageSetup", 14))
1365 else if (!strncmp(line
, "%%BeginFeature:", 15))
1369 if (doc
->number_up
> 1 || doc
->fitplot
)
1372 else if (!strncmp(line
, "%%EndFeature:", 13))
1376 if (doc
->number_up
> 1 || doc
->fitplot
)
1379 else if (!strncmp(line
, "%%Include", 9))
1382 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1383 doc_write(doc
, line
, linelen
);
1387 * Skip %%EndPageSetup...
1391 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1395 * Finish the PageSetup section as needed...
1399 doc_puts(doc
, "%%EndPageSetup\n");
1402 * Read the rest of the page description...
1410 (!strncmp(line
, "%%Page:", 7) ||
1411 !strncmp(line
, "%%Trailer", 9) ||
1412 !strncmp(line
, "%%EOF", 5)))
1414 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1415 !strncmp(line
, "%ADO_BeginApplication", 21))
1417 doc_write(doc
, line
, linelen
);
1421 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1422 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1424 doc_write(doc
, line
, linelen
);
1428 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1429 (!strncmp(line
, "%%BeginData:", 12) &&
1430 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1433 * Copy binary data...
1436 int bytes
; /* Bytes of data */
1439 doc_write(doc
, line
, linelen
);
1441 bytes
= atoi(strchr(line
, ':') + 1);
1445 if (bytes
> linesize
)
1446 linelen
= cupsFileRead(fp
, line
, linesize
);
1448 linelen
= cupsFileRead(fp
, line
, bytes
);
1453 perror("ERROR: Early end-of-file while reading binary data");
1457 doc_write(doc
, line
, linelen
);
1463 doc_write(doc
, line
, linelen
);
1465 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1468 * Finish up this page and return...
1471 end_nup(doc
, number
);
1473 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1480 * 'copy_prolog()' - Copy the document prolog section...
1482 * This function expects "line" to be filled with a %%BeginProlog comment line.
1483 * On return, "line" will contain the next line in the file, if any.
1486 static size_t /* O - Length of next line */
1487 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1488 pstops_doc_t
*doc
, /* I - Document info */
1489 ppd_file_t
*ppd
, /* I - PPD file */
1490 char *line
, /* I - Line buffer */
1491 size_t linelen
, /* I - Length of initial line */
1492 size_t linesize
) /* I - Size of line buffer */
1494 while (strncmp(line
, "%%BeginProlog", 13))
1496 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1499 fwrite(line
, 1, linelen
, stdout
);
1501 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1505 puts("%%BeginProlog");
1507 do_prolog(doc
, ppd
);
1509 if (!strncmp(line
, "%%BeginProlog", 13))
1511 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1513 if (!strncmp(line
, "%%EndProlog", 11) ||
1514 !strncmp(line
, "%%BeginSetup", 12) ||
1515 !strncmp(line
, "%%Page:", 7))
1518 fwrite(line
, 1, linelen
, stdout
);
1521 if (!strncmp(line
, "%%EndProlog", 11))
1522 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1524 fputs("ERROR: Missing %%EndProlog!\n", stderr
);
1527 puts("%%EndProlog");
1534 * 'copy_setup()' - Copy the document setup section...
1536 * This function expects "line" to be filled with a %%BeginSetup comment line.
1537 * On return, "line" will contain the next line in the file, if any.
1540 static size_t /* O - Length of next line */
1541 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1542 pstops_doc_t
*doc
, /* I - Document info */
1543 ppd_file_t
*ppd
, /* I - PPD file */
1544 char *line
, /* I - Line buffer */
1545 size_t linelen
, /* I - Length of initial line */
1546 size_t linesize
) /* I - Size of line buffer */
1548 while (strncmp(line
, "%%BeginSetup", 12))
1550 if (!strncmp(line
, "%%Page:", 7))
1553 fwrite(line
, 1, linelen
, stdout
);
1555 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1559 if (!strncmp(line
, "%%BeginSetup", 12))
1561 while (strncmp(line
, "%%EndSetup", 10))
1563 if (!strncmp(line
, "%%Page:", 7))
1565 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1568 * %%IncludeFeature: *MainKeyword OptionKeyword
1571 if (doc
->number_up
== 1 && !doc
->fitplot
)
1572 doc
->num_options
= include_feature(ppd
, line
, doc
->num_options
,
1576 fwrite(line
, 1, linelen
, stdout
);
1578 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1582 if (!strncmp(line
, "%%EndSetup", 10))
1583 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1585 fputs("ERROR: Missing %%EndSetup!\n", stderr
);
1588 puts("%%BeginSetup");
1599 * 'copy_trailer()' - Copy the document trailer...
1601 * This function expects "line" to be filled with a %%Trailer comment line.
1602 * On return, "line" will contain the next line in the file, if any.
1605 static size_t /* O - Length of next line */
1606 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1607 pstops_doc_t
*doc
, /* I - Document info */
1608 ppd_file_t
*ppd
, /* I - PPD file */
1609 int number
, /* I - Number of pages */
1610 char *line
, /* I - Line buffer */
1611 size_t linelen
, /* I - Length of initial line */
1612 size_t linesize
) /* I - Size of line buffer */
1615 * Write the trailer comments...
1622 if (!strncmp(line
, "%%EOF", 5))
1624 else if (strncmp(line
, "%%Trailer", 9) &&
1625 strncmp(line
, "%%Pages:", 8) &&
1626 strncmp(line
, "%%BoundingBox:", 14))
1627 fwrite(line
, 1, linelen
, stdout
);
1629 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1632 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1634 printf("%%%%Pages: %d\n", number
);
1635 if (doc
->number_up
> 1 || doc
->fitplot
)
1636 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1637 PageLeft
, PageBottom
, PageRight
, PageTop
);
1639 printf("%%%%BoundingBox: %d %d %d %d\n",
1640 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1641 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1648 * 'do_prolog()' - Send the necessary document prolog commands...
1652 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1653 ppd_file_t
*ppd
) /* I - PPD file */
1656 * Send the document prolog commands...
1659 if (ppd
&& ppd
->patches
)
1661 puts("%%BeginFeature: *JobPatchFile 1");
1663 puts("%%EndFeature");
1666 ppdEmit(ppd
, stdout
, PPD_ORDER_PROLOG
);
1669 * Define ESPshowpage here so that applications that define their
1670 * own procedure to do a showpage pick it up...
1673 if (doc
->use_ESPshowpage
)
1674 puts("userdict/ESPshowpage/showpage load put\n"
1675 "userdict/showpage{}put");
1681 * 'do_setup()' - Send the necessary document setup commands...
1685 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1686 ppd_file_t
*ppd
) /* I - PPD file */
1689 * Mark any options from %%IncludeFeature: comments...
1692 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
1695 * Send all the printer-specific setup commands...
1698 ppdEmit(ppd
, stdout
, PPD_ORDER_DOCUMENT
);
1699 ppdEmit(ppd
, stdout
, PPD_ORDER_ANY
);
1702 * Set the number of copies for the job...
1705 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1707 printf("%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
1708 printf("%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
1709 "{1 dict begin/NumCopies exch def currentdict end setpagedevice}\n"
1710 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
1711 puts("%RBIEndNonPPDFeature");
1715 * If we are doing N-up printing, disable setpagedevice...
1718 if (doc
->number_up
> 1)
1719 puts("userdict/setpagedevice{pop}bind put");
1722 * Changes to the transfer function must be made AFTER any
1723 * setpagedevice code...
1726 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
1727 printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
1728 "ifelse %.3f mul } bind settransfer\n", doc
->gamma
,
1732 * Make sure we have rectclip and rectstroke procedures of some sort...
1738 * Write the page and label prologs...
1741 if (doc
->number_up
== 2 || doc
->number_up
== 6)
1744 * For 2- and 6-up output, rotate the labels to match the orientation
1748 if (Orientation
& 1)
1749 WriteLabelProlog(doc
->page_label
, PageBottom
,
1750 PageWidth
- PageLength
+ PageTop
, PageLength
);
1752 WriteLabelProlog(doc
->page_label
, PageLeft
, PageRight
, PageLength
);
1755 WriteLabelProlog(doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
1760 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
1762 * This function should be used for all page-level output that is affected
1763 * by ordering, collation, etc.
1767 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
1768 const char *format
, /* I - Printf-style format string */
1769 ...) /* I - Additional arguments as needed */
1771 va_list ap
; /* Pointer to arguments */
1772 char buffer
[1024]; /* Output buffer */
1773 size_t bytes
; /* Number of bytes to write */
1776 va_start(ap
, format
);
1777 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
1780 if (bytes
> sizeof(buffer
))
1783 "ERROR: doc_printf overflow (%d bytes) detected, aborting!\n",
1788 doc_write(doc
, buffer
, bytes
);
1793 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
1795 * This function should be used for all page-level output that is affected
1796 * by ordering, collation, etc.
1800 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
1801 const char *s
) /* I - String to send */
1803 doc_write(doc
, s
, strlen(s
));
1808 * 'doc_write()' - Send data to stdout and/or the temp file.
1812 doc_write(pstops_doc_t
*doc
, /* I - Document information */
1813 const char *s
, /* I - Data to send */
1814 size_t len
) /* I - Number of bytes to send */
1816 if (!doc
->slow_order
)
1817 fwrite(s
, 1, len
, stdout
);
1820 cupsFileWrite(doc
->temp
, s
, len
);
1825 * 'end_nup()' - End processing for N-up printing...
1829 end_nup(pstops_doc_t
*doc
, /* I - Document information */
1830 int number
) /* I - Page number */
1832 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
1833 puts("userdict /ESPsave get restore");
1835 switch (doc
->number_up
)
1838 if (doc
->use_ESPshowpage
)
1840 WriteLabels(Orientation
);
1841 puts("ESPshowpage");
1847 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1849 if (Orientation
& 1)
1852 * Rotate the labels back to portrait...
1855 WriteLabels(Orientation
- 1);
1857 else if (Orientation
== 0)
1860 * Rotate the labels to landscape...
1863 WriteLabels(doc
->normal_landscape
? 1 : 3);
1868 * Rotate the labels to landscape...
1871 WriteLabels(doc
->normal_landscape
? 3 : 1);
1874 puts("ESPshowpage");
1879 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1881 WriteLabels(Orientation
);
1882 puts("ESPshowpage");
1892 * 'include_feature()' - Include a printer option/feature command.
1895 static int /* O - New number of options */
1897 ppd_file_t
*ppd
, /* I - PPD file */
1898 const char *line
, /* I - DSC line */
1899 int num_options
, /* I - Number of options */
1900 cups_option_t
**options
) /* IO - Options */
1902 char name
[255], /* Option name */
1903 value
[255]; /* Option value */
1904 ppd_option_t
*option
; /* Option in file */
1905 ppd_choice_t
*choice
; /* Choice */
1909 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
1912 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
1914 fputs("ERROR: Bad %%IncludeFeature: comment!\n", stderr
);
1915 return (num_options
);
1919 * Find the option and choice...
1922 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
1924 fprintf(stderr
, "WARNING: Unknown option \"%s\"!\n", name
+ 1);
1925 return (num_options
);
1928 if (option
->section
== PPD_ORDER_EXIT
||
1929 option
->section
== PPD_ORDER_JCL
)
1931 fprintf(stderr
, "WARNING: Option \"%s\" cannot be included via "
1932 "IncludeFeature!\n", name
+ 1);
1933 return (num_options
);
1936 if ((choice
= ppdFindChoice(option
, value
)) == NULL
)
1938 fprintf(stderr
, "WARNING: Unknown choice \"%s\" for option \"%s\"!\n",
1940 return (num_options
);
1944 * Add the option to the option array and return...
1947 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
1952 * 'parse_text()' - Parse a text value in a comment...
1954 * This function parses a DSC text value as defined on page 36 of the
1955 * DSC specification. Text values are either surrounded by parenthesis
1956 * or whitespace-delimited.
1958 * The value returned is the literal characters for the entire text
1959 * string, including any parenthesis and escape characters.
1962 static char * /* O - Value or NULL on error */
1963 parse_text(const char *start
, /* I - Start of text value */
1964 char **end
, /* O - End of text value */
1965 char *buffer
, /* I - Buffer */
1966 size_t bufsize
) /* I - Size of buffer */
1968 char *bufptr
, /* Pointer in buffer */
1969 *bufend
; /* End of buffer */
1970 int level
; /* Parenthesis level */
1974 * Skip leading whitespace...
1977 while (isspace(*start
& 255))
1981 * Then copy the value...
1986 bufend
= buffer
+ bufsize
- 1;
1988 while (bufptr
< bufend
)
1990 if (isspace(*start
& 255) && !level
)
1997 else if (*start
== ')')
2007 else if (*start
== '\\')
2010 * Copy escaped character...
2013 int i
; /* Looping var */
2017 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
2018 *bufptr
++ = start
[i
], i
++);
2027 * Return the value and new pointer into the line...
2031 *end
= (char *)start
;
2033 if (bufptr
== bufend
)
2041 * 'set_pstops_options()' - Set pstops options...
2046 pstops_doc_t
*doc
, /* I - Document information */
2047 ppd_file_t
*ppd
, /* I - PPD file */
2048 char *argv
[], /* I - Command-line arguments */
2049 int num_options
, /* I - Number of options */
2050 cups_option_t
*options
) /* I - Options */
2052 const char *val
; /* Option value */
2053 int intval
; /* Integer option value */
2054 ppd_attr_t
*attr
; /* PPD attribute */
2055 ppd_option_t
*option
; /* PPD option */
2056 ppd_choice_t
*choice
; /* PPD choice */
2060 * Initialize document information structure...
2063 memset(doc
, 0, sizeof(pstops_doc_t
));
2065 doc
->job_id
= atoi(argv
[1]);
2066 doc
->user
= argv
[2];
2067 doc
->title
= argv
[3];
2068 doc
->copies
= atoi(argv
[4]);
2070 if (ppd
&& ppd
->landscape
> 0)
2071 doc
->normal_landscape
= 1;
2073 doc
->bounding_box
[0] = (int)PageLeft
;
2074 doc
->bounding_box
[1] = (int)PageBottom
;
2075 doc
->bounding_box
[2] = (int)PageRight
;
2076 doc
->bounding_box
[3] = (int)PageTop
;
2078 doc
->new_bounding_box
[0] = INT_MAX
;
2079 doc
->new_bounding_box
[1] = INT_MAX
;
2080 doc
->new_bounding_box
[2] = INT_MIN
;
2081 doc
->new_bounding_box
[3] = INT_MIN
;
2084 * AP_FIRSTPAGE_InputSlot
2087 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2091 * AP_FIRSTPAGE_ManualFeed
2094 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2101 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2104 * Get brightness value from 10 to 1000.
2109 if (intval
< 10 || intval
> 1000)
2111 fprintf(stderr
, "ERROR: Unsupported brightness value %s, using "
2112 "brightness=100!\n", val
);
2113 doc
->brightness
= 1.0f
;
2116 doc
->brightness
= intval
* 0.01f
;
2119 doc
->brightness
= 1.0f
;
2122 * collate, multiple-document-handling
2125 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2128 * This IPP attribute is unnecessarily complicated...
2130 * single-document, separate-documents-collated-copies, and
2131 * single-document-new-sheet all require collated copies.
2133 * separate-documents-uncollated-copies allows for uncollated copies.
2136 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2139 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2140 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2141 !strcasecmp(val
, "yes")))
2148 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2149 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2150 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2159 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
2160 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2161 !strcasecmp(val
, "yes")))
2168 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2171 * Get gamma value from 1 to 10000...
2176 if (intval
< 1 || intval
> 10000)
2178 fprintf(stderr
, "ERROR: Unsupported gamma value %s, using "
2179 "gamma=1000!\n", val
);
2183 doc
->gamma
= intval
* 0.001f
;
2192 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2193 doc
->input_slot
= choice
->choice
;
2199 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2200 doc
->manual_feed
= choice
->choice
;
2202 if ((val
= cupsGetOption("mirror", num_options
, options
)) != NULL
&&
2203 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2204 !strcasecmp(val
, "yes")))
2211 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2213 switch (intval
= atoi(val
))
2221 doc
->number_up
= intval
;
2225 "ERROR: Unsupported number-up value %d, using number-up=1!\n",
2238 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2240 if (!strcasecmp(val
, "lrtb"))
2241 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2242 else if (!strcasecmp(val
, "lrbt"))
2243 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2244 else if (!strcasecmp(val
, "rltb"))
2245 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2246 else if (!strcasecmp(val
, "rlbt"))
2247 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2248 else if (!strcasecmp(val
, "tblr"))
2249 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2250 else if (!strcasecmp(val
, "tbrl"))
2251 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2252 else if (!strcasecmp(val
, "btlr"))
2253 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2254 else if (!strcasecmp(val
, "btrl"))
2255 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2258 fprintf(stderr
, "ERROR: Unsupported number-up-layout value %s, using "
2259 "number-up-layout=lrtb!\n", val
);
2260 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2264 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2270 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2272 if (!strcasecmp(val
, "Reverse"))
2273 doc
->output_order
= 1;
2278 * Figure out the right default output order from the PPD file...
2281 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2282 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2284 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2285 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2287 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2294 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2296 if (!strcasecmp(val
, "none"))
2297 doc
->page_border
= PSTOPS_BORDERNONE
;
2298 else if (!strcasecmp(val
, "single"))
2299 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2300 else if (!strcasecmp(val
, "single-thick"))
2301 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2302 else if (!strcasecmp(val
, "double"))
2303 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2304 else if (!strcasecmp(val
, "double-thick"))
2305 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2308 fprintf(stderr
, "ERROR: Unsupported page-border value %s, using "
2309 "page-border=none!\n", val
);
2310 doc
->page_border
= PSTOPS_BORDERNONE
;
2314 doc
->page_border
= PSTOPS_BORDERNONE
;
2320 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2326 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2332 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2335 * Now figure out if we have to force collated copies, etc.
2338 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2341 * Force collated copies when printing a duplexed document to
2342 * a non-PS printer that doesn't do hardware copy generation.
2343 * Otherwise the copies will end up on the front/back side of
2351 * See if we have to filter the fast or slow way...
2354 if (doc
->collate
&& doc
->copies
> 1)
2357 * See if we need to manually collate the pages...
2360 doc
->slow_collate
= 1;
2362 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2363 !strcasecmp(choice
->choice
, "True"))
2366 * Hardware collate option is selected, see if the option is
2367 * conflicting - if not, collate in hardware. Otherwise,
2368 * turn the hardware collate option off...
2371 if ((option
= ppdFindOption(ppd
, "Option")) != NULL
&&
2372 !option
->conflicted
)
2373 doc
->slow_collate
= 0;
2375 ppdMarkOption(ppd
, "Collate", "False");
2379 doc
->slow_collate
= 0;
2381 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2382 doc
->slow_order
= 1;
2384 doc
->slow_order
= 0;
2386 if ((doc
->slow_collate
|| doc
->slow_order
) && Duplex
)
2387 doc
->slow_duplex
= 1;
2389 doc
->slow_duplex
= 0;
2392 * Create a temporary file for page data if we need to filter slowly...
2395 if (doc
->slow_order
|| doc
->slow_collate
)
2397 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2398 sizeof(doc
->tempfile
))) == NULL
)
2400 fprintf(stderr
, "ERROR: Unable to create temporary file: %s\n",
2407 * Figure out if we should use ESPshowpage or not...
2410 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2414 * Yes, use ESPshowpage...
2417 doc
->use_ESPshowpage
= 1;
2420 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2421 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2426 * 'skip_page()' - Skip past a page that won't be printed...
2429 static size_t /* O - Length of next line */
2430 skip_page(cups_file_t
*fp
, /* I - File to read from */
2431 char *line
, /* I - Line buffer */
2432 size_t linelen
, /* I - Length of initial line */
2433 size_t linesize
) /* I - Size of line buffer */
2435 int level
; /* Embedded document level */
2440 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2443 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer", 9)))
2445 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2446 !strncmp(line
, "%ADO_BeginApplication", 21))
2448 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2449 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2451 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2452 (!strncmp(line
, "%%BeginData:", 12) &&
2453 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2456 * Skip binary data...
2459 int bytes
; /* Bytes of data */
2462 bytes
= atoi(strchr(line
, ':') + 1);
2466 if (bytes
> linesize
)
2467 linelen
= cupsFileRead(fp
, line
, linesize
);
2469 linelen
= cupsFileRead(fp
, line
, bytes
);
2474 perror("ERROR: Early end-of-file while reading binary data");
2488 * 'start_nup()' - Start processing for N-up printing...
2492 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2493 int number
, /* I - Page number */
2494 int show_border
, /* I - Show the border? */
2495 const int *bounding_box
) /* I - BoundingBox value */
2497 int pos
; /* Position on page */
2498 int x
, y
; /* Relative position of subpage */
2499 float w
, l
, /* Width and length of subpage */
2500 tx
, ty
; /* Translation values for subpage */
2501 float pagew
, /* Printable width of page */
2502 pagel
; /* Printable height of page */
2503 int bboxw
, /* BoundingBox width */
2504 bboxl
; /* BoundingBox height */
2507 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
2508 doc_puts(doc
, "userdict/ESPsave save put\n");
2511 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
2513 pos
= (number
- 1) % doc
->number_up
;
2514 pagew
= PageRight
- PageLeft
;
2515 pagel
= PageTop
- PageBottom
;
2519 bboxw
= bounding_box
[2] - bounding_box
[0];
2520 bboxl
= bounding_box
[3] - bounding_box
[1];
2528 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2529 fprintf(stderr
, "DEBUG: bboxw = %d, bboxl = %d\n", bboxw
, bboxl
);
2530 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2531 PageLeft
, PageRight
);
2532 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2533 PageTop
, PageBottom
);
2534 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2535 PageWidth
, PageLength
);
2537 switch (Orientation
)
2539 case 1 : /* Landscape */
2540 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2542 case 2 : /* Reverse Portrait */
2543 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2546 case 3 : /* Reverse Landscape */
2547 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2551 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2552 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2553 else if (doc
->number_up
> 1 || doc
->fitplot
)
2554 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2556 switch (doc
->number_up
)
2562 l
= w
* bboxl
/ bboxw
;
2567 w
= l
* bboxw
/ bboxl
;
2570 tx
= 0.5 * (pagew
- w
);
2571 ty
= 0.5 * (pagel
- l
);
2573 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2574 w
/ bboxw
, l
/ bboxl
);
2584 if (Orientation
& 1)
2588 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2592 l
= w
* bboxl
/ bboxw
;
2594 if (l
> (pagew
* 0.5))
2597 w
= l
* bboxw
/ bboxl
;
2600 tx
= 0.5 * (pagew
* 0.5 - l
);
2601 ty
= 0.5 * (pagel
- w
);
2603 if (doc
->normal_landscape
)
2604 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2606 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2608 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2609 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2615 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2619 w
= l
* bboxw
/ bboxl
;
2621 if (w
> (pagel
* 0.5))
2624 l
= w
* bboxl
/ bboxw
;
2627 tx
= 0.5 * (pagel
* 0.5 - w
);
2628 ty
= 0.5 * (pagew
- l
);
2630 if (doc
->normal_landscape
)
2631 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2633 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2635 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2636 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
2641 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2652 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2655 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2659 l
= w
* bboxl
/ bboxw
;
2661 if (l
> (pagel
* 0.5))
2664 w
= l
* bboxw
/ bboxl
;
2667 tx
= 0.5 * (pagew
* 0.5 - w
);
2668 ty
= 0.5 * (pagel
* 0.5 - l
);
2670 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2671 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
2672 w
/ bboxw
, l
/ bboxl
);
2676 if (Orientation
& 1)
2678 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2683 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2686 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2694 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2697 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2702 l
= w
* bboxl
/ bboxw
;
2704 if (l
> (pagew
* 0.333))
2707 w
= l
* bboxw
/ bboxl
;
2710 tx
= 0.5 * (pagel
- 2 * w
);
2711 ty
= 0.5 * (pagew
- 3 * l
);
2713 if (doc
->normal_landscape
)
2714 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2716 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2718 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2719 tx
+ x
* y
* pagel
* 0.5, ty
+ pagew
* 0.333,
2720 w
/ bboxw
, l
/ bboxl
);
2724 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2729 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2732 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2740 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2743 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2748 w
= l
* bboxw
/ bboxl
;
2750 if (w
> (pagel
* 0.333))
2753 l
= w
* bboxl
/ bboxw
;
2756 tx
= 0.5 * (pagel
- 3 * w
);
2757 ty
= 0.5 * (pagew
- 2 * l
);
2759 if (doc
->normal_landscape
)
2760 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2762 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2764 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2765 tx
+ x
* pagel
* 0.333, ty
+ y
* pagew
* 0.5,
2766 w
/ bboxw
, l
/ bboxl
);
2771 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2782 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2785 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2789 l
= w
* bboxl
/ bboxw
;
2791 if (l
> (pagel
* 0.333))
2794 w
= l
* bboxw
/ bboxl
;
2797 tx
= 0.5 * (pagew
* 0.333 - w
);
2798 ty
= 0.5 * (pagel
* 0.333 - l
);
2800 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2801 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
2802 w
/ bboxw
, l
/ bboxl
);
2806 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2817 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2820 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2824 l
= w
* bboxl
/ bboxw
;
2826 if (l
> (pagel
* 0.25))
2829 w
= l
* bboxw
/ bboxl
;
2832 tx
= 0.5 * (pagew
* 0.25 - w
);
2833 ty
= 0.5 * (pagel
* 0.25 - l
);
2835 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2836 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
2837 w
/ bboxw
, l
/ bboxl
);
2842 * Draw borders as necessary...
2845 if (doc
->page_border
&& show_border
)
2847 int rects
; /* Number of border rectangles */
2848 float fscale
, /* Scaling value for points */
2849 margin
; /* Current margin for borders */
2852 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
2853 fscale
= PageWidth
/ w
;
2854 margin
= 2.25 * fscale
;
2857 * Set the line width and color...
2860 doc_puts(doc
, "gsave\n");
2861 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
2862 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
2866 * Draw border boxes...
2869 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
2870 if (doc
->number_up
> 1)
2871 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2872 margin
- 2.25 * fscale
,
2873 margin
- 2.25 * fscale
,
2874 bboxw
+ 4.5 * fscale
- 2 * margin
,
2875 bboxl
+ 4.5 * fscale
- 2 * margin
);
2877 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2879 PageBottom
+ margin
,
2880 PageRight
- PageLeft
- 2 * margin
,
2881 PageTop
- PageBottom
- 2 * margin
);
2884 * Restore pen settings...
2887 doc_puts(doc
, "grestore\n");
2893 * Clip the page that follows to the bounding box of the page...
2896 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
2898 doc_printf(doc
, "%d %d %d %d ESPrc\n", bounding_box
[0], bounding_box
[1],
2901 else if (doc
->number_up
> 1)
2904 * Clip the page that follows to the default page size...
2907 doc_printf(doc
, "0 0 %d %d ESPrc\n", bboxw
, bboxl
);
2913 * End of "$Id: pstops.c 5382 2006-04-07 14:58:44Z mike $".