From 8646c6b2ddaf32ac7342cc8b61e559d46885af4f Mon Sep 17 00:00:00 2001 From: root <> Date: Sun, 8 Feb 2009 16:49:14 +0000 Subject: *** empty log message *** --- src/xfig.c | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 src/xfig.c (limited to 'src/xfig.c') diff --git a/src/xfig.c b/src/xfig.c new file mode 100644 index 0000000..10da5e4 --- /dev/null +++ b/src/xfig.c @@ -0,0 +1,253 @@ +#include "project.h" + +BEGIN_OBJECT(Xfc) + int r,g,b,n; +END_OBJECT(Xfc) + +CREATOR(Xfc)=Obj_DefaultCreator; +DESTRUCTOR(Xfc)=Obj_DefaultDestructor; + +BEGIN_OBJECT(Private) + Xfc_list xfcs; + int maxcol; + FILE *tmpfile; + FILE *file; +END_OBJECT(Private) + +static void private_constructor(Private p) +{ +char name[1024]; + +p->xfcs=CREATE_LIST(Xfc); + +p->tmpfile=fopen(tmpnam(name),"w+"); + +unlink(name); + + + +} + +#define BUFSIZ 1024 + +static void private_destructor(Private p) +{ +Xfc c; +char buf[BUFSIZ]; +int i; + +fflush(p->tmpfile); +rewind(p->tmpfile); + + +printf("JWG: Writing xfig colors\n"); + +c=p->xfcs->head; + +while (c) { +fprintf(p->file,"0 %d #%02x%02x%02x\n",c->n,c->r,c->g,c->b); +c=c->next; +} + + +Obj_Delete(p->xfcs); + +printf("JWG: Writing xfig file\n"); + +while ((i=fread(buf,1,BUFSIZ,p->tmpfile))>0) { + + fwrite(buf,1,i,p->file); +} + +fclose(p->tmpfile); + +printf("JWG: xfig done\n"); + + + +free(p); +} + + +CREATOR(Private)=private_constructor; +DESTRUCTOR(Private)=private_destructor; + + + + +void xfig_init_private(Handle h) +{ +Private p; + +p=CREATE_OBJ(Private); +p->maxcol=32; +p->file=h->file; + +h->private=(void *) p; + + fprintf(h->file,"#FIG 3.1\n"); + fprintf(h->file,"Portrait\nFlush Left\nInches\n1200 2\n"); + +} + + +int xfig_sortout_color(Handle h,int r,int g,int b) +{ +Private p=(Private) h->private; +Xfc c; + +c=p->xfcs->head; + +while (c) +{ +if ((c->r==r) && (c->g==g) && (c->b==b)) return(c->n); +c=c->next; +} + +if (p->maxcol==512) { + printf("JWG: Xfig colors exhusted: this kludge needs fixing...\n"); + return(32); +} + +c=CREATE_OBJ(Xfc); +c->r=r; +c->g=g; +c->b=b; +c->n=(p->maxcol++); + +Obj_Insert(p->xfcs,c,ObjInsertHead); + + +return(c->n); +} + +void xfig_do_line(Handle h,Jwgline *line) +{ +Private p=(Private) h->private; +int i,c; +int r,g,b; +int w; +int x,y; +int n=line->npts; +extern double sqrt(double); +extern double fabs(double); + +r=(int) (h->pen.color.r*255.0); +g=(int) (h->pen.color.g*255.0); +b=(int) (h->pen.color.b*255.0); +c=xfig_sortout_color(h,r,g,b); + +if (h->pen.width==0.0) { + w=1; +} else { + w=(int) ((h->pen.width)/15.0); + if (w<1) w=1; +} + + + +fprintf(p->tmpfile,"2 1 0 %d %d 0 0 0 -1 0.0 1 1 -1 0 0 %d\n",w,c,n); + +for (i=0;idata[i].x; +y=(int) line->data[i].y; + +fprintf(p->tmpfile,"%d %d ",x,y); +} +fprintf(p->tmpfile,"\n"); + + +} + +void xfig_init_xform(Handle h) +{ + +h->transform.xc=0.0; +h->transform.yc=14422.8; +h->transform.a=10.2; +h->transform.d=-10.2; + +h->transform.b=0.0; +h->transform.c=0.0; + + +} + +xfig_do_poly(Handle h,Jwgline *line) +{ +int i,c; +int r,g,b; +int w; +int x,y; +int n=line->npts; +Private p=(Private) h->private; + +r=(int) (h->brush.color.r*255.0); +g=(int) (h->brush.color.g*255.0); +b=(int) (h->brush.color.b*255.0); +c=xfig_sortout_color(h,r,g,b); + + +printf("COL FOR POLY %d\n",c); + + +fprintf(p->tmpfile,"2 3 0 0 0 %d 0 0 20 0.0 1 1 -1 0 0 %d\n",c,n+1); + +for (i=0;idata[i].x; +y=(int) line->data[i].y; + +fprintf(p->tmpfile,"%d %d ",x,y); +} + +x=(int) line->data->x; +y=(int) line->data->y; + +fprintf(p->tmpfile,"%d %d",x,y); + +fprintf(p->tmpfile,"\n"); + +} + +void xfig_do_text(Handle h,Jwgpos pos,char *str) +{ +int c,r,g,b; +int x,y; +double atan2(double,double); + +Transform t=h->transform; +Private p=(Private) h->private; +int height; +float angle; + +x=(int) pos.x; +y=(int) pos.y; + +height=(int) (h->ink.height/16.66); + +r=(int) (h->ink.color.r*255.0); +g=(int) (h->ink.color.g*255.0); +b=(int) (h->ink.color.b*255.0); +c=xfig_sortout_color(h,r,g,b); + + +if (t.det>0) { + printf("JWG: Text cannot be written backwards in an xfig file\n"); + return; +} + + +angle=-atan2(t.b,t.a); + + +fprintf(p->tmpfile,"4 0 %d 0 0 %d %d %f 4 1 1 %d %d %s\\001\n",c,0, + height, angle,x,y,str); + + + + + +return; +} -- cgit v1.2.3