17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22f928ce67Sceastha /*
23f928ce67Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24f928ce67Sceastha * Use is subject to license terms.
25f928ce67Sceastha */
26f928ce67Sceastha
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate * Drawing routines used by dpost. Almost no real work is done here. Instead
437c478bd9Sstevel@tonic-gate * the required calculations are done in special Postscript procedures that
447c478bd9Sstevel@tonic-gate * include:
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate *
477c478bd9Sstevel@tonic-gate * Dl
487c478bd9Sstevel@tonic-gate *
497c478bd9Sstevel@tonic-gate * x1 y1 x y Dl -
507c478bd9Sstevel@tonic-gate *
517c478bd9Sstevel@tonic-gate * Starts a new path and then draws a line from the current point
527c478bd9Sstevel@tonic-gate * (x, y) to (x1, y1).
537c478bd9Sstevel@tonic-gate *
547c478bd9Sstevel@tonic-gate * De
557c478bd9Sstevel@tonic-gate *
567c478bd9Sstevel@tonic-gate * x y a b De -
577c478bd9Sstevel@tonic-gate *
587c478bd9Sstevel@tonic-gate * Starts a new path and then draws an ellipse that has its left side
597c478bd9Sstevel@tonic-gate * at the current point (x, y) and horizontal and vertical axes lengths
607c478bd9Sstevel@tonic-gate * given by a and b respectively.
617c478bd9Sstevel@tonic-gate *
627c478bd9Sstevel@tonic-gate * Da
637c478bd9Sstevel@tonic-gate *
647c478bd9Sstevel@tonic-gate * x y dx1 dy1 dx2 dy2 Da -
657c478bd9Sstevel@tonic-gate *
667c478bd9Sstevel@tonic-gate * Starts a new segment and then draws a circular arc from the current
677c478bd9Sstevel@tonic-gate * point (x, y) to (x + dx1 + dx2, y + dy1 + dy2). The center of the
687c478bd9Sstevel@tonic-gate * circle is at (x + dx1, y + dy1). Arcs always go counter-clockwise
697c478bd9Sstevel@tonic-gate * from the starting point to the end point.
707c478bd9Sstevel@tonic-gate *
717c478bd9Sstevel@tonic-gate * DA
727c478bd9Sstevel@tonic-gate *
737c478bd9Sstevel@tonic-gate * x y dx1 dy1 dx2 dy2 DA -
747c478bd9Sstevel@tonic-gate *
757c478bd9Sstevel@tonic-gate * Draws a clockwise arc from (x, y) to (x + dx1 + dx2, y + dy1 + dy2)
767c478bd9Sstevel@tonic-gate * with center at (x + dx1, y + dy1). Only needed when we're building
777c478bd9Sstevel@tonic-gate * large paths that use arcs and want to control the current point. The
787c478bd9Sstevel@tonic-gate * arguments passed to drawarc() will be whatever they would have been
797c478bd9Sstevel@tonic-gate * for a counter-clockwise arc, so we need to map them into appropriate
807c478bd9Sstevel@tonic-gate * arguments for PostScript's arcn operator. The mapping is,
817c478bd9Sstevel@tonic-gate *
827c478bd9Sstevel@tonic-gate * x = hpos + dx1' + dx2'
837c478bd9Sstevel@tonic-gate * y = vpos + dy1' + dy2'
847c478bd9Sstevel@tonic-gate * dx1 = -dx2'
857c478bd9Sstevel@tonic-gate * dy1 = -dy2'
867c478bd9Sstevel@tonic-gate * dx2 = -dx1'
877c478bd9Sstevel@tonic-gate * dy2 = -dy1'
887c478bd9Sstevel@tonic-gate *
897c478bd9Sstevel@tonic-gate * where primed values represent the drawarc() arguments and (hpos, vpos)
907c478bd9Sstevel@tonic-gate * is our current position.
917c478bd9Sstevel@tonic-gate *
927c478bd9Sstevel@tonic-gate * Ds
937c478bd9Sstevel@tonic-gate *
947c478bd9Sstevel@tonic-gate * x0 y0 x1 y1 x2 y2 Ds -
957c478bd9Sstevel@tonic-gate *
967c478bd9Sstevel@tonic-gate * Starts a new segment and then draws a quadratic spline connecting
977c478bd9Sstevel@tonic-gate * point ((x0 + x1)/2, (y0 + y1)/2) to ((x1 + x2)/2, (y1 + y2)/2).
987c478bd9Sstevel@tonic-gate * The points used in Postscript's curveto procedure are given by,
997c478bd9Sstevel@tonic-gate *
1007c478bd9Sstevel@tonic-gate * x0' = (x0 + 5 * x1) / 6
1017c478bd9Sstevel@tonic-gate * x1' = (x2 + 5 * x1) / 6
1027c478bd9Sstevel@tonic-gate * x2' = (x1 + x2) / 2
1037c478bd9Sstevel@tonic-gate *
1047c478bd9Sstevel@tonic-gate * with similar equations for the y coordinates.
1057c478bd9Sstevel@tonic-gate *
1067c478bd9Sstevel@tonic-gate * By default all the PostScript drawing procedures begin with a newpath (just to
1077c478bd9Sstevel@tonic-gate * be safe) and end with a stroke, which essentially isolates the path elements
1087c478bd9Sstevel@tonic-gate * built by the drawing procedures. In order to accommodate big paths built from
1097c478bd9Sstevel@tonic-gate * smaller pieces each of the PostScript drawing procedures can forced to retain
1107c478bd9Sstevel@tonic-gate * the path that's being built. That's what happens in beginpath() when an "x X
1117c478bd9Sstevel@tonic-gate * BeginPath" command is read. beginpath() sets the PostScript variable inpath to
1127c478bd9Sstevel@tonic-gate * true, and that essentially eliminates the newpath/stroke pair that bracket the
1137c478bd9Sstevel@tonic-gate * individual pieces. In that case the path is terminated and drawn when dpost
1147c478bd9Sstevel@tonic-gate * reads an "x X DrawPath" command.
1157c478bd9Sstevel@tonic-gate *
1167c478bd9Sstevel@tonic-gate * Early versions of dpost included the PostScript drawing procedures as part of
1177c478bd9Sstevel@tonic-gate * the prologue, and as a result they were included with every job, even if they
1187c478bd9Sstevel@tonic-gate * were never used. This version has separated the drawing procedures from the
1197c478bd9Sstevel@tonic-gate * default prologue (they're now in *drawfile) and only includes them if they're
1207c478bd9Sstevel@tonic-gate * really needed, which is yet another convenient violation of page independence.
1217c478bd9Sstevel@tonic-gate * Routine getdraw() is responsible for adding *drawfile to the output file, and
1227c478bd9Sstevel@tonic-gate * if it can't read *drawfile it continues on as if nothing happened. That means
1237c478bd9Sstevel@tonic-gate * everything should still work if you append *drawfile to *prologue and then
1247c478bd9Sstevel@tonic-gate * delete *drawfile.
1257c478bd9Sstevel@tonic-gate *
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate #include <stdio.h>
1307c478bd9Sstevel@tonic-gate #include <math.h>
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate #include "gen.h" /* general purpose definitions */
1337c478bd9Sstevel@tonic-gate #include "ext.h" /* external variable definitions */
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate int gotdraw = FALSE; /* TRUE when *drawfile has been added */
1377c478bd9Sstevel@tonic-gate int gotbaseline = FALSE; /* TRUE after *baselinefile is added */
1387c478bd9Sstevel@tonic-gate int inpath = FALSE; /* TRUE if we're putting pieces together */
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate *
1437c478bd9Sstevel@tonic-gate * All these should be defined in file dpost.c.
1447c478bd9Sstevel@tonic-gate *
1457c478bd9Sstevel@tonic-gate */
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate extern int hpos;
1497c478bd9Sstevel@tonic-gate extern int vpos;
1507c478bd9Sstevel@tonic-gate extern int encoding;
1517c478bd9Sstevel@tonic-gate extern int maxencoding;
1527c478bd9Sstevel@tonic-gate extern int realencoding;
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate extern char *drawfile;
1557c478bd9Sstevel@tonic-gate extern char *baselinefile;
1567c478bd9Sstevel@tonic-gate extern FILE *tf;
1577c478bd9Sstevel@tonic-gate
158f928ce67Sceastha void drawcirc(int);
159f928ce67Sceastha void drawellip(int, int);
160f928ce67Sceastha static void parsebuf(char *);
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate /*****************************************************************************/
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate
165f928ce67Sceastha void
getdraw(void)166f928ce67Sceastha getdraw(void)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate *
1727c478bd9Sstevel@tonic-gate * Responsible for making sure the PostScript drawing procedures are downloaded
1737c478bd9Sstevel@tonic-gate * from *drawfile. Stuff is done at most once per job, and only if the job needs
1747c478bd9Sstevel@tonic-gate * them. For now I've decided not to quit if we can't read the drawing file. That
1757c478bd9Sstevel@tonic-gate * pretty much assumes an old version of prologue is being used that includes all
1767c478bd9Sstevel@tonic-gate * the drawing procedures.
1777c478bd9Sstevel@tonic-gate *
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate if ( gotdraw == FALSE && access(drawfile, 04) == 0 )
1827c478bd9Sstevel@tonic-gate doglobal(drawfile);
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate if ( tf == stdout )
1857c478bd9Sstevel@tonic-gate gotdraw = TRUE;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate } /* End of getdraw */
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /*****************************************************************************/
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate
193f928ce67Sceastha void
drawline(int dx,int dy)194f928ce67Sceastha drawline(int dx, int dy)
195f928ce67Sceastha /* endpoint is (hpos+dx, vpos+dy) */
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate *
2007c478bd9Sstevel@tonic-gate * Draws a line from (hpos, vpos) to (hpos+dx, vpos+dy), and leaves the current
2017c478bd9Sstevel@tonic-gate * position at the endpoint.
2027c478bd9Sstevel@tonic-gate *
2037c478bd9Sstevel@tonic-gate */
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate if ( dx == 0 && dy == 0 )
2077c478bd9Sstevel@tonic-gate drawcirc(1);
2087c478bd9Sstevel@tonic-gate else fprintf(tf, "%d %d %d %d Dl\n", hpos + dx, vpos + dy, hpos, vpos);
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate hgoto(hpos+dx); /* where troff expects to be */
2117c478bd9Sstevel@tonic-gate vgoto(vpos+dy);
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate resetpos(); /* not sure where the printer is */
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate } /* End of drawline */
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate /*****************************************************************************/
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate
221f928ce67Sceastha void
drawcirc(int d)222f928ce67Sceastha drawcirc(int d)
223f928ce67Sceastha /* diameter of the circle */
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /*
2277c478bd9Sstevel@tonic-gate *
2287c478bd9Sstevel@tonic-gate * Draws a circle of diameter d with the left 'side' of the circle at the
2297c478bd9Sstevel@tonic-gate * current point. After we're finished drawing we move the current position
2307c478bd9Sstevel@tonic-gate * to the right side.
2317c478bd9Sstevel@tonic-gate *
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate drawellip(d, d);
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate } /* End of drawcirc */
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*****************************************************************************/
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate
242f928ce67Sceastha void
drawellip(int a,int b)243f928ce67Sceastha drawellip(int a, int b)
244f928ce67Sceastha /* axes lengths for the ellipse */
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate *
2497c478bd9Sstevel@tonic-gate * Draws an ellipse having axes lengths horizontally and vertically of a and
2507c478bd9Sstevel@tonic-gate * b. The left side of the ellipse is at the current point. After we're done
2517c478bd9Sstevel@tonic-gate * drawing the path we move the current position to the right side.
2527c478bd9Sstevel@tonic-gate *
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate if ( a == 0 && b == 0 )
2577c478bd9Sstevel@tonic-gate return;
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate fprintf(tf, "%d %d %d %d De\n", hpos, vpos, a, b);
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate hgoto(hpos + a); /* where troff expects to be */
2627c478bd9Sstevel@tonic-gate vgoto(vpos);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate resetpos(); /* not sure where the printer is */
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate } /* End of drawellip */
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate /*****************************************************************************/
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate
272f928ce67Sceastha void
drawarc(int dx1,int dy1,int dx2,int dy2,int c)273f928ce67Sceastha drawarc(int dx1, int dy1, int dx2, int dy2, int c)
274f928ce67Sceastha /* dx1, dy1 - vector from current pos to center */
275f928ce67Sceastha /* dx2, dy2 - from center to end of the arc */
276f928ce67Sceastha /* c - clockwise if c is A */
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate *
2817c478bd9Sstevel@tonic-gate * If c isn't set to 'A' a counter-clockwise arc is drawn from the current point
2827c478bd9Sstevel@tonic-gate * (hpos, vpos) to (hpos+dx1+dx2, vpos+dy1+dy2). The center of the circle is the
2837c478bd9Sstevel@tonic-gate * point (hpos+dx1, vpos+dy1). If c is 'A' the arc goes clockwise from the point
2847c478bd9Sstevel@tonic-gate * (hpos+dx1+dx2, vpos+dy1+dy2) to (hpos, vpos). Clockwise arcs are only needed
2857c478bd9Sstevel@tonic-gate * if we're building a larger path out of pieces that include arcs, and want to
2867c478bd9Sstevel@tonic-gate * have PostScript manage the path for us. Arguments (for a clockwise arc) are
2877c478bd9Sstevel@tonic-gate * what would have been supplied if the arc was drawn in a counter-clockwise
2887c478bd9Sstevel@tonic-gate * direction, and are converted to values suitable for use with PostScript's arcn
2897c478bd9Sstevel@tonic-gate * operator.
2907c478bd9Sstevel@tonic-gate *
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate if ( (dx1 != 0 || dy1 != 0) && (dx2 != 0 || dy2 != 0) )
2957c478bd9Sstevel@tonic-gate if ( c != 'A' )
2967c478bd9Sstevel@tonic-gate fprintf(tf, "%d %d %d %d %d %d Da\n", hpos, vpos, dx1, dy1, dx2, dy2);
2977c478bd9Sstevel@tonic-gate else fprintf(tf, "%d %d %d %d %d %d DA\n", hpos+dx1+dx2, vpos+dy1+dy2,
2987c478bd9Sstevel@tonic-gate -dx2, -dy2, -dx1, -dy1);
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate hgoto(hpos + dx1 + dx2); /* where troff expects to be */
3017c478bd9Sstevel@tonic-gate vgoto(vpos + dy1 + dy2);
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate resetpos(); /* not sure where the printer is */
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate } /* End of drawarc */
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate /*****************************************************************************/
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate
311f928ce67Sceastha void
drawspline(FILE * fp,int flag)312f928ce67Sceastha drawspline(FILE *fp, int flag)
313f928ce67Sceastha /* fp - input for point list */
314f928ce67Sceastha /* flag - flag!=1 connect end points */
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate int x[100], y[100];
3197c478bd9Sstevel@tonic-gate int i, N;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate *
3247c478bd9Sstevel@tonic-gate * Spline drawing routine for Postscript printers. The complicated stuff is
3257c478bd9Sstevel@tonic-gate * handled by procedure Ds, which should be defined in the library file. I've
3267c478bd9Sstevel@tonic-gate * seen wrong implementations of troff's spline drawing, so fo the record I'll
3277c478bd9Sstevel@tonic-gate * write down the parametric equations and the necessary conversions to Bezier
3287c478bd9Sstevel@tonic-gate * cubic splines (as used in Postscript).
3297c478bd9Sstevel@tonic-gate *
3307c478bd9Sstevel@tonic-gate *
3317c478bd9Sstevel@tonic-gate * Parametric equation (x coordinate only):
3327c478bd9Sstevel@tonic-gate *
3337c478bd9Sstevel@tonic-gate *
3347c478bd9Sstevel@tonic-gate * (x2 - 2 * x1 + x0) 2 (x0 + x1)
3357c478bd9Sstevel@tonic-gate * x = ------------------ * t + (x1 - x0) * t + ---------
3367c478bd9Sstevel@tonic-gate * 2 2
3377c478bd9Sstevel@tonic-gate *
3387c478bd9Sstevel@tonic-gate *
3397c478bd9Sstevel@tonic-gate * The coefficients in the Bezier cubic are,
3407c478bd9Sstevel@tonic-gate *
3417c478bd9Sstevel@tonic-gate *
3427c478bd9Sstevel@tonic-gate * A = 0
3437c478bd9Sstevel@tonic-gate * B = (x2 - 2 * x1 + x0) / 2
3447c478bd9Sstevel@tonic-gate * C = x1 - x0
3457c478bd9Sstevel@tonic-gate *
3467c478bd9Sstevel@tonic-gate *
3477c478bd9Sstevel@tonic-gate * while the current point is,
3487c478bd9Sstevel@tonic-gate *
3497c478bd9Sstevel@tonic-gate * current-point = (x0 + x1) / 2
3507c478bd9Sstevel@tonic-gate *
3517c478bd9Sstevel@tonic-gate * Using the relationships given in the Postscript manual (page 121) it's easy to
3527c478bd9Sstevel@tonic-gate * see that the control points are given by,
3537c478bd9Sstevel@tonic-gate *
3547c478bd9Sstevel@tonic-gate *
3557c478bd9Sstevel@tonic-gate * x0' = (x0 + 5 * x1) / 6
3567c478bd9Sstevel@tonic-gate * x1' = (x2 + 5 * x1) / 6
3577c478bd9Sstevel@tonic-gate * x2' = (x1 + x2) / 2
3587c478bd9Sstevel@tonic-gate *
3597c478bd9Sstevel@tonic-gate *
3607c478bd9Sstevel@tonic-gate * where the primed variables are the ones used by curveto. The calculations
3617c478bd9Sstevel@tonic-gate * shown above are done in procedure Ds using the coordinates set up in both
3627c478bd9Sstevel@tonic-gate * the x[] and y[] arrays.
3637c478bd9Sstevel@tonic-gate *
3647c478bd9Sstevel@tonic-gate * A simple test of whether your spline drawing is correct would be to use cip
3657c478bd9Sstevel@tonic-gate * to draw a spline and some tangent lines at appropriate points and then print
3667c478bd9Sstevel@tonic-gate * the file.
3677c478bd9Sstevel@tonic-gate *
3687c478bd9Sstevel@tonic-gate */
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate for ( N = 2; N < sizeof(x)/sizeof(x[0]); N++ )
3727c478bd9Sstevel@tonic-gate if (fscanf(fp, "%d %d", &x[N], &y[N]) != 2)
3737c478bd9Sstevel@tonic-gate break;
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate x[0] = x[1] = hpos;
3767c478bd9Sstevel@tonic-gate y[0] = y[1] = vpos;
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate for (i = 1; i < N; i++) {
3797c478bd9Sstevel@tonic-gate x[i+1] += x[i];
3807c478bd9Sstevel@tonic-gate y[i+1] += y[i];
3817c478bd9Sstevel@tonic-gate } /* End for */
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate x[N] = x[N-1];
3847c478bd9Sstevel@tonic-gate y[N] = y[N-1];
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate for (i = ((flag!=1)?0:1); i < ((flag!=1)?N-1:N-2); i++)
3877c478bd9Sstevel@tonic-gate fprintf(tf, "%d %d %d %d %d %d Ds\n", x[i], y[i], x[i+1], y[i+1], x[i+2], y[i+2]);
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate hgoto(x[N]); /* where troff expects to be */
3907c478bd9Sstevel@tonic-gate vgoto(y[N]);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate resetpos(); /* not sure where the printer is */
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate } /* End of drawspline */
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate /*****************************************************************************/
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate
400f928ce67Sceastha void
beginpath(char * buf,int copy)401f928ce67Sceastha beginpath(char *buf, int copy)
402f928ce67Sceastha /* buf - whatever followed "x X BeginPath" */
403f928ce67Sceastha /* copy - ignore *buf if FALSE */
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate *
4087c478bd9Sstevel@tonic-gate * Called from devcntrl() whenever an "x X BeginPath" command is read. It's used
4097c478bd9Sstevel@tonic-gate * to mark the start of a sequence of drawing commands that should be grouped
4107c478bd9Sstevel@tonic-gate * together and treated as a single path. By default the drawing procedures in
4117c478bd9Sstevel@tonic-gate * *drawfile treat each drawing command as a separate object, and usually start
4127c478bd9Sstevel@tonic-gate * with a newpath (just as a precaution) and end with a stroke. The newpath and
4137c478bd9Sstevel@tonic-gate * stroke isolate individual drawing commands and make it impossible to deal with
4147c478bd9Sstevel@tonic-gate * composite objects. "x X BeginPath" can be used to mark the start of drawing
4157c478bd9Sstevel@tonic-gate * commands that should be grouped together and treated as a single object, and
4167c478bd9Sstevel@tonic-gate * part of what's done here ensures that the PostScript drawing commands defined
4177c478bd9Sstevel@tonic-gate * in *drawfile skip the newpath and stroke, until after the next "x X DrawPath"
4187c478bd9Sstevel@tonic-gate * command. At that point the path that's been built up can be manipulated in
4197c478bd9Sstevel@tonic-gate * various ways (eg. filled and/or stroked with a different line width).
4207c478bd9Sstevel@tonic-gate *
4217c478bd9Sstevel@tonic-gate * String *buf is unnecessary and is only included for compatibility with an early
4227c478bd9Sstevel@tonic-gate * verion of that's still in use. In that version "x X BeginObject" marked the
4237c478bd9Sstevel@tonic-gate * start of a graphical object, and whatever followed it was passed along in *buf
4247c478bd9Sstevel@tonic-gate * and copied to the output file. Color selection is one of the options that's
4257c478bd9Sstevel@tonic-gate * available in parsebuf(), so if we get here we add *colorfile to the output
4267c478bd9Sstevel@tonic-gate * file before doing anything important.
4277c478bd9Sstevel@tonic-gate *
4287c478bd9Sstevel@tonic-gate */
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate if ( inpath == FALSE ) {
4337c478bd9Sstevel@tonic-gate endtext();
4347c478bd9Sstevel@tonic-gate getdraw();
4357c478bd9Sstevel@tonic-gate getcolor();
4367c478bd9Sstevel@tonic-gate fprintf(tf, "gsave\n");
4377c478bd9Sstevel@tonic-gate fprintf(tf, "newpath\n");
4387c478bd9Sstevel@tonic-gate fprintf(tf, "%d %d m\n", hpos, vpos);
4397c478bd9Sstevel@tonic-gate fprintf(tf, "/inpath true def\n");
4407c478bd9Sstevel@tonic-gate if ( copy == TRUE )
4417c478bd9Sstevel@tonic-gate fprintf(tf, "%s", buf);
4427c478bd9Sstevel@tonic-gate inpath = TRUE;
4437c478bd9Sstevel@tonic-gate } /* End if */
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate } /* End of beginpath */
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate /*****************************************************************************/
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate
451f928ce67Sceastha void
drawpath(char * buf,int copy)452f928ce67Sceastha drawpath(char *buf, int copy)
4537c478bd9Sstevel@tonic-gate {
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate /*
4567c478bd9Sstevel@tonic-gate *
4577c478bd9Sstevel@tonic-gate * Called from devcntrl() whenever an "x X DrawPath" command is read. It marks the
4587c478bd9Sstevel@tonic-gate * end of the path started by the last "x X BeginPath" command and uses whatever
4597c478bd9Sstevel@tonic-gate * has been passed along in *buf to manipulate the path (eg. fill and/or stroke
4607c478bd9Sstevel@tonic-gate * the path). Once that's been done the drawing procedures are restored to their
4617c478bd9Sstevel@tonic-gate * default behavior in which each drawing command is treated as an isolated path.
4627c478bd9Sstevel@tonic-gate * The new version (called after "x X DrawPath") has copy set to FALSE, and calls
4637c478bd9Sstevel@tonic-gate * parsebuf() to figure out what goes in the output file. It's a feeble attempt
4647c478bd9Sstevel@tonic-gate * to free users and preprocessors (like pic) from having to know PostScript. The
4657c478bd9Sstevel@tonic-gate * comments in parsebuf() describe what's handled.
4667c478bd9Sstevel@tonic-gate *
4677c478bd9Sstevel@tonic-gate * In the early version a path was started with "x X BeginObject" and ended with
4687c478bd9Sstevel@tonic-gate * "x X EndObject". In both cases *buf was just copied to the output file, and
4697c478bd9Sstevel@tonic-gate * was expected to be legitimate PostScript that manipulated the current path.
4707c478bd9Sstevel@tonic-gate * The old escape sequence will be supported for a while (for Ravi), and always
4717c478bd9Sstevel@tonic-gate * call this routine with copy set to TRUE.
472*2a8bcb4eSToomas Soome *
4737c478bd9Sstevel@tonic-gate *
4747c478bd9Sstevel@tonic-gate */
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate if ( inpath == TRUE ) {
4787c478bd9Sstevel@tonic-gate if ( copy == TRUE )
4797c478bd9Sstevel@tonic-gate fprintf(tf, "%s", buf);
4807c478bd9Sstevel@tonic-gate else parsebuf(buf);
4817c478bd9Sstevel@tonic-gate fprintf(tf, "grestore\n");
4827c478bd9Sstevel@tonic-gate fprintf(tf, "/inpath false def\n");
4837c478bd9Sstevel@tonic-gate reset();
4847c478bd9Sstevel@tonic-gate inpath = FALSE;
4857c478bd9Sstevel@tonic-gate } /* End if */
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate } /* End of drawpath */
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate /*****************************************************************************/
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate
493f928ce67Sceastha static void
parsebuf(char * buf)494f928ce67Sceastha parsebuf(char *buf)
495f928ce67Sceastha /* whatever followed "x X DrawPath" */
4967c478bd9Sstevel@tonic-gate {
4977c478bd9Sstevel@tonic-gate char *p; /* usually the next token */
4987c478bd9Sstevel@tonic-gate char *p1; /* for grabbing arguments */
4997c478bd9Sstevel@tonic-gate char *pend; /* end of the original string (ie. *buf) */
5007c478bd9Sstevel@tonic-gate int gsavelevel = 0; /* non-zero if we've done a gsave */
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate *
5047c478bd9Sstevel@tonic-gate * Simple minded attempt at parsing the string that followed an "x X DrawPath"
5057c478bd9Sstevel@tonic-gate * command. Everything not recognized here is simply ignored - there's absolutely
5067c478bd9Sstevel@tonic-gate * no error checking and what was originally in buf is clobbered by strtok().
5077c478bd9Sstevel@tonic-gate * A typical *buf might look like,
5087c478bd9Sstevel@tonic-gate *
5097c478bd9Sstevel@tonic-gate * gray .9 fill stroke
5107c478bd9Sstevel@tonic-gate *
5117c478bd9Sstevel@tonic-gate * to fill the current path with a gray level of .9 and follow that by stroking the
5127c478bd9Sstevel@tonic-gate * outline of the path. Since unrecognized tokens are ignored the last example
5137c478bd9Sstevel@tonic-gate * could also be written as,
5147c478bd9Sstevel@tonic-gate *
5157c478bd9Sstevel@tonic-gate * with gray .9 fill then stroke
5167c478bd9Sstevel@tonic-gate *
5177c478bd9Sstevel@tonic-gate * The "with" and "then" strings aren't recognized tokens and are simply discarded.
5187c478bd9Sstevel@tonic-gate * The "stroke", "fill", and "wfill" force out appropriate PostScript code and are
5197c478bd9Sstevel@tonic-gate * followed by a grestore. In otherwords changes to the grahics state (eg. a gray
5207c478bd9Sstevel@tonic-gate * level or color) are reset to default values immediately after the stroke, fill,
5217c478bd9Sstevel@tonic-gate * or wfill tokens. For now "fill" gets invokes PostScript's eofill operator and
5227c478bd9Sstevel@tonic-gate * "wfill" calls fill (ie. the operator that uses the non-zero winding rule).
5237c478bd9Sstevel@tonic-gate *
5247c478bd9Sstevel@tonic-gate * The tokens that cause temporary changes to the graphics state are "gray" (for
5257c478bd9Sstevel@tonic-gate * setting the gray level), "color" (for selecting a known color from the colordict
5267c478bd9Sstevel@tonic-gate * dictionary defined in *colorfile), and "line" (for setting the line width). All
5277c478bd9Sstevel@tonic-gate * three tokens can be extended since strncmp() makes the comparison. For example
5287c478bd9Sstevel@tonic-gate * the strings "line" and "linewidth" accomplish the same thing. Colors are named
5297c478bd9Sstevel@tonic-gate * (eg. "red"), but must be appropriately defined in *colorfile. For now all three
5307c478bd9Sstevel@tonic-gate * tokens must be followed immediately by their single argument. The gray level
5317c478bd9Sstevel@tonic-gate * (ie. the argument that follows "gray") should be a number between 0 and 1, with
5327c478bd9Sstevel@tonic-gate * 0 for black and 1 for white.
5337c478bd9Sstevel@tonic-gate *
5347c478bd9Sstevel@tonic-gate * To pass straight PostScript through enclose the appropriate commands in double
5357c478bd9Sstevel@tonic-gate * quotes. Straight PostScript is only bracketed by the outermost gsave/grestore
5367c478bd9Sstevel@tonic-gate * pair (ie. the one from the initial "x X BeginPath") although that's probably
5377c478bd9Sstevel@tonic-gate * a mistake. Suspect I may have to change the double quote delimiters.
5387c478bd9Sstevel@tonic-gate *
5397c478bd9Sstevel@tonic-gate */
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate pend = buf + strlen(buf);
5437c478bd9Sstevel@tonic-gate p = strtok(buf, " \n");
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate while ( p != NULL ) {
5467c478bd9Sstevel@tonic-gate if ( gsavelevel == 0 ) {
5477c478bd9Sstevel@tonic-gate fprintf(tf, "gsave\n");
5487c478bd9Sstevel@tonic-gate gsavelevel++;
5497c478bd9Sstevel@tonic-gate } /* End if */
5507c478bd9Sstevel@tonic-gate if ( strcmp(p, "stroke") == 0 ) {
5517c478bd9Sstevel@tonic-gate fprintf(tf, "closepath stroke\ngrestore\n");
5527c478bd9Sstevel@tonic-gate gsavelevel--;
5537c478bd9Sstevel@tonic-gate } else if ( strcmp(p, "openstroke") == 0 ) {
5547c478bd9Sstevel@tonic-gate fprintf(tf, "stroke\ngrestore\n");
5557c478bd9Sstevel@tonic-gate gsavelevel--;
5567c478bd9Sstevel@tonic-gate } else if ( strcmp(p, "fill") == 0 ) {
5577c478bd9Sstevel@tonic-gate fprintf(tf, "eofill\ngrestore\n");
5587c478bd9Sstevel@tonic-gate gsavelevel--;
5597c478bd9Sstevel@tonic-gate } else if ( strcmp(p, "wfill") == 0 ) {
5607c478bd9Sstevel@tonic-gate fprintf(tf, "fill\ngrestore\n");
5617c478bd9Sstevel@tonic-gate gsavelevel--;
5627c478bd9Sstevel@tonic-gate } else if ( strcmp(p, "sfill") == 0 ) {
5637c478bd9Sstevel@tonic-gate fprintf(tf, "eofill\ngrestore\ngsave\nstroke\ngrestore\n");
5647c478bd9Sstevel@tonic-gate gsavelevel--;
5657c478bd9Sstevel@tonic-gate } else if ( strncmp(p, "gray", strlen("gray")) == 0 ) {
5667c478bd9Sstevel@tonic-gate p1 = strtok(NULL, " \n");
5677c478bd9Sstevel@tonic-gate fprintf(tf, "%s setgray\n", p1);
5687c478bd9Sstevel@tonic-gate } else if ( strncmp(p, "color", strlen("color")) == 0 ) {
5697c478bd9Sstevel@tonic-gate p1 = strtok(NULL, " \n");
5707c478bd9Sstevel@tonic-gate fprintf(tf, "/%s setcolor\n", p1);
5717c478bd9Sstevel@tonic-gate } else if ( strncmp(p, "line", strlen("line")) == 0 ) {
5727c478bd9Sstevel@tonic-gate p1 = strtok(NULL, " \n");
5737c478bd9Sstevel@tonic-gate fprintf(tf, "%s resolution mul 2 div setlinewidth\n", p1);
5747c478bd9Sstevel@tonic-gate } else if ( strncmp(p, "reverse", strlen("reverse")) == 0 )
5757c478bd9Sstevel@tonic-gate fprintf(tf, "reversepath\n");
5767c478bd9Sstevel@tonic-gate else if ( *p == '"' ) {
5777c478bd9Sstevel@tonic-gate for ( ; gsavelevel > 0; gsavelevel-- )
5787c478bd9Sstevel@tonic-gate fprintf(tf, "grestore\n");
5797c478bd9Sstevel@tonic-gate if ( (p1 = p + strlen(p)) < pend )
5807c478bd9Sstevel@tonic-gate *p1 = ' ';
5817c478bd9Sstevel@tonic-gate p = strtok(p, "\"\n");
5827c478bd9Sstevel@tonic-gate fprintf(tf, "%s\n", p);
5837c478bd9Sstevel@tonic-gate } /* End else */
5847c478bd9Sstevel@tonic-gate p = strtok(NULL, " \n");
5857c478bd9Sstevel@tonic-gate } /* End while */
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate for ( ; gsavelevel > 0; gsavelevel-- )
5887c478bd9Sstevel@tonic-gate fprintf(tf, "grestore\n");
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate } /* End of parsebuf */
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate /*****************************************************************************/
5947c478bd9Sstevel@tonic-gate
595f928ce67Sceastha static void
getbaseline(void)596f928ce67Sceastha getbaseline(void)
5977c478bd9Sstevel@tonic-gate {
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate /*
6007c478bd9Sstevel@tonic-gate *
6017c478bd9Sstevel@tonic-gate * Responsible for making sure the PostScript procedures needed for printing text
6027c478bd9Sstevel@tonic-gate * along an arbitrary baseline are downloaded from *baselinefile. Done at most
6037c478bd9Sstevel@tonic-gate * once per job, and only if the the stuff is really used.
6047c478bd9Sstevel@tonic-gate *
6057c478bd9Sstevel@tonic-gate */
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate if ( gotbaseline == FALSE && access(baselinefile, 04) == 0 )
6097c478bd9Sstevel@tonic-gate doglobal(baselinefile);
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate if ( tf == stdout )
6127c478bd9Sstevel@tonic-gate gotbaseline = TRUE;
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate } /* End of getbaseline */
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate /*****************************************************************************/
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate
620f928ce67Sceastha void
newbaseline(char * buf)621f928ce67Sceastha newbaseline(char *buf)
622f928ce67Sceastha /* whatever followed "x X NewBaseline" */
6237c478bd9Sstevel@tonic-gate {
6247c478bd9Sstevel@tonic-gate char *p; /* for eliminating white space etc. */
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate *
6297c478bd9Sstevel@tonic-gate * Called from devcntrl() whenever an "x X NewBaseline" command is recognized. We
6307c478bd9Sstevel@tonic-gate * assume whatever is in *buf is a set of parametric equations that describe the
6317c478bd9Sstevel@tonic-gate * new baseline. Equations for x(t), y(t), dx/dt, and dy/dt must be written in
6327c478bd9Sstevel@tonic-gate * PostScript, bracketed by { and } characters, and supplied in exactly that order.
6337c478bd9Sstevel@tonic-gate * In particular the equation for x must come first in *buf and it ends up as the
6347c478bd9Sstevel@tonic-gate * last one on the stack, while the equation for dy/dt comes last (in *buf) and
6357c478bd9Sstevel@tonic-gate * ends up on the top of the PostScript stack. For example if *buf is given by,
6367c478bd9Sstevel@tonic-gate *
6377c478bd9Sstevel@tonic-gate * {} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
6387c478bd9Sstevel@tonic-gate *
6397c478bd9Sstevel@tonic-gate * text will be printed along the curve y = cos(x).
6407c478bd9Sstevel@tonic-gate *
6417c478bd9Sstevel@tonic-gate * Angles given in radians must be converted to degrees for the PostScript trig
6427c478bd9Sstevel@tonic-gate * functions, and things are scaled so that 1 unit maps into 1 inch. In the last
6437c478bd9Sstevel@tonic-gate * example the cosine curve that describes the baseline has an amplitude of 1 inch.
6447c478bd9Sstevel@tonic-gate * As another example of this rather confusing syntax if *buf is,
6457c478bd9Sstevel@tonic-gate *
6467c478bd9Sstevel@tonic-gate * {} {} {pop 1} {pop 1}
6477c478bd9Sstevel@tonic-gate *
6487c478bd9Sstevel@tonic-gate * the baseline will be the 45 degree line y = x.
6497c478bd9Sstevel@tonic-gate *
6507c478bd9Sstevel@tonic-gate * When any of the four functions is used they're called with a single number on
6517c478bd9Sstevel@tonic-gate * the stack that's equal to the current value of the parameter t. The coordinate
6527c478bd9Sstevel@tonic-gate * system axes run parallel to the PostScript coordinate system that's currently
6537c478bd9Sstevel@tonic-gate * being used.
6547c478bd9Sstevel@tonic-gate *
6557c478bd9Sstevel@tonic-gate */
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate for ( p = buf; *p; p++ ) /* eliminate trailing '\n' */
6597c478bd9Sstevel@tonic-gate if ( *p == '\n' ) {
6607c478bd9Sstevel@tonic-gate *p = '\0';
6617c478bd9Sstevel@tonic-gate break;
6627c478bd9Sstevel@tonic-gate } /* End if */
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate if ( *p != '\0' ) { /* something's there */
6677c478bd9Sstevel@tonic-gate endtext();
6687c478bd9Sstevel@tonic-gate getbaseline();
6697c478bd9Sstevel@tonic-gate fprintf(tf, "mark resolution %s newbaseline\n", p);
6707c478bd9Sstevel@tonic-gate t_sf();
6717c478bd9Sstevel@tonic-gate resetpos();
6727c478bd9Sstevel@tonic-gate } /* End if */
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate } /* End of newbaseline */
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate
6777c478bd9Sstevel@tonic-gate /*****************************************************************************/
6787c478bd9Sstevel@tonic-gate
679f928ce67Sceastha void
drawtext(char * buf)680f928ce67Sceastha drawtext(char *buf)
681f928ce67Sceastha /* whatever followed "x X DrawText */
6827c478bd9Sstevel@tonic-gate {
6837c478bd9Sstevel@tonic-gate char *p; /* for eliminating white space etc. */
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate *
6887c478bd9Sstevel@tonic-gate * Called from devcntrl() whenever an "x X DrawText command is recognized. *buf
6897c478bd9Sstevel@tonic-gate * should contain three arguments in the following order. First comes the text we
6907c478bd9Sstevel@tonic-gate * want to print along the current baseline. Right now the string should be given
6917c478bd9Sstevel@tonic-gate * as a PostScript string using characters '(' and ')' as the delimiters. Next in
6927c478bd9Sstevel@tonic-gate * *buf comes a justification mode that can be the words left, right, or center.
6937c478bd9Sstevel@tonic-gate * Last comes a number that represents the starting value of the parameter t that's
6947c478bd9Sstevel@tonic-gate * given as the argument to the parametric equations that describe the current
6957c478bd9Sstevel@tonic-gate * baseline. For example if *buf is given by,
6967c478bd9Sstevel@tonic-gate *
6977c478bd9Sstevel@tonic-gate * (hello world) left .5
6987c478bd9Sstevel@tonic-gate *
6997c478bd9Sstevel@tonic-gate * hello world will be printed along the path described by the current baseline
7007c478bd9Sstevel@tonic-gate * and left justified at whatever (x(.5), y(.5)) happens to be. Usually will be
7017c478bd9Sstevel@tonic-gate * preceeded by an "x X NewBaseline" call that defines the current baseline. The
7027c478bd9Sstevel@tonic-gate * origin of the coordinate system used by the parametric equations will be the
7037c478bd9Sstevel@tonic-gate * current point.
7047c478bd9Sstevel@tonic-gate *
7057c478bd9Sstevel@tonic-gate */
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate for ( p = buf; *p; p++ ) /* eliminate trailing '\n' */
7097c478bd9Sstevel@tonic-gate if ( *p == '\n' ) {
7107c478bd9Sstevel@tonic-gate *p = '\0';
7117c478bd9Sstevel@tonic-gate break;
7127c478bd9Sstevel@tonic-gate } /* End if */
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate if ( *p != '\0' ) { /* something's there */
7177c478bd9Sstevel@tonic-gate endtext();
7187c478bd9Sstevel@tonic-gate getbaseline();
7197c478bd9Sstevel@tonic-gate xymove(hpos, vpos);
7207c478bd9Sstevel@tonic-gate fprintf(tf, "mark %s drawfunnytext\n", p);
7217c478bd9Sstevel@tonic-gate resetpos();
7227c478bd9Sstevel@tonic-gate } /* End if */
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate } /* End of drawtext */
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate
7277c478bd9Sstevel@tonic-gate /*****************************************************************************/
7287c478bd9Sstevel@tonic-gate
729f928ce67Sceastha void
settext(char * buf)730f928ce67Sceastha settext(char *buf)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate char *p;
7337c478bd9Sstevel@tonic-gate
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate /*
7367c478bd9Sstevel@tonic-gate *
7377c478bd9Sstevel@tonic-gate * Does whatever is needed to ensure any text that follows will be set along the
7387c478bd9Sstevel@tonic-gate * curve described by the PostScript procedures listed in *buf. If *buf doesn't
7397c478bd9Sstevel@tonic-gate * contain anything useful (eg. just a newline) things are restored to whatever
7407c478bd9Sstevel@tonic-gate * they originally were. Doesn't work well if we try to start in the middle of a
7417c478bd9Sstevel@tonic-gate * line of text.
7427c478bd9Sstevel@tonic-gate *
7437c478bd9Sstevel@tonic-gate * The parametric equations needed are,
7447c478bd9Sstevel@tonic-gate *
7457c478bd9Sstevel@tonic-gate * x = f(t)
7467c478bd9Sstevel@tonic-gate * y = g(t)
7477c478bd9Sstevel@tonic-gate * dx/dt = f'(t)
7487c478bd9Sstevel@tonic-gate * dy/dt = g'(t)
7497c478bd9Sstevel@tonic-gate *
7507c478bd9Sstevel@tonic-gate * and must be given as proper PostScript procedures. The equation for x must come
7517c478bd9Sstevel@tonic-gate * first (ie. it ends up on the bottom of the stack) and the equation for dy/dt
7527c478bd9Sstevel@tonic-gate * must be given last (ie. it ends up on top of the stack). For example if *buf
7537c478bd9Sstevel@tonic-gate * is given by,
7547c478bd9Sstevel@tonic-gate *
7557c478bd9Sstevel@tonic-gate * {} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
7567c478bd9Sstevel@tonic-gate *
7577c478bd9Sstevel@tonic-gate * text will be set along the curve y=cos(x).
7587c478bd9Sstevel@tonic-gate *
7597c478bd9Sstevel@tonic-gate */
7607c478bd9Sstevel@tonic-gate
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate endtext();
7637c478bd9Sstevel@tonic-gate getbaseline();
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate for ( p = buf; *p && *p == ' '; p++ ) ;
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate if ( *p && *p != '\n' ) {
7687c478bd9Sstevel@tonic-gate encoding = maxencoding + 2;
7697c478bd9Sstevel@tonic-gate fprintf(tf, "mark resolution %s newbaseline\n", buf);
7707c478bd9Sstevel@tonic-gate } else encoding = realencoding;
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gate fprintf(tf, "%d setdecoding\n", encoding);
7737c478bd9Sstevel@tonic-gate resetpos();
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate } /* End of settext */
776