plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

pltex.c (3446B)


      1 /* replacement for pltroff.c to produce a TeX file that makes a box */
      2 
      3 #include <stdio.h>
      4 #include <math.h>
      5 #include "pic.h"
      6 
      7 double rangex, rangey;  /* probably already available inside pic somewhere */
      8 extern int dbg;
      9 int frameno;
     10 
     11 /*-----------copied from old version----------*/
     12 
     13 void
     14 arrow(double x0, double y0, double x1, double y1, double w, double h, double ang, int nhead) 	/* draw arrow (without shaft) */
     15 	/* head wid w, len h, rotated ang */
     16 	/* and drawn with nhead lines */
     17 {
     18 	double alpha, rot, drot, hyp;
     19 	float dx, dy;
     20 	int i;
     21 
     22 	rot = atan2(w / 2, h);
     23 	hyp = sqrt(w/2 * w/2 + h * h);
     24 	alpha = atan2(y1-y0, x1-x0) + ang;
     25 	if (nhead < 2)
     26 		nhead = 2;
     27 	for (i = nhead-1; i >= 0; i--) {
     28 		drot = 2 * rot / (double) (nhead-1) * (double) i;
     29 		dx = hyp * cos(alpha + PI - rot + drot);
     30 		dy = hyp * sin(alpha + PI - rot + drot);
     31 		line(x1+dx, y1+dy, x1, y1);
     32 	}
     33 }
     34 
     35 
     36 /*-----------new code----------*/
     37 
     38 void
     39 printlf(int line, char *name)
     40 {
     41 }
     42 
     43 void
     44 fillstart(double v)	/* only choose black, light grey (.75), or white, for now */
     45 {
     46 	if (v<.05)
     47 		fprintf(TEXFILE, "    \\special{bk}%%\n");
     48 	else if (v>.95)
     49 		fprintf(TEXFILE, "    \\special{wh}%%\n");
     50 	else
     51 		fprintf(TEXFILE, "    \\special{sh}%%\n");
     52 }
     53 
     54 void
     55 fillend(void)
     56 {
     57 }
     58 
     59 void
     60 troff(char *s)
     61 {
     62 	int size;
     63 
     64 	if (strncmp(s, ".ps", 3) == 0) {
     65 	    if (sscanf(&s[3], " %d ", &size) > 0) {
     66 		fprintf(TEXFILE, "    \\special{pn %d}%%\n", size);
     67 		e1->pdiam = size;
     68 	    } else fprintf(stderr, "Malformed .ps command: %s\n", s);
     69 	}
     70 }
     71 
     72 
     73 void
     74 space(double x0, double y0, double x1, double y1)	/* set limits of page */
     75 {
     76 	e0->sidex = e1->sidex = deltx*1000;
     77 	e0->sidey = e1->sidey = e0->bottom = e1->bottom = delty*1000;
     78 	range(x0, y0, x1, y1);
     79 }
     80 
     81 void
     82 dot(void)
     83 {
     84 	/* use .005" radius at nominal 9pt pen size */
     85 	disc(e1->copyx,e1->copyy,(e1->pdiam/9.0)*(4.3/e1->scalex));
     86 }
     87 
     88 void
     89 label(char *s, int t, int nh)	/* text s of type t nh half-lines up */
     90 {
     91 	double nem;
     92 
     93 	if (t & ABOVE)
     94 		nh++;
     95 	else if (t & BELOW)
     96 		nh--;
     97 	nem = .2 - nh*.6;
     98 	fprintf(TEXFILE,"    \\rlap{\\kern %6.3fin\\lower%6.3fin\\hbox{\\lower%5.2fem\\hbox to 0pt{",
     99 			INCHES(DTRX(e1->copyx)), INCHES(DTRY(e1->copyy)), nem);
    100 	fprintf(TEXFILE,t&LJUST?"%s\\hss":(t&RJUST?"\\hss %s":"\\hss %s\\hss"),s);
    101 	fprintf(TEXFILE,"}}}%%\n");
    102 }
    103 
    104 void
    105 spline(double x, double y, double/*sic*/ n, float *p, int dashed, double ddval)
    106 {
    107 	int k, j;
    108 
    109 	fprintf(TEXFILE,"    \\special{pa %d %d}%%\n",TRX(x),TRY(y));
    110 	for(k=0, j=0; k<n; k++, j+=2){
    111 		x += p[j];
    112 		y += p[j+1];
    113 		fprintf(TEXFILE,"    \\special{pa %d %d}%%\n",TRX(x),TRY(y));
    114 	}
    115 	fprintf(TEXFILE,"    \\special{sp}%%\n");
    116 }
    117 
    118 void
    119 ellipse(double x, double y, double r1, double r2)
    120 {
    121 	fprintf(TEXFILE, "    \\special{ar %d %d %d %d 0.0 6.2832}%%\n",
    122 		TRX(x), TRY(y), SCX(r1), -SCY(r2));
    123 }
    124 
    125 void
    126 arc(double xc, double yc, double x0, double y0, double x1, double y1)	/* draw arc with center xc,yc */
    127 {
    128 	devarc(x0, y0, x1, y1, xc, yc, 1 );   /* radius=1 means counterclockwise */
    129 }
    130 
    131 /* If NOEXPANDDASH is defined, use this instead of the normal dotline
    132  * in print().  This dotline relies on vec() noticing that e1->pen
    133  * is not SOLIDPEN, and putting out a call to a different postscript
    134  * routine.
    135  */
    136 #ifdef NOEXPANDDASH
    137 
    138 void
    139 dotline(double x0, double y0, double x1, double y1, int ddtype, double ddval)
    140 {
    141 	if (ddval != 0)
    142 		e1->dashlen = ddval;
    143 	e1->pen = (ddtype&DOTBIT)? DOTPEN : DASHPEN;
    144 	move(x0, y0);
    145 	vec(x1, y1);
    146 	e1->pen = SOLIDPEN;
    147 	e1->dashlen = e0->dashlen;
    148 }
    149 #endif