DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T f

⟦5b244ab6b⟧ TextFile

    Length: 30412 (0x76cc)
    Types: TextFile
    Names: »fig2tex.c,v«

Derivation

└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
    └─⟦this⟧ »./tex82/TeXgraphics/transfig/fig2tex/fig2tex.c,v« 

TextFile

head     1.13;
access   ;
symbols  ;
locks    ; strict;
comment  @ * @;


1.13
date     88.02.24.12.23.04;  author beck;  state Exp;
branches ;
next     1.12;

1.12
date     88.02.18.16.23.46;  author beck;  state Exp;
branches ;
next     1.11;

1.11
date     88.02.17.11.20.05;  author beck;  state Exp;
branches ;
next     1.10;

1.10
date     88.02.17.10.30.57;  author beck;  state Exp;
branches ;
next     1.9;

1.9
date     88.02.16.12.10.54;  author beck;  state Exp;
branches ;
next     1.8;

1.8
date     88.02.15.16.27.35;  author beck;  state Exp;
branches ;
next     1.7;

1.7
date     88.02.15.15.57.03;  author beck;  state Exp;
branches ;
next     1.6;

1.6
date     88.02.15.11.44.37;  author beck;  state Exp;
branches ;
next     1.5;

1.5
date     88.02.12.01.06.09;  author beck;  state Exp;
branches ;
next     1.4;

1.4
date     88.02.11.11.11.28;  author beck;  state Exp;
branches ;
next     1.3;

1.3
date     88.02.09.11.25.07;  author beck;  state Exp;
branches ;
next     1.2;

1.2
date     88.01.04.10.40.01;  author beck;  state Exp;
branches ;
next     1.1;

1.1
date     87.12.22.13.00.24;  author beck;  state Exp;
branches ;
next     ;


desc
@Fig-to-PicTeX conversion program with LaTeX optimization
@


1.13
log
@fix bounding box calculation, a bug in arbitary text
@
text
@/* 
 *	Fig2tex : The fig-to-PicTeX translator
 *
 *	Modified from ftp, the fig-to-to-pic translator
 *
 *	University of Texas at Austin,
 *
*/
/*
 * Modified 1987 for PicTeX output by Micah Beck (beck@@svax.cs.cornell.edu)
 *
 */
#include <stdio.h>
#include <math.h>
#include "object.h"
#include "choices.h"

#define	round(x)	((int) (x + .5))

#define max(a,b)	((a > b) ? a : b)
#define min(a,b)	((a < b) ? a : b)

#define MINMAX(X,Y) {	min_x = min(X, min_x);	\
			min_y = min(Y, min_y);	\
			max_x = max(X, max_x);	\
			max_y = max(Y, max_y);	\
			}

#define SWITCH(T,A,B) {	register T t;	\
			t = A;		\
			A = B;		\
			B = t;		\
			}
#define EPSILON 0.02
#define CLOSE(A,B) (fabs(A-B) < EPSILON)

extern int getopt();
extern char *optarg;
extern int optind;

extern double sin(), cos(), acos(), fabs();

FILE		*tfp;
float		PIX_PER_INCH, mag;
int		cur_style, cur_dashlength;

main(argc, argv)
int	 argc;
char	*argv[];
{
	char		*textfont, *linethick, *plotsymbol;
	char		*from, *to, text[80], c;
	FILE		*ffp;
	int		arb, size, type, style, thickness, direction;
	int		n, num_obj, font, object;
	int		f_arrow, b_arrow, arrow_wid, arrow_ht;
	float		CANVAS_WIDTH, CANVAS_HEIGHT, ORIGIN;
	float		dummy, width, height, length, dash_length;
	float		a, b;
	float		x, y, x1, y1, x2, y2, xsav, ysav;
	float		cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
	float		min_x, min_y, max_x, max_y;
	double		dx1, dx2, dy1, dy2, r1, th1, r2, th2, theta, t;

	mag = 1.0;
	textfont = "\\twltt";
	linethick = ".7pt";
	plotsymbol = "\\sevrm .";

	from = NULL;
	to = NULL;

	while ((c = getopt(argc, argv, "af:l:p:m:")) != EOF)

	    switch (c) {

		case 'a':			/* arbitrary text */
		    arb = 1;

		case 'f':			/* set text font */
		    textfont = optarg;
		    break;

		case 'l':			/* set line thickness */
		    linethick = optarg;
		    break;

		case 'p':			/* set plot symbol */
		    plotsymbol = optarg;
		    break;

		case 'm':
		    mag = atof(optarg);		/* set magnification */
		    break;

		case '?':
		    exit(1);
		    break;
	    }

	if (optind < argc) from = argv[optind++];  /*  from file  */
	if (optind < argc) to   = argv[optind];  /*  to file    */

	if (from == NULL) 
	    ffp = stdin;
	else if ((ffp = fopen(from, "r")) == NULL) {
	    fprintf(stderr, "Couldn't open %s\n", from);
	    exit(1);
	    }
	if (to == NULL) 
	    tfp = stdout;
	else if ((tfp = fopen(to, "w")) == NULL) {
	    fprintf(stderr, "Couldn't open %s\n", to);
	    exit(1);
	    }

	cur_style = SOLID_LINE;
	cur_dashlength = 0;

	fscanf(ffp,"%f %f %f %f\n", &PIX_PER_INCH, &ORIGIN, 
		&CANVAS_WIDTH, &CANVAS_HEIGHT);

	max_x = max_y = 0;
	min_x = CANVAS_WIDTH;
	min_y = CANVAS_HEIGHT;

	fprintf(tfp, "\\mbox{\\beginpicture\n");
	fprintf(tfp, "\\setcoordinatesystem units <%6.3fin,%6.3fin>\n",
			mag, mag);
	fprintf(tfp, "\\linethickness=%s\n", linethick);
	fprintf(tfp, "\\setplotsymbol ({%s})\n", plotsymbol);
	fprintf(tfp, "\\setlinear\n");

        fprintf(tfp, "\\if \\picturemode \\nopics \\else\n");
	fprintf(tfp, "\\if \\picturemode \\dottedpics \\setdots \\fi");

        fprintf(tfp, "\\if \\picturemode \\optpics\n");
	fprintf(tfp, "\\unitlength=%6.3fin\n", mag);
	fprintf(tfp, "\\thicklines\n");
	fprintf(tfp, "\\fi\n");

	num_obj = 0;
	while ((fscanf(ffp, "%d", &object)) != EOF) {
	    switch (object) {

		case ARC :
		    num_obj++;
		    fprintf(tfp, "%%\n%% Fig ARC object (#%d)\n%%\n", num_obj);

		    n = fscanf(ffp, " %d %d %d %f %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
				&type, &style, &thickness, 
				&dash_length, &direction, &f_arrow, &b_arrow,
				&arrow_ht, &arrow_wid, &x, &y,
				&x1, &y1, &dummy, &dummy, &x2, &y2);
		    if (n != 17) {
			fprintf(stderr, "Arc (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			}

		    if (direction == 1) {
			SWITCH(float, x1, x2);
			SWITCH(float, y1, y2);
			SWITCH(int, f_arrow, b_arrow);
		 	}

		    dx1 = x1 - x;
		    dy1 = y1 - y;
		    dx2 = x2 - x;
		    dy2 = y2 - y;
		    
		    rtop(dx1, dy1, &r1, &th1);
		    rtop(dx2, dy2, &r2, &th2);
		    theta = th1 - th2;
		    if (theta > 0) theta -= 360;

		    MINMAX(x1, y1);
		    MINMAX(x2, y2);
		    for (t = 0; t > theta * acos(0.0) / 90; t -= .1)
			MINMAX(x + r1 * cos(th1+t), y + r1 * sin(th1+t));

		    x = x / PIX_PER_INCH; /*  (x,y) is the center of the arc */
		    y = (CANVAS_HEIGHT - y) / PIX_PER_INCH;
		    x1 = x1 / PIX_PER_INCH;
		    y1 = (CANVAS_HEIGHT - y1) / PIX_PER_INCH;
		    x2 = x2 / PIX_PER_INCH;
		    y2 = (CANVAS_HEIGHT - y2) / PIX_PER_INCH;

		    if (b_arrow) setarrow(tfp,
				((float)arrow_wid)/PIX_PER_INCH,
				((float)arrow_ht)/PIX_PER_INCH,
				x1+(y1-y), y1-(x1-x), x1, y1);
		    if (f_arrow) setarrow(tfp,
				((float)arrow_wid)/PIX_PER_INCH,
				((float)arrow_ht)/PIX_PER_INCH,
				x2-(y2-y), y2+(x2-x), x2, y2);

		    setstyle(style, dash_length);

		    fprintf(tfp, "\\circulararc %6.3f degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
			theta, x1, y1, x, y);
		    break;

		case POLYLINE :
		    num_obj++;
		    fprintf(tfp, "%%\n%% Fig POLYLINE object (#%d)\n%%\n",
			    num_obj);

		    n = fscanf(ffp, " %d %d %d %f %d %d %d %d", 
				&type, &style, &thickness, 
				&dash_length, &f_arrow, &b_arrow,
				&arrow_ht, &arrow_wid);
		    if (n != 8) {
			fprintf(stderr, "Line (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			}

		    if (fscanf(ffp, " %f %f %f %f", &x1, &y1, &x2, &y2) != 4) {
			fprintf(stderr, "Line (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			};

		    MINMAX(x1, y1);

		    x1 = x1 / PIX_PER_INCH;
		    y1 = (CANVAS_HEIGHT - y1) / PIX_PER_INCH;
		    if (x2 == 9999 && y2 == 9999) { /* A single point line */
			fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f/\n",
			    	x1, y1, x1, y1);
		        break;
			}

		    MINMAX(x2, y2);

		    x2 = x2 / PIX_PER_INCH;
		    y2 = (CANVAS_HEIGHT - y2) / PIX_PER_INCH;

		    if (b_arrow) setarrow(tfp,
				((float)arrow_wid)/PIX_PER_INCH,
				((float)arrow_ht)/PIX_PER_INCH,
				x2, y2, x1, y1);

		    setstyle(style, dash_length);

		    putline(x1, y1, x2, y2);

		    for (;;) {
			if (fscanf(ffp, " %f %f", &x, &y) != 2) {
			    fprintf(stderr, "Line (object #%d) is incomplete\n",
				num_obj);
			    fscanf(ffp, "%*[^\n]");  /* Flush the buffer */
			    break;
			    };
			if (x == 9999) break;

		        MINMAX(x, y);

			x = x / PIX_PER_INCH;
			y = (CANVAS_HEIGHT - y) / PIX_PER_INCH;

			putline(x2, y2, x, y);

			x1 = x2;
			y1 = y2;
			x2 = x;
			y2 = y;
			}

		    if (f_arrow) setarrow(tfp,
					((float)arrow_wid)/PIX_PER_INCH, 
					((float)arrow_ht) /PIX_PER_INCH,
					x1, y1, x2, y2);

		    break;

		case SPLINE :
		    num_obj++;
		    fprintf(tfp, "%%\n%% Fig SPLINE object (#%d)\n%%\n",
			    num_obj);

		    n = fscanf(ffp, " %d %d %d %f %d %d %d %d", &type, &style,
				&thickness, &dash_length, 
				&f_arrow, &b_arrow, &arrow_ht, &arrow_wid);
		    if (n != 8) {
			fprintf(stderr, "Spline (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			}

		    if (fscanf(ffp, " %f %f %f %f", &x1, &y1, &x2, &y2) != 4) {
			fprintf(stderr, "Spline (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			};

		    MINMAX(x1, y1);
		    MINMAX(x2, y2);

		    y1 = (CANVAS_HEIGHT - y1);
		    y2 = (CANVAS_HEIGHT - y2);

		    if (b_arrow) setarrow(tfp,
					((float)arrow_wid)/PIX_PER_INCH,
					((float)arrow_ht)/PIX_PER_INCH,
					x2/PIX_PER_INCH, y2/PIX_PER_INCH,
					x1/PIX_PER_INCH, y1/PIX_PER_INCH);

		    setstyle(style, dash_length);

		    cx1 = (x1 + x2) / 2;      cy1 = (y1 + y2) / 2;
		    cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;

		    if (type == DRAW_SPLINE)
			    fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f\n",
			    	x1/PIX_PER_INCH, y1/PIX_PER_INCH,
				cx1/PIX_PER_INCH, cy1/PIX_PER_INCH);
		    else
			    fprintf(tfp, "\\plot \n");

		    /* save closure point for close splines */
		    xsav = x2;
		    ysav = y2;

		    for (n=2;;n++) {
			if (fscanf(ffp, " %f %f", &x, &y) != 2) {
			    fprintf(stderr, "Spline (object #%d) is incomplete\n",
				num_obj);
			    fscanf(ffp, "%*[^\n]");  /* Flush the buffer */
			    break;
			    };
			if (x == 9999) break;

		        MINMAX(x, y);
			y = (CANVAS_HEIGHT - y);

	    		x1 = x2;  y1 = y2;
	    		x2 = x;  y2 = y;
	    		cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
	    		cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
	    		chaikin_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
	    		cx1 = cx4;  cy1 = cy4;
	    		cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
	    		}

		    if (type == DRAW_SPLINE)
			fprintf(tfp, "\t%6.3f %6.3f /\n",
			    (int)x2/PIX_PER_INCH, (int)y2/PIX_PER_INCH);
		    else {
			fprintf(tfp, "\t/\n\\plot\n");
			x1 = x2;  y1 = y2;
			x2 = xsav;  y2 = ysav;
			cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
			cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;

			chaikin_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
			fprintf(tfp, "\t/\n");
			}
		
	       	    if (f_arrow) setarrow(tfp,
					((float)arrow_wid)/PIX_PER_INCH, 
					((float)arrow_ht) /PIX_PER_INCH,
					x1/PIX_PER_INCH, y1/PIX_PER_INCH,
					x2/PIX_PER_INCH, y2/PIX_PER_INCH);
		    break;

		case ELLIPSE :
		    num_obj++;
		    fprintf(tfp, "%%\n%% Fig ELLIPSE object (#%d)\n%%\n",
			    num_obj);

		    n = fscanf(ffp, " %d %d %d %f %d %f %f %f %f %f %f %f %f\n", 
				&type, &style, &thickness, &dash_length,
				&direction, &x, &y, &a, &b, 
				&dummy, &dummy, &dummy, &dummy);
		    if (n != 13) {
			fprintf(stderr, "Ellipse (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			}

		    setstyle(style, dash_length);

		    MINMAX(x+a, y);
		    MINMAX(x-a, y);
		    MINMAX(x, y+b);
		    MINMAX(x, y-b);

		    x = x / PIX_PER_INCH;
		    y = (CANVAS_HEIGHT - y) / PIX_PER_INCH;
		    width = a / PIX_PER_INCH;
		    height = b / PIX_PER_INCH;
		    if (!latexcircle(width, height, x, y))
		 	fprintf(tfp, "\\iffalse ");
		    fprintf(tfp, "\\else\n");
		    fprintf(tfp, "\\ellipticalarc axes ratio %6.3f:%-6.3f 360 degrees \n",
			    width, height);
		    fprintf(tfp, "\tfrom %6.3f %6.3f center at %6.3f %6.3f\n",
			    x+width, y, x, y);
		    fprintf(tfp, "\\fi\n");

		    break;

		case TEXT :
		    num_obj++;
		    fprintf(tfp, "%%\n%% Fig TEXT object (#%d)\n%%\n",
			    num_obj);

		    n = fscanf(ffp, "%d %d %d %f %f %f %f %[^\n]",
				&font, &size,
				&style, &height, &length, &x, &y, text);
		    if (n != 8) {
			fprintf(stderr, "Text (object #%d) is incomplete\n",
				num_obj);
			fscanf(ffp, " %[^\n]", text); /* skip to next line */
			break;
			}

		    MINMAX(x,y);
		    MINMAX(x+length, y-height)
		    x = x / PIX_PER_INCH;
		    y = (CANVAS_HEIGHT - y) / PIX_PER_INCH;
		    if (arb)
			/* arbitrary tex needs no hbox */
		    	fprintf(tfp, "\\put {%s %s} [lB] at %6.3f %6.3f\n",
			    textfont, text, x, y);
		    else
		    	fprintf(tfp, "\\put {\\hbox to %6.3fin{%s %s}} [lB] at %6.3f %6.3f\n",
			    length/PIX_PER_INCH, textfont, text, x, y);
		    break;

		case COMPOUND :
		    fscanf(ffp, " %[^\n]", text); /* ignore the rest */

		default :
		    break;
		}
	    }
	fprintf(tfp, "\\fi\n");
	fprintf(tfp, "\\linethickness=0pt\n");
        fprintf(tfp, "\\putrectangle corners at %6.3f %6.3f and %6.3f %6.3f\n",
			min_x/PIX_PER_INCH,(CANVAS_HEIGHT-max_y)/PIX_PER_INCH,
			max_x/PIX_PER_INCH,(CANVAS_HEIGHT-min_y)/PIX_PER_INCH);
	fprintf(tfp, "\\endpicture}\n");
	}

/*
 * putline - use rules if possible
 */
putline (start_x, start_y, end_x, end_y)
float	start_x, start_y, end_x, end_y;
{
    if (cur_style == SOLID_LINE &&
	    (CLOSE (start_x, end_x) || CLOSE (start_y, end_y)))
	fprintf(tfp, "\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
		start_x, start_y, end_x, end_y);

    else {
	if (!latexline(start_x, start_y, end_x, end_y))
	    fprintf(tfp, "\\iffalse\n");
	fprintf(tfp, "\\else\n");
	fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
					start_x, start_y, end_x, end_y);
	fprintf(tfp, "\\fi\n");
	}
}


/* 
 * setstyle - issue style commands as appropriate
 */
setstyle(style, dash_length)
int style;
float dash_length;
{
    switch (style) {
	 case SOLID_LINE:
	    if (cur_style == SOLID_LINE) break;
	    fprintf(tfp, "\\setsolid\n");
	    break;

	case DASH_LINE:
	    if (cur_style == DASH_LINE && cur_dashlength == dash_length)
		break;
	    fprintf(tfp, "\\setdashes <%7.4fin>\n",dash_length / PIX_PER_INCH);
	    break;

	case DOTTED_LINE:
	    if (cur_style == DOTTED_LINE)
		break;
	    fprintf(tfp, "\\setdots \n");
	    break;
	    }

	cur_style = style;
	cur_dashlength = dash_length;
    }

/*
 * setarrow - construct an arrow from a given direction
 */
setarrow(tfp, w, l, ex, ey, ax, ay)
FILE *tfp;
float w, l, ex, ey, ax, ay;
{
	float L, beta, gamma;

	L = hypot(ex - ax, ey - ay);
	ex = (ax + .01*(ex - ax)/L);
	ey = (ay + .01*(ey - ay)/L);

	gamma = w/l;
	beta = gamma/2;
	setstyle(SOLID_LINE, 0.0);
	fprintf(tfp, "\\arrow <%6.3fin> [%6.3f,%6.3f] from %6.3f %6.3f to %6.3f %6.3f\n",
		l*mag, beta, gamma, ex, ey, ax, ay);
}


/*
 * rtop - rectangular to polar conversion
 */
rtop(x, y, r, th)
double x, y, *r, *th;
{
	*r = hypot(x,y);
	*th = acos(x/(*r)) * 90 /acos(0.0);

	if (y < 0) *th = 360 - *th;
}


/****************************************************************************

	The following spline drawing routine is from 

	"An Algorithm for High-Speed Curve Generation" 
	by George Merrill Chaikin,
	Computer Graphics and Image Processing, 3, Academic Press, 
	1974, 346-349.

	and

	"On Chaikin's Algorithm" by R. F. Riesenfeld,
	Computer Graphics and Image Processing, 4, Academic Press, 
	1975, 304-310.

*****************************************************************************/

chaikin_spline(x1, y1, x2, y2, x3, y3, x4, y4)
float	x1, y1, x2, y2, x3, y3, x4, y4;
{
	float	xmid, ymid;

	xmid = (x2 + x3) / 2;  ymid = (y2 + y3) / 2;
	if (fabs(x1 - xmid) < 1 && fabs(y1 - ymid) < 1) 
	    draw_vector(x1, y1, xmid, ymid);

	else {
	    chaikin_spline(x1, y1, 
			((x1 + x2) / 2),  ((y1 + y2) / 2),
			((3*x2 + x3) / 4), ((3*y2 + y3) / 4), xmid, ymid);
	    }

	if (fabs(xmid - x4) < 1 && fabs(ymid - y4) < 1) {
	    draw_vector(xmid, ymid, x4, y4);
	    }
	else {
	    chaikin_spline(xmid, ymid, 
			((x2 + 3*x3) / 4),  ((y2 + 3*y3) / 4),
			((x3 + x4) / 2),  ((y3 + y4) / 2), x4, y4);

	    }
	}

draw_vector(x1, y1, x2, y2)
float x1, y1, x2, y2;
{
	fprintf(tfp, "\t%6.3f %6.3f\n",
		x2 / PIX_PER_INCH, y2 / PIX_PER_INCH);
}


/********************************************************************

	LaTeX Object Optimizer Routines

********************************************************************/

/*
 * Slopes implemented in LaTeX and the corresponding args to \line
 */
float slopes[][2]= {	{0.,1.},
			{1.,1.},{2.,1.},{3.,1.},{4.,1.},{5.,1.},{6.,1.},
			{1.,2.},	{3.,2.},	{5.,2.},
			{1.,3.},{2.,3.},	{4.,3.},{5.,3.},
			{1.,4.},	{3.,4.},	{5.,4.},
			{1.,5.},{2.,5.},{3.,5.},{4.,5.},{6.,5.},
			{1.,6.},			{5.,6.},
			{-1.,0.}};

float upslope[2]={1.,0.}, downslope[2]={-1.,0.};

/*
 * latexline - generate a LaTeX line if possible
 */
latexline(x1, y1, x2, y2)
float x1, y1, x2, y2;
{
	float *lineargs;
	float len, sl, t, delta;
	int  sign = 1;
	int i;

	if (cur_style != SOLID_LINE) return(0);

	if (CLOSE(x1, x2)) {

	    len = fabs(y2-y1);
	    if (y2 > y1)

	        lineargs = upslope;
	    else {
	    	lineargs = downslope;
		}
	     }
	else {

	    if (x2 < x1) {
		SWITCH(float, x1, x2);
		SWITCH(float, y1, y2);
		}

	    len = x2 - x1;
	    if (len*mag < 1/7.) return(0);

	    sl = (y2 - y1) / (x2 - x1);
	    if (sl < 0) {
		sl = -sl;
		sign = -1;
	    }

	
	    for (i=0, delta=1.0; slopes[i][0] >= 0; i++) 
		if ((t = fabs(atan(sl) - atan(slopes[i][0]/slopes[i][1]))) < delta) {
		    delta = t;
		    lineargs = slopes[i];
		}
	    }

	if (CLOSE(delta, 0.0)) {
	    fprintf(tfp, "\\if \\picturemode \\optpics\n");
	    fprintf(tfp,"\\put {\\line(%.0f,%.0f){%6.3f}} [Bl] at %6.3f %6.3f\n",
		    	lineargs[1], sign*lineargs[0], len, x1, y1);
	    return(1);
 	    }
	else
	    return(0);

    }

/*
 * latexcircle - generate a LaTeX circle if possible
 */
latexcircle(w, h, x, y)
float w, h, x, y;
{
	if (cur_style != SOLID_LINE) return(0);
	if (!CLOSE(w, h)) return(0);
	if (2*w > 15.5/72.27) return(0);

	fprintf(tfp, "\\if \\picturemode \\optpics\n");
	fprintf(tfp, "\\put {\\circle{%6.3f}} [lB] at %6.3f %6.3f\n",
		    2*w, x, y);
	return(1);
}

	
@


1.12
log
@use rules when possible,even when not optimizing
@
text
@d425 3
d433 1
a433 1
			    mag*length/PIX_PER_INCH, textfont, text, x, y);
d436 1
a436 1
			    mag*length/PIX_PER_INCH, textfont, text, x, y);
d519 1
a519 1
	gamma = (w+0.0)/l;
@


1.11
log
@close splines work now
.,
@
text
@d67 1
a67 1
	linethick = ".07pt";
d233 1
a233 1
			fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
a242 1

d250 2
a251 7
		    if (!latexline(x1, y1, x2, y2))
		 	fprintf(tfp, "\\iffalse\n");
		    fprintf(tfp, "\\else\n");
		    fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
					x1, y1, x2, y2);
		    fprintf(tfp, "\\fi\n");
		    
d266 1
a266 6
		    	if (!latexline(x2, y2, x, y))
		 	    fprintf(tfp, "\\iffalse ");
		    	fprintf(tfp, "\\else\n");
		    	fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
				x2, y2, x, y);
		    	fprintf(tfp, "\\fi\n");
d450 22
@


1.10
log
@added some pretty printing
@
text
@d60 1
a60 1
	float		x, y, x1, y1, x2, y2;
d330 12
a341 4
		    fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f \n",
		    	x1/PIX_PER_INCH, y1/PIX_PER_INCH,
			cx1/PIX_PER_INCH, cy1/PIX_PER_INCH);
		    
a351 1

d363 9
a371 2
		    fprintf(tfp, "\t%6.3f %6.3f /\n",
			(int)x2/PIX_PER_INCH, (int)y2/PIX_PER_INCH);
d373 4
@


1.9
log
@Adjusted splines for greater resolution (300 BPI for printing)
@
text
@d108 1
a108 1
	    exit();
d114 1
a114 1
	    exit();
d148 2
a161 2
		    setstyle(style, dash_length);

d198 3
d207 3
a220 2
		    setstyle(style, dash_length);

d233 1
a233 1
			fprintf(tfp, "\plot %6.3f,%6.3f %6.3f,%6.3f\n",
d249 2
d254 1
a254 1
		    fprintf(tfp, "\\setlinear \\plot %6.3f %6.3f %6.3f %6.3f /\n",
d285 4
a288 5
		    if (f_arrow)
			setarrow(tfp,
			    ((float)arrow_wid)/PIX_PER_INCH, 
			    ((float)arrow_ht) /PIX_PER_INCH,
			    x1, y1, x2, y2);
d294 3
a306 2
		    setstyle(style, dash_length);

d326 1
d356 1
a356 1
		    fprintf(tfp, "\t%6.3f %6.3f /",
d368 3
d396 4
a399 2
		    fprintf(tfp, "\\ellipticalarc axes ratio %6.3f:%-6.3f 360 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
			width, height, x+width, y, x, y);
d406 3
d489 1
@


1.8
log
@splines integrated more cleanly
@
text
@a11 1
 * Problems:	rendering of splines (PicTeX uses quadratic)
d324 2
a325 2
		    	(int)x1/PIX_PER_INCH, (int)y1/PIX_PER_INCH,
			round(cx1)/PIX_PER_INCH, round(cy1)/PIX_PER_INCH);
d515 2
a516 2
	if (fabs(x1 - xmid) < 3 && fabs(y1 - ymid) < 3) 
	    draw_vector(round(x1), round(y1), round(xmid), round(ymid));
d524 2
a525 2
	if (fabs(xmid - x4) < 3 && fabs(ymid - y4) < 3) {
	    draw_vector(round(xmid), round(ymid), round(x4), round(y4));
d536 1
a536 1
int x1, y1, x2, y2;
d539 1
a539 1
		(float)x2 / PIX_PER_INCH, (float)y2 / PIX_PER_INCH);
@


1.7
log
@splines work
@
text
@d268 1
a268 1
		 	    fprintf(tfp, "\\iffalse\n");
d324 3
a326 1
		    draw_vector((int)x1, (int)y1, round(cx1), round(cy1));
d350 2
a351 1
		    draw_vector(round(cx1), round(cy1), (int)x2, (int)y2);
d385 1
a385 1
		 	fprintf(tfp, "\\iffalse\n");
d539 1
a539 2
	fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
		(float)x1 / PIX_PER_INCH, (float)y1 / PIX_PER_INCH,
@


1.6
log
@some optimizer changes: remove point massaging
@
text
@d19 2
d62 1
a62 1
	float		ox, oy, ox1, oy1, ox2, oy2;
d130 1
a130 1
		mag, mag);
d133 1
d230 1
a230 1
			fprintf(tfp, "\setlinear\n\plot %6.3f,%6.3f %6.3f,%6.3f\n",
d270 1
a270 1
		    	fprintf(tfp, "\\setlinear \\plot %6.3f %6.3f %6.3f %6.3f /\n",
d312 2
a313 4
		    x1 = x1 / PIX_PER_INCH;
		    y1 = (CANVAS_HEIGHT - y1) / PIX_PER_INCH;
		    x2 = x2 / PIX_PER_INCH;
		    y2 = (CANVAS_HEIGHT - y2) / PIX_PER_INCH;
d318 2
a319 1
					x2, y2, x1, y1);
a320 1
		    fprintf(tfp, "\\setquadratic \\plot %6.3f %6.3f %6.3f %6.3f",
d322 3
a324 1
				x1, y1, x2, y2);
d337 1
a337 2
			x = x / PIX_PER_INCH;
			y = (CANVAS_HEIGHT - y) / PIX_PER_INCH;
d339 8
a346 1
			fprintf(tfp, "\n\t %6.3f %6.3f", x, y);
d348 1
a348 6
			x1 = x2;
			y1 = y2;
			x2 = x;
			y2 = y;
			}
		    if (!(n%2)) fprintf(stderr, "Spline (ojbect #%d) has an even number of point\n", num_obj);
a349 2
		    fprintf(tfp, " /\n");

d353 2
a354 1
					x1, y1, x2, y2);
d476 1
d489 58
@


1.5
log
@some fixes
@
text
@d2 1
a2 1
 *	F2t : The fig-to-PicTeX translator
a35 3
#define GRAN		32
#define MASSAGE(X)   	{X = rint(X * GRAN) / GRAN;}

a242 1
		    fprintf(tfp, "\\if \\picturemode \\optpics\n");
d244 1
a244 3
			    fprintf(tfp, "\\setlinear \\plot %6.3f %6.3f %6.3f %6.3f /\n",
					x1, y1, x2, y2);

a263 1
		    	fprintf(tfp, "\\if \\picturemode \\optpics\n");
d265 1
a265 2
			    fprintf(tfp, "\\setlinear \\plot %6.3f %6.3f %6.3f %6.3f /\n",
			    	x2, y2, x, y);
a377 1
		    fprintf(tfp, "\\if \\picturemode \\optpics\n");
d379 1
a379 2
			    fprintf(tfp, "\\ellipticalarc axes ratio %6.3f:%-6.3f 360 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
				width, height, x+width, y, x, y);
d446 1
a446 1
	    fprintf(tfp, "\\setdots \n", dash_length / PIX_PER_INCH);
a510 5
	MASSAGE(x1);
	MASSAGE(y1);
	MASSAGE(x2);
	MASSAGE(y2);

d548 1
a548 1

a563 5
	MASSAGE(w);
	MASSAGE(h);
	MASSAGE(x);
	MASSAGE(y);

d568 1
@


1.4
log
@makes optimization a run-time option, along with dotted and noplot
output now needs fig2tex.tex to work right
@
text
@d36 2
a37 2
#define GRAN		(PIX_PER_INCH/32.)
#define MASSAGE(X)   	{X = rint(X / GRAN) * GRAN;}
d56 1
a56 1
	int		size, type, style, thickness, direction;
d75 1
a75 1
	while ((c = getopt(argc, argv, "dnOf:l:p:m:")) != EOF)
d79 3
d129 1
a129 1
	fprintf(tfp, "\\beginpicture\n");
d276 1
a276 1
				x1, y1, x2, y2);
d410 3
a412 1
		    fprintf(tfp, "\\put {\\hbox to %6.3fin{%s %s}} [lB] at %6.3f %6.3f\n",
d414 3
d431 1
a431 1
	fprintf(tfp, "\\endpicture\n");
a443 1
	    fprintf(tfp, "\\if \\picturemode \\pics\n");
a444 1
	    fprintf(tfp, "\\fi\n");
a449 1
	    fprintf(tfp, "\\if \\picturemode \\pics\n");
a450 1
	    fprintf(tfp, "\\fi\n");
a455 1
	    fprintf(tfp, "\\if \\picturemode \\pics\n");
a456 1
	    fprintf(tfp, "\\fi\n");
@


1.3
log
@fixed text placement and spacing problems
@
text
@d36 3
a46 1
int		alldots, noplot, optimize;
d63 1
a66 1
	alldots = noplot = optimize = 0;
a78 12
		case 'd':			/* all plotting in dots */
		    alldots = 1;
		    break;

		case 'n':			/* no plotting */
		    noplot = 1;
		    break;

		case 'O':			/* no plotting */
		    optimize = 1;
		    break;

a130 4
	if (optimize) {
	    fprintf(tfp, "\\unitlength=%6.3fin\n", mag);
	    fprintf(tfp, "\\thicklines\n");
	    }
d132 8
d158 1
a158 1
		    setstyle(alldots? DOTTED_LINE:style, dash_length);
a175 4
		   if (optimize) {
			massage(&x1, &y1);
			massage(&x2, &y2);
			}
d188 10
a197 12
		    if (!noplot) {
		        if (b_arrow) setarrow(tfp, alldots,
					((float)arrow_wid)/PIX_PER_INCH,
					((float)arrow_ht)/PIX_PER_INCH,
					x1+(y1-y), y1-(x1-x), x1, y1);
		        if (f_arrow) setarrow(tfp, alldots,
					((float)arrow_wid)/PIX_PER_INCH,
					((float)arrow_ht)/PIX_PER_INCH,
					x2-(y2-y), y2+(x2-x), x2, y2);
			fprintf(tfp, "\\circulararc %6.3f degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
				theta, x1, y1, x, y);
			}
d213 1
a213 1
		    setstyle(alldots? DOTTED_LINE:style, dash_length);
a221 1
		    if (optimize) massage(&x1, &y1);
d227 3
a229 4
			if (!noplot)
				fprintf(tfp, "\setlinear\n\plot %6.3f,%6.3f %6.3f,%6.3f\n",
				    	x1, y1, x1, y1);
			break;
a231 1
		    if (optimize) massage(&x2, &y2);
a236 1
		    if (!noplot) {
d238 7
a244 5
		        if (b_arrow) setarrow(tfp, alldots,
					((float)arrow_wid)/PIX_PER_INCH,
					((float)arrow_ht)/PIX_PER_INCH,
					x2, y2, x1, y1);
			if (!optimize || !latexline(x1, y1, x2, y2))
d247 5
a251 1
			}
a261 1
		    	if (optimize) massage(&x, &y);
d267 8
a274 4
			if (!noplot)
			    if (!optimize || !latexline(x2, y2, x, y))
				fprintf(tfp, "\\setlinear \\plot %6.3f %6.3f %6.3f %6.3f /\n",
				    	x2, y2, x, y);
d282 2
a283 2
		    if (!noplot && f_arrow)
			setarrow(tfp, alldots,
d302 1
a302 1
		    setstyle(alldots? DOTTED_LINE:style, dash_length);
a310 4
		    if (optimize) {
			massage(&x1, &y1);
			massage(&x2,&y2);
			}
d319 1
a319 3
		    if (!noplot) {

		        if (b_arrow) setarrow(tfp, alldots,
a322 1
			fprintf(tfp, "\\setquadratic \\plot %6.3f %6.3f %6.3f %6.3f",
d324 2
a326 1
			}
a336 1
			if (optimize) massage(&x, &y);
d342 1
a342 1
			if (!noplot) fprintf(tfp, "\n\t %6.3f %6.3f", x, y);
d351 1
a351 1
		    if (!noplot) {
d353 1
a353 2
			fprintf(tfp, " /\n");
		        if (f_arrow) setarrow(tfp, alldots,
a356 1
		    	}
d372 1
a372 1
		    setstyle(alldots? DOTTED_LINE:style, dash_length);
a373 4
		    if (optimize) {
			massage(&x, &y);
			massage(&a, &b);
			}
d383 2
a384 2
		    if (!noplot)
			if (!optimize || !latexcircle(width, height, x, y))
d386 6
a391 1
					width, height, x+width, y, x, y);
d418 1
d436 1
d438 1
d444 1
d446 1
d452 1
d454 1
d465 1
a465 1
setarrow(tfp, d, w, l, ex, ey, ax, ay)
a466 1
int d;
a470 6
	if (d) {

	    fprintf(tfp, "\\put {\\tt *} at %6.3f %6.3f\n", ax, ay);
	    return;
	    }

a492 9
/*
 * massage - round coordinates to nearest 1/16 of inch
 */
massage(xp, yp)
float *xp, *yp;
{
    *xp = rint(*xp * (32 / PIX_PER_INCH)) * (PIX_PER_INCH / 32);
    *yp = rint(*yp * (32 / PIX_PER_INCH)) * (PIX_PER_INCH / 32);
    }
d497 8
a504 8
float slopes[] = {	0.,
			1/1.,	2/1.,	3/1.,	4/1.,	5/1.,	6/1.,
			1/2.,		3/2.,		5/2.,
			1/3.,	2/3.,		4/3.,	5/3.,
			1/4.,		3/4.,		5/4.,
			1/5.,	2/5.,	3/5.,	4/5.,		6/5.,
			1/6.,				5/6.
			-1.};
d506 1
a507 9
char *args[] = {	"1,0",
			"1,1",	"1,2",	"1,3",	"1,4",	"1,5",	"1,6",
			"2,1",		"2,3",		"2,5",
			"3,1",	"3,2",		"3,4",	"3,5",
			"4,1",		"4,3",		"4,5",
			"5,1",	"5,2",	"5,3",	"5,4",		"5,6",
			"6,1",				"6,5"};
			

d514 1
a514 2
	char *lineargs = (char *)0;
	char  *sign = " ";
d516 1
d519 4
a522 1
	if ((cur_style != SOLID_LINE)  && !alldots) return(0);
d524 2
d531 1
a531 1
	        lineargs = "0,1";
d533 1
a533 2
	    	lineargs = "0,1";
		sign = "-";
d549 1
a549 1
		sign = "-";
d552 3
a554 2
	    for (i=0, delta=1.0; slopes[i] >= 0; i++) 
		if ((t = fabs(atan(sl) - atan(slopes[i]))) < delta) {
d556 1
a556 1
		    lineargs = args[i];
d562 2
a563 2
	    fprintf(tfp,"\\put {\\line(%c,%s%c){%6.3f}} [Bl] at %6.3f %6.3f\n",
		    	lineargs[0], sign, lineargs[2], len, x1, y1);
d577 6
a582 1
	if ((cur_style != SOLID_LINE)  && !alldots) return(0);
@


1.2
log
@Beta distribution version
@
text
@a46 18
float slopes[] = {	0.,
			1/1.,	2/1.,	3/1.,	4/1.,	5/1.,	6/1.,
			1/2.,		3/2.,		5/2.,
			1/3.,	2/3.,		4/3.,	5/3.,
			1/4.,		3/4.,		5/4.,
			1/5.,	2/5.,	3/5.,	4/5.,		6/5.,
			1/6.,				5/6.
			-1.};


char *args[] = {	"1,0",
			"1,1",	"1,2",	"1,3",	"1,4",	"1,5",	"1,6",
			"2,1",		"2,3",		"2,5",
			"3,1",	"3,2",		"3,4",	"3,5",
			"4,1",		"4,3",		"4,5",
			"5,1",	"5,2",	"5,3",	"5,4",		"5,6",
			"6,1",				"6,5"};
			
d66 1
a66 1
	textfont = "\\tt";
d422 2
a423 2
		    fprintf(tfp, "\\put {%s %s} [lb] at %6.3f %6.3f\n",
			    textfont, text, x, y);
d519 22
d608 1
a608 1
	fprintf(tfp, "\\put {\\circle{%6.3f}} [Bl] at %6.3f %6.3f\n",
@


1.1
log
@Initial revision
@
text
@d22 5
a26 4
#define MINMAX(X,Y) {	min_x = min(X, min_x); \
			min_y = min(Y, min_y); \
			max_x = max(X, max_x); \
			max_y = max(Y, max_y); }
d28 5
d34 1
a34 1
#define CLOSE(a,b) (fabs(a-b) < EPSILON)
d73 1
a73 1
	int		n, num_obj, first, font, object;
d77 1
a77 1
	float		a, b, sx, sy, ex, ey;
d134 1
a134 1
	    printf("Couldn't open %s\n", from);
d140 1
a140 1
	    printf("Couldn't open %s\n", to);
d176 1
a176 1
			printf("Arc object (object #%d) is incomplete\n",
d185 3
a187 11
			t = x1;
			x1 = x2;
			x2 = t;

			t = y1;
			y1 = y2;
			y2 = t;

			n = f_arrow;
			f_arrow = b_arrow;
			b_arrow = n;
d237 1
a237 1
			printf("Line object (object #%d) is incomplete\n",
d246 2
a247 1
			printf("incomplete line object\n");
d283 1
a283 1
			    printf("Line object (object #%d) is incomplete\n",
d321 1
a321 1
			printf("Spline object (object #%d) is incomplete\n",
d330 2
a331 1
			printf("incomplete spline object\n");
d359 1
a359 1
		    for (;;) {
d361 1
a361 1
			    printf("Spline object (object #%d) is incomplete\n",
d381 1
d400 1
a400 1
			printf("Ellipse object (object #%d) is incomplete\n",
d408 4
a411 1
		    if (optimize) massage(&x, &y, &a, &b);
d433 1
a433 1
			printf("Text object (object #%d) is incomplete\n",
d543 1
a543 1
	char  *sign = "";
d563 2
a564 7
		t = x1;
		x1 = x2;
		x2 = t;

		t = y1;
		y1 = y2;
		y2 = t;
d602 1
a602 1
	if (w > 15.5/72.27) return(0);
d604 2
a605 1
	fprintf(tfp, "\\put {\\circle{%6.3f}} at %6.3f %6.3f\n", 2*w, x, y);
@