1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #pragma ident "%Z%%M% %I% %E% SMI"
41
42 /*
43 *
44 * Drawing routines used by dpost. Almost no real work is done here. Instead
45 * the required calculations are done in special Postscript procedures that
46 * include:
47 *
48 *
49 * Dl
50 *
51 * x1 y1 x y Dl -
52 *
53 * Starts a new path and then draws a line from the current point
54 * (x, y) to (x1, y1).
55 *
56 * De
57 *
58 * x y a b De -
59 *
60 * Starts a new path and then draws an ellipse that has its left side
61 * at the current point (x, y) and horizontal and vertical axes lengths
62 * given by a and b respectively.
63 *
64 * Da
65 *
66 * x y dx1 dy1 dx2 dy2 Da -
67 *
68 * Starts a new segment and then draws a circular arc from the current
69 * point (x, y) to (x + dx1 + dx2, y + dy1 + dy2). The center of the
70 * circle is at (x + dx1, y + dy1). Arcs always go counter-clockwise
71 * from the starting point to the end point.
72 *
73 * DA
74 *
75 * x y dx1 dy1 dx2 dy2 DA -
76 *
77 * Draws a clockwise arc from (x, y) to (x + dx1 + dx2, y + dy1 + dy2)
78 * with center at (x + dx1, y + dy1). Only needed when we're building
79 * large paths that use arcs and want to control the current point. The
80 * arguments passed to drawarc() will be whatever they would have been
81 * for a counter-clockwise arc, so we need to map them into appropriate
82 * arguments for PostScript's arcn operator. The mapping is,
83 *
84 * x = hpos + dx1' + dx2'
85 * y = vpos + dy1' + dy2'
86 * dx1 = -dx2'
87 * dy1 = -dy2'
88 * dx2 = -dx1'
89 * dy2 = -dy1'
90 *
91 * where primed values represent the drawarc() arguments and (hpos, vpos)
92 * is our current position.
93 *
94 * Ds
95 *
96 * x0 y0 x1 y1 x2 y2 Ds -
97 *
98 * Starts a new segment and then draws a quadratic spline connecting
99 * point ((x0 + x1)/2, (y0 + y1)/2) to ((x1 + x2)/2, (y1 + y2)/2).
100 * The points used in Postscript's curveto procedure are given by,
101 *
102 * x0' = (x0 + 5 * x1) / 6
103 * x1' = (x2 + 5 * x1) / 6
104 * x2' = (x1 + x2) / 2
105 *
106 * with similar equations for the y coordinates.
107 *
108 * By default all the PostScript drawing procedures begin with a newpath (just to
109 * be safe) and end with a stroke, which essentially isolates the path elements
110 * built by the drawing procedures. In order to accommodate big paths built from
111 * smaller pieces each of the PostScript drawing procedures can forced to retain
112 * the path that's being built. That's what happens in beginpath() when an "x X
113 * BeginPath" command is read. beginpath() sets the PostScript variable inpath to
114 * true, and that essentially eliminates the newpath/stroke pair that bracket the
115 * individual pieces. In that case the path is terminated and drawn when dpost
116 * reads an "x X DrawPath" command.
117 *
118 * Early versions of dpost included the PostScript drawing procedures as part of
119 * the prologue, and as a result they were included with every job, even if they
120 * were never used. This version has separated the drawing procedures from the
121 * default prologue (they're now in *drawfile) and only includes them if they're
122 * really needed, which is yet another convenient violation of page independence.
123 * Routine getdraw() is responsible for adding *drawfile to the output file, and
124 * if it can't read *drawfile it continues on as if nothing happened. That means
125 * everything should still work if you append *drawfile to *prologue and then
126 * delete *drawfile.
127 *
128 */
129
130
131 #include <stdio.h>
132 #include <math.h>
133
134 #include "gen.h" /* general purpose definitions */
135 #include "ext.h" /* external variable definitions */
136
137
138 int gotdraw = FALSE; /* TRUE when *drawfile has been added */
139 int gotbaseline = FALSE; /* TRUE after *baselinefile is added */
140 int inpath = FALSE; /* TRUE if we're putting pieces together */
141
142
143 /*
144 *
145 * All these should be defined in file dpost.c.
146 *
147 */
148
149
150 extern int hpos;
151 extern int vpos;
152 extern int encoding;
153 extern int maxencoding;
154 extern int realencoding;
155
156 extern char *drawfile;
157 extern char *baselinefile;
158 extern FILE *tf;
159
160 void drawcirc(int);
161 void drawellip(int, int);
162 static void parsebuf(char *);
163
164 /*****************************************************************************/
165
166
167 void
getdraw(void)168 getdraw(void)
169 {
170
171
172 /*
173 *
174 * Responsible for making sure the PostScript drawing procedures are downloaded
175 * from *drawfile. Stuff is done at most once per job, and only if the job needs
176 * them. For now I've decided not to quit if we can't read the drawing file. That
177 * pretty much assumes an old version of prologue is being used that includes all
178 * the drawing procedures.
179 *
180 */
181
182
183 if ( gotdraw == FALSE && access(drawfile, 04) == 0 )
184 doglobal(drawfile);
185
186 if ( tf == stdout )
187 gotdraw = TRUE;
188
189 } /* End of getdraw */
190
191
192 /*****************************************************************************/
193
194
195 void
drawline(int dx,int dy)196 drawline(int dx, int dy)
197 /* endpoint is (hpos+dx, vpos+dy) */
198 {
199
200 /*
201 *
202 * Draws a line from (hpos, vpos) to (hpos+dx, vpos+dy), and leaves the current
203 * position at the endpoint.
204 *
205 */
206
207
208 if ( dx == 0 && dy == 0 )
209 drawcirc(1);
210 else fprintf(tf, "%d %d %d %d Dl\n", hpos + dx, vpos + dy, hpos, vpos);
211
212 hgoto(hpos+dx); /* where troff expects to be */
213 vgoto(vpos+dy);
214
215 resetpos(); /* not sure where the printer is */
216
217 } /* End of drawline */
218
219
220 /*****************************************************************************/
221
222
223 void
drawcirc(int d)224 drawcirc(int d)
225 /* diameter of the circle */
226 {
227
228 /*
229 *
230 * Draws a circle of diameter d with the left 'side' of the circle at the
231 * current point. After we're finished drawing we move the current position
232 * to the right side.
233 *
234 */
235
236 drawellip(d, d);
237
238 } /* End of drawcirc */
239
240
241 /*****************************************************************************/
242
243
244 void
drawellip(int a,int b)245 drawellip(int a, int b)
246 /* axes lengths for the ellipse */
247 {
248
249 /*
250 *
251 * Draws an ellipse having axes lengths horizontally and vertically of a and
252 * b. The left side of the ellipse is at the current point. After we're done
253 * drawing the path we move the current position to the right side.
254 *
255 */
256
257
258 if ( a == 0 && b == 0 )
259 return;
260
261 fprintf(tf, "%d %d %d %d De\n", hpos, vpos, a, b);
262
263 hgoto(hpos + a); /* where troff expects to be */
264 vgoto(vpos);
265
266 resetpos(); /* not sure where the printer is */
267
268 } /* End of drawellip */
269
270
271 /*****************************************************************************/
272
273
274 void
drawarc(int dx1,int dy1,int dx2,int dy2,int c)275 drawarc(int dx1, int dy1, int dx2, int dy2, int c)
276 /* dx1, dy1 - vector from current pos to center */
277 /* dx2, dy2 - from center to end of the arc */
278 /* c - clockwise if c is A */
279 {
280
281 /*
282 *
283 * If c isn't set to 'A' a counter-clockwise arc is drawn from the current point
284 * (hpos, vpos) to (hpos+dx1+dx2, vpos+dy1+dy2). The center of the circle is the
285 * point (hpos+dx1, vpos+dy1). If c is 'A' the arc goes clockwise from the point
286 * (hpos+dx1+dx2, vpos+dy1+dy2) to (hpos, vpos). Clockwise arcs are only needed
287 * if we're building a larger path out of pieces that include arcs, and want to
288 * have PostScript manage the path for us. Arguments (for a clockwise arc) are
289 * what would have been supplied if the arc was drawn in a counter-clockwise
290 * direction, and are converted to values suitable for use with PostScript's arcn
291 * operator.
292 *
293 */
294
295
296 if ( (dx1 != 0 || dy1 != 0) && (dx2 != 0 || dy2 != 0) )
297 if ( c != 'A' )
298 fprintf(tf, "%d %d %d %d %d %d Da\n", hpos, vpos, dx1, dy1, dx2, dy2);
299 else fprintf(tf, "%d %d %d %d %d %d DA\n", hpos+dx1+dx2, vpos+dy1+dy2,
300 -dx2, -dy2, -dx1, -dy1);
301
302 hgoto(hpos + dx1 + dx2); /* where troff expects to be */
303 vgoto(vpos + dy1 + dy2);
304
305 resetpos(); /* not sure where the printer is */
306
307 } /* End of drawarc */
308
309
310 /*****************************************************************************/
311
312
313 void
drawspline(FILE * fp,int flag)314 drawspline(FILE *fp, int flag)
315 /* fp - input for point list */
316 /* flag - flag!=1 connect end points */
317 {
318
319
320 int x[100], y[100];
321 int i, N;
322
323
324 /*
325 *
326 * Spline drawing routine for Postscript printers. The complicated stuff is
327 * handled by procedure Ds, which should be defined in the library file. I've
328 * seen wrong implementations of troff's spline drawing, so fo the record I'll
329 * write down the parametric equations and the necessary conversions to Bezier
330 * cubic splines (as used in Postscript).
331 *
332 *
333 * Parametric equation (x coordinate only):
334 *
335 *
336 * (x2 - 2 * x1 + x0) 2 (x0 + x1)
337 * x = ------------------ * t + (x1 - x0) * t + ---------
338 * 2 2
339 *
340 *
341 * The coefficients in the Bezier cubic are,
342 *
343 *
344 * A = 0
345 * B = (x2 - 2 * x1 + x0) / 2
346 * C = x1 - x0
347 *
348 *
349 * while the current point is,
350 *
351 * current-point = (x0 + x1) / 2
352 *
353 * Using the relationships given in the Postscript manual (page 121) it's easy to
354 * see that the control points are given by,
355 *
356 *
357 * x0' = (x0 + 5 * x1) / 6
358 * x1' = (x2 + 5 * x1) / 6
359 * x2' = (x1 + x2) / 2
360 *
361 *
362 * where the primed variables are the ones used by curveto. The calculations
363 * shown above are done in procedure Ds using the coordinates set up in both
364 * the x[] and y[] arrays.
365 *
366 * A simple test of whether your spline drawing is correct would be to use cip
367 * to draw a spline and some tangent lines at appropriate points and then print
368 * the file.
369 *
370 */
371
372
373 for ( N = 2; N < sizeof(x)/sizeof(x[0]); N++ )
374 if (fscanf(fp, "%d %d", &x[N], &y[N]) != 2)
375 break;
376
377 x[0] = x[1] = hpos;
378 y[0] = y[1] = vpos;
379
380 for (i = 1; i < N; i++) {
381 x[i+1] += x[i];
382 y[i+1] += y[i];
383 } /* End for */
384
385 x[N] = x[N-1];
386 y[N] = y[N-1];
387
388 for (i = ((flag!=1)?0:1); i < ((flag!=1)?N-1:N-2); i++)
389 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]);
390
391 hgoto(x[N]); /* where troff expects to be */
392 vgoto(y[N]);
393
394 resetpos(); /* not sure where the printer is */
395
396 } /* End of drawspline */
397
398
399 /*****************************************************************************/
400
401
402 void
beginpath(char * buf,int copy)403 beginpath(char *buf, int copy)
404 /* buf - whatever followed "x X BeginPath" */
405 /* copy - ignore *buf if FALSE */
406 {
407
408 /*
409 *
410 * Called from devcntrl() whenever an "x X BeginPath" command is read. It's used
411 * to mark the start of a sequence of drawing commands that should be grouped
412 * together and treated as a single path. By default the drawing procedures in
413 * *drawfile treat each drawing command as a separate object, and usually start
414 * with a newpath (just as a precaution) and end with a stroke. The newpath and
415 * stroke isolate individual drawing commands and make it impossible to deal with
416 * composite objects. "x X BeginPath" can be used to mark the start of drawing
417 * commands that should be grouped together and treated as a single object, and
418 * part of what's done here ensures that the PostScript drawing commands defined
419 * in *drawfile skip the newpath and stroke, until after the next "x X DrawPath"
420 * command. At that point the path that's been built up can be manipulated in
421 * various ways (eg. filled and/or stroked with a different line width).
422 *
423 * String *buf is unnecessary and is only included for compatibility with an early
424 * verion of that's still in use. In that version "x X BeginObject" marked the
425 * start of a graphical object, and whatever followed it was passed along in *buf
426 * and copied to the output file. Color selection is one of the options that's
427 * available in parsebuf(), so if we get here we add *colorfile to the output
428 * file before doing anything important.
429 *
430 */
431
432
433
434 if ( inpath == FALSE ) {
435 endtext();
436 getdraw();
437 getcolor();
438 fprintf(tf, "gsave\n");
439 fprintf(tf, "newpath\n");
440 fprintf(tf, "%d %d m\n", hpos, vpos);
441 fprintf(tf, "/inpath true def\n");
442 if ( copy == TRUE )
443 fprintf(tf, "%s", buf);
444 inpath = TRUE;
445 } /* End if */
446
447 } /* End of beginpath */
448
449
450 /*****************************************************************************/
451
452
453 void
drawpath(char * buf,int copy)454 drawpath(char *buf, int copy)
455 {
456
457 /*
458 *
459 * Called from devcntrl() whenever an "x X DrawPath" command is read. It marks the
460 * end of the path started by the last "x X BeginPath" command and uses whatever
461 * has been passed along in *buf to manipulate the path (eg. fill and/or stroke
462 * the path). Once that's been done the drawing procedures are restored to their
463 * default behavior in which each drawing command is treated as an isolated path.
464 * The new version (called after "x X DrawPath") has copy set to FALSE, and calls
465 * parsebuf() to figure out what goes in the output file. It's a feeble attempt
466 * to free users and preprocessors (like pic) from having to know PostScript. The
467 * comments in parsebuf() describe what's handled.
468 *
469 * In the early version a path was started with "x X BeginObject" and ended with
470 * "x X EndObject". In both cases *buf was just copied to the output file, and
471 * was expected to be legitimate PostScript that manipulated the current path.
472 * The old escape sequence will be supported for a while (for Ravi), and always
473 * call this routine with copy set to TRUE.
474 *
475 *
476 */
477
478
479 if ( inpath == TRUE ) {
480 if ( copy == TRUE )
481 fprintf(tf, "%s", buf);
482 else parsebuf(buf);
483 fprintf(tf, "grestore\n");
484 fprintf(tf, "/inpath false def\n");
485 reset();
486 inpath = FALSE;
487 } /* End if */
488
489 } /* End of drawpath */
490
491
492 /*****************************************************************************/
493
494
495 static void
parsebuf(char * buf)496 parsebuf(char *buf)
497 /* whatever followed "x X DrawPath" */
498 {
499 char *p; /* usually the next token */
500 char *p1; /* for grabbing arguments */
501 char *pend; /* end of the original string (ie. *buf) */
502 int gsavelevel = 0; /* non-zero if we've done a gsave */
503
504 /*
505 *
506 * Simple minded attempt at parsing the string that followed an "x X DrawPath"
507 * command. Everything not recognized here is simply ignored - there's absolutely
508 * no error checking and what was originally in buf is clobbered by strtok().
509 * A typical *buf might look like,
510 *
511 * gray .9 fill stroke
512 *
513 * to fill the current path with a gray level of .9 and follow that by stroking the
514 * outline of the path. Since unrecognized tokens are ignored the last example
515 * could also be written as,
516 *
517 * with gray .9 fill then stroke
518 *
519 * The "with" and "then" strings aren't recognized tokens and are simply discarded.
520 * The "stroke", "fill", and "wfill" force out appropriate PostScript code and are
521 * followed by a grestore. In otherwords changes to the grahics state (eg. a gray
522 * level or color) are reset to default values immediately after the stroke, fill,
523 * or wfill tokens. For now "fill" gets invokes PostScript's eofill operator and
524 * "wfill" calls fill (ie. the operator that uses the non-zero winding rule).
525 *
526 * The tokens that cause temporary changes to the graphics state are "gray" (for
527 * setting the gray level), "color" (for selecting a known color from the colordict
528 * dictionary defined in *colorfile), and "line" (for setting the line width). All
529 * three tokens can be extended since strncmp() makes the comparison. For example
530 * the strings "line" and "linewidth" accomplish the same thing. Colors are named
531 * (eg. "red"), but must be appropriately defined in *colorfile. For now all three
532 * tokens must be followed immediately by their single argument. The gray level
533 * (ie. the argument that follows "gray") should be a number between 0 and 1, with
534 * 0 for black and 1 for white.
535 *
536 * To pass straight PostScript through enclose the appropriate commands in double
537 * quotes. Straight PostScript is only bracketed by the outermost gsave/grestore
538 * pair (ie. the one from the initial "x X BeginPath") although that's probably
539 * a mistake. Suspect I may have to change the double quote delimiters.
540 *
541 */
542
543
544 pend = buf + strlen(buf);
545 p = strtok(buf, " \n");
546
547 while ( p != NULL ) {
548 if ( gsavelevel == 0 ) {
549 fprintf(tf, "gsave\n");
550 gsavelevel++;
551 } /* End if */
552 if ( strcmp(p, "stroke") == 0 ) {
553 fprintf(tf, "closepath stroke\ngrestore\n");
554 gsavelevel--;
555 } else if ( strcmp(p, "openstroke") == 0 ) {
556 fprintf(tf, "stroke\ngrestore\n");
557 gsavelevel--;
558 } else if ( strcmp(p, "fill") == 0 ) {
559 fprintf(tf, "eofill\ngrestore\n");
560 gsavelevel--;
561 } else if ( strcmp(p, "wfill") == 0 ) {
562 fprintf(tf, "fill\ngrestore\n");
563 gsavelevel--;
564 } else if ( strcmp(p, "sfill") == 0 ) {
565 fprintf(tf, "eofill\ngrestore\ngsave\nstroke\ngrestore\n");
566 gsavelevel--;
567 } else if ( strncmp(p, "gray", strlen("gray")) == 0 ) {
568 p1 = strtok(NULL, " \n");
569 fprintf(tf, "%s setgray\n", p1);
570 } else if ( strncmp(p, "color", strlen("color")) == 0 ) {
571 p1 = strtok(NULL, " \n");
572 fprintf(tf, "/%s setcolor\n", p1);
573 } else if ( strncmp(p, "line", strlen("line")) == 0 ) {
574 p1 = strtok(NULL, " \n");
575 fprintf(tf, "%s resolution mul 2 div setlinewidth\n", p1);
576 } else if ( strncmp(p, "reverse", strlen("reverse")) == 0 )
577 fprintf(tf, "reversepath\n");
578 else if ( *p == '"' ) {
579 for ( ; gsavelevel > 0; gsavelevel-- )
580 fprintf(tf, "grestore\n");
581 if ( (p1 = p + strlen(p)) < pend )
582 *p1 = ' ';
583 p = strtok(p, "\"\n");
584 fprintf(tf, "%s\n", p);
585 } /* End else */
586 p = strtok(NULL, " \n");
587 } /* End while */
588
589 for ( ; gsavelevel > 0; gsavelevel-- )
590 fprintf(tf, "grestore\n");
591
592 } /* End of parsebuf */
593
594
595 /*****************************************************************************/
596
597 static void
getbaseline(void)598 getbaseline(void)
599 {
600
601 /*
602 *
603 * Responsible for making sure the PostScript procedures needed for printing text
604 * along an arbitrary baseline are downloaded from *baselinefile. Done at most
605 * once per job, and only if the the stuff is really used.
606 *
607 */
608
609
610 if ( gotbaseline == FALSE && access(baselinefile, 04) == 0 )
611 doglobal(baselinefile);
612
613 if ( tf == stdout )
614 gotbaseline = TRUE;
615
616 } /* End of getbaseline */
617
618
619 /*****************************************************************************/
620
621
622 void
newbaseline(char * buf)623 newbaseline(char *buf)
624 /* whatever followed "x X NewBaseline" */
625 {
626 char *p; /* for eliminating white space etc. */
627
628
629 /*
630 *
631 * Called from devcntrl() whenever an "x X NewBaseline" command is recognized. We
632 * assume whatever is in *buf is a set of parametric equations that describe the
633 * new baseline. Equations for x(t), y(t), dx/dt, and dy/dt must be written in
634 * PostScript, bracketed by { and } characters, and supplied in exactly that order.
635 * In particular the equation for x must come first in *buf and it ends up as the
636 * last one on the stack, while the equation for dy/dt comes last (in *buf) and
637 * ends up on the top of the PostScript stack. For example if *buf is given by,
638 *
639 * {} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
640 *
641 * text will be printed along the curve y = cos(x).
642 *
643 * Angles given in radians must be converted to degrees for the PostScript trig
644 * functions, and things are scaled so that 1 unit maps into 1 inch. In the last
645 * example the cosine curve that describes the baseline has an amplitude of 1 inch.
646 * As another example of this rather confusing syntax if *buf is,
647 *
648 * {} {} {pop 1} {pop 1}
649 *
650 * the baseline will be the 45 degree line y = x.
651 *
652 * When any of the four functions is used they're called with a single number on
653 * the stack that's equal to the current value of the parameter t. The coordinate
654 * system axes run parallel to the PostScript coordinate system that's currently
655 * being used.
656 *
657 */
658
659
660 for ( p = buf; *p; p++ ) /* eliminate trailing '\n' */
661 if ( *p == '\n' ) {
662 *p = '\0';
663 break;
664 } /* End if */
665
666 for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;
667
668 if ( *p != '\0' ) { /* something's there */
669 endtext();
670 getbaseline();
671 fprintf(tf, "mark resolution %s newbaseline\n", p);
672 t_sf();
673 resetpos();
674 } /* End if */
675
676 } /* End of newbaseline */
677
678
679 /*****************************************************************************/
680
681 void
drawtext(char * buf)682 drawtext(char *buf)
683 /* whatever followed "x X DrawText */
684 {
685 char *p; /* for eliminating white space etc. */
686
687
688 /*
689 *
690 * Called from devcntrl() whenever an "x X DrawText command is recognized. *buf
691 * should contain three arguments in the following order. First comes the text we
692 * want to print along the current baseline. Right now the string should be given
693 * as a PostScript string using characters '(' and ')' as the delimiters. Next in
694 * *buf comes a justification mode that can be the words left, right, or center.
695 * Last comes a number that represents the starting value of the parameter t that's
696 * given as the argument to the parametric equations that describe the current
697 * baseline. For example if *buf is given by,
698 *
699 * (hello world) left .5
700 *
701 * hello world will be printed along the path described by the current baseline
702 * and left justified at whatever (x(.5), y(.5)) happens to be. Usually will be
703 * preceeded by an "x X NewBaseline" call that defines the current baseline. The
704 * origin of the coordinate system used by the parametric equations will be the
705 * current point.
706 *
707 */
708
709
710 for ( p = buf; *p; p++ ) /* eliminate trailing '\n' */
711 if ( *p == '\n' ) {
712 *p = '\0';
713 break;
714 } /* End if */
715
716 for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;
717
718 if ( *p != '\0' ) { /* something's there */
719 endtext();
720 getbaseline();
721 xymove(hpos, vpos);
722 fprintf(tf, "mark %s drawfunnytext\n", p);
723 resetpos();
724 } /* End if */
725
726 } /* End of drawtext */
727
728
729 /*****************************************************************************/
730
731 void
settext(char * buf)732 settext(char *buf)
733 {
734 char *p;
735
736
737 /*
738 *
739 * Does whatever is needed to ensure any text that follows will be set along the
740 * curve described by the PostScript procedures listed in *buf. If *buf doesn't
741 * contain anything useful (eg. just a newline) things are restored to whatever
742 * they originally were. Doesn't work well if we try to start in the middle of a
743 * line of text.
744 *
745 * The parametric equations needed are,
746 *
747 * x = f(t)
748 * y = g(t)
749 * dx/dt = f'(t)
750 * dy/dt = g'(t)
751 *
752 * and must be given as proper PostScript procedures. The equation for x must come
753 * first (ie. it ends up on the bottom of the stack) and the equation for dy/dt
754 * must be given last (ie. it ends up on top of the stack). For example if *buf
755 * is given by,
756 *
757 * {} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
758 *
759 * text will be set along the curve y=cos(x).
760 *
761 */
762
763
764 endtext();
765 getbaseline();
766
767 for ( p = buf; *p && *p == ' '; p++ ) ;
768
769 if ( *p && *p != '\n' ) {
770 encoding = maxencoding + 2;
771 fprintf(tf, "mark resolution %s newbaseline\n", buf);
772 } else encoding = realencoding;
773
774 fprintf(tf, "%d setdecoding\n", encoding);
775 resetpos();
776
777 } /* End of settext */
778