3 * Boundingbox code for PostScript translators. The boundingbox for each page
4 * is accumulated in bbox - the one for the whole document goes in docbbox. A
5 * call to writebbox() puts out an appropriate comment, updates docbbox, and
6 * resets bbox for the next page. The assumption made at the end of writebbox()
7 * is that we're really printing the current page only if output is now going
8 * to stdout - a valid assumption for all supplied translators. Needs the math
16 #include <sys/types.h>
20 #include "comments.h" /* PostScript file structuring comments */
21 #include "gen.h" /* a few general purpose definitions */
22 #include "ext.h" /* external variable declarations */
30 Bbox bbox = {FALSE, 0.0, 0.0, 0.0, 0.0};
31 Bbox docbbox = {FALSE, 0.0, 0.0, 0.0, 0.0};
33 double ctm[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
34 double matrix1[6], matrix2[6];
36 /*****************************************************************************/
47 * Adds point (x, y) to bbox. Coordinates are in user space - the transformation
48 * to default coordinates happens in writebbox().
52 if ( bbox.set == FALSE ) {
53 bbox.llx = bbox.urx = x;
54 bbox.lly = bbox.ury = y;
69 /*****************************************************************************/
73 writebbox(fp, keyword, slop)
75 FILE *fp; /* the comment is written here */
76 char *keyword; /* the boundingbox comment string */
77 int slop; /* expand (or contract?) the box a bit */
81 Bbox ubbox; /* user space bounding box */
86 * Transforms the numbers in the bbox[] using ctm[], adjusts the corners a bit
87 * (depending on slop) and then writes comment. If *keyword is BoundingBox use
88 * whatever's been saved in docbbox, otherwise assume the comment is just for
93 if ( strcmp(keyword, BOUNDINGBOX) == 0 )
96 if ( bbox.set == TRUE ) {
98 bbox.set = FALSE; /* so cover() works properly */
99 x = ctm[0] * ubbox.llx + ctm[2] * ubbox.lly + ctm[4];
100 y = ctm[1] * ubbox.llx + ctm[3] * ubbox.lly + ctm[5];
102 x = ctm[0] * ubbox.llx + ctm[2] * ubbox.ury + ctm[4];
103 y = ctm[1] * ubbox.llx + ctm[3] * ubbox.ury + ctm[5];
105 x = ctm[0] * ubbox.urx + ctm[2] * ubbox.ury + ctm[4];
106 y = ctm[1] * ubbox.urx + ctm[3] * ubbox.ury + ctm[5];
108 x = ctm[0] * ubbox.urx + ctm[2] * ubbox.lly + ctm[4];
109 y = ctm[1] * ubbox.urx + ctm[3] * ubbox.lly + ctm[5];
111 bbox.llx -= slop + 0.5;
112 bbox.lly -= slop + 0.5;
113 bbox.urx += slop + 0.5;
114 bbox.ury += slop + 0.5;
115 fprintf(fp, "%s %d %d %d %d\n", keyword, (int)bbox.llx, (int)bbox.lly,(int)bbox.urx, (int)bbox.ury);
119 resetbbox((fp == stdout) ? TRUE : FALSE);
121 } /* End of writebbox */
123 /*****************************************************************************/
133 * Adds bbox to docbbox and resets bbox for the next page. Only update docbbox
134 * if we really did output on the last page.
138 if ( docbbox.set == TRUE ) {
139 cover(docbbox.llx, docbbox.lly);
140 cover(docbbox.urx, docbbox.ury);
143 if ( output == TRUE ) {
150 } /* End of resetbbox */
152 /*****************************************************************************/
162 * Scales the default matrix.
177 /*****************************************************************************/
187 * Translates the default matrix.
200 } /* End of translate */
202 /*****************************************************************************/
212 * Rotates by angle degrees.
216 angle *= 3.1416 / 180;
218 matrix1[0] = matrix1[3] = cos(angle);
219 matrix1[1] = sin(angle);
220 matrix1[2] = -matrix1[1];
226 } /* End of rotate */
228 /*****************************************************************************/
241 * Replaces the ctm[] by the result of the matrix multiplication m1[] x ctm[].
252 ctm[0] = m1[0] * m2[0] + m1[1] * m2[2];
253 ctm[1] = m1[0] * m2[1] + m1[1] * m2[3];
254 ctm[2] = m1[2] * m2[0] + m1[3] * m2[2];
255 ctm[3] = m1[2] * m2[1] + m1[3] * m2[3];
256 ctm[4] = m1[4] * m2[0] + m1[5] * m2[2] + m2[4];
257 ctm[5] = m1[4] * m2[1] + m1[5] * m2[3] + m2[5];
259 } /* End of concat */
261 /*****************************************************************************/