]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/pstops.c
2 * "$Id: pstops.c 5369 2006-04-03 15:09:58Z 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...
60 #include <cups/file.h>
61 #include <cups/array.h>
68 #define PSTOPS_BORDERNONE 0 /* No border or hairline border */
69 #define PSTOPS_BORDERTHICK 1 /* Think border */
70 #define PSTOPS_BORDERSINGLE 2 /* Single-line hairline border */
71 #define PSTOPS_BORDERSINGLE2 3 /* Single-line thick border */
72 #define PSTOPS_BORDERDOUBLE 4 /* Double-line hairline border */
73 #define PSTOPS_BORDERDOUBLE2 5 /* Double-line thick border */
75 #define PSTOPS_LAYOUT_LRBT 0 /* Left to right, bottom to top */
76 #define PSTOPS_LAYOUT_LRTB 1 /* Left to right, top to bottom */
77 #define PSTOPS_LAYOUT_RLBT 2 /* Right to left, bottom to top */
78 #define PSTOPS_LAYOUT_RLTB 3 /* Right to left, top to bottom */
79 #define PSTOPS_LAYOUT_BTLR 4 /* Bottom to top, left to right */
80 #define PSTOPS_LAYOUT_TBLR 5 /* Top to bottom, left to right */
81 #define PSTOPS_LAYOUT_BTRL 6 /* Bottom to top, right to left */
82 #define PSTOPS_LAYOUT_TBRL 7 /* Top to bottom, right to left */
84 #define PSTOPS_LAYOUT_NEGATEY 1 /* The bits for the layout */
85 #define PSTOPS_LAYOUT_NEGATEX 2 /* definitions above... */
86 #define PSTOPS_LAYOUT_VERTICAL 4
93 typedef struct /**** Page information ****/
95 char *label
; /* Page label */
96 int bounding_box
[4]; /* PageBoundingBox */
97 off_t offset
; /* Offset to start of page */
98 ssize_t length
; /* Number of bytes for page */
99 int num_options
; /* Number of options for this page */
100 cups_option_t
*options
; /* Options for this page */
103 typedef struct /**** Document information ****/
105 int page
; /* Current page */
106 int bounding_box
[4]; /* BoundingBox from header */
107 int new_bounding_box
[4]; /* New composite bounding box */
108 int num_options
; /* Number of document-wide options */
109 cups_option_t
*options
; /* Document-wide options */
110 int normal_landscape
, /* Normal rotation for landscape? */
111 saw_eof
, /* Saw the %%EOF comment? */
112 slow_collate
, /* Collate copies by hand? */
113 slow_duplex
, /* Duplex pages slowly? */
114 slow_order
, /* Reverse pages slowly? */
115 use_ESPshowpage
; /* Use ESPshowpage? */
116 cups_array_t
*pages
; /* Pages in document */
117 cups_file_t
*temp
; /* Temporary file, if any */
118 char tempfile
[1024]; /* Temporary filename */
119 int job_id
; /* Job ID */
120 const char *user
, /* User name */
121 *title
; /* Job name */
122 int copies
; /* Number of copies */
123 const char *ap_input_slot
, /* AP_FIRSTPAGE_InputSlot value */
124 *ap_manual_feed
; /* AP_FIRSTPAGE_ManualFeed value */
125 float brightness
; /* brightness value */
126 int collate
, /* Collate copies? */
127 emit_jcl
, /* Emit JCL commands? */
128 fitplot
; /* Fit pages to media */
129 float gamma
; /* gamma value */
130 const char *input_slot
, /* InputSlot value */
131 *manual_feed
; /* ManualFeed value */
132 int mirror
, /* doc->mirror/mirror pages */
133 number_up
, /* Number of pages on each sheet */
134 number_up_layout
, /* doc->number_up_layout of N-up pages */
135 output_order
, /* Requested reverse output order? */
136 page_border
; /* doc->page_border around pages */
137 const char *page_label
, /* page-label option, if any */
138 *page_ranges
, /* page-ranges option, if any */
139 *page_set
; /* page-set option, if any */
144 * Convenience macros...
147 #define is_first_page(p) (doc->number_up == 1 || \
148 ((p) % doc->number_up) == 1)
149 #define is_last_page(p) (doc->number_up == 1 || \
150 ((p) % doc->number_up) == 0)
151 #define is_not_last_page(p) (doc->number_up > 1 && \
152 ((p) % doc->number_up) != 0)
159 static pstops_page_t
*add_page(pstops_doc_t
*doc
, const char *label
);
160 static int check_range(pstops_doc_t
*doc
, int page
);
161 static void copy_bytes(cups_file_t
*fp
, off_t offset
,
163 static size_t copy_comments(cups_file_t
*fp
, pstops_doc_t
*doc
,
164 char *line
, size_t linelen
,
166 static void copy_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
167 ppd_file_t
*ppd
, char *line
, size_t linelen
,
169 static void copy_non_dsc(cups_file_t
*fp
, pstops_doc_t
*doc
,
170 ppd_file_t
*ppd
, char *line
,
171 size_t linelen
, size_t linesize
);
172 static size_t copy_page(cups_file_t
*fp
, pstops_doc_t
*doc
,
173 ppd_file_t
*ppd
, int number
, char *line
,
174 size_t linelen
, size_t linesize
);
175 static size_t copy_prolog(cups_file_t
*fp
, pstops_doc_t
*doc
,
176 ppd_file_t
*ppd
, char *line
,
177 size_t linelen
, size_t linesize
);
178 static size_t copy_setup(cups_file_t
*fp
, pstops_doc_t
*doc
,
179 ppd_file_t
*ppd
, char *line
,
180 size_t linelen
, size_t linesize
);
181 static size_t copy_trailer(cups_file_t
*fp
, pstops_doc_t
*doc
,
182 ppd_file_t
*ppd
, int number
, char *line
,
183 size_t linelen
, size_t linesize
);
184 static void do_prolog(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
185 static void do_setup(pstops_doc_t
*doc
, ppd_file_t
*ppd
);
186 static void doc_printf(pstops_doc_t
*doc
, const char *format
, ...);
187 static void doc_puts(pstops_doc_t
*doc
, const char *s
);
188 static void doc_write(pstops_doc_t
*doc
, const char *s
, size_t len
);
189 static void end_nup(pstops_doc_t
*doc
, int number
);
190 static int include_feature(ppd_file_t
*ppd
, const char *line
,
192 cups_option_t
**options
);
193 static char *parse_text(const char *start
, char **end
, char *buffer
,
195 static void set_pstops_options(pstops_doc_t
*doc
, ppd_file_t
*ppd
,
196 char *argv
[], int num_options
,
197 cups_option_t
*options
);
198 static size_t skip_page(cups_file_t
*fp
, char *line
, size_t linelen
,
200 static void start_nup(pstops_doc_t
*doc
, int number
,
201 int show_border
, const int *bounding_box
);
205 * 'main()' - Main entry...
208 int /* O - Exit status */
209 main(int argc
, /* I - Number of command-line args */
210 char *argv
[]) /* I - Command-line arguments */
212 pstops_doc_t doc
; /* Document information */
213 cups_file_t
*fp
; /* Print file */
214 ppd_file_t
*ppd
; /* PPD file */
215 int num_options
; /* Number of print options */
216 cups_option_t
*options
; /* Print options */
217 char line
[8192]; /* Line buffer */
218 size_t len
; /* Length of line buffer */
222 * Make sure status messages are not buffered...
225 setbuf(stderr
, NULL
);
228 * Check command-line...
231 if (argc
< 6 || argc
> 7)
233 fputs("ERROR: pstops job-id user title copies options [file]\n", stderr
);
238 * If we have 7 arguments, print the file named on the command-line.
239 * Otherwise, send stdin instead...
243 fp
= cupsFileStdin();
247 * Try to open the print file...
250 if ((fp
= cupsFileOpen(argv
[6], "r")) == NULL
)
252 fprintf(stderr
, "ERROR: Unable to open print file \"%s\" - %s\n",
253 argv
[6], strerror(errno
));
259 * Read the first line to see if we have DSC comments...
262 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
264 fputs("ERROR: Empty print file!\n", stderr
);
269 * Process command-line options...
273 num_options
= cupsParseOptions(argv
[5], 0, &options
);
274 ppd
= SetCommonOptions(num_options
, options
, 1);
276 set_pstops_options(&doc
, ppd
, argv
, num_options
, options
);
279 * Write any "exit server" options that have been selected...
282 ppdEmit(ppd
, stdout
, PPD_ORDER_EXIT
);
285 * Write any JCL commands that are needed to print PostScript code...
289 ppdEmitJCL(ppd
, stdout
, doc
.job_id
, doc
.user
, doc
.title
);
292 * Start with a DSC header...
295 puts("%!PS-Adobe-3.0");
298 * Skip leading PJL in the document...
301 while (!strncmp(line
, "\033%-12345X", 9) || !strncmp(line
, "@PJL ", 5))
304 * Yup, we have leading PJL fun, so skip it until we hit the line
305 * with "ENTER LANGUAGE"...
308 fputs("DEBUG: Skipping PJL header...\n", stderr
);
310 while (strstr(line
, "ENTER LANGUAGE") == NULL
&& strncmp(line
, "%!", 2))
311 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
314 if (!strncmp(line
, "%!", 2))
317 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
322 * Now see if the document conforms to the Adobe Document Structuring
326 if (!strncmp(line
, "%!PS-Adobe-", 11))
329 * Yes, filter the document...
332 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
337 * No, display an error message and treat the file as if it contains
341 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
345 * Send %%EOF as needed...
352 * End the job with the appropriate JCL command or CTRL-D...
357 if (ppd
&& ppd
->jcl_end
)
358 ppdEmitJCLEnd(ppd
, stdout
);
364 * Close files and remove the temporary file if needed...
369 cupsFileClose(doc
.temp
);
370 unlink(doc
.tempfile
);
374 cupsFreeOptions(num_options
, options
);
383 * 'add_page()' - Add a page to the pages array...
386 static pstops_page_t
* /* O - New page info object */
387 add_page(pstops_doc_t
*doc
, /* I - Document information */
388 const char *label
) /* I - Page label */
390 pstops_page_t
*pageinfo
; /* New page info object */
394 doc
->pages
= cupsArrayNew(NULL
, NULL
);
398 fprintf(stderr
, "EMERG: Unable to allocate memory for pages array: %s\n",
403 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
405 fprintf(stderr
, "EMERG: Unable to allocate memory for page info: %s\n",
410 pageinfo
->label
= strdup(label
);
411 pageinfo
->offset
= cupsFileTell(doc
->temp
);
413 cupsArrayAdd(doc
->pages
, pageinfo
);
422 * 'check_range()' - Check to see if the current page is selected for
426 static int /* O - 1 if selected, 0 otherwise */
427 check_range(pstops_doc_t
*doc
, /* I - Document information */
428 int page
) /* I - Page number */
430 const char *range
; /* Pointer into range string */
431 int lower
, upper
; /* Lower and upper page numbers */
437 * See if we only print even or odd pages...
440 if (!strcasecmp(doc
->page_set
, "even") &&
441 ((page
- 1) % (doc
->number_up
<< 1)) < doc
->number_up
)
444 if (!strcasecmp(doc
->page_set
, "odd") &&
445 ((page
- 1) % (doc
->number_up
<< 1)) >= doc
->number_up
)
449 if (!doc
->page_ranges
)
450 return (1); /* No range, print all pages... */
452 for (range
= doc
->page_ranges
; *range
!= '\0';)
458 upper
= strtol(range
, (char **)&range
, 10);
462 lower
= strtol(range
, (char **)&range
, 10);
467 if (!isdigit(*range
& 255))
470 upper
= strtol(range
, (char **)&range
, 10);
476 if (page
>= lower
&& page
<= upper
)
490 * 'copy_bytes()' - Copy bytes from the input file to stdout...
494 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
495 off_t offset
, /* I - Offset to page data */
496 size_t length
) /* I - Length of page data */
498 char buffer
[8192]; /* Data buffer */
499 ssize_t nbytes
; /* Number of bytes read */
500 size_t nleft
; /* Number of bytes left/remaining */
505 if (cupsFileSeek(fp
, offset
) < 0)
507 fprintf(stderr
, "ERROR: Unable to seek to offset " CUPS_LLFMT
509 CUPS_LLCAST offset
, strerror(errno
));
513 while (nleft
> 0 || length
== 0)
515 if (nleft
> sizeof(buffer
) || length
== 0)
516 nbytes
= sizeof(buffer
);
520 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
525 fwrite(buffer
, 1, nbytes
, stdout
);
531 * 'copy_comments()' - Copy all of the comments section...
533 * This function expects "line" to be filled with a comment line.
534 * On return, "line" will contain the next line in the file, if any.
537 static size_t /* O - Length of next line */
538 copy_comments(cups_file_t
*fp
, /* I - File to read from */
539 pstops_doc_t
*doc
, /* I - Document info */
540 char *line
, /* I - Line buffer */
541 size_t linelen
, /* I - Length of initial line */
542 size_t linesize
) /* I - Size of line buffer */
544 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
545 saw_for
, /* Saw %%For: comment? */
546 saw_pages
, /* Saw %%Pages: comment? */
547 saw_title
; /* Saw %%Title: comment? */
551 * Loop until we see %%EndComments or a non-comment line...
554 saw_bounding_box
= 0;
559 while (line
[0] == '%')
562 * Strip trailing whitespace...
569 if (!isspace(line
[linelen
] & 255))
572 line
[linelen
] = '\0';
579 fprintf(stderr
, "DEBUG: %s\n", line
);
582 * Pull the headers out...
585 if (!strncmp(line
, "%%Pages:", 8))
588 fputs("ERROR: Duplicate %%Pages: comment seen!\n", stderr
);
592 else if (!strncmp(line
, "%%BoundingBox:", 14))
594 if (saw_bounding_box
)
595 fputs("ERROR: Duplicate %%BoundingBox: comment seen!\n", stderr
);
596 else if (strstr(line
+ 14, "(atend)"))
599 * Do nothing for now but use the default imageable area...
602 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
603 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
604 doc
->bounding_box
+ 3) != 4)
606 fputs("ERROR: Bad %%BoundingBox: comment seen!\n", stderr
);
608 doc
->bounding_box
[0] = (int)PageLeft
;
609 doc
->bounding_box
[1] = (int)PageBottom
;
610 doc
->bounding_box
[2] = (int)PageRight
;
611 doc
->bounding_box
[3] = (int)PageTop
;
614 saw_bounding_box
= 1;
616 else if (!strncmp(line
, "%%For:", 6))
619 printf("%s\n", line
);
621 else if (!strncmp(line
, "%%Title:", 8))
624 printf("%s\n", line
);
626 else if (!strncmp(line
, "%cupsRotation:", 14))
629 * Reset orientation of document?
632 int orient
= (atoi(line
+ 14) / 90) & 3;
634 if (orient
!= Orientation
)
637 * Yes, update things so that the pages come out right...
640 Orientation
= (4 - Orientation
+ orient
) & 3;
642 Orientation
= orient
;
645 else if (!strcmp(line
, "%%EndComments"))
647 linelen
= cupsFileGetLine(fp
, line
, linesize
);
650 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
651 printf("%s\n", line
);
653 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
657 if (!saw_bounding_box
)
658 fputs("ERROR: No %%BoundingBox: comment in header!\n", stderr
);
661 fputs("ERROR: No %%Pages: comment in header!\n", stderr
);
664 printf("%%%%For: %s\n", doc
->user
);
667 printf("%%%%Title: %s\n", doc
->title
);
669 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
672 * Tell the document processor the copy and duplex options
673 * that are required...
676 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
677 doc
->collate
? " collate" : "",
678 Duplex
? " duplex" : "");
681 * Apple uses RBI comments for various non-PPD options...
684 printf("%%RBINumCopies: %d\n", doc
->copies
);
689 * Tell the document processor the duplex option that is required...
693 puts("%%Requirements: duplex");
696 * Apple uses RBI comments for various non-PPD options...
699 puts("%RBINumCopies: 1");
702 puts("%%Pages: (atend)");
703 puts("%%BoundingBox: (atend)");
704 puts("%%EndComments");
711 * 'copy_dsc()' - Copy a DSC-conforming document...
713 * This function expects "line" to be filled with the %!PS-Adobe comment line.
717 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
718 pstops_doc_t
*doc
, /* I - Document info */
719 ppd_file_t
*ppd
, /* I - PPD file */
720 char *line
, /* I - Line buffer */
721 size_t linelen
, /* I - Length of initial line */
722 size_t linesize
) /* I - Size of line buffer */
724 int number
; /* Page number */
725 pstops_page_t
*pageinfo
; /* Page information */
729 * Make sure we use ESPshowpage for EPS files...
732 if (strstr(line
, "EPSF"))
734 doc
->use_ESPshowpage
= 1;
739 * Start sending the document with any commands needed...
742 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
743 linelen
= copy_comments(fp
, doc
, line
, linelen
, linesize
);
746 * Now find the prolog section, if any...
749 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
750 linelen
= copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
753 * Then the document setup section...
756 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
757 linelen
= copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
760 * Copy until we see %%Page:...
763 while (strncmp(line
, "%%Page:", 7) && strncmp(line
, "%%Trailer", 9))
765 fwrite(line
, 1, linelen
, stdout
);
767 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
772 * Then process pages until we have no more...
777 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
778 while (!strncmp(line
, "%%Page:", 7))
782 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
784 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
785 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
789 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
790 linelen
= skip_page(fp
, line
, linelen
, linesize
);
795 * Finish up the last page(s)...
798 if (number
&& is_not_last_page(number
))
800 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
802 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
803 doc_puts(doc
, "showpage\n");
804 end_nup(doc
, doc
->number_up
);
806 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
809 if (doc
->slow_duplex
&& (doc
->page
& 1))
812 * Make sure we have an even number of pages...
815 pageinfo
= add_page(doc
, "(filler)");
817 if (!doc
->slow_order
)
819 if (!ppd
|| !ppd
->num_filters
)
820 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
821 doc
->slow_collate
? 1 : doc
->copies
);
823 printf("%%%%Page: (filler) %d\n", doc
->page
);
826 start_nup(doc
, doc
->number_up
, 0, doc
->bounding_box
);
827 doc_puts(doc
, "showpage\n");
828 end_nup(doc
, doc
->number_up
);
830 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
834 * Make additional copies as necessary...
837 number
= doc
->slow_order
? 0 : doc
->page
;
841 int copy
; /* Current copy */
845 * Reopen the temporary file for reading...
848 cupsFileClose(doc
->temp
);
850 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
856 for (copy
= !doc
->slow_order
; copy
< doc
->copies
; copy
++)
858 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
859 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
865 if (!ppd
|| !ppd
->num_filters
)
866 fprintf(stderr
, "PAGE: %d 1\n", number
);
868 if (doc
->number_up
> 1)
870 printf("%%%%Page: (%d) %d\n", number
, number
);
871 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
872 PageLeft
, PageBottom
, PageRight
, PageTop
);
876 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
877 printf("%%%%PageBoundingBox: %d %d %d %d\n",
878 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
879 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
882 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
884 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
885 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
891 * Write/copy the trailer...
894 linelen
= copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
899 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC...
901 * This function expects "line" to be filled with the %! comment line.
905 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
906 pstops_doc_t
*doc
, /* I - Document info */
907 ppd_file_t
*ppd
, /* I - PPD file */
908 char *line
, /* I - Line buffer */
909 size_t linelen
, /* I - Length of initial line */
910 size_t linesize
) /* I - Size of line buffer */
912 int copy
; /* Current copy */
913 char buffer
[8192]; /* Copy buffer */
914 int bytes
; /* Number of bytes copied */
918 * First let the user know that they are attempting to print a file
919 * that may not print correctly...
922 fputs("WARNING: This document does not conform to the Adobe Document "
923 "Structuring Conventions and may not print correctly!\n", stderr
);
926 * Then write a standard DSC comment section...
929 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
932 if (doc
->slow_collate
&& doc
->copies
> 1)
933 printf("%%%%Pages: %d\n", doc
->copies
);
937 printf("%%%%For: %s\n", doc
->user
);
938 printf("%%%%Title: %s\n", doc
->title
);
940 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
943 * Tell the document processor the copy and duplex options
944 * that are required...
947 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
948 doc
->collate
? " collate" : "",
949 Duplex
? " duplex" : "");
952 * Apple uses RBI comments for various non-PPD options...
955 printf("%%RBINumCopies: %d\n", doc
->copies
);
960 * Tell the document processor the duplex option that is required...
964 puts("%%Requirements: duplex");
967 * Apple uses RBI comments for various non-PPD options...
970 puts("%RBINumCopies: 1");
973 puts("%%EndComments");
979 puts("%%BeginProlog");
986 * Then the setup section...
989 puts("%%BeginSetup");
996 * Finally, embed a copy of the file inside a %%Page...
999 if (!ppd
|| !ppd
->num_filters
)
1000 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
1002 puts("%%Page: 1 1");
1003 puts("%%BeginPageSetup");
1004 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1005 puts("%%EndPageSetup");
1006 puts("%%BeginDocument: nondsc");
1008 fwrite(line
, linelen
, 1, stdout
);
1011 cupsFileWrite(doc
->temp
, line
, linelen
);
1013 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1015 fwrite(buffer
, 1, bytes
, stdout
);
1018 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1021 puts("%%EndDocument");
1023 if (doc
->use_ESPshowpage
)
1025 WriteLabels(Orientation
);
1026 puts("ESPshowpage");
1032 * Reopen the temporary file for reading...
1035 cupsFileClose(doc
->temp
);
1037 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1040 * Make the additional copies as needed...
1043 for (copy
= 1; copy
< doc
->copies
; copy
++)
1045 if (!ppd
|| !ppd
->num_filters
)
1046 fputs("PAGE: 1 1\n", stderr
);
1048 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1049 puts("%%BeginPageSetup");
1050 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1051 puts("%%EndPageSetup");
1052 puts("%%BeginDocument: nondsc");
1054 copy_bytes(doc
->temp
, 0, 0);
1056 puts("%%EndDocument");
1058 if (doc
->use_ESPshowpage
)
1060 WriteLabels(Orientation
);
1061 puts("ESPshowpage");
1069 * 'copy_page()' - Copy a page description...
1071 * This function expects "line" to be filled with a %%Page comment line.
1072 * On return, "line" will contain the next line in the file, if any.
1075 static size_t /* O - Length of next line */
1076 copy_page(cups_file_t
*fp
, /* I - File to read from */
1077 pstops_doc_t
*doc
, /* I - Document info */
1078 ppd_file_t
*ppd
, /* I - PPD file */
1079 int number
, /* I - Current page number */
1080 char *line
, /* I - Line buffer */
1081 size_t linelen
, /* I - Length of initial line */
1082 size_t linesize
) /* I - Size of line buffer */
1084 char label
[256], /* Page label string */
1085 *ptr
; /* Pointer into line */
1086 int level
; /* Embedded document level */
1087 pstops_page_t
*pageinfo
; /* Page information */
1088 int first_page
; /* First page on N-up output? */
1089 int bounding_box
[4]; /* PageBoundingBox */
1093 * Get the page label for this page...
1096 first_page
= is_first_page(number
);
1098 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1100 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1104 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1106 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1111 * Create or update the current output page...
1115 pageinfo
= add_page(doc
, label
);
1117 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1120 * Handle first page override...
1123 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1128 * First page/sheet gets AP_FIRSTPAGE_* options...
1131 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1132 pageinfo
->num_options
,
1133 &(pageinfo
->options
));
1134 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->ap_manual_feed
,
1135 pageinfo
->num_options
,
1136 &(pageinfo
->options
));
1138 else if (doc
->page
== (Duplex
+ 2))
1141 * Second page/sheet gets default options...
1144 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1145 pageinfo
->num_options
,
1146 &(pageinfo
->options
));
1147 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->manual_feed
,
1148 pageinfo
->num_options
,
1149 &(pageinfo
->options
));
1154 * Scan comments until we see something other than %%Page*: or
1158 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1160 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1162 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1165 * %%PageBoundingBox: llx lly urx ury
1168 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1169 bounding_box
+ 1, bounding_box
+ 2,
1170 bounding_box
+ 3) != 4)
1172 fputs("ERROR: Bad %%PageBoundingBox: comment in file!\n", stderr
);
1173 memcpy(bounding_box
, doc
->bounding_box
,
1174 sizeof(bounding_box
));
1178 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1179 !strncmp(line
, "%%PageMedia:", 12) ||
1180 !strncmp(line
, "%%PageOrientation:", 18) ||
1181 !strncmp(line
, "%%PageProcessColors:", 20) ||
1182 !strncmp(line
, "%%PageRequirements:", 18) ||
1183 !strncmp(line
, "%%PageResources:", 16))
1190 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1193 * %%PageCustomColors: ...
1196 else if (!strncmp(line
, "%%PageMedia:", 12))
1202 else if (!strncmp(line
, "%%PageOrientation:", 18))
1205 * %%PageOrientation: ...
1208 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1211 * %%PageProcessColors: ...
1214 else if (!strncmp(line
, "%%PageRequirements:", 18))
1217 * %%PageRequirements: ...
1220 else if (!strncmp(line
, "%%PageResources:", 16))
1223 * %%PageResources: ...
1226 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1229 * %%IncludeFeature: *MainKeyword OptionKeyword
1232 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1233 pageinfo
->num_options
= include_feature(ppd
, line
,
1234 pageinfo
->num_options
,
1235 &(pageinfo
->options
));
1237 else if (strncmp(line
, "%%Include", 9))
1241 if (doc
->number_up
== 1)
1244 * Update the document's composite and page bounding box...
1247 memcpy(pageinfo
->bounding_box
, bounding_box
,
1248 sizeof(pageinfo
->bounding_box
));
1250 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1251 doc
->new_bounding_box
[0] = bounding_box
[0];
1252 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1253 doc
->new_bounding_box
[1] = bounding_box
[1];
1254 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1255 doc
->new_bounding_box
[2] = bounding_box
[2];
1256 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1257 doc
->new_bounding_box
[3] = bounding_box
[3];
1261 * Output the page header as needed...
1264 if (!doc
->slow_order
&& first_page
)
1266 if (!ppd
|| !ppd
->num_filters
)
1267 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1268 doc
->slow_collate
? 1 : doc
->copies
);
1270 if (doc
->number_up
> 1)
1272 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1273 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1274 PageLeft
, PageBottom
, PageRight
, PageTop
);
1278 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1279 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1280 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1281 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1286 * Copy any page setup commands...
1289 if (!strncmp(line
, "%%BeginPageSetup", 16))
1292 * Copy page setup commands...
1295 doc_write(doc
, line
, linelen
);
1297 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1299 if (!strncmp(line
, "%%EndPageSetup", 14))
1301 else if (!strncmp(line
, "%%Include", 9))
1304 if (doc
->number_up
== 1 && !doc
->fitplot
)
1305 doc_write(doc
, line
, linelen
);
1309 * Skip %%EndPageSetup...
1313 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1315 if (pageinfo
->num_options
== 0)
1316 doc_puts(doc
, "%%EndPageSetup\n");
1318 else if (first_page
&& pageinfo
->num_options
> 0)
1319 doc_puts(doc
, "%%BeginPageSetup\n");
1321 if (first_page
&& pageinfo
->num_options
> 0)
1323 int i
; /* Looping var */
1324 ppd_option_t
*option
; /* PPD option */
1325 int min_order
; /* Minimum OrderDependency value */
1326 char *doc_setup
, /* DocumentSetup commands to send */
1327 *any_setup
; /* AnySetup commands to send */
1331 * Yes, figure out the minimum OrderDependency value...
1334 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1335 min_order
= option
->order
;
1339 for (i
= 0; i
< pageinfo
->num_options
; i
++)
1340 if ((option
= ppdFindOption(ppd
, pageinfo
->options
[i
].name
)) != NULL
&&
1341 option
->order
< min_order
)
1342 min_order
= option
->order
;
1345 * Mark and extract them...
1348 cupsMarkOptions(ppd
, pageinfo
->num_options
, pageinfo
->options
);
1350 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
1351 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
1354 * Then send them out...
1358 doc_puts(doc
, doc_setup
);
1361 doc_puts(doc
, any_setup
);
1364 * Free the command strings...
1373 doc_puts(doc
, "%%EndPageSetup\n");
1377 * Prep for the start of the page description...
1380 start_nup(doc
, number
, 1, bounding_box
);
1383 * Read the rest of the page description...
1391 (!strncmp(line
, "%%Page:", 7) ||
1392 !strncmp(line
, "%%Trailer", 9) ||
1393 !strncmp(line
, "%%EOF", 5)))
1395 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1396 !strncmp(line
, "%ADO_BeginApplication", 21))
1398 doc_write(doc
, line
, linelen
);
1402 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1403 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1405 doc_write(doc
, line
, linelen
);
1409 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1410 (!strncmp(line
, "%%BeginData:", 12) &&
1411 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1414 * Copy binary data...
1417 int bytes
; /* Bytes of data */
1420 doc_write(doc
, line
, linelen
);
1422 bytes
= atoi(strchr(line
, ':') + 1);
1426 if (bytes
> linesize
)
1427 linelen
= cupsFileRead(fp
, line
, linesize
);
1429 linelen
= cupsFileRead(fp
, line
, bytes
);
1434 perror("ERROR: Early end-of-file while reading binary data");
1438 doc_write(doc
, line
, linelen
);
1444 doc_write(doc
, line
, linelen
);
1446 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1449 * Finish up this page and return...
1452 end_nup(doc
, number
);
1454 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1461 * 'copy_prolog()' - Copy the document prolog section...
1463 * This function expects "line" to be filled with a %%BeginProlog comment line.
1464 * On return, "line" will contain the next line in the file, if any.
1467 static size_t /* O - Length of next line */
1468 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1469 pstops_doc_t
*doc
, /* I - Document info */
1470 ppd_file_t
*ppd
, /* I - PPD file */
1471 char *line
, /* I - Line buffer */
1472 size_t linelen
, /* I - Length of initial line */
1473 size_t linesize
) /* I - Size of line buffer */
1475 while (strncmp(line
, "%%BeginProlog", 13))
1477 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1480 fwrite(line
, 1, linelen
, stdout
);
1482 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1486 puts("%%BeginProlog");
1488 do_prolog(doc
, ppd
);
1490 if (!strncmp(line
, "%%BeginProlog", 13))
1492 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1494 if (!strncmp(line
, "%%EndProlog", 11) ||
1495 !strncmp(line
, "%%BeginSetup", 12) ||
1496 !strncmp(line
, "%%Page:", 7))
1499 fwrite(line
, 1, linelen
, stdout
);
1502 if (!strncmp(line
, "%%EndProlog", 11))
1503 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1505 fputs("ERROR: Missing %%EndProlog!\n", stderr
);
1508 puts("%%EndProlog");
1515 * 'copy_setup()' - Copy the document setup section...
1517 * This function expects "line" to be filled with a %%BeginSetup comment line.
1518 * On return, "line" will contain the next line in the file, if any.
1521 static size_t /* O - Length of next line */
1522 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1523 pstops_doc_t
*doc
, /* I - Document info */
1524 ppd_file_t
*ppd
, /* I - PPD file */
1525 char *line
, /* I - Line buffer */
1526 size_t linelen
, /* I - Length of initial line */
1527 size_t linesize
) /* I - Size of line buffer */
1529 while (strncmp(line
, "%%BeginSetup", 12))
1531 if (!strncmp(line
, "%%Page:", 7))
1534 fwrite(line
, 1, linelen
, stdout
);
1536 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1540 if (!strncmp(line
, "%%BeginSetup", 12))
1542 while (strncmp(line
, "%%EndSetup", 10))
1544 if (!strncmp(line
, "%%Page:", 7))
1546 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1549 * %%IncludeFeature: *MainKeyword OptionKeyword
1552 if (doc
->number_up
== 1 && !doc
->fitplot
)
1553 doc
->num_options
= include_feature(ppd
, line
, doc
->num_options
,
1557 fwrite(line
, 1, linelen
, stdout
);
1559 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1563 if (!strncmp(line
, "%%EndSetup", 10))
1564 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1566 fputs("ERROR: Missing %%EndSetup!\n", stderr
);
1569 puts("%%BeginSetup");
1580 * 'copy_trailer()' - Copy the document trailer...
1582 * This function expects "line" to be filled with a %%Trailer comment line.
1583 * On return, "line" will contain the next line in the file, if any.
1586 static size_t /* O - Length of next line */
1587 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1588 pstops_doc_t
*doc
, /* I - Document info */
1589 ppd_file_t
*ppd
, /* I - PPD file */
1590 int number
, /* I - Number of pages */
1591 char *line
, /* I - Line buffer */
1592 size_t linelen
, /* I - Length of initial line */
1593 size_t linesize
) /* I - Size of line buffer */
1596 * Write the trailer comments...
1603 if (!strncmp(line
, "%%EOF", 5))
1605 else if (strncmp(line
, "%%Trailer", 9) &&
1606 strncmp(line
, "%%Pages:", 8) &&
1607 strncmp(line
, "%%BoundingBox:", 14))
1608 fwrite(line
, 1, linelen
, stdout
);
1610 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1613 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1615 printf("%%%%Pages: %d\n", number
);
1616 if (doc
->number_up
> 1 || doc
->fitplot
)
1617 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1618 PageLeft
, PageBottom
, PageRight
, PageTop
);
1620 printf("%%%%BoundingBox: %d %d %d %d\n",
1621 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1622 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1629 * 'do_prolog()' - Send the necessary document prolog commands...
1633 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1634 ppd_file_t
*ppd
) /* I - PPD file */
1637 * Send the document prolog commands...
1640 if (ppd
&& ppd
->patches
)
1642 puts("%%BeginFeature: *JobPatchFile 1");
1644 puts("%%EndFeature");
1647 ppdEmit(ppd
, stdout
, PPD_ORDER_PROLOG
);
1650 * Define ESPshowpage here so that applications that define their
1651 * own procedure to do a showpage pick it up...
1654 if (doc
->use_ESPshowpage
)
1655 puts("userdict/ESPshowpage/showpage load put\n"
1656 "userdict/showpage{}put");
1662 * 'do_setup()' - Send the necessary document setup commands...
1666 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1667 ppd_file_t
*ppd
) /* I - PPD file */
1670 * Mark any options from %%IncludeFeature: comments...
1673 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
1676 * Send all the printer-specific setup commands...
1679 ppdEmit(ppd
, stdout
, PPD_ORDER_DOCUMENT
);
1680 ppdEmit(ppd
, stdout
, PPD_ORDER_ANY
);
1683 * Set the number of copies for the job...
1686 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1688 printf("%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
1689 printf("%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
1690 "{1 dict begin/NumCopies exch def currentdict end setpagedevice}\n"
1691 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
1692 puts("%RBIEndNonPPDFeature");
1696 * If we are doing N-up printing, disable setpagedevice...
1699 if (doc
->number_up
> 1)
1700 puts("userdict/setpagedevice{pop}bind put");
1703 * Changes to the transfer function must be made AFTER any
1704 * setpagedevice code...
1707 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
1708 printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
1709 "ifelse %.3f mul } bind settransfer\n", doc
->gamma
,
1713 * Make sure we have rectclip and rectstroke procedures of some sort...
1719 * Write the page and label prologs...
1722 if (doc
->number_up
== 2 || doc
->number_up
== 6)
1725 * For 2- and 6-up output, rotate the labels to match the orientation
1729 if (Orientation
& 1)
1730 WriteLabelProlog(doc
->page_label
, PageBottom
,
1731 PageWidth
- PageLength
+ PageTop
, PageLength
);
1733 WriteLabelProlog(doc
->page_label
, PageLeft
, PageRight
, PageLength
);
1736 WriteLabelProlog(doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
1741 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
1743 * This function should be used for all page-level output that is affected
1744 * by ordering, collation, etc.
1748 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
1749 const char *format
, /* I - Printf-style format string */
1750 ...) /* I - Additional arguments as needed */
1752 va_list ap
; /* Pointer to arguments */
1753 char buffer
[1024]; /* Output buffer */
1754 size_t bytes
; /* Number of bytes to write */
1757 va_start(ap
, format
);
1758 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
1761 if (bytes
> sizeof(buffer
))
1764 "ERROR: doc_printf overflow (%d bytes) detected, aborting!\n",
1769 doc_write(doc
, buffer
, bytes
);
1774 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
1776 * This function should be used for all page-level output that is affected
1777 * by ordering, collation, etc.
1781 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
1782 const char *s
) /* I - String to send */
1784 doc_write(doc
, s
, strlen(s
));
1789 * 'doc_write()' - Send data to stdout and/or the temp file.
1793 doc_write(pstops_doc_t
*doc
, /* I - Document information */
1794 const char *s
, /* I - Data to send */
1795 size_t len
) /* I - Number of bytes to send */
1797 if (!doc
->slow_order
)
1798 fwrite(s
, 1, len
, stdout
);
1801 cupsFileWrite(doc
->temp
, s
, len
);
1806 * 'end_nup()' - End processing for N-up printing...
1810 end_nup(pstops_doc_t
*doc
, /* I - Document information */
1811 int number
) /* I - Page number */
1813 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
1814 puts("userdict /ESPsave get restore");
1816 switch (doc
->number_up
)
1819 if (doc
->use_ESPshowpage
)
1821 WriteLabels(Orientation
);
1822 puts("ESPshowpage");
1828 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1830 if (Orientation
& 1)
1833 * Rotate the labels back to portrait...
1836 WriteLabels(Orientation
- 1);
1838 else if (Orientation
== 0)
1841 * Rotate the labels to landscape...
1844 WriteLabels(doc
->normal_landscape
? 1 : 3);
1849 * Rotate the labels to landscape...
1852 WriteLabels(doc
->normal_landscape
? 3 : 1);
1855 puts("ESPshowpage");
1860 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1862 WriteLabels(Orientation
);
1863 puts("ESPshowpage");
1873 * 'include_feature()' - Include a printer option/feature command.
1876 static int /* O - New number of options */
1878 ppd_file_t
*ppd
, /* I - PPD file */
1879 const char *line
, /* I - DSC line */
1880 int num_options
, /* I - Number of options */
1881 cups_option_t
**options
) /* IO - Options */
1883 char name
[255], /* Option name */
1884 value
[255]; /* Option value */
1885 ppd_option_t
*option
; /* Option in file */
1886 ppd_choice_t
*choice
; /* Choice */
1890 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
1893 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
1895 fputs("ERROR: Bad %%IncludeFeature: comment!\n", stderr
);
1896 return (num_options
);
1900 * Find the option and choice...
1903 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
1905 fprintf(stderr
, "WARNING: Unknown option \"%s\"!\n", name
+ 1);
1906 return (num_options
);
1909 if (option
->section
== PPD_ORDER_EXIT
||
1910 option
->section
== PPD_ORDER_JCL
)
1912 fprintf(stderr
, "WARNING: Option \"%s\" cannot be included via "
1913 "IncludeFeature!\n", name
+ 1);
1914 return (num_options
);
1917 if ((choice
= ppdFindChoice(option
, value
)) == NULL
)
1919 fprintf(stderr
, "WARNING: Unknown choice \"%s\" for option \"%s\"!\n",
1921 return (num_options
);
1925 * Add the option to the option array and return...
1928 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
1933 * 'parse_text()' - Parse a text value in a comment...
1935 * This function parses a DSC text value as defined on page 36 of the
1936 * DSC specification. Text values are either surrounded by parenthesis
1937 * or whitespace-delimited.
1939 * The value returned is the literal characters for the entire text
1940 * string, including any parenthesis and escape characters.
1943 static char * /* O - Value or NULL on error */
1944 parse_text(const char *start
, /* I - Start of text value */
1945 char **end
, /* O - End of text value */
1946 char *buffer
, /* I - Buffer */
1947 size_t bufsize
) /* I - Size of buffer */
1949 char *bufptr
, /* Pointer in buffer */
1950 *bufend
; /* End of buffer */
1951 int level
; /* Parenthesis level */
1955 * Skip leading whitespace...
1958 while (isspace(*start
& 255))
1962 * Then copy the value...
1967 bufend
= buffer
+ bufsize
- 1;
1969 while (bufptr
< bufend
)
1971 if (isspace(*start
& 255) && !level
)
1978 else if (*start
== ')')
1988 else if (*start
== '\\')
1991 * Copy escaped character...
1994 int i
; /* Looping var */
1998 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
1999 *bufptr
++ = start
[i
], i
++);
2008 * Return the value and new pointer into the line...
2012 *end
= (char *)start
;
2014 if (bufptr
== bufend
)
2022 * 'set_pstops_options()' - Set pstops options...
2027 pstops_doc_t
*doc
, /* I - Document information */
2028 ppd_file_t
*ppd
, /* I - PPD file */
2029 char *argv
[], /* I - Command-line arguments */
2030 int num_options
, /* I - Number of options */
2031 cups_option_t
*options
) /* I - Options */
2033 const char *val
; /* Option value */
2034 int intval
; /* Integer option value */
2035 ppd_attr_t
*attr
; /* PPD attribute */
2036 ppd_option_t
*option
; /* PPD option */
2037 ppd_choice_t
*choice
; /* PPD choice */
2041 * Initialize document information structure...
2044 memset(doc
, 0, sizeof(pstops_doc_t
));
2046 doc
->job_id
= atoi(argv
[1]);
2047 doc
->user
= argv
[2];
2048 doc
->title
= argv
[3];
2049 doc
->copies
= atoi(argv
[4]);
2051 if (ppd
&& ppd
->landscape
> 0)
2052 doc
->normal_landscape
= 1;
2054 doc
->bounding_box
[0] = (int)PageLeft
;
2055 doc
->bounding_box
[1] = (int)PageBottom
;
2056 doc
->bounding_box
[2] = (int)PageRight
;
2057 doc
->bounding_box
[3] = (int)PageTop
;
2059 doc
->new_bounding_box
[0] = INT_MAX
;
2060 doc
->new_bounding_box
[1] = INT_MAX
;
2061 doc
->new_bounding_box
[2] = INT_MIN
;
2062 doc
->new_bounding_box
[3] = INT_MIN
;
2065 * AP_FIRSTPAGE_InputSlot
2068 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2072 * AP_FIRSTPAGE_ManualFeed
2075 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2082 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2085 * Get brightness value from 10 to 1000.
2090 if (intval
< 10 || intval
> 1000)
2092 fprintf(stderr
, "ERROR: Unsupported brightness value %s, using "
2093 "brightness=100!\n", val
);
2094 doc
->brightness
= 1.0f
;
2097 doc
->brightness
= intval
* 0.01f
;
2100 doc
->brightness
= 1.0f
;
2103 * collate, multiple-document-handling
2106 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2109 * This IPP attribute is unnecessarily complicated...
2111 * single-document, separate-documents-collated-copies, and
2112 * single-document-new-sheet all require collated copies.
2114 * separate-documents-uncollated-copies allows for uncollated copies.
2117 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2120 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2121 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2122 !strcasecmp(val
, "yes")))
2129 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2130 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2131 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2140 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
2141 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2142 !strcasecmp(val
, "yes")))
2149 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2152 * Get gamma value from 1 to 10000...
2157 if (intval
< 1 || intval
> 10000)
2159 fprintf(stderr
, "ERROR: Unsupported gamma value %s, using "
2160 "gamma=1000!\n", val
);
2164 doc
->gamma
= intval
* 0.001f
;
2173 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2174 doc
->input_slot
= choice
->choice
;
2180 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2181 doc
->manual_feed
= choice
->choice
;
2183 if ((val
= cupsGetOption("mirror", num_options
, options
)) != NULL
&&
2184 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2185 !strcasecmp(val
, "yes")))
2192 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2194 switch (intval
= atoi(val
))
2202 doc
->number_up
= intval
;
2206 "ERROR: Unsupported number-up value %d, using number-up=1!\n",
2219 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2221 if (!strcasecmp(val
, "lrtb"))
2222 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2223 else if (!strcasecmp(val
, "lrbt"))
2224 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2225 else if (!strcasecmp(val
, "rltb"))
2226 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2227 else if (!strcasecmp(val
, "rlbt"))
2228 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2229 else if (!strcasecmp(val
, "tblr"))
2230 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2231 else if (!strcasecmp(val
, "tbrl"))
2232 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2233 else if (!strcasecmp(val
, "btlr"))
2234 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2235 else if (!strcasecmp(val
, "btrl"))
2236 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2239 fprintf(stderr
, "ERROR: Unsupported number-up-layout value %s, using "
2240 "number-up-layout=lrtb!\n", val
);
2241 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2245 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2251 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2253 if (!strcasecmp(val
, "Reverse"))
2254 doc
->output_order
= 1;
2259 * Figure out the right default output order from the PPD file...
2262 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2263 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2265 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2266 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2268 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2275 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2277 if (!strcasecmp(val
, "none"))
2278 doc
->page_border
= PSTOPS_BORDERNONE
;
2279 else if (!strcasecmp(val
, "single"))
2280 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2281 else if (!strcasecmp(val
, "single-thick"))
2282 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2283 else if (!strcasecmp(val
, "double"))
2284 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2285 else if (!strcasecmp(val
, "double-thick"))
2286 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2289 fprintf(stderr
, "ERROR: Unsupported page-border value %s, using "
2290 "page-border=none!\n", val
);
2291 doc
->page_border
= PSTOPS_BORDERNONE
;
2295 doc
->page_border
= PSTOPS_BORDERNONE
;
2301 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2307 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2313 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2316 * Now figure out if we have to force collated copies, etc.
2319 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2322 * Force collated copies when printing a duplexed document to
2323 * a non-PS printer that doesn't do hardware copy generation.
2324 * Otherwise the copies will end up on the front/back side of
2332 * See if we have to filter the fast or slow way...
2335 if (doc
->collate
&& doc
->copies
> 1)
2338 * See if we need to manually collate the pages...
2341 doc
->slow_collate
= 1;
2343 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2344 !strcasecmp(choice
->choice
, "True"))
2347 * Hardware collate option is selected, see if the option is
2348 * conflicting - if not, collate in hardware. Otherwise,
2349 * turn the hardware collate option off...
2352 if ((option
= ppdFindOption(ppd
, "Option")) != NULL
&&
2353 !option
->conflicted
)
2354 doc
->slow_collate
= 0;
2356 ppdMarkOption(ppd
, "Collate", "False");
2360 doc
->slow_collate
= 0;
2362 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2363 doc
->slow_order
= 1;
2365 doc
->slow_order
= 0;
2367 if ((doc
->slow_collate
|| doc
->slow_order
) && Duplex
)
2368 doc
->slow_duplex
= 1;
2370 doc
->slow_duplex
= 0;
2373 * Create a temporary file for page data if we need to filter slowly...
2376 if (doc
->slow_order
|| doc
->slow_collate
)
2378 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2379 sizeof(doc
->tempfile
))) == NULL
)
2381 fprintf(stderr
, "ERROR: Unable to create temporary file: %s\n",
2388 * Figure out if we should use ESPshowpage or not...
2391 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2395 * Yes, use ESPshowpage...
2398 doc
->use_ESPshowpage
= 1;
2401 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2402 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2407 * 'skip_page()' - Skip past a page that won't be printed...
2410 static size_t /* O - Length of next line */
2411 skip_page(cups_file_t
*fp
, /* I - File to read from */
2412 char *line
, /* I - Line buffer */
2413 size_t linelen
, /* I - Length of initial line */
2414 size_t linesize
) /* I - Size of line buffer */
2416 int level
; /* Embedded document level */
2421 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2424 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer", 9)))
2426 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2427 !strncmp(line
, "%ADO_BeginApplication", 21))
2429 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2430 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2432 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2433 (!strncmp(line
, "%%BeginData:", 12) &&
2434 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2437 * Skip binary data...
2440 int bytes
; /* Bytes of data */
2443 bytes
= atoi(strchr(line
, ':') + 1);
2447 if (bytes
> linesize
)
2448 linelen
= cupsFileRead(fp
, line
, linesize
);
2450 linelen
= cupsFileRead(fp
, line
, bytes
);
2455 perror("ERROR: Early end-of-file while reading binary data");
2469 * 'start_nup()' - Start processing for N-up printing...
2473 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2474 int number
, /* I - Page number */
2475 int show_border
, /* I - Show the border? */
2476 const int *bounding_box
) /* I - BoundingBox value */
2478 int pos
; /* Position on page */
2479 int x
, y
; /* Relative position of subpage */
2480 float w
, l
, /* Width and length of subpage */
2481 tx
, ty
; /* Translation values for subpage */
2482 float pagew
, /* Printable width of page */
2483 pagel
; /* Printable height of page */
2484 int bboxw
, /* BoundingBox width */
2485 bboxl
; /* BoundingBox height */
2488 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
2489 doc_puts(doc
, "userdict/ESPsave save put\n");
2492 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
2494 pos
= (number
- 1) % doc
->number_up
;
2495 pagew
= PageRight
- PageLeft
;
2496 pagel
= PageTop
- PageBottom
;
2500 bboxw
= bounding_box
[2] - bounding_box
[0];
2501 bboxl
= bounding_box
[3] - bounding_box
[1];
2509 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2510 fprintf(stderr
, "DEBUG: bboxw = %d, bboxl = %d\n", bboxw
, bboxl
);
2511 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2512 PageLeft
, PageRight
);
2513 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2514 PageTop
, PageBottom
);
2515 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2516 PageWidth
, PageLength
);
2518 switch (Orientation
)
2520 case 1 : /* Landscape */
2521 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2523 case 2 : /* Reverse Portrait */
2524 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2527 case 3 : /* Reverse Landscape */
2528 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2532 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2533 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2534 else if (doc
->number_up
> 1 || doc
->fitplot
)
2535 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2537 switch (doc
->number_up
)
2543 l
= w
* bboxl
/ bboxw
;
2548 w
= l
* bboxw
/ bboxl
;
2551 tx
= 0.5 * (pagew
- w
);
2552 ty
= 0.5 * (pagel
- l
);
2554 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2555 w
/ bboxw
, l
/ bboxl
);
2565 if (Orientation
& 1)
2569 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2573 l
= w
* bboxl
/ bboxw
;
2575 if (l
> (pagew
* 0.5))
2578 w
= l
* bboxw
/ bboxl
;
2581 tx
= 0.5 * (pagew
* 0.5 - l
);
2582 ty
= 0.5 * (pagel
- w
);
2584 if (doc
->normal_landscape
)
2585 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2587 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2589 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2590 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2596 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2600 w
= l
* bboxw
/ bboxl
;
2602 if (w
> (pagel
* 0.5))
2605 l
= w
* bboxl
/ bboxw
;
2608 tx
= 0.5 * (pagel
* 0.5 - w
);
2609 ty
= 0.5 * (pagew
- l
);
2611 if (doc
->normal_landscape
)
2612 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2614 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2616 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2617 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
2622 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2633 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2636 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2640 l
= w
* bboxl
/ bboxw
;
2642 if (l
> (pagel
* 0.5))
2645 w
= l
* bboxw
/ bboxl
;
2648 tx
= 0.5 * (pagew
* 0.5 - w
);
2649 ty
= 0.5 * (pagel
* 0.5 - l
);
2651 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2652 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
2653 w
/ bboxw
, l
/ bboxl
);
2657 if (Orientation
& 1)
2659 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2664 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2667 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2675 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2678 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2683 l
= w
* bboxl
/ bboxw
;
2685 if (l
> (pagew
* 0.333))
2688 w
= l
* bboxw
/ bboxl
;
2691 tx
= 0.5 * (pagel
- 2 * w
);
2692 ty
= 0.5 * (pagew
- 3 * l
);
2694 if (doc
->normal_landscape
)
2695 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2697 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2699 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2700 tx
+ x
* y
* pagel
* 0.5, ty
+ pagew
* 0.333,
2701 w
/ bboxw
, l
/ bboxl
);
2705 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2710 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2713 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2721 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2724 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2729 w
= l
* bboxw
/ bboxl
;
2731 if (w
> (pagel
* 0.333))
2734 l
= w
* bboxl
/ bboxw
;
2737 tx
= 0.5 * (pagel
- 3 * w
);
2738 ty
= 0.5 * (pagew
- 2 * l
);
2740 if (doc
->normal_landscape
)
2741 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2743 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2745 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2746 tx
+ x
* pagel
* 0.333, ty
+ y
* pagew
* 0.5,
2747 w
/ bboxw
, l
/ bboxl
);
2752 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2763 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2766 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2770 l
= w
* bboxl
/ bboxw
;
2772 if (l
> (pagel
* 0.333))
2775 w
= l
* bboxw
/ bboxl
;
2778 tx
= 0.5 * (pagew
* 0.333 - w
);
2779 ty
= 0.5 * (pagel
* 0.333 - l
);
2781 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2782 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
2783 w
/ bboxw
, l
/ bboxl
);
2787 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2798 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2801 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2805 l
= w
* bboxl
/ bboxw
;
2807 if (l
> (pagel
* 0.25))
2810 w
= l
* bboxw
/ bboxl
;
2813 tx
= 0.5 * (pagew
* 0.25 - w
);
2814 ty
= 0.5 * (pagel
* 0.25 - l
);
2816 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2817 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
2818 w
/ bboxw
, l
/ bboxl
);
2823 * Draw borders as necessary...
2826 if (doc
->page_border
&& show_border
)
2828 int rects
; /* Number of border rectangles */
2829 float fscale
, /* Scaling value for points */
2830 margin
; /* Current margin for borders */
2833 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
2834 fscale
= PageWidth
/ w
;
2835 margin
= 2.25 * fscale
;
2838 * Set the line width and color...
2841 doc_puts(doc
, "gsave\n");
2842 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
2843 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
2847 * Draw border boxes...
2850 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
2851 if (doc
->number_up
> 1)
2852 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2853 margin
- 2.25 * fscale
,
2854 margin
- 2.25 * fscale
,
2855 bboxw
+ 4.5 * fscale
- 2 * margin
,
2856 bboxl
+ 4.5 * fscale
- 2 * margin
);
2858 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2860 PageBottom
+ margin
,
2861 PageRight
- PageLeft
- 2 * margin
,
2862 PageTop
- PageBottom
- 2 * margin
);
2865 * Restore pen settings...
2868 doc_puts(doc
, "grestore\n");
2874 * Clip the page that follows to the bounding box of the page...
2877 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
2879 doc_printf(doc
, "%d %d %d %d ESPrc\n", bounding_box
[0], bounding_box
[1],
2882 else if (doc
->number_up
> 1)
2885 * Clip the page that follows to the default page size...
2888 doc_printf(doc
, "0 0 %d %d ESPrc\n", bboxw
, bboxl
);
2894 * End of "$Id: pstops.c 5369 2006-04-03 15:09:58Z mike $".