]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/pstops.c
2 * "$Id: pstops.c 5570 2006-05-22 18:31:23Z 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
, ...)
189 __attribute__ ((__format__ (__printf__
, 2, 3)))
190 #endif /* __GNUC__ */
192 static void doc_puts(pstops_doc_t
*doc
, const char *s
);
193 static void doc_write(pstops_doc_t
*doc
, const char *s
, size_t len
);
194 static void end_nup(pstops_doc_t
*doc
, int number
);
195 static int include_feature(ppd_file_t
*ppd
, const char *line
,
197 cups_option_t
**options
);
198 static char *parse_text(const char *start
, char **end
, char *buffer
,
200 static void set_pstops_options(pstops_doc_t
*doc
, ppd_file_t
*ppd
,
201 char *argv
[], int num_options
,
202 cups_option_t
*options
);
203 static size_t skip_page(cups_file_t
*fp
, char *line
, size_t linelen
,
205 static void start_nup(pstops_doc_t
*doc
, int number
,
206 int show_border
, const int *bounding_box
);
210 * 'main()' - Main entry...
213 int /* O - Exit status */
214 main(int argc
, /* I - Number of command-line args */
215 char *argv
[]) /* I - Command-line arguments */
217 pstops_doc_t doc
; /* Document information */
218 cups_file_t
*fp
; /* Print file */
219 ppd_file_t
*ppd
; /* PPD file */
220 int num_options
; /* Number of print options */
221 cups_option_t
*options
; /* Print options */
222 char line
[8192]; /* Line buffer */
223 size_t len
; /* Length of line buffer */
227 * Make sure status messages are not buffered...
230 setbuf(stderr
, NULL
);
233 * Check command-line...
236 if (argc
< 6 || argc
> 7)
238 fputs("ERROR: pstops job-id user title copies options [file]\n", stderr
);
243 * If we have 7 arguments, print the file named on the command-line.
244 * Otherwise, send stdin instead...
248 fp
= cupsFileStdin();
252 * Try to open the print file...
255 if ((fp
= cupsFileOpen(argv
[6], "r")) == NULL
)
257 fprintf(stderr
, "ERROR: Unable to open print file \"%s\" - %s\n",
258 argv
[6], strerror(errno
));
264 * Read the first line to see if we have DSC comments...
267 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
269 fputs("ERROR: Empty print file!\n", stderr
);
274 * Process command-line options...
278 num_options
= cupsParseOptions(argv
[5], 0, &options
);
279 ppd
= SetCommonOptions(num_options
, options
, 1);
281 set_pstops_options(&doc
, ppd
, argv
, num_options
, options
);
284 * Write any "exit server" options that have been selected...
287 ppdEmit(ppd
, stdout
, PPD_ORDER_EXIT
);
290 * Write any JCL commands that are needed to print PostScript code...
294 ppdEmitJCL(ppd
, stdout
, doc
.job_id
, doc
.user
, doc
.title
);
297 * Start with a DSC header...
300 puts("%!PS-Adobe-3.0");
303 * Skip leading PJL in the document...
306 while (!strncmp(line
, "\033%-12345X", 9) || !strncmp(line
, "@PJL ", 5))
309 * Yup, we have leading PJL fun, so skip it until we hit the line
310 * with "ENTER LANGUAGE"...
313 fputs("DEBUG: Skipping PJL header...\n", stderr
);
315 while (strstr(line
, "ENTER LANGUAGE") == NULL
&& strncmp(line
, "%!", 2))
316 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
319 if (!strncmp(line
, "%!", 2))
322 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
327 * Now see if the document conforms to the Adobe Document Structuring
331 if (!strncmp(line
, "%!PS-Adobe-", 11))
334 * Yes, filter the document...
337 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
342 * No, display an error message and treat the file as if it contains
346 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
350 * Send %%EOF as needed...
357 * End the job with the appropriate JCL command or CTRL-D...
362 if (ppd
&& ppd
->jcl_end
)
363 ppdEmitJCLEnd(ppd
, stdout
);
369 * Close files and remove the temporary file if needed...
374 cupsFileClose(doc
.temp
);
375 unlink(doc
.tempfile
);
379 cupsFreeOptions(num_options
, options
);
388 * 'add_page()' - Add a page to the pages array...
391 static pstops_page_t
* /* O - New page info object */
392 add_page(pstops_doc_t
*doc
, /* I - Document information */
393 const char *label
) /* I - Page label */
395 pstops_page_t
*pageinfo
; /* New page info object */
399 doc
->pages
= cupsArrayNew(NULL
, NULL
);
403 fprintf(stderr
, "EMERG: Unable to allocate memory for pages array: %s\n",
408 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
410 fprintf(stderr
, "EMERG: Unable to allocate memory for page info: %s\n",
415 pageinfo
->label
= strdup(label
);
416 pageinfo
->offset
= cupsFileTell(doc
->temp
);
418 cupsArrayAdd(doc
->pages
, pageinfo
);
427 * 'check_range()' - Check to see if the current page is selected for
431 static int /* O - 1 if selected, 0 otherwise */
432 check_range(pstops_doc_t
*doc
, /* I - Document information */
433 int page
) /* I - Page number */
435 const char *range
; /* Pointer into range string */
436 int lower
, upper
; /* Lower and upper page numbers */
442 * See if we only print even or odd pages...
445 if (!strcasecmp(doc
->page_set
, "even") && (page
& 1))
448 if (!strcasecmp(doc
->page_set
, "odd") && !(page
& 1))
452 if (!doc
->page_ranges
)
453 return (1); /* No range, print all pages... */
455 for (range
= doc
->page_ranges
; *range
!= '\0';)
461 upper
= strtol(range
, (char **)&range
, 10);
465 lower
= strtol(range
, (char **)&range
, 10);
470 if (!isdigit(*range
& 255))
473 upper
= strtol(range
, (char **)&range
, 10);
479 if (page
>= lower
&& page
<= upper
)
493 * 'copy_bytes()' - Copy bytes from the input file to stdout...
497 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
498 off_t offset
, /* I - Offset to page data */
499 size_t length
) /* I - Length of page data */
501 char buffer
[8192]; /* Data buffer */
502 ssize_t nbytes
; /* Number of bytes read */
503 size_t nleft
; /* Number of bytes left/remaining */
508 if (cupsFileSeek(fp
, offset
) < 0)
510 fprintf(stderr
, "ERROR: Unable to seek to offset " CUPS_LLFMT
512 CUPS_LLCAST offset
, strerror(errno
));
516 while (nleft
> 0 || length
== 0)
518 if (nleft
> sizeof(buffer
) || length
== 0)
519 nbytes
= sizeof(buffer
);
523 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
528 fwrite(buffer
, 1, nbytes
, stdout
);
534 * 'copy_comments()' - Copy all of the comments section...
536 * This function expects "line" to be filled with a comment line.
537 * On return, "line" will contain the next line in the file, if any.
540 static size_t /* O - Length of next line */
541 copy_comments(cups_file_t
*fp
, /* I - File to read from */
542 pstops_doc_t
*doc
, /* I - Document info */
543 char *line
, /* I - Line buffer */
544 size_t linelen
, /* I - Length of initial line */
545 size_t linesize
) /* I - Size of line buffer */
547 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
548 saw_for
, /* Saw %%For: comment? */
549 saw_pages
, /* Saw %%Pages: comment? */
550 saw_title
; /* Saw %%Title: comment? */
554 * Loop until we see %%EndComments or a non-comment line...
557 saw_bounding_box
= 0;
562 while (line
[0] == '%')
565 * Strip trailing whitespace...
572 if (!isspace(line
[linelen
] & 255))
575 line
[linelen
] = '\0';
582 fprintf(stderr
, "DEBUG: %s\n", line
);
585 * Pull the headers out...
588 if (!strncmp(line
, "%%Pages:", 8))
591 fputs("ERROR: Duplicate %%Pages: comment seen!\n", stderr
);
595 else if (!strncmp(line
, "%%BoundingBox:", 14))
597 if (saw_bounding_box
)
598 fputs("ERROR: Duplicate %%BoundingBox: comment seen!\n", stderr
);
599 else if (strstr(line
+ 14, "(atend)"))
602 * Do nothing for now but use the default imageable area...
605 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
606 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
607 doc
->bounding_box
+ 3) != 4)
609 fputs("ERROR: Bad %%BoundingBox: comment seen!\n", stderr
);
611 doc
->bounding_box
[0] = (int)PageLeft
;
612 doc
->bounding_box
[1] = (int)PageBottom
;
613 doc
->bounding_box
[2] = (int)PageRight
;
614 doc
->bounding_box
[3] = (int)PageTop
;
617 saw_bounding_box
= 1;
619 else if (!strncmp(line
, "%%For:", 6))
622 printf("%s\n", line
);
624 else if (!strncmp(line
, "%%Title:", 8))
627 printf("%s\n", line
);
629 else if (!strncmp(line
, "%cupsRotation:", 14))
632 * Reset orientation of document?
635 int orient
= (atoi(line
+ 14) / 90) & 3;
637 if (orient
!= Orientation
)
640 * Yes, update things so that the pages come out right...
643 Orientation
= (4 - Orientation
+ orient
) & 3;
645 Orientation
= orient
;
648 else if (!strcmp(line
, "%%EndComments"))
650 linelen
= cupsFileGetLine(fp
, line
, linesize
);
653 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
654 printf("%s\n", line
);
656 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
660 if (!saw_bounding_box
)
661 fputs("ERROR: No %%BoundingBox: comment in header!\n", stderr
);
664 fputs("ERROR: No %%Pages: comment in header!\n", stderr
);
667 printf("%%%%For: %s\n", doc
->user
);
670 printf("%%%%Title: %s\n", doc
->title
);
672 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
675 * Tell the document processor the copy and duplex options
676 * that are required...
679 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
680 doc
->collate
? " collate" : "",
681 Duplex
? " duplex" : "");
684 * Apple uses RBI comments for various non-PPD options...
687 printf("%%RBINumCopies: %d\n", doc
->copies
);
692 * Tell the document processor the duplex option that is required...
696 puts("%%Requirements: duplex");
699 * Apple uses RBI comments for various non-PPD options...
702 puts("%RBINumCopies: 1");
705 puts("%%Pages: (atend)");
706 puts("%%BoundingBox: (atend)");
707 puts("%%EndComments");
714 * 'copy_dsc()' - Copy a DSC-conforming document...
716 * This function expects "line" to be filled with the %!PS-Adobe comment line.
720 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
721 pstops_doc_t
*doc
, /* I - Document info */
722 ppd_file_t
*ppd
, /* I - PPD file */
723 char *line
, /* I - Line buffer */
724 size_t linelen
, /* I - Length of initial line */
725 size_t linesize
) /* I - Size of line buffer */
727 int number
; /* Page number */
728 pstops_page_t
*pageinfo
; /* Page information */
732 * Make sure we use ESPshowpage for EPS files...
735 if (strstr(line
, "EPSF"))
737 doc
->use_ESPshowpage
= 1;
742 * Start sending the document with any commands needed...
745 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
746 linelen
= copy_comments(fp
, doc
, line
, linelen
, linesize
);
749 * Now find the prolog section, if any...
752 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
753 linelen
= copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
756 * Then the document setup section...
759 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
760 linelen
= copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
763 * Copy until we see %%Page:...
766 while (strncmp(line
, "%%Page:", 7) && strncmp(line
, "%%Trailer", 9))
768 fwrite(line
, 1, linelen
, stdout
);
770 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
775 * Then process pages until we have no more...
780 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
781 while (!strncmp(line
, "%%Page:", 7))
785 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
787 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
788 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
792 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
793 linelen
= skip_page(fp
, line
, linelen
, linesize
);
798 * Finish up the last page(s)...
801 if (number
&& is_not_last_page(number
) && cupsArrayLast(doc
->pages
))
803 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
805 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
806 doc_puts(doc
, "showpage\n");
807 end_nup(doc
, doc
->number_up
);
809 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
812 if (doc
->slow_duplex
&& (doc
->page
& 1))
815 * Make sure we have an even number of pages...
818 pageinfo
= add_page(doc
, "(filler)");
820 if (!doc
->slow_order
)
822 if (!ppd
|| !ppd
->num_filters
)
823 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
824 doc
->slow_collate
? 1 : doc
->copies
);
826 printf("%%%%Page: (filler) %d\n", doc
->page
);
829 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
830 doc_puts(doc
, "showpage\n");
831 end_nup(doc
, doc
->number_up
);
833 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
837 * Make additional copies as necessary...
840 number
= doc
->slow_order
? 0 : doc
->page
;
844 int copy
; /* Current copy */
848 * Reopen the temporary file for reading...
851 cupsFileClose(doc
->temp
);
853 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
859 for (copy
= !doc
->slow_order
; copy
< doc
->copies
; copy
++)
861 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
862 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
868 if (!ppd
|| !ppd
->num_filters
)
869 fprintf(stderr
, "PAGE: %d 1\n", number
);
871 if (doc
->number_up
> 1)
873 printf("%%%%Page: (%d) %d\n", number
, number
);
874 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
875 PageLeft
, PageBottom
, PageRight
, PageTop
);
879 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
880 printf("%%%%PageBoundingBox: %d %d %d %d\n",
881 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
882 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
885 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
887 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
888 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
894 * Restore the old showpage operator as needed...
897 if (doc
->use_ESPshowpage
)
898 puts("userdict/showpage/ESPshowpage load put\n");
901 * Write/copy the trailer...
904 linelen
= copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
909 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC...
911 * This function expects "line" to be filled with the %! comment line.
915 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
916 pstops_doc_t
*doc
, /* I - Document info */
917 ppd_file_t
*ppd
, /* I - PPD file */
918 char *line
, /* I - Line buffer */
919 size_t linelen
, /* I - Length of initial line */
920 size_t linesize
) /* I - Size of line buffer */
922 int copy
; /* Current copy */
923 char buffer
[8192]; /* Copy buffer */
924 int bytes
; /* Number of bytes copied */
928 * First let the user know that they are attempting to print a file
929 * that may not print correctly...
932 fputs("WARNING: This document does not conform to the Adobe Document "
933 "Structuring Conventions and may not print correctly!\n", stderr
);
936 * Then write a standard DSC comment section...
939 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
942 if (doc
->slow_collate
&& doc
->copies
> 1)
943 printf("%%%%Pages: %d\n", doc
->copies
);
947 printf("%%%%For: %s\n", doc
->user
);
948 printf("%%%%Title: %s\n", doc
->title
);
950 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
953 * Tell the document processor the copy and duplex options
954 * that are required...
957 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
958 doc
->collate
? " collate" : "",
959 Duplex
? " duplex" : "");
962 * Apple uses RBI comments for various non-PPD options...
965 printf("%%RBINumCopies: %d\n", doc
->copies
);
970 * Tell the document processor the duplex option that is required...
974 puts("%%Requirements: duplex");
977 * Apple uses RBI comments for various non-PPD options...
980 puts("%RBINumCopies: 1");
983 puts("%%EndComments");
989 puts("%%BeginProlog");
996 * Then the setup section...
999 puts("%%BeginSetup");
1006 * Finally, embed a copy of the file inside a %%Page...
1009 if (!ppd
|| !ppd
->num_filters
)
1010 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
1012 puts("%%Page: 1 1");
1013 puts("%%BeginPageSetup");
1014 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1015 puts("%%EndPageSetup");
1016 puts("%%BeginDocument: nondsc");
1018 fwrite(line
, linelen
, 1, stdout
);
1021 cupsFileWrite(doc
->temp
, line
, linelen
);
1023 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1025 fwrite(buffer
, 1, bytes
, stdout
);
1028 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1031 puts("%%EndDocument");
1033 if (doc
->use_ESPshowpage
)
1035 WriteLabels(Orientation
);
1036 puts("ESPshowpage");
1042 * Reopen the temporary file for reading...
1045 cupsFileClose(doc
->temp
);
1047 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1050 * Make the additional copies as needed...
1053 for (copy
= 1; copy
< doc
->copies
; copy
++)
1055 if (!ppd
|| !ppd
->num_filters
)
1056 fputs("PAGE: 1 1\n", stderr
);
1058 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1059 puts("%%BeginPageSetup");
1060 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1061 puts("%%EndPageSetup");
1062 puts("%%BeginDocument: nondsc");
1064 copy_bytes(doc
->temp
, 0, 0);
1066 puts("%%EndDocument");
1068 if (doc
->use_ESPshowpage
)
1070 WriteLabels(Orientation
);
1071 puts("ESPshowpage");
1077 * Restore the old showpage operator as needed...
1080 if (doc
->use_ESPshowpage
)
1081 puts("userdict/showpage/ESPshowpage load put\n");
1086 * 'copy_page()' - Copy a page description...
1088 * This function expects "line" to be filled with a %%Page comment line.
1089 * On return, "line" will contain the next line in the file, if any.
1092 static size_t /* O - Length of next line */
1093 copy_page(cups_file_t
*fp
, /* I - File to read from */
1094 pstops_doc_t
*doc
, /* I - Document info */
1095 ppd_file_t
*ppd
, /* I - PPD file */
1096 int number
, /* I - Current page number */
1097 char *line
, /* I - Line buffer */
1098 size_t linelen
, /* I - Length of initial line */
1099 size_t linesize
) /* I - Size of line buffer */
1101 char label
[256], /* Page label string */
1102 *ptr
; /* Pointer into line */
1103 int level
; /* Embedded document level */
1104 pstops_page_t
*pageinfo
; /* Page information */
1105 int first_page
; /* First page on N-up output? */
1106 int bounding_box
[4]; /* PageBoundingBox */
1110 * Get the page label for this page...
1113 first_page
= is_first_page(number
);
1115 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1117 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1121 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1123 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1128 * Create or update the current output page...
1132 pageinfo
= add_page(doc
, label
);
1134 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1137 * Handle first page override...
1140 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1145 * First page/sheet gets AP_FIRSTPAGE_* options...
1148 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1149 pageinfo
->num_options
,
1150 &(pageinfo
->options
));
1151 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->ap_manual_feed
,
1152 pageinfo
->num_options
,
1153 &(pageinfo
->options
));
1155 else if (doc
->page
== (Duplex
+ 2))
1158 * Second page/sheet gets default options...
1161 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1162 pageinfo
->num_options
,
1163 &(pageinfo
->options
));
1164 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->manual_feed
,
1165 pageinfo
->num_options
,
1166 &(pageinfo
->options
));
1171 * Scan comments until we see something other than %%Page*: or
1175 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1177 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1179 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1182 * %%PageBoundingBox: llx lly urx ury
1185 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1186 bounding_box
+ 1, bounding_box
+ 2,
1187 bounding_box
+ 3) != 4)
1189 fputs("ERROR: Bad %%PageBoundingBox: comment in file!\n", stderr
);
1190 memcpy(bounding_box
, doc
->bounding_box
,
1191 sizeof(bounding_box
));
1195 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1196 !strncmp(line
, "%%PageMedia:", 12) ||
1197 !strncmp(line
, "%%PageOrientation:", 18) ||
1198 !strncmp(line
, "%%PageProcessColors:", 20) ||
1199 !strncmp(line
, "%%PageRequirements:", 18) ||
1200 !strncmp(line
, "%%PageResources:", 16))
1207 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1210 * %%PageCustomColors: ...
1213 else if (!strncmp(line
, "%%PageMedia:", 12))
1219 else if (!strncmp(line
, "%%PageOrientation:", 18))
1222 * %%PageOrientation: ...
1225 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1228 * %%PageProcessColors: ...
1231 else if (!strncmp(line
, "%%PageRequirements:", 18))
1234 * %%PageRequirements: ...
1237 else if (!strncmp(line
, "%%PageResources:", 16))
1240 * %%PageResources: ...
1243 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1246 * %%IncludeFeature: *MainKeyword OptionKeyword
1249 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1250 pageinfo
->num_options
= include_feature(ppd
, line
,
1251 pageinfo
->num_options
,
1252 &(pageinfo
->options
));
1254 else if (strncmp(line
, "%%Include", 9))
1258 if (doc
->number_up
== 1)
1261 * Update the document's composite and page bounding box...
1264 memcpy(pageinfo
->bounding_box
, bounding_box
,
1265 sizeof(pageinfo
->bounding_box
));
1267 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1268 doc
->new_bounding_box
[0] = bounding_box
[0];
1269 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1270 doc
->new_bounding_box
[1] = bounding_box
[1];
1271 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1272 doc
->new_bounding_box
[2] = bounding_box
[2];
1273 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1274 doc
->new_bounding_box
[3] = bounding_box
[3];
1278 * Output the page header as needed...
1281 if (!doc
->slow_order
&& first_page
)
1283 if (!ppd
|| !ppd
->num_filters
)
1284 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1285 doc
->slow_collate
? 1 : doc
->copies
);
1287 if (doc
->number_up
> 1)
1289 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1290 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1291 PageLeft
, PageBottom
, PageRight
, PageTop
);
1295 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1296 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1297 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1298 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1303 * Copy any page setup commands...
1308 doc_puts(doc
, "%%BeginPageSetup\n");
1310 if (pageinfo
->num_options
> 0)
1312 int i
; /* Looping var */
1313 ppd_option_t
*option
; /* PPD option */
1314 int min_order
; /* Minimum OrderDependency value */
1315 char *doc_setup
, /* DocumentSetup commands to send */
1316 *any_setup
; /* AnySetup commands to send */
1320 * Yes, figure out the minimum OrderDependency value...
1323 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1324 min_order
= option
->order
;
1328 for (i
= 0; i
< pageinfo
->num_options
; i
++)
1329 if ((option
= ppdFindOption(ppd
, pageinfo
->options
[i
].name
)) != NULL
&&
1330 option
->order
< min_order
)
1331 min_order
= option
->order
;
1334 * Mark and extract them...
1337 cupsMarkOptions(ppd
, pageinfo
->num_options
, pageinfo
->options
);
1339 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
1340 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
1343 * Then send them out...
1347 doc_puts(doc
, doc_setup
);
1350 doc_puts(doc
, any_setup
);
1353 * Free the command strings...
1365 * Prep for the start of the page description...
1368 start_nup(doc
, number
, 1, bounding_box
);
1371 * Copy page setup commands as needed...
1374 if (!strncmp(line
, "%%BeginPageSetup", 16))
1376 int feature
= 0; /* In a Begin/EndFeature block? */
1379 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1381 if (!strncmp(line
, "%%EndPageSetup", 14))
1383 else if (!strncmp(line
, "%%BeginFeature:", 15))
1387 if (doc
->number_up
> 1 || doc
->fitplot
)
1390 else if (!strncmp(line
, "%%EndFeature:", 13))
1394 if (doc
->number_up
> 1 || doc
->fitplot
)
1397 else if (!strncmp(line
, "%%Include", 9))
1400 if (!feature
|| (doc
->number_up
== 1 && !doc
->fitplot
))
1401 doc_write(doc
, line
, linelen
);
1405 * Skip %%EndPageSetup...
1409 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1413 * Finish the PageSetup section as needed...
1417 doc_puts(doc
, "%%EndPageSetup\n");
1420 * Read the rest of the page description...
1428 (!strncmp(line
, "%%Page:", 7) ||
1429 !strncmp(line
, "%%Trailer", 9) ||
1430 !strncmp(line
, "%%EOF", 5)))
1432 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1433 !strncmp(line
, "%ADO_BeginApplication", 21))
1435 doc_write(doc
, line
, linelen
);
1439 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1440 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1442 doc_write(doc
, line
, linelen
);
1446 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1447 (!strncmp(line
, "%%BeginData:", 12) &&
1448 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1451 * Copy binary data...
1454 int bytes
; /* Bytes of data */
1457 doc_write(doc
, line
, linelen
);
1459 bytes
= atoi(strchr(line
, ':') + 1);
1463 if (bytes
> linesize
)
1464 linelen
= cupsFileRead(fp
, line
, linesize
);
1466 linelen
= cupsFileRead(fp
, line
, bytes
);
1471 perror("ERROR: Early end-of-file while reading binary data");
1475 doc_write(doc
, line
, linelen
);
1481 doc_write(doc
, line
, linelen
);
1483 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1486 * Finish up this page and return...
1489 end_nup(doc
, number
);
1491 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1498 * 'copy_prolog()' - Copy the document prolog section...
1500 * This function expects "line" to be filled with a %%BeginProlog comment line.
1501 * On return, "line" will contain the next line in the file, if any.
1504 static size_t /* O - Length of next line */
1505 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1506 pstops_doc_t
*doc
, /* I - Document info */
1507 ppd_file_t
*ppd
, /* I - PPD file */
1508 char *line
, /* I - Line buffer */
1509 size_t linelen
, /* I - Length of initial line */
1510 size_t linesize
) /* I - Size of line buffer */
1512 while (strncmp(line
, "%%BeginProlog", 13))
1514 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1517 fwrite(line
, 1, linelen
, stdout
);
1519 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1523 puts("%%BeginProlog");
1525 do_prolog(doc
, ppd
);
1527 if (!strncmp(line
, "%%BeginProlog", 13))
1529 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1531 if (!strncmp(line
, "%%EndProlog", 11) ||
1532 !strncmp(line
, "%%BeginSetup", 12) ||
1533 !strncmp(line
, "%%Page:", 7))
1536 fwrite(line
, 1, linelen
, stdout
);
1539 if (!strncmp(line
, "%%EndProlog", 11))
1540 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1542 fputs("ERROR: Missing %%EndProlog!\n", stderr
);
1545 puts("%%EndProlog");
1552 * 'copy_setup()' - Copy the document setup section...
1554 * This function expects "line" to be filled with a %%BeginSetup comment line.
1555 * On return, "line" will contain the next line in the file, if any.
1558 static size_t /* O - Length of next line */
1559 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1560 pstops_doc_t
*doc
, /* I - Document info */
1561 ppd_file_t
*ppd
, /* I - PPD file */
1562 char *line
, /* I - Line buffer */
1563 size_t linelen
, /* I - Length of initial line */
1564 size_t linesize
) /* I - Size of line buffer */
1566 while (strncmp(line
, "%%BeginSetup", 12))
1568 if (!strncmp(line
, "%%Page:", 7))
1571 fwrite(line
, 1, linelen
, stdout
);
1573 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1577 if (!strncmp(line
, "%%BeginSetup", 12))
1579 while (strncmp(line
, "%%EndSetup", 10))
1581 if (!strncmp(line
, "%%Page:", 7))
1583 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1586 * %%IncludeFeature: *MainKeyword OptionKeyword
1589 if (doc
->number_up
== 1 && !doc
->fitplot
)
1590 doc
->num_options
= include_feature(ppd
, line
, doc
->num_options
,
1594 fwrite(line
, 1, linelen
, stdout
);
1596 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1600 if (!strncmp(line
, "%%EndSetup", 10))
1601 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1603 fputs("ERROR: Missing %%EndSetup!\n", stderr
);
1606 puts("%%BeginSetup");
1617 * 'copy_trailer()' - Copy the document trailer...
1619 * This function expects "line" to be filled with a %%Trailer comment line.
1620 * On return, "line" will contain the next line in the file, if any.
1623 static size_t /* O - Length of next line */
1624 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1625 pstops_doc_t
*doc
, /* I - Document info */
1626 ppd_file_t
*ppd
, /* I - PPD file */
1627 int number
, /* I - Number of pages */
1628 char *line
, /* I - Line buffer */
1629 size_t linelen
, /* I - Length of initial line */
1630 size_t linesize
) /* I - Size of line buffer */
1633 * Write the trailer comments...
1640 if (!strncmp(line
, "%%EOF", 5))
1642 else if (strncmp(line
, "%%Trailer", 9) &&
1643 strncmp(line
, "%%Pages:", 8) &&
1644 strncmp(line
, "%%BoundingBox:", 14))
1645 fwrite(line
, 1, linelen
, stdout
);
1647 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1650 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1652 printf("%%%%Pages: %d\n", number
);
1653 if (doc
->number_up
> 1 || doc
->fitplot
)
1654 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1655 PageLeft
, PageBottom
, PageRight
, PageTop
);
1657 printf("%%%%BoundingBox: %d %d %d %d\n",
1658 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1659 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1666 * 'do_prolog()' - Send the necessary document prolog commands...
1670 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1671 ppd_file_t
*ppd
) /* I - PPD file */
1674 * Send the document prolog commands...
1677 if (ppd
&& ppd
->patches
)
1679 puts("%%BeginFeature: *JobPatchFile 1");
1681 puts("%%EndFeature");
1684 ppdEmit(ppd
, stdout
, PPD_ORDER_PROLOG
);
1687 * Define ESPshowpage here so that applications that define their
1688 * own procedure to do a showpage pick it up...
1691 if (doc
->use_ESPshowpage
)
1692 puts("userdict/ESPshowpage/showpage load put\n"
1693 "userdict/showpage{}put");
1699 * 'do_setup()' - Send the necessary document setup commands...
1703 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1704 ppd_file_t
*ppd
) /* I - PPD file */
1707 * Disable CTRL-D so that embedded files don't cause printing
1711 puts("% Disable CTRL-D as an end-of-file marker...");
1712 puts("userdict dup(\\004)cvn{}put (\\004\\004)cvn{}put");
1715 * Mark any options from %%IncludeFeature: comments...
1718 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
1721 * Send all the printer-specific setup commands...
1724 ppdEmit(ppd
, stdout
, PPD_ORDER_DOCUMENT
);
1725 ppdEmit(ppd
, stdout
, PPD_ORDER_ANY
);
1728 * Set the number of copies for the job...
1731 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1733 printf("%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
1734 printf("%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
1735 "{1 dict begin/NumCopies exch def currentdict end setpagedevice}\n"
1736 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
1737 puts("%RBIEndNonPPDFeature");
1741 * If we are doing N-up printing, disable setpagedevice...
1744 if (doc
->number_up
> 1)
1745 puts("userdict/setpagedevice{pop}bind put");
1748 * Changes to the transfer function must be made AFTER any
1749 * setpagedevice code...
1752 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
1753 printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
1754 "ifelse %.3f mul } bind settransfer\n", doc
->gamma
,
1758 * Make sure we have rectclip and rectstroke procedures of some sort...
1764 * Write the page and label prologs...
1767 if (doc
->number_up
== 2 || doc
->number_up
== 6)
1770 * For 2- and 6-up output, rotate the labels to match the orientation
1774 if (Orientation
& 1)
1775 WriteLabelProlog(doc
->page_label
, PageBottom
,
1776 PageWidth
- PageLength
+ PageTop
, PageLength
);
1778 WriteLabelProlog(doc
->page_label
, PageLeft
, PageRight
, PageLength
);
1781 WriteLabelProlog(doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
1786 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
1788 * This function should be used for all page-level output that is affected
1789 * by ordering, collation, etc.
1793 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
1794 const char *format
, /* I - Printf-style format string */
1795 ...) /* I - Additional arguments as needed */
1797 va_list ap
; /* Pointer to arguments */
1798 char buffer
[1024]; /* Output buffer */
1799 size_t bytes
; /* Number of bytes to write */
1802 va_start(ap
, format
);
1803 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
1806 if (bytes
> sizeof(buffer
))
1809 "ERROR: doc_printf overflow (%d bytes) detected, aborting!\n",
1814 doc_write(doc
, buffer
, bytes
);
1819 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
1821 * This function should be used for all page-level output that is affected
1822 * by ordering, collation, etc.
1826 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
1827 const char *s
) /* I - String to send */
1829 doc_write(doc
, s
, strlen(s
));
1834 * 'doc_write()' - Send data to stdout and/or the temp file.
1838 doc_write(pstops_doc_t
*doc
, /* I - Document information */
1839 const char *s
, /* I - Data to send */
1840 size_t len
) /* I - Number of bytes to send */
1842 if (!doc
->slow_order
)
1843 fwrite(s
, 1, len
, stdout
);
1846 cupsFileWrite(doc
->temp
, s
, len
);
1851 * 'end_nup()' - End processing for N-up printing...
1855 end_nup(pstops_doc_t
*doc
, /* I - Document information */
1856 int number
) /* I - Page number */
1858 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
1859 puts("userdict/ESPsave get restore");
1861 switch (doc
->number_up
)
1864 if (doc
->use_ESPshowpage
)
1866 WriteLabels(Orientation
);
1867 puts("ESPshowpage");
1873 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1875 if (Orientation
& 1)
1878 * Rotate the labels back to portrait...
1881 WriteLabels(Orientation
- 1);
1883 else if (Orientation
== 0)
1886 * Rotate the labels to landscape...
1889 WriteLabels(doc
->normal_landscape
? 1 : 3);
1894 * Rotate the labels to landscape...
1897 WriteLabels(doc
->normal_landscape
? 3 : 1);
1900 puts("ESPshowpage");
1905 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1907 WriteLabels(Orientation
);
1908 puts("ESPshowpage");
1918 * 'include_feature()' - Include a printer option/feature command.
1921 static int /* O - New number of options */
1923 ppd_file_t
*ppd
, /* I - PPD file */
1924 const char *line
, /* I - DSC line */
1925 int num_options
, /* I - Number of options */
1926 cups_option_t
**options
) /* IO - Options */
1928 char name
[255], /* Option name */
1929 value
[255]; /* Option value */
1930 ppd_option_t
*option
; /* Option in file */
1931 ppd_choice_t
*choice
; /* Choice */
1935 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
1938 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
1940 fputs("ERROR: Bad %%IncludeFeature: comment!\n", stderr
);
1941 return (num_options
);
1945 * Find the option and choice...
1948 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
1950 fprintf(stderr
, "WARNING: Unknown option \"%s\"!\n", name
+ 1);
1951 return (num_options
);
1954 if (option
->section
== PPD_ORDER_EXIT
||
1955 option
->section
== PPD_ORDER_JCL
)
1957 fprintf(stderr
, "WARNING: Option \"%s\" cannot be included via "
1958 "IncludeFeature!\n", name
+ 1);
1959 return (num_options
);
1962 if ((choice
= ppdFindChoice(option
, value
)) == NULL
)
1964 fprintf(stderr
, "WARNING: Unknown choice \"%s\" for option \"%s\"!\n",
1966 return (num_options
);
1970 * Add the option to the option array and return...
1973 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
1978 * 'parse_text()' - Parse a text value in a comment...
1980 * This function parses a DSC text value as defined on page 36 of the
1981 * DSC specification. Text values are either surrounded by parenthesis
1982 * or whitespace-delimited.
1984 * The value returned is the literal characters for the entire text
1985 * string, including any parenthesis and escape characters.
1988 static char * /* O - Value or NULL on error */
1989 parse_text(const char *start
, /* I - Start of text value */
1990 char **end
, /* O - End of text value */
1991 char *buffer
, /* I - Buffer */
1992 size_t bufsize
) /* I - Size of buffer */
1994 char *bufptr
, /* Pointer in buffer */
1995 *bufend
; /* End of buffer */
1996 int level
; /* Parenthesis level */
2000 * Skip leading whitespace...
2003 while (isspace(*start
& 255))
2007 * Then copy the value...
2012 bufend
= buffer
+ bufsize
- 1;
2014 while (bufptr
< bufend
)
2016 if (isspace(*start
& 255) && !level
)
2023 else if (*start
== ')')
2033 else if (*start
== '\\')
2036 * Copy escaped character...
2039 int i
; /* Looping var */
2043 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
2044 *bufptr
++ = start
[i
], i
++);
2053 * Return the value and new pointer into the line...
2057 *end
= (char *)start
;
2059 if (bufptr
== bufend
)
2067 * 'set_pstops_options()' - Set pstops options...
2072 pstops_doc_t
*doc
, /* I - Document information */
2073 ppd_file_t
*ppd
, /* I - PPD file */
2074 char *argv
[], /* I - Command-line arguments */
2075 int num_options
, /* I - Number of options */
2076 cups_option_t
*options
) /* I - Options */
2078 const char *val
; /* Option value */
2079 int intval
; /* Integer option value */
2080 ppd_attr_t
*attr
; /* PPD attribute */
2081 ppd_option_t
*option
; /* PPD option */
2082 ppd_choice_t
*choice
; /* PPD choice */
2086 * Initialize document information structure...
2089 memset(doc
, 0, sizeof(pstops_doc_t
));
2091 doc
->job_id
= atoi(argv
[1]);
2092 doc
->user
= argv
[2];
2093 doc
->title
= argv
[3];
2094 doc
->copies
= atoi(argv
[4]);
2096 if (ppd
&& ppd
->landscape
> 0)
2097 doc
->normal_landscape
= 1;
2099 doc
->bounding_box
[0] = (int)PageLeft
;
2100 doc
->bounding_box
[1] = (int)PageBottom
;
2101 doc
->bounding_box
[2] = (int)PageRight
;
2102 doc
->bounding_box
[3] = (int)PageTop
;
2104 doc
->new_bounding_box
[0] = INT_MAX
;
2105 doc
->new_bounding_box
[1] = INT_MAX
;
2106 doc
->new_bounding_box
[2] = INT_MIN
;
2107 doc
->new_bounding_box
[3] = INT_MIN
;
2110 * AP_FIRSTPAGE_InputSlot
2113 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2117 * AP_FIRSTPAGE_ManualFeed
2120 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2127 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2130 * Get brightness value from 10 to 1000.
2135 if (intval
< 10 || intval
> 1000)
2137 fprintf(stderr
, "ERROR: Unsupported brightness value %s, using "
2138 "brightness=100!\n", val
);
2139 doc
->brightness
= 1.0f
;
2142 doc
->brightness
= intval
* 0.01f
;
2145 doc
->brightness
= 1.0f
;
2148 * collate, multiple-document-handling
2151 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2154 * This IPP attribute is unnecessarily complicated...
2156 * single-document, separate-documents-collated-copies, and
2157 * single-document-new-sheet all require collated copies.
2159 * separate-documents-uncollated-copies allows for uncollated copies.
2162 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2165 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2166 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2167 !strcasecmp(val
, "yes")))
2174 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2175 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2176 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2185 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
2186 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2187 !strcasecmp(val
, "yes")))
2194 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2197 * Get gamma value from 1 to 10000...
2202 if (intval
< 1 || intval
> 10000)
2204 fprintf(stderr
, "ERROR: Unsupported gamma value %s, using "
2205 "gamma=1000!\n", val
);
2209 doc
->gamma
= intval
* 0.001f
;
2218 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2219 doc
->input_slot
= choice
->choice
;
2225 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2226 doc
->manual_feed
= choice
->choice
;
2228 if ((val
= cupsGetOption("mirror", num_options
, options
)) != NULL
&&
2229 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2230 !strcasecmp(val
, "yes")))
2237 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2239 switch (intval
= atoi(val
))
2247 doc
->number_up
= intval
;
2251 "ERROR: Unsupported number-up value %d, using number-up=1!\n",
2264 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2266 if (!strcasecmp(val
, "lrtb"))
2267 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2268 else if (!strcasecmp(val
, "lrbt"))
2269 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2270 else if (!strcasecmp(val
, "rltb"))
2271 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2272 else if (!strcasecmp(val
, "rlbt"))
2273 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2274 else if (!strcasecmp(val
, "tblr"))
2275 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2276 else if (!strcasecmp(val
, "tbrl"))
2277 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2278 else if (!strcasecmp(val
, "btlr"))
2279 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2280 else if (!strcasecmp(val
, "btrl"))
2281 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2284 fprintf(stderr
, "ERROR: Unsupported number-up-layout value %s, using "
2285 "number-up-layout=lrtb!\n", val
);
2286 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2290 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2296 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2298 if (!strcasecmp(val
, "Reverse"))
2299 doc
->output_order
= 1;
2304 * Figure out the right default output order from the PPD file...
2307 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2308 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2310 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2311 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2313 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2320 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2322 if (!strcasecmp(val
, "none"))
2323 doc
->page_border
= PSTOPS_BORDERNONE
;
2324 else if (!strcasecmp(val
, "single"))
2325 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2326 else if (!strcasecmp(val
, "single-thick"))
2327 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2328 else if (!strcasecmp(val
, "double"))
2329 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2330 else if (!strcasecmp(val
, "double-thick"))
2331 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2334 fprintf(stderr
, "ERROR: Unsupported page-border value %s, using "
2335 "page-border=none!\n", val
);
2336 doc
->page_border
= PSTOPS_BORDERNONE
;
2340 doc
->page_border
= PSTOPS_BORDERNONE
;
2346 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2352 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2358 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2361 * Now figure out if we have to force collated copies, etc.
2364 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2367 * Force collated copies when printing a duplexed document to
2368 * a non-PS printer that doesn't do hardware copy generation.
2369 * Otherwise the copies will end up on the front/back side of
2377 * See if we have to filter the fast or slow way...
2380 if (doc
->collate
&& doc
->copies
> 1)
2383 * See if we need to manually collate the pages...
2386 doc
->slow_collate
= 1;
2388 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2389 !strcasecmp(choice
->choice
, "True"))
2392 * Hardware collate option is selected, see if the option is
2393 * conflicting - if not, collate in hardware. Otherwise,
2394 * turn the hardware collate option off...
2397 if ((option
= ppdFindOption(ppd
, "Option")) != NULL
&&
2398 !option
->conflicted
)
2399 doc
->slow_collate
= 0;
2401 ppdMarkOption(ppd
, "Collate", "False");
2405 doc
->slow_collate
= 0;
2407 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2408 doc
->slow_order
= 1;
2410 doc
->slow_order
= 0;
2412 if ((doc
->slow_collate
|| doc
->slow_order
) && Duplex
)
2413 doc
->slow_duplex
= 1;
2415 doc
->slow_duplex
= 0;
2418 * Create a temporary file for page data if we need to filter slowly...
2421 if (doc
->slow_order
|| doc
->slow_collate
)
2423 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2424 sizeof(doc
->tempfile
))) == NULL
)
2426 fprintf(stderr
, "ERROR: Unable to create temporary file: %s\n",
2433 * Figure out if we should use ESPshowpage or not...
2436 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2440 * Yes, use ESPshowpage...
2443 doc
->use_ESPshowpage
= 1;
2446 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2447 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2452 * 'skip_page()' - Skip past a page that won't be printed...
2455 static size_t /* O - Length of next line */
2456 skip_page(cups_file_t
*fp
, /* I - File to read from */
2457 char *line
, /* I - Line buffer */
2458 size_t linelen
, /* I - Length of initial line */
2459 size_t linesize
) /* I - Size of line buffer */
2461 int level
; /* Embedded document level */
2466 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2469 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer", 9)))
2471 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2472 !strncmp(line
, "%ADO_BeginApplication", 21))
2474 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2475 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2477 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2478 (!strncmp(line
, "%%BeginData:", 12) &&
2479 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2482 * Skip binary data...
2485 int bytes
; /* Bytes of data */
2488 bytes
= atoi(strchr(line
, ':') + 1);
2492 if (bytes
> linesize
)
2493 linelen
= cupsFileRead(fp
, line
, linesize
);
2495 linelen
= cupsFileRead(fp
, line
, bytes
);
2500 perror("ERROR: Early end-of-file while reading binary data");
2514 * 'start_nup()' - Start processing for N-up printing...
2518 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2519 int number
, /* I - Page number */
2520 int show_border
, /* I - Show the border? */
2521 const int *bounding_box
) /* I - BoundingBox value */
2523 int pos
; /* Position on page */
2524 int x
, y
; /* Relative position of subpage */
2525 float w
, l
, /* Width and length of subpage */
2526 tx
, ty
; /* Translation values for subpage */
2527 float pagew
, /* Printable width of page */
2528 pagel
; /* Printable height of page */
2529 int bboxw
, /* BoundingBox width */
2530 bboxl
; /* BoundingBox height */
2533 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
2534 doc_puts(doc
, "userdict/ESPsave save put\n");
2537 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
2539 pos
= (number
- 1) % doc
->number_up
;
2540 pagew
= PageRight
- PageLeft
;
2541 pagel
= PageTop
- PageBottom
;
2545 bboxw
= bounding_box
[2] - bounding_box
[0];
2546 bboxl
= bounding_box
[3] - bounding_box
[1];
2554 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2555 fprintf(stderr
, "DEBUG: bboxw = %d, bboxl = %d\n", bboxw
, bboxl
);
2556 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2557 PageLeft
, PageRight
);
2558 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2559 PageTop
, PageBottom
);
2560 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2561 PageWidth
, PageLength
);
2563 switch (Orientation
)
2565 case 1 : /* Landscape */
2566 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2568 case 2 : /* Reverse Portrait */
2569 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2572 case 3 : /* Reverse Landscape */
2573 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2577 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2578 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2579 else if (doc
->number_up
> 1 || doc
->fitplot
)
2580 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2582 switch (doc
->number_up
)
2588 l
= w
* bboxl
/ bboxw
;
2593 w
= l
* bboxw
/ bboxl
;
2596 tx
= 0.5 * (pagew
- w
);
2597 ty
= 0.5 * (pagel
- l
);
2599 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2600 w
/ bboxw
, l
/ bboxl
);
2610 if (Orientation
& 1)
2614 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2618 l
= w
* bboxl
/ bboxw
;
2620 if (l
> (pagew
* 0.5))
2623 w
= l
* bboxw
/ bboxl
;
2626 tx
= 0.5 * (pagew
* 0.5 - l
);
2627 ty
= 0.5 * (pagel
- w
);
2629 if (doc
->normal_landscape
)
2630 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2632 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2634 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2635 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2641 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2645 w
= l
* bboxw
/ bboxl
;
2647 if (w
> (pagel
* 0.5))
2650 l
= w
* bboxl
/ bboxw
;
2653 tx
= 0.5 * (pagel
* 0.5 - w
);
2654 ty
= 0.5 * (pagew
- l
);
2656 if (doc
->normal_landscape
)
2657 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2659 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2661 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2662 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
2667 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2678 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2681 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2685 l
= w
* bboxl
/ bboxw
;
2687 if (l
> (pagel
* 0.5))
2690 w
= l
* bboxw
/ bboxl
;
2693 tx
= 0.5 * (pagew
* 0.5 - w
);
2694 ty
= 0.5 * (pagel
* 0.5 - l
);
2696 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2697 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
2698 w
/ bboxw
, l
/ bboxl
);
2702 if (Orientation
& 1)
2704 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2709 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2712 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2720 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2723 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2728 l
= w
* bboxl
/ bboxw
;
2730 if (l
> (pagew
* 0.333))
2733 w
= l
* bboxw
/ bboxl
;
2736 tx
= 0.5 * (pagel
- 2 * w
);
2737 ty
= 0.5 * (pagew
- 3 * l
);
2739 if (doc
->normal_landscape
)
2740 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
2742 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
2744 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2745 tx
+ x
* w
, ty
+ y
* l
, l
/ bboxl
, w
/ bboxw
);
2749 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2754 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2757 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2765 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2768 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2773 w
= l
* bboxw
/ bboxl
;
2775 if (w
> (pagel
* 0.333))
2778 l
= w
* bboxl
/ bboxw
;
2781 tx
= 0.5 * (pagel
- 3 * w
);
2782 ty
= 0.5 * (pagew
- 2 * l
);
2784 if (doc
->normal_landscape
)
2785 doc_printf(doc
, "%.1f 0 translate 90 rotate\n", pagew
);
2787 doc_printf(doc
, "0 %.1f translate -90 rotate\n", pagel
);
2789 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2790 tx
+ w
* x
, ty
+ l
* y
, w
/ bboxw
, l
/ bboxl
);
2796 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2807 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2810 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2814 l
= w
* bboxl
/ bboxw
;
2816 if (l
> (pagel
* 0.333))
2819 w
= l
* bboxw
/ bboxl
;
2822 tx
= 0.5 * (pagew
* 0.333 - w
);
2823 ty
= 0.5 * (pagel
* 0.333 - l
);
2825 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2826 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
2827 w
/ bboxw
, l
/ bboxl
);
2831 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2842 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2845 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2849 l
= w
* bboxl
/ bboxw
;
2851 if (l
> (pagel
* 0.25))
2854 w
= l
* bboxw
/ bboxl
;
2857 tx
= 0.5 * (pagew
* 0.25 - w
);
2858 ty
= 0.5 * (pagel
* 0.25 - l
);
2860 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2861 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
2862 w
/ bboxw
, l
/ bboxl
);
2867 * Draw borders as necessary...
2870 if (doc
->page_border
&& show_border
)
2872 int rects
; /* Number of border rectangles */
2873 float fscale
, /* Scaling value for points */
2874 margin
; /* Current margin for borders */
2877 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
2878 fscale
= PageWidth
/ w
;
2879 margin
= 2.25 * fscale
;
2882 * Set the line width and color...
2885 doc_puts(doc
, "gsave\n");
2886 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
2887 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
2891 * Draw border boxes...
2894 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
2895 if (doc
->number_up
> 1)
2896 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2897 margin
- 2.25 * fscale
,
2898 margin
- 2.25 * fscale
,
2899 bboxw
+ 4.5 * fscale
- 2 * margin
,
2900 bboxl
+ 4.5 * fscale
- 2 * margin
);
2902 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2904 PageBottom
+ margin
,
2905 PageRight
- PageLeft
- 2 * margin
,
2906 PageTop
- PageBottom
- 2 * margin
);
2909 * Restore pen settings...
2912 doc_puts(doc
, "grestore\n");
2918 * Clip the page that follows to the bounding box of the page...
2921 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
2923 doc_printf(doc
, "%d %d %d %d ESPrc\n", bounding_box
[0], bounding_box
[1],
2926 else if (doc
->number_up
> 1)
2929 * Clip the page that follows to the default page size...
2932 doc_printf(doc
, "0 0 %d %d ESPrc\n", bboxw
, bboxl
);
2938 * End of "$Id: pstops.c 5570 2006-05-22 18:31:23Z mike $".