]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/pstops.c
2 * "$Id: pstops.c 5326 2006-03-23 19:33:35Z 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
)
311 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
314 if ((len
= cupsFileGetLine(fp
, line
, sizeof(line
))) == 0)
319 * Now see if the document conforms to the Adobe Document Structuring
323 if (!strncmp(line
, "%!PS-Adobe-", 11))
326 * Yes, filter the document...
329 copy_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
334 * No, display an error message and treat the file as if it contains
338 copy_non_dsc(fp
, &doc
, ppd
, line
, len
, sizeof(line
));
342 * Send %%EOF as needed...
349 * End the job with the appropriate JCL command or CTRL-D...
354 if (ppd
&& ppd
->jcl_end
)
355 ppdEmitJCLEnd(ppd
, stdout
);
361 * Close files and remove the temporary file if needed...
366 cupsFileClose(doc
.temp
);
367 unlink(doc
.tempfile
);
371 cupsFreeOptions(num_options
, options
);
380 * 'add_page()' - Add a page to the pages array...
383 static pstops_page_t
* /* O - New page info object */
384 add_page(pstops_doc_t
*doc
, /* I - Document information */
385 const char *label
) /* I - Page label */
387 pstops_page_t
*pageinfo
; /* New page info object */
391 doc
->pages
= cupsArrayNew(NULL
, NULL
);
395 fprintf(stderr
, "EMERG: Unable to allocate memory for pages array: %s\n",
400 if ((pageinfo
= calloc(1, sizeof(pstops_page_t
))) == NULL
)
402 fprintf(stderr
, "EMERG: Unable to allocate memory for page info: %s\n",
407 pageinfo
->label
= strdup(label
);
408 pageinfo
->offset
= cupsFileTell(doc
->temp
);
410 cupsArrayAdd(doc
->pages
, pageinfo
);
419 * 'check_range()' - Check to see if the current page is selected for
423 static int /* O - 1 if selected, 0 otherwise */
424 check_range(pstops_doc_t
*doc
, /* I - Document information */
425 int page
) /* I - Page number */
427 const char *range
; /* Pointer into range string */
428 int lower
, upper
; /* Lower and upper page numbers */
434 * See if we only print even or odd pages...
437 if (!strcasecmp(doc
->page_set
, "even") &&
438 ((page
- 1) % (doc
->number_up
<< 1)) < doc
->number_up
)
441 if (!strcasecmp(doc
->page_set
, "odd") &&
442 ((page
- 1) % (doc
->number_up
<< 1)) >= doc
->number_up
)
446 if (!doc
->page_ranges
)
447 return (1); /* No range, print all pages... */
449 for (range
= doc
->page_ranges
; *range
!= '\0';)
455 upper
= strtol(range
, (char **)&range
, 10);
459 lower
= strtol(range
, (char **)&range
, 10);
464 if (!isdigit(*range
& 255))
467 upper
= strtol(range
, (char **)&range
, 10);
473 if (page
>= lower
&& page
<= upper
)
487 * 'copy_bytes()' - Copy bytes from the input file to stdout...
491 copy_bytes(cups_file_t
*fp
, /* I - File to read from */
492 off_t offset
, /* I - Offset to page data */
493 size_t length
) /* I - Length of page data */
495 char buffer
[8192]; /* Data buffer */
496 ssize_t nbytes
; /* Number of bytes read */
497 size_t nleft
; /* Number of bytes left/remaining */
502 if (cupsFileSeek(fp
, offset
) < 0)
504 fprintf(stderr
, "ERROR: Unable to seek to offset " CUPS_LLFMT
506 CUPS_LLCAST offset
, strerror(errno
));
510 while (nleft
> 0 || length
== 0)
512 if (nleft
> sizeof(buffer
) || length
== 0)
513 nbytes
= sizeof(buffer
);
517 if ((nbytes
= cupsFileRead(fp
, buffer
, nbytes
)) < 1)
522 fwrite(buffer
, 1, nbytes
, stdout
);
528 * 'copy_comments()' - Copy all of the comments section...
530 * This function expects "line" to be filled with a comment line.
531 * On return, "line" will contain the next line in the file, if any.
534 static size_t /* O - Length of next line */
535 copy_comments(cups_file_t
*fp
, /* I - File to read from */
536 pstops_doc_t
*doc
, /* I - Document info */
537 char *line
, /* I - Line buffer */
538 size_t linelen
, /* I - Length of initial line */
539 size_t linesize
) /* I - Size of line buffer */
541 int saw_bounding_box
, /* Saw %%BoundingBox: comment? */
542 saw_for
, /* Saw %%For: comment? */
543 saw_pages
, /* Saw %%Pages: comment? */
544 saw_title
; /* Saw %%Title: comment? */
548 * Loop until we see %%EndComments or a non-comment line...
551 saw_bounding_box
= 0;
556 while (line
[0] == '%')
559 * Strip trailing whitespace...
566 if (!isspace(line
[linelen
] & 255))
569 line
[linelen
] = '\0';
576 fprintf(stderr
, "DEBUG: %s\n", line
);
579 * Pull the headers out...
582 if (!strncmp(line
, "%%Pages:", 8))
585 fputs("ERROR: Duplicate %%Pages: comment seen!\n", stderr
);
589 else if (!strncmp(line
, "%%BoundingBox:", 14))
591 if (saw_bounding_box
)
592 fputs("ERROR: Duplicate %%BoundingBox: comment seen!\n", stderr
);
593 else if (sscanf(line
+ 14, "%d%d%d%d", doc
->bounding_box
+ 0,
594 doc
->bounding_box
+ 1, doc
->bounding_box
+ 2,
595 doc
->bounding_box
+ 3) != 4)
597 fputs("ERROR: Bad %%BoundingBox: comment seen!\n", stderr
);
599 doc
->bounding_box
[0] = (int)PageLeft
;
600 doc
->bounding_box
[1] = (int)PageBottom
;
601 doc
->bounding_box
[2] = (int)PageRight
;
602 doc
->bounding_box
[3] = (int)PageTop
;
605 saw_bounding_box
= 1;
607 else if (!strncmp(line
, "%%For:", 6))
610 printf("%s\n", line
);
612 else if (!strncmp(line
, "%%Title:", 8))
615 printf("%s\n", line
);
617 else if (!strncmp(line
, "%cupsRotation:", 14))
620 * Reset orientation of document?
623 int orient
= (atoi(line
+ 14) / 90) & 3;
625 if (orient
!= Orientation
)
628 * Yes, update things so that the pages come out right...
631 Orientation
= (4 - Orientation
+ orient
) & 3;
633 Orientation
= orient
;
636 else if (!strcmp(line
, "%%EndComments"))
638 linelen
= cupsFileGetLine(fp
, line
, linesize
);
641 else if (strncmp(line
, "%!", 2) && strncmp(line
, "%cups", 5))
642 printf("%s\n", line
);
644 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
648 if (!saw_bounding_box
)
649 fputs("ERROR: No %%BoundingBox: comment in header!\n", stderr
);
652 fputs("ERROR: No %%Pages: comment in header!\n", stderr
);
655 printf("%%%%For: %s\n", doc
->user
);
658 printf("%%%%Title: %s\n", doc
->title
);
660 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
663 * Tell the document processor the copy and duplex options
664 * that are required...
667 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
668 doc
->collate
? " collate" : "",
669 Duplex
? " duplex" : "");
672 * Apple uses RBI comments for various non-PPD options...
675 printf("%%RBINumCopies: %d\n", doc
->copies
);
680 * Tell the document processor the duplex option that is required...
684 puts("%%Requirements: duplex");
687 * Apple uses RBI comments for various non-PPD options...
690 puts("%RBINumCopies: 1");
693 puts("%%Pages: (atend)");
694 puts("%%BoundingBox: (atend)");
695 puts("%%EndComments");
702 * 'copy_dsc()' - Copy a DSC-conforming document...
704 * This function expects "line" to be filled with the %!PS-Adobe comment line.
708 copy_dsc(cups_file_t
*fp
, /* I - File to read from */
709 pstops_doc_t
*doc
, /* I - Document info */
710 ppd_file_t
*ppd
, /* I - PPD file */
711 char *line
, /* I - Line buffer */
712 size_t linelen
, /* I - Length of initial line */
713 size_t linesize
) /* I - Size of line buffer */
715 int number
; /* Page number */
716 pstops_page_t
*pageinfo
; /* Page information */
720 * Make sure we use ESPshowpage for EPS files...
723 if (strstr(line
, "EPSF"))
725 doc
->use_ESPshowpage
= 1;
730 * Start sending the document with any commands needed...
733 fprintf(stderr
, "DEBUG: Before copy_comments - %s", line
);
734 linelen
= copy_comments(fp
, doc
, line
, linelen
, linesize
);
737 * Now find the prolog section, if any...
740 fprintf(stderr
, "DEBUG: Before copy_prolog - %s", line
);
741 copy_prolog(fp
, doc
, ppd
, line
, linelen
, linesize
);
744 * Then the document setup section...
747 fprintf(stderr
, "DEBUG: Before copy_setup - %s", line
);
748 copy_setup(fp
, doc
, ppd
, line
, linelen
, linesize
);
751 * Then process pages until we have no more...
756 fprintf(stderr
, "DEBUG: Before page loop - %s", line
);
757 while (!strncmp(line
, "%%Page:", 7))
761 if (check_range(doc
, (number
- 1) / doc
->number_up
+ 1))
763 fprintf(stderr
, "DEBUG: Copying page %d...\n", number
);
764 linelen
= copy_page(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
768 fprintf(stderr
, "DEBUG: Skipping page %d...\n", number
);
769 linelen
= skip_page(fp
, line
, linelen
, linesize
);
774 * Finish up the last page(s)...
777 if (number
&& is_not_last_page(number
))
779 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
781 start_nup(doc
, doc
->number_up
- 1, 0, doc
->bounding_box
);
782 doc_puts(doc
, "showpage\n");
783 end_nup(doc
, doc
->number_up
- 1);
785 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
788 if (doc
->slow_duplex
&& (doc
->page
& 1))
791 * Make sure we have an even number of pages...
794 pageinfo
= add_page(doc
, "(filler)");
796 if (!doc
->slow_order
)
798 if (!ppd
|| !ppd
->num_filters
)
799 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
800 doc
->slow_collate
? 1 : doc
->copies
);
802 printf("%%%%Page: (filler) %d\n", doc
->page
);
805 start_nup(doc
, doc
->number_up
- 1, 0, doc
->bounding_box
);
806 doc_puts(doc
, "showpage\n");
807 end_nup(doc
, doc
->number_up
- 1);
809 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
813 * Make additional copies as necessary...
816 number
= doc
->slow_order
? 0 : doc
->page
;
820 int copy
; /* Current copy */
824 * Reopen the temporary file for reading...
827 cupsFileClose(doc
->temp
);
829 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
835 for (copy
= !doc
->slow_order
; copy
< doc
->copies
; copy
++)
837 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayLast(doc
->pages
) :
838 (pstops_page_t
*)cupsArrayFirst(doc
->pages
);
844 if (!ppd
|| !ppd
->num_filters
)
845 fprintf(stderr
, "PAGE: %d 1\n", number
);
847 if (doc
->number_up
> 1)
849 printf("%%%%Page: (%d) %d\n", number
, number
);
850 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
851 PageLeft
, PageBottom
, PageRight
, PageTop
);
855 printf("%%%%Page: %s %d\n", pageinfo
->label
, number
);
856 printf("%%%%PageBoundingBox: %d %d %d %d\n",
857 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
858 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
861 copy_bytes(doc
->temp
, pageinfo
->offset
, pageinfo
->length
);
863 pageinfo
= doc
->slow_order
? (pstops_page_t
*)cupsArrayPrev(doc
->pages
) :
864 (pstops_page_t
*)cupsArrayNext(doc
->pages
);
870 * Write/copy the trailer...
873 linelen
= copy_trailer(fp
, doc
, ppd
, number
, line
, linelen
, linesize
);
878 * 'copy_non_dsc()' - Copy a document that does not conform to the DSC...
880 * This function expects "line" to be filled with the %! comment line.
884 copy_non_dsc(cups_file_t
*fp
, /* I - File to read from */
885 pstops_doc_t
*doc
, /* I - Document info */
886 ppd_file_t
*ppd
, /* I - PPD file */
887 char *line
, /* I - Line buffer */
888 size_t linelen
, /* I - Length of initial line */
889 size_t linesize
) /* I - Size of line buffer */
891 int copy
; /* Current copy */
892 char buffer
[8192]; /* Copy buffer */
893 int bytes
; /* Number of bytes copied */
897 * First let the user know that they are attempting to print a file
898 * that may not print correctly...
901 fputs("WARNING: This document does not conform to the Adobe Document "
902 "Structuring Conventions and may not print correctly!\n", stderr
);
905 * Then write a standard DSC comment section...
908 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft
, PageBottom
,
911 if (doc
->slow_collate
&& doc
->copies
> 1)
912 printf("%%%%Pages: %d\n", doc
->copies
);
916 printf("%%%%For: %s\n", doc
->user
);
917 printf("%%%%Title: %s\n", doc
->title
);
919 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
922 * Tell the document processor the copy and duplex options
923 * that are required...
926 printf("%%%%Requirements: numcopies(%d)%s%s\n", doc
->copies
,
927 doc
->collate
? " collate" : "",
928 Duplex
? " duplex" : "");
931 * Apple uses RBI comments for various non-PPD options...
934 printf("%%RBINumCopies: %d\n", doc
->copies
);
939 * Tell the document processor the duplex option that is required...
943 puts("%%Requirements: duplex");
946 * Apple uses RBI comments for various non-PPD options...
949 puts("%RBINumCopies: 1");
952 puts("%%EndComments");
958 puts("%%BeginProlog");
965 * Then the setup section...
968 puts("%%BeginSetup");
975 * Finally, embed a copy of the file inside a %%Page...
978 if (!ppd
|| !ppd
->num_filters
)
979 fprintf(stderr
, "PAGE: 1 %d\n", doc
->temp
? 1 : doc
->copies
);
982 puts("%%BeginPageSetup");
983 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
984 puts("%%EndPageSetup");
985 puts("%%BeginDocument: nondsc");
987 fwrite(line
, linelen
, 1, stdout
);
990 cupsFileWrite(doc
->temp
, line
, linelen
);
992 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
994 fwrite(buffer
, 1, bytes
, stdout
);
997 cupsFileWrite(doc
->temp
, buffer
, bytes
);
1000 puts("%%EndDocument");
1002 if (doc
->use_ESPshowpage
)
1004 WriteLabels(Orientation
);
1005 puts("ESPshowpage");
1011 * Reopen the temporary file for reading...
1014 cupsFileClose(doc
->temp
);
1016 doc
->temp
= cupsFileOpen(doc
->tempfile
, "r");
1019 * Make the additional copies as needed...
1022 for (copy
= 1; copy
< doc
->copies
; copy
++)
1024 if (!ppd
|| !ppd
->num_filters
)
1025 fputs("PAGE: 1 1\n", stderr
);
1027 printf("%%%%Page: %d %d\n", copy
+ 1, copy
+ 1);
1028 puts("%%BeginPageSetup");
1029 ppdEmit(ppd
, stdout
, PPD_ORDER_PAGE
);
1030 puts("%%EndPageSetup");
1031 puts("%%BeginDocument: nondsc");
1033 copy_bytes(doc
->temp
, 0, 0);
1035 puts("%%EndDocument");
1037 if (doc
->use_ESPshowpage
)
1039 WriteLabels(Orientation
);
1040 puts("ESPshowpage");
1048 * 'copy_page()' - Copy a page description...
1050 * This function expects "line" to be filled with a %%Page comment line.
1051 * On return, "line" will contain the next line in the file, if any.
1054 static size_t /* O - Length of next line */
1055 copy_page(cups_file_t
*fp
, /* I - File to read from */
1056 pstops_doc_t
*doc
, /* I - Document info */
1057 ppd_file_t
*ppd
, /* I - PPD file */
1058 int number
, /* I - Current page number */
1059 char *line
, /* I - Line buffer */
1060 size_t linelen
, /* I - Length of initial line */
1061 size_t linesize
) /* I - Size of line buffer */
1063 char label
[256], /* Page label string */
1064 *ptr
; /* Pointer into line */
1065 int level
; /* Embedded document level */
1066 pstops_page_t
*pageinfo
; /* Page information */
1067 int first_page
; /* First page on N-up output? */
1068 int bounding_box
[4]; /* PageBoundingBox */
1072 * Get the page label for this page...
1075 first_page
= is_first_page(number
);
1077 if (!parse_text(line
+ 7, &ptr
, label
, sizeof(label
)))
1079 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1083 else if (strtol(ptr
, &ptr
, 10) == LONG_MAX
|| !isspace(*ptr
& 255))
1085 fputs("ERROR: Bad %%Page: comment in file!\n", stderr
);
1090 * Create or update the current output page...
1094 pageinfo
= add_page(doc
, label
);
1096 pageinfo
= (pstops_page_t
*)cupsArrayLast(doc
->pages
);
1099 * Handle first page override...
1102 if (doc
->ap_input_slot
|| doc
->ap_manual_feed
)
1107 * First page/sheet gets AP_FIRSTPAGE_* options...
1110 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->ap_input_slot
,
1111 pageinfo
->num_options
,
1112 &(pageinfo
->options
));
1113 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->ap_manual_feed
,
1114 pageinfo
->num_options
,
1115 &(pageinfo
->options
));
1117 else if (doc
->page
== (Duplex
+ 2))
1120 * Second page/sheet gets default options...
1123 pageinfo
->num_options
= cupsAddOption("InputSlot", doc
->input_slot
,
1124 pageinfo
->num_options
,
1125 &(pageinfo
->options
));
1126 pageinfo
->num_options
= cupsAddOption("ManualFeed", doc
->manual_feed
,
1127 pageinfo
->num_options
,
1128 &(pageinfo
->options
));
1133 * Scan comments until we see something other than %%Page*: or
1137 memcpy(bounding_box
, doc
->bounding_box
, sizeof(bounding_box
));
1139 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1141 if (!strncmp(line
, "%%PageBoundingBox:", 18))
1144 * %%PageBoundingBox: llx lly urx ury
1147 if (sscanf(line
+ 18, "%d%d%d%d", bounding_box
+ 0,
1148 bounding_box
+ 1, bounding_box
+ 2,
1149 bounding_box
+ 3) != 4)
1151 fputs("ERROR: Bad %%PageBoundingBox: comment in file!\n", stderr
);
1152 memcpy(bounding_box
, doc
->bounding_box
,
1153 sizeof(bounding_box
));
1157 else if (!strncmp(line
, "%%PageCustomColors:", 19) ||
1158 !strncmp(line
, "%%PageMedia:", 12) ||
1159 !strncmp(line
, "%%PageOrientation:", 18) ||
1160 !strncmp(line
, "%%PageProcessColors:", 20) ||
1161 !strncmp(line
, "%%PageRequirements:", 18) ||
1162 !strncmp(line
, "%%PageResources:", 16))
1169 else if (!strncmp(line
, "%%PageCustomColors:", 19))
1172 * %%PageCustomColors: ...
1175 else if (!strncmp(line
, "%%PageMedia:", 12))
1181 else if (!strncmp(line
, "%%PageOrientation:", 18))
1184 * %%PageOrientation: ...
1187 else if (!strncmp(line
, "%%PageProcessColors:", 20))
1190 * %%PageProcessColors: ...
1193 else if (!strncmp(line
, "%%PageRequirements:", 18))
1196 * %%PageRequirements: ...
1199 else if (!strncmp(line
, "%%PageResources:", 16))
1202 * %%PageResources: ...
1205 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1208 * %%IncludeFeature: *MainKeyword OptionKeyword
1211 if (doc
->number_up
== 1 &&!doc
->fitplot
)
1212 pageinfo
->num_options
= include_feature(ppd
, line
,
1213 pageinfo
->num_options
,
1214 &(pageinfo
->options
));
1216 else if (strncmp(line
, "%%Include", 9))
1220 if (doc
->number_up
== 1)
1223 * Update the document's composite and page bounding box...
1226 memcpy(pageinfo
->bounding_box
, bounding_box
,
1227 sizeof(pageinfo
->bounding_box
));
1229 if (bounding_box
[0] < doc
->new_bounding_box
[0])
1230 doc
->new_bounding_box
[0] = bounding_box
[0];
1231 if (bounding_box
[1] < doc
->new_bounding_box
[1])
1232 doc
->new_bounding_box
[1] = bounding_box
[1];
1233 if (bounding_box
[2] > doc
->new_bounding_box
[2])
1234 doc
->new_bounding_box
[2] = bounding_box
[2];
1235 if (bounding_box
[3] > doc
->new_bounding_box
[3])
1236 doc
->new_bounding_box
[3] = bounding_box
[3];
1240 * Output the page header as needed...
1243 if (!doc
->slow_order
&& first_page
)
1245 if (!ppd
|| !ppd
->num_filters
)
1246 fprintf(stderr
, "PAGE: %d %d\n", doc
->page
,
1247 doc
->slow_collate
? 1 : doc
->copies
);
1249 if (doc
->number_up
> 1)
1251 printf("%%%%Page: (%d) %d\n", doc
->page
, doc
->page
);
1252 printf("%%%%PageBoundingBox: %.0f %.0f %.0f %.0f\n",
1253 PageLeft
, PageBottom
, PageRight
, PageTop
);
1257 printf("%%%%Page: %s %d\n", pageinfo
->label
, doc
->page
);
1258 printf("%%%%PageBoundingBox: %d %d %d %d\n",
1259 pageinfo
->bounding_box
[0], pageinfo
->bounding_box
[1],
1260 pageinfo
->bounding_box
[2], pageinfo
->bounding_box
[3]);
1265 * Copy any page setup commands...
1268 if (!strncmp(line
, "%%BeginPageSetup", 16))
1271 * Copy page setup commands...
1274 doc_write(doc
, line
, linelen
);
1276 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1278 if (!strncmp(line
, "%%EndPageSetup", 14))
1280 else if (!strncmp(line
, "%%Include", 9))
1283 if (doc
->number_up
== 1 && !doc
->fitplot
)
1284 doc_write(doc
, line
, linelen
);
1288 * Skip %%EndPageSetup...
1292 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1294 if (pageinfo
->num_options
== 0)
1295 doc_puts(doc
, "%%EndPageSetup\n");
1297 else if (first_page
&& pageinfo
->num_options
> 0)
1298 doc_puts(doc
, "%%BeginPageSetup\n");
1300 if (first_page
&& pageinfo
->num_options
> 0)
1302 int i
; /* Looping var */
1303 ppd_option_t
*option
; /* PPD option */
1304 int min_order
; /* Minimum OrderDependency value */
1305 char *doc_setup
, /* DocumentSetup commands to send */
1306 *any_setup
; /* AnySetup commands to send */
1310 * Yes, figure out the minimum OrderDependency value...
1313 if ((option
= ppdFindOption(ppd
, "PageRegion")) != NULL
)
1314 min_order
= option
->order
;
1318 for (i
= 0; i
< pageinfo
->num_options
; i
++)
1319 if ((option
= ppdFindOption(ppd
, pageinfo
->options
[i
].name
)) != NULL
&&
1320 option
->order
< min_order
)
1321 min_order
= option
->order
;
1324 * Mark and extract them...
1327 cupsMarkOptions(ppd
, pageinfo
->num_options
, pageinfo
->options
);
1329 doc_setup
= ppdEmitString(ppd
, PPD_ORDER_DOCUMENT
, min_order
);
1330 any_setup
= ppdEmitString(ppd
, PPD_ORDER_ANY
, min_order
);
1333 * Then send them out...
1337 doc_puts(doc
, doc_setup
);
1340 doc_puts(doc
, any_setup
);
1343 * Free the command strings...
1352 doc_puts(doc
, "%%EndPageSetup\n");
1356 * Prep for the start of the page description...
1359 start_nup(doc
, number
, 1, bounding_box
);
1362 * Read the rest of the page description...
1370 (!strncmp(line
, "%%Page:", 7) ||
1371 !strncmp(line
, "%%Trailer:", 10) ||
1372 !strncmp(line
, "%%EOF", 5)))
1374 else if (!strncmp(line
, "%%BeginDocument", 15) ||
1375 !strncmp(line
, "%ADO_BeginApplication", 21))
1377 doc_write(doc
, line
, linelen
);
1381 else if ((!strncmp(line
, "%%EndDocument", 13) ||
1382 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
1384 doc_write(doc
, line
, linelen
);
1388 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
1389 (!strncmp(line
, "%%BeginData:", 12) &&
1390 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
1393 * Copy binary data...
1396 int bytes
; /* Bytes of data */
1399 doc_write(doc
, line
, linelen
);
1401 bytes
= atoi(strchr(line
, ':') + 1);
1405 if (bytes
> linesize
)
1406 linelen
= cupsFileRead(fp
, line
, linesize
);
1408 linelen
= cupsFileRead(fp
, line
, bytes
);
1413 perror("ERROR: Early end-of-file while reading binary data");
1417 doc_write(doc
, line
, linelen
);
1423 doc_write(doc
, line
, linelen
);
1425 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0);
1428 * Finish up this page and return...
1431 end_nup(doc
, number
);
1433 pageinfo
->length
= cupsFileTell(doc
->temp
) - pageinfo
->offset
;
1440 * 'copy_prolog()' - Copy the document prolog section...
1442 * This function expects "line" to be filled with a %%BeginProlog comment line.
1443 * On return, "line" will contain the next line in the file, if any.
1446 static size_t /* O - Length of next line */
1447 copy_prolog(cups_file_t
*fp
, /* I - File to read from */
1448 pstops_doc_t
*doc
, /* I - Document info */
1449 ppd_file_t
*ppd
, /* I - PPD file */
1450 char *line
, /* I - Line buffer */
1451 size_t linelen
, /* I - Length of initial line */
1452 size_t linesize
) /* I - Size of line buffer */
1454 while (strncmp(line
, "%%BeginProlog", 13))
1456 if (!strncmp(line
, "%%BeginSetup", 12) || !strncmp(line
, "%%Page:", 7))
1459 fwrite(line
, 1, linelen
, stdout
);
1461 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1465 puts("%%BeginProlog");
1467 do_prolog(doc
, ppd
);
1469 if (!strncmp(line
, "%%BeginProlog", 13))
1471 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
1473 if (!strncmp(line
, "%%EndProlog", 11) ||
1474 !strncmp(line
, "%%BeginSetup", 12) ||
1475 !strncmp(line
, "%%Page:", 7))
1478 fwrite(line
, 1, linelen
, stdout
);
1481 if (!strncmp(line
, "%%EndProlog", 11))
1482 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1484 fputs("ERROR: Missing %%EndProlog!\n", stderr
);
1487 puts("%%EndProlog");
1494 * 'copy_setup()' - Copy the document setup section...
1496 * This function expects "line" to be filled with a %%BeginSetup comment line.
1497 * On return, "line" will contain the next line in the file, if any.
1500 static size_t /* O - Length of next line */
1501 copy_setup(cups_file_t
*fp
, /* I - File to read from */
1502 pstops_doc_t
*doc
, /* I - Document info */
1503 ppd_file_t
*ppd
, /* I - PPD file */
1504 char *line
, /* I - Line buffer */
1505 size_t linelen
, /* I - Length of initial line */
1506 size_t linesize
) /* I - Size of line buffer */
1508 while (strncmp(line
, "%%BeginSetup", 12))
1510 if (!strncmp(line
, "%%Page:", 7))
1513 fwrite(line
, 1, linelen
, stdout
);
1515 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1519 if (!strncmp(line
, "%%BeginSetup", 12))
1521 while (strncmp(line
, "%%EndSetup", 10))
1523 if (!strncmp(line
, "%%Page:", 7))
1525 else if (!strncmp(line
, "%%IncludeFeature:", 17))
1528 * %%IncludeFeature: *MainKeyword OptionKeyword
1531 if (doc
->number_up
== 1 && !doc
->fitplot
)
1532 doc
->num_options
= include_feature(ppd
, line
, doc
->num_options
,
1536 fwrite(line
, 1, linelen
, stdout
);
1538 if ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) == 0)
1542 if (!strncmp(line
, "%%EndSetup", 10))
1543 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1545 fputs("ERROR: Missing %%EndSetup!\n", stderr
);
1548 puts("%%BeginSetup");
1559 * 'copy_trailer()' - Copy the document trailer...
1561 * This function expects "line" to be filled with a %%Trailer comment line.
1562 * On return, "line" will contain the next line in the file, if any.
1565 static size_t /* O - Length of next line */
1566 copy_trailer(cups_file_t
*fp
, /* I - File to read from */
1567 pstops_doc_t
*doc
, /* I - Document info */
1568 ppd_file_t
*ppd
, /* I - PPD file */
1569 int number
, /* I - Number of pages */
1570 char *line
, /* I - Line buffer */
1571 size_t linelen
, /* I - Length of initial line */
1572 size_t linesize
) /* I - Size of line buffer */
1575 * Write the trailer comments...
1582 if (!strncmp(line
, "%%EOF", 5))
1584 else if (strncmp(line
, "%%Trailer", 9) &&
1585 strncmp(line
, "%%Pages:", 8) &&
1586 strncmp(line
, "%%BoundingBox:", 14))
1587 fwrite(line
, 1, linelen
, stdout
);
1589 linelen
= cupsFileGetLine(fp
, line
, linesize
);
1592 fprintf(stderr
, "DEBUG: Wrote %d pages...\n", number
);
1594 printf("%%%%Pages: %d\n", number
);
1595 if (doc
->number_up
> 1 || doc
->fitplot
)
1596 printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
1597 PageLeft
, PageBottom
, PageRight
, PageTop
);
1599 printf("%%%%BoundingBox: %d %d %d %d\n",
1600 doc
->new_bounding_box
[0], doc
->new_bounding_box
[1],
1601 doc
->new_bounding_box
[2], doc
->new_bounding_box
[3]);
1608 * 'do_prolog()' - Send the necessary document prolog commands...
1612 do_prolog(pstops_doc_t
*doc
, /* I - Document information */
1613 ppd_file_t
*ppd
) /* I - PPD file */
1616 * Send the document prolog commands...
1619 if (ppd
&& ppd
->patches
)
1621 puts("%%BeginFeature: *JobPatchFile 1");
1623 puts("%%EndFeature");
1626 ppdEmit(ppd
, stdout
, PPD_ORDER_PROLOG
);
1629 * Define ESPshowpage here so that applications that define their
1630 * own procedure to do a showpage pick it up...
1633 if (doc
->use_ESPshowpage
)
1634 puts("userdict/ESPshowpage/showpage load put\n"
1635 "userdict/showpage{}put");
1641 * 'do_setup()' - Send the necessary document setup commands...
1645 do_setup(pstops_doc_t
*doc
, /* I - Document information */
1646 ppd_file_t
*ppd
) /* I - PPD file */
1649 * Mark any options from %%IncludeFeature: comments...
1652 cupsMarkOptions(ppd
, doc
->num_options
, doc
->options
);
1655 * Send all the printer-specific setup commands...
1658 ppdEmit(ppd
, stdout
, PPD_ORDER_DOCUMENT
);
1659 ppdEmit(ppd
, stdout
, PPD_ORDER_ANY
);
1662 * Set the number of copies for the job...
1665 if (doc
->copies
!= 1 && (!doc
->collate
|| !doc
->slow_collate
))
1667 printf("%%RBIBeginNonPPDFeature: *NumCopies %d\n", doc
->copies
);
1668 printf("%d/languagelevel where{pop languagelevel 2 ge}{false}ifelse\n"
1669 "{1 dict begin/NumCopies exch def currentdict end setpagedevice}\n"
1670 "{userdict/#copies 3 -1 roll put}ifelse\n", doc
->copies
);
1671 puts("%RBIEndNonPPDFeature");
1675 * If we are doing N-up printing, disable setpagedevice...
1678 if (doc
->number_up
> 1)
1679 puts("userdict/setpagedevice{pop}bind put");
1682 * Changes to the transfer function must be made AFTER any
1683 * setpagedevice code...
1686 if (doc
->gamma
!= 1.0f
|| doc
->brightness
!= 1.0f
)
1687 printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
1688 "ifelse %.3f mul } bind settransfer\n", doc
->gamma
,
1692 * Make sure we have rectclip and rectstroke procedures of some sort...
1698 * Write the page and label prologs...
1701 if (doc
->number_up
== 2 || doc
->number_up
== 6)
1704 * For 2- and 6-up output, rotate the labels to match the orientation
1708 if (Orientation
& 1)
1709 WriteLabelProlog(doc
->page_label
, PageBottom
,
1710 PageWidth
- PageLength
+ PageTop
, PageLength
);
1712 WriteLabelProlog(doc
->page_label
, PageLeft
, PageRight
, PageLength
);
1715 WriteLabelProlog(doc
->page_label
, PageBottom
, PageTop
, PageWidth
);
1720 * 'doc_printf()' - Send a formatted string to stdout and/or the temp file.
1722 * This function should be used for all page-level output that is affected
1723 * by ordering, collation, etc.
1727 doc_printf(pstops_doc_t
*doc
, /* I - Document information */
1728 const char *format
, /* I - Printf-style format string */
1729 ...) /* I - Additional arguments as needed */
1731 va_list ap
; /* Pointer to arguments */
1732 char buffer
[1024]; /* Output buffer */
1733 size_t bytes
; /* Number of bytes to write */
1736 va_start(ap
, format
);
1737 bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
1740 if (bytes
> sizeof(buffer
))
1743 "ERROR: doc_printf overflow (%d bytes) detected, aborting!\n",
1748 doc_write(doc
, buffer
, bytes
);
1753 * 'doc_puts()' - Send a nul-terminated string to stdout and/or the temp file.
1755 * This function should be used for all page-level output that is affected
1756 * by ordering, collation, etc.
1760 doc_puts(pstops_doc_t
*doc
, /* I - Document information */
1761 const char *s
) /* I - String to send */
1763 doc_write(doc
, s
, strlen(s
));
1768 * 'doc_write()' - Send data to stdout and/or the temp file.
1772 doc_write(pstops_doc_t
*doc
, /* I - Document information */
1773 const char *s
, /* I - Data to send */
1774 size_t len
) /* I - Number of bytes to send */
1776 if (!doc
->slow_order
)
1777 fwrite(s
, 1, len
, stdout
);
1780 cupsFileWrite(doc
->temp
, s
, len
);
1785 * 'end_nup()' - End processing for N-up printing...
1789 end_nup(pstops_doc_t
*doc
, /* I - Document information */
1790 int number
) /* I - Page number */
1792 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
1793 puts("userdict /ESPsave get restore");
1795 switch (doc
->number_up
)
1798 if (doc
->use_ESPshowpage
)
1800 WriteLabels(Orientation
);
1801 puts("ESPshowpage");
1807 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1809 if (Orientation
& 1)
1812 * Rotate the labels back to portrait...
1815 WriteLabels(Orientation
- 1);
1817 else if (Orientation
== 0)
1820 * Rotate the labels to landscape...
1823 WriteLabels(doc
->normal_landscape
? 1 : 3);
1828 * Rotate the labels to landscape...
1831 WriteLabels(doc
->normal_landscape
? 3 : 1);
1834 puts("ESPshowpage");
1839 if (is_last_page(number
) && doc
->use_ESPshowpage
)
1841 WriteLabels(Orientation
);
1842 puts("ESPshowpage");
1852 * 'include_feature()' - Include a printer option/feature command.
1855 static int /* O - New number of options */
1857 ppd_file_t
*ppd
, /* I - PPD file */
1858 const char *line
, /* I - DSC line */
1859 int num_options
, /* I - Number of options */
1860 cups_option_t
**options
) /* IO - Options */
1862 char name
[255], /* Option name */
1863 value
[255]; /* Option value */
1864 ppd_option_t
*option
; /* Option in file */
1865 ppd_choice_t
*choice
; /* Choice */
1869 * Get the "%%IncludeFeature: *Keyword OptionKeyword" values...
1872 if (sscanf(line
+ 17, "%254s%254s", name
, value
) != 2)
1874 fputs("ERROR: Bad %%IncludeFeature: comment!\n", stderr
);
1875 return (num_options
);
1879 * Find the option and choice...
1882 if ((option
= ppdFindOption(ppd
, name
+ 1)) == NULL
)
1884 fprintf(stderr
, "WARNING: Unknown option \"%s\"!\n", name
+ 1);
1885 return (num_options
);
1888 if (option
->section
== PPD_ORDER_EXIT
||
1889 option
->section
== PPD_ORDER_JCL
)
1891 fprintf(stderr
, "WARNING: Option \"%s\" cannot be included via "
1892 "IncludeFeature!\n", name
+ 1);
1893 return (num_options
);
1896 if ((choice
= ppdFindChoice(option
, value
)) == NULL
)
1898 fprintf(stderr
, "WARNING: Unknown choice \"%s\" for option \"%s\"!\n",
1900 return (num_options
);
1904 * Add the option to the option array and return...
1907 return (cupsAddOption(name
+ 1, value
, num_options
, options
));
1912 * 'parse_text()' - Parse a text value in a comment...
1914 * This function parses a DSC text value as defined on page 36 of the
1915 * DSC specification. Text values are either surrounded by parenthesis
1916 * or whitespace-delimited.
1918 * The value returned is the literal characters for the entire text
1919 * string, including any parenthesis and escape characters.
1922 static char * /* O - Value or NULL on error */
1923 parse_text(const char *start
, /* I - Start of text value */
1924 char **end
, /* O - End of text value */
1925 char *buffer
, /* I - Buffer */
1926 size_t bufsize
) /* I - Size of buffer */
1928 char *bufptr
, /* Pointer in buffer */
1929 *bufend
; /* End of buffer */
1930 int level
; /* Parenthesis level */
1934 * Skip leading whitespace...
1937 while (isspace(*start
& 255))
1941 * Then copy the value...
1946 bufend
= buffer
+ bufsize
- 1;
1948 while (bufptr
< bufend
)
1950 if (isspace(*start
& 255) && !level
)
1957 else if (*start
== ')')
1967 else if (*start
== '\\')
1970 * Copy escaped character...
1973 int i
; /* Looping var */
1977 i
<= 3 && isdigit(start
[i
] & 255) && bufptr
< bufend
;
1978 *bufptr
++ = start
[i
], i
++);
1987 * Return the value and new pointer into the line...
1991 *end
= (char *)start
;
1993 if (bufptr
== bufend
)
2001 * 'set_pstops_options()' - Set pstops options...
2006 pstops_doc_t
*doc
, /* I - Document information */
2007 ppd_file_t
*ppd
, /* I - PPD file */
2008 char *argv
[], /* I - Command-line arguments */
2009 int num_options
, /* I - Number of options */
2010 cups_option_t
*options
) /* I - Options */
2012 const char *val
; /* Option value */
2013 int intval
; /* Integer option value */
2014 ppd_attr_t
*attr
; /* PPD attribute */
2015 ppd_option_t
*option
; /* PPD option */
2016 ppd_choice_t
*choice
; /* PPD choice */
2020 * Initialize document information structure...
2023 memset(doc
, 0, sizeof(pstops_doc_t
));
2025 doc
->job_id
= atoi(argv
[1]);
2026 doc
->user
= argv
[2];
2027 doc
->title
= argv
[3];
2028 doc
->copies
= atoi(argv
[4]);
2030 if (ppd
&& ppd
->landscape
> 0)
2031 doc
->normal_landscape
= 1;
2033 doc
->bounding_box
[0] = (int)PageLeft
;
2034 doc
->bounding_box
[1] = (int)PageBottom
;
2035 doc
->bounding_box
[2] = (int)PageRight
;
2036 doc
->bounding_box
[3] = (int)PageTop
;
2038 doc
->new_bounding_box
[0] = INT_MAX
;
2039 doc
->new_bounding_box
[1] = INT_MAX
;
2040 doc
->new_bounding_box
[2] = INT_MIN
;
2041 doc
->new_bounding_box
[3] = INT_MIN
;
2044 * AP_FIRSTPAGE_InputSlot
2047 doc
->ap_input_slot
= cupsGetOption("AP_FIRSTPAGE_InputSlot", num_options
,
2051 * AP_FIRSTPAGE_ManualFeed
2054 doc
->ap_manual_feed
= cupsGetOption("AP_FIRSTPAGE_ManualFeed", num_options
,
2061 if ((val
= cupsGetOption("brightness", num_options
, options
)) != NULL
)
2064 * Get brightness value from 10 to 1000.
2069 if (intval
< 10 || intval
> 1000)
2071 fprintf(stderr
, "ERROR: Unsupported brightness value %s, using "
2072 "brightness=100!\n", val
);
2073 doc
->brightness
= 1.0f
;
2076 doc
->brightness
= intval
* 0.01f
;
2079 doc
->brightness
= 1.0f
;
2082 * collate, multiple-document-handling
2085 if ((val
= cupsGetOption("multiple-document-handling", num_options
, options
)) != NULL
)
2088 * This IPP attribute is unnecessarily complicated...
2090 * single-document, separate-documents-collated-copies, and
2091 * single-document-new-sheet all require collated copies.
2093 * separate-documents-uncollated-copies allows for uncollated copies.
2096 doc
->collate
= strcasecmp(val
, "separate-documents-uncollated-copies") != 0;
2099 if ((val
= cupsGetOption("Collate", num_options
, options
)) != NULL
&&
2100 (!strcasecmp(val
, "true") ||!strcasecmp(val
, "on") ||
2101 !strcasecmp(val
, "yes")))
2108 if ((val
= cupsGetOption("emit-jcl", num_options
, options
)) != NULL
&&
2109 (!strcasecmp(val
, "false") || !strcasecmp(val
, "off") ||
2110 !strcasecmp(val
, "no") || !strcmp(val
, "0")))
2119 if ((val
= cupsGetOption("fitplot", num_options
, options
)) != NULL
&&
2120 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2121 !strcasecmp(val
, "yes")))
2128 if ((val
= cupsGetOption("gamma", num_options
, options
)) != NULL
)
2131 * Get gamma value from 1 to 10000...
2136 if (intval
< 1 || intval
> 10000)
2138 fprintf(stderr
, "ERROR: Unsupported gamma value %s, using "
2139 "gamma=1000!\n", val
);
2143 doc
->gamma
= intval
* 0.001f
;
2152 if ((choice
= ppdFindMarkedChoice(ppd
, "InputSlot")) != NULL
)
2153 doc
->input_slot
= choice
->choice
;
2159 if ((choice
= ppdFindMarkedChoice(ppd
, "ManualFeed")) != NULL
)
2160 doc
->manual_feed
= choice
->choice
;
2162 if ((val
= cupsGetOption("mirror", num_options
, options
)) != NULL
&&
2163 (!strcasecmp(val
, "true") || !strcasecmp(val
, "on") ||
2164 !strcasecmp(val
, "yes")))
2171 if ((val
= cupsGetOption("number-up", num_options
, options
)) != NULL
)
2173 switch (intval
= atoi(val
))
2181 doc
->number_up
= intval
;
2185 "ERROR: Unsupported number-up value %d, using number-up=1!\n",
2198 if ((val
= cupsGetOption("number-up-layout", num_options
, options
)) != NULL
)
2200 if (!strcasecmp(val
, "lrtb"))
2201 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2202 else if (!strcasecmp(val
, "lrbt"))
2203 doc
->number_up_layout
= PSTOPS_LAYOUT_LRBT
;
2204 else if (!strcasecmp(val
, "rltb"))
2205 doc
->number_up_layout
= PSTOPS_LAYOUT_RLTB
;
2206 else if (!strcasecmp(val
, "rlbt"))
2207 doc
->number_up_layout
= PSTOPS_LAYOUT_RLBT
;
2208 else if (!strcasecmp(val
, "tblr"))
2209 doc
->number_up_layout
= PSTOPS_LAYOUT_TBLR
;
2210 else if (!strcasecmp(val
, "tbrl"))
2211 doc
->number_up_layout
= PSTOPS_LAYOUT_TBRL
;
2212 else if (!strcasecmp(val
, "btlr"))
2213 doc
->number_up_layout
= PSTOPS_LAYOUT_BTLR
;
2214 else if (!strcasecmp(val
, "btrl"))
2215 doc
->number_up_layout
= PSTOPS_LAYOUT_BTRL
;
2218 fprintf(stderr
, "ERROR: Unsupported number-up-layout value %s, using "
2219 "number-up-layout=lrtb!\n", val
);
2220 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2224 doc
->number_up_layout
= PSTOPS_LAYOUT_LRTB
;
2230 if ((val
= cupsGetOption("OutputOrder", num_options
, options
)) != NULL
)
2232 if (!strcasecmp(val
, "Reverse"))
2233 doc
->output_order
= 1;
2238 * Figure out the right default output order from the PPD file...
2241 if ((choice
= ppdFindMarkedChoice(ppd
, "OutputBin")) != NULL
&&
2242 (attr
= ppdFindAttr(ppd
, "PageStackOrder", choice
->choice
)) != NULL
&&
2244 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2245 else if ((attr
= ppdFindAttr(ppd
, "DefaultOutputOrder", NULL
)) != NULL
&&
2247 doc
->output_order
= !strcasecmp(attr
->value
, "Reverse");
2254 if ((val
= cupsGetOption("page-border", num_options
, options
)) != NULL
)
2256 if (!strcasecmp(val
, "none"))
2257 doc
->page_border
= PSTOPS_BORDERNONE
;
2258 else if (!strcasecmp(val
, "single"))
2259 doc
->page_border
= PSTOPS_BORDERSINGLE
;
2260 else if (!strcasecmp(val
, "single-thick"))
2261 doc
->page_border
= PSTOPS_BORDERSINGLE2
;
2262 else if (!strcasecmp(val
, "double"))
2263 doc
->page_border
= PSTOPS_BORDERDOUBLE
;
2264 else if (!strcasecmp(val
, "double-thick"))
2265 doc
->page_border
= PSTOPS_BORDERDOUBLE2
;
2268 fprintf(stderr
, "ERROR: Unsupported page-border value %s, using "
2269 "page-border=none!\n", val
);
2270 doc
->page_border
= PSTOPS_BORDERNONE
;
2274 doc
->page_border
= PSTOPS_BORDERNONE
;
2280 doc
->page_label
= cupsGetOption("page-label", num_options
, options
);
2286 doc
->page_ranges
= cupsGetOption("page-ranges", num_options
, options
);
2292 doc
->page_set
= cupsGetOption("page-set", num_options
, options
);
2295 * Now figure out if we have to force collated copies, etc.
2298 if (ppd
&& ppd
->manual_copies
&& Duplex
&& doc
->copies
> 1)
2301 * Force collated copies when printing a duplexed document to
2302 * a non-PS printer that doesn't do hardware copy generation.
2303 * Otherwise the copies will end up on the front/back side of
2311 * See if we have to filter the fast or slow way...
2314 if (doc
->collate
&& doc
->copies
> 1)
2317 * See if we need to manually collate the pages...
2320 doc
->slow_collate
= 1;
2322 if ((choice
= ppdFindMarkedChoice(ppd
, "Collate")) != NULL
&&
2323 !strcasecmp(choice
->choice
, "True"))
2326 * Hardware collate option is selected, see if the option is
2327 * conflicting - if not, collate in hardware. Otherwise,
2328 * turn the hardware collate option off...
2331 if ((option
= ppdFindOption(ppd
, "Option")) != NULL
&&
2332 !option
->conflicted
)
2333 doc
->slow_collate
= 0;
2335 ppdMarkOption(ppd
, "Collate", "False");
2339 doc
->slow_collate
= 0;
2341 if (!ppdFindOption(ppd
, "OutputOrder") && doc
->output_order
)
2342 doc
->slow_order
= 1;
2344 doc
->slow_order
= 0;
2346 if ((doc
->slow_collate
|| doc
->slow_order
) && Duplex
)
2347 doc
->slow_duplex
= 1;
2349 doc
->slow_duplex
= 0;
2352 * Create a temporary file for page data if we need to filter slowly...
2355 if (doc
->slow_order
|| doc
->slow_collate
)
2357 if ((doc
->temp
= cupsTempFile2(doc
->tempfile
,
2358 sizeof(doc
->tempfile
))) == NULL
)
2360 fprintf(stderr
, "ERROR: Unable to create temporary file: %s\n",
2367 * Figure out if we should use ESPshowpage or not...
2370 if (doc
->page_label
|| getenv("CLASSIFICATION") || doc
->number_up
> 1 ||
2374 * Yes, use ESPshowpage...
2377 doc
->use_ESPshowpage
= 1;
2380 fprintf(stderr
, "DEBUG: slow_collate=%d, slow_duplex=%d, slow_order=%d\n",
2381 doc
->slow_collate
, doc
->slow_duplex
, doc
->slow_order
);
2386 * 'skip_page()' - Skip past a page that won't be printed...
2389 static size_t /* O - Length of next line */
2390 skip_page(cups_file_t
*fp
, /* I - File to read from */
2391 char *line
, /* I - Line buffer */
2392 size_t linelen
, /* I - Length of initial line */
2393 size_t linesize
) /* I - Size of line buffer */
2395 int level
; /* Embedded document level */
2400 while ((linelen
= cupsFileGetLine(fp
, line
, linesize
)) > 0)
2403 (!strncmp(line
, "%%Page:", 7) || !strncmp(line
, "%%Trailer:", 10)))
2405 else if (!strncmp(line
, "%%BeginDocument", 15) ||
2406 !strncmp(line
, "%ADO_BeginApplication", 21))
2408 else if ((!strncmp(line
, "%%EndDocument", 13) ||
2409 !strncmp(line
, "%ADO_EndApplication", 19)) && level
> 0)
2411 else if (!strncmp(line
, "%%BeginBinary:", 14) ||
2412 (!strncmp(line
, "%%BeginData:", 12) &&
2413 !strstr(line
, "ASCII") && !strstr(line
, "Hex")))
2416 * Skip binary data...
2419 int bytes
; /* Bytes of data */
2422 bytes
= atoi(strchr(line
, ':') + 1);
2426 if (bytes
> linesize
)
2427 linelen
= cupsFileRead(fp
, line
, linesize
);
2429 linelen
= cupsFileRead(fp
, line
, bytes
);
2434 perror("ERROR: Early end-of-file while reading binary data");
2448 * 'start_nup()' - Start processing for N-up printing...
2452 start_nup(pstops_doc_t
*doc
, /* I - Document information */
2453 int number
, /* I - Page number */
2454 int show_border
, /* I - Show the border? */
2455 const int *bounding_box
) /* I - BoundingBox value */
2457 int pos
; /* Position on page */
2458 int x
, y
; /* Relative position of subpage */
2459 float w
, l
, /* Width and length of subpage */
2460 tx
, ty
; /* Translation values for subpage */
2461 float pagew
, /* Printable width of page */
2462 pagel
; /* Printable height of page */
2463 int bboxw
, /* BoundingBox width */
2464 bboxl
; /* BoundingBox height */
2467 if (doc
->mirror
|| Orientation
|| doc
->number_up
> 1)
2468 doc_puts(doc
, "userdict/ESPsave save put\n");
2471 doc_printf(doc
, "%.1f 0.0 translate -1 1 scale\n", PageWidth
);
2473 pos
= (number
- 1) % doc
->number_up
;
2474 pagew
= PageRight
- PageLeft
;
2475 pagel
= PageTop
- PageBottom
;
2479 bboxw
= bounding_box
[2] - bounding_box
[0];
2480 bboxl
= bounding_box
[3] - bounding_box
[1];
2488 fprintf(stderr
, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew
, pagel
);
2489 fprintf(stderr
, "DEBUG: bboxw = %d, bboxl = %d\n", bboxw
, bboxl
);
2490 fprintf(stderr
, "DEBUG: PageLeft = %.1f, PageRight = %.1f\n",
2491 PageLeft
, PageRight
);
2492 fprintf(stderr
, "DEBUG: PageTop = %.1f, PageBottom = %.1f\n",
2493 PageTop
, PageBottom
);
2494 fprintf(stderr
, "DEBUG: PageWidth = %.1f, PageLength = %.1f\n",
2495 PageWidth
, PageLength
);
2497 switch (Orientation
)
2499 case 1 : /* Landscape */
2500 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", PageLength
);
2502 case 2 : /* Reverse Portrait */
2503 doc_printf(doc
, "%.1f %.1f translate 180 rotate\n", PageWidth
,
2506 case 3 : /* Reverse Landscape */
2507 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", PageWidth
);
2511 if (Duplex
&& doc
->number_up
> 1 && ((number
/ doc
->number_up
) & 1))
2512 doc_printf(doc
, "%.1f %.1f translate\n", PageWidth
- PageRight
, PageBottom
);
2513 else if (doc
->number_up
> 1 || doc
->fitplot
)
2514 doc_printf(doc
, "%.1f %.1f translate\n", PageLeft
, PageBottom
);
2516 switch (doc
->number_up
)
2522 l
= w
* bboxl
/ bboxw
;
2527 w
= l
* bboxw
/ bboxl
;
2530 tx
= 0.5 * (pagew
- w
);
2531 ty
= 0.5 * (pagel
- l
);
2533 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n", tx
, ty
,
2534 w
/ bboxw
, l
/ bboxl
);
2544 if (Orientation
& 1)
2548 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2552 l
= w
* bboxl
/ bboxw
;
2554 if (l
> (pagew
* 0.5))
2557 w
= l
* bboxw
/ bboxl
;
2560 tx
= 0.5 * (pagew
* 0.5 - l
);
2561 ty
= 0.5 * (pagel
- w
);
2563 if (doc
->normal_landscape
)
2564 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2566 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2568 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2569 ty
, tx
+ pagew
* 0.5 * x
, w
/ bboxw
, l
/ bboxl
);
2575 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2579 w
= l
* bboxw
/ bboxl
;
2581 if (w
> (pagel
* 0.5))
2584 l
= w
* bboxl
/ bboxw
;
2587 tx
= 0.5 * (pagel
* 0.5 - w
);
2588 ty
= 0.5 * (pagew
- l
);
2590 if (doc
->normal_landscape
)
2591 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2593 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2595 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2596 tx
+ pagel
* 0.5 * x
, ty
, w
/ bboxw
, l
/ bboxl
);
2601 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2612 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2615 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2619 l
= w
* bboxl
/ bboxw
;
2621 if (l
> (pagel
* 0.5))
2624 w
= l
* bboxw
/ bboxl
;
2627 tx
= 0.5 * (pagew
* 0.5 - w
);
2628 ty
= 0.5 * (pagel
* 0.5 - l
);
2630 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2631 tx
+ x
* pagew
* 0.5, ty
+ y
* pagel
* 0.5,
2632 w
/ bboxw
, l
/ bboxl
);
2636 if (Orientation
& 1)
2638 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2643 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2646 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2654 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2657 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2662 l
= w
* bboxl
/ bboxw
;
2664 if (l
> (pagew
* 0.333))
2667 w
= l
* bboxw
/ bboxl
;
2670 tx
= 0.5 * (pagel
- 2 * w
);
2671 ty
= 0.5 * (pagew
- 3 * l
);
2673 if (doc
->normal_landscape
)
2674 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2676 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2678 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2679 tx
+ x
* y
* pagel
* 0.5, ty
+ pagew
* 0.333,
2680 w
/ bboxw
, l
/ bboxl
);
2684 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2689 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2692 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2700 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2703 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2708 w
= l
* bboxw
/ bboxl
;
2710 if (w
> (pagel
* 0.333))
2713 l
= w
* bboxl
/ bboxw
;
2716 tx
= 0.5 * (pagel
- 3 * w
);
2717 ty
= 0.5 * (pagew
- 2 * l
);
2719 if (doc
->normal_landscape
)
2720 doc_printf(doc
, "%.1f 0.0 translate 90 rotate\n", pagew
);
2722 doc_printf(doc
, "0.0 %.1f translate -90 rotate\n", pagel
);
2724 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2725 tx
+ x
* pagel
* 0.333, ty
+ y
* pagew
* 0.5,
2726 w
/ bboxw
, l
/ bboxl
);
2731 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2742 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2745 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2749 l
= w
* bboxl
/ bboxw
;
2751 if (l
> (pagel
* 0.333))
2754 w
= l
* bboxw
/ bboxl
;
2757 tx
= 0.5 * (pagew
* 0.333 - w
);
2758 ty
= 0.5 * (pagel
* 0.333 - l
);
2760 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2761 tx
+ x
* pagew
* 0.333, ty
+ y
* pagel
* 0.333,
2762 w
/ bboxw
, l
/ bboxl
);
2766 if (doc
->number_up_layout
& PSTOPS_LAYOUT_VERTICAL
)
2777 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEX
)
2780 if (doc
->number_up_layout
& PSTOPS_LAYOUT_NEGATEY
)
2784 l
= w
* bboxl
/ bboxw
;
2786 if (l
> (pagel
* 0.25))
2789 w
= l
* bboxw
/ bboxl
;
2792 tx
= 0.5 * (pagew
* 0.25 - w
);
2793 ty
= 0.5 * (pagel
* 0.25 - l
);
2795 doc_printf(doc
, "%.1f %.1f translate %.3f %.3f scale\n",
2796 tx
+ x
* pagew
* 0.25, ty
+ y
* pagel
* 0.25,
2797 w
/ bboxw
, l
/ bboxl
);
2802 * Draw borders as necessary...
2805 if (doc
->page_border
&& show_border
)
2807 int rects
; /* Number of border rectangles */
2808 float fscale
, /* Scaling value for points */
2809 margin
; /* Current margin for borders */
2812 rects
= (doc
->page_border
& PSTOPS_BORDERDOUBLE
) ? 2 : 1;
2813 fscale
= PageWidth
/ w
;
2814 margin
= 2.25 * fscale
;
2817 * Set the line width and color...
2820 doc_puts(doc
, "gsave\n");
2821 doc_printf(doc
, "%.3f setlinewidth 0 setgray newpath\n",
2822 (doc
->page_border
& PSTOPS_BORDERTHICK
) ? 0.5 * fscale
:
2826 * Draw border boxes...
2829 for (; rects
> 0; rects
--, margin
+= 2 * fscale
)
2830 if (doc
->number_up
> 1)
2831 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2832 margin
- 2.25 * fscale
,
2833 margin
- 2.25 * fscale
,
2834 bboxw
+ 4.5 * fscale
- 2 * margin
,
2835 bboxl
+ 4.5 * fscale
- 2 * margin
);
2837 doc_printf(doc
, "%.1f %.1f %.1f %.1f ESPrs\n",
2839 PageBottom
+ margin
,
2840 PageRight
- PageLeft
- 2 * margin
,
2841 PageTop
- PageBottom
- 2 * margin
);
2844 * Restore pen settings...
2847 doc_puts(doc
, "grestore\n");
2853 * Clip the page that follows to the bounding box of the page...
2856 doc_printf(doc
, "%d %d translate\n", -bounding_box
[0],
2858 doc_printf(doc
, "%d %d %d %d ESPrc\n", bounding_box
[0], bounding_box
[1],
2861 else if (doc
->number_up
> 1)
2864 * Clip the page that follows to the default page size...
2867 doc_printf(doc
, "0 0 %d %d ESPrc\n", bboxw
, bboxl
);
2873 * End of "$Id: pstops.c 5326 2006-03-23 19:33:35Z mike $".