Rev 16344 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
7675 | bpr | 17 | /* line input / output / translation routines |
18 | * and error routines */ |
||
8102 | bpr | 19 | #include "flydraw.h" |
10 | reyssat | 20 | |
8195 | bpr | 21 | void fly_error(char *p) |
10 | reyssat | 22 | { |
12473 | bpr | 23 | fprintf(stderr,"%s %d\n",p,linecnt); |
10 | reyssat | 24 | } |
25 | |||
7675 | bpr | 26 | /* Get a line in a stored working file. |
27 | * Buffer length is always MAX_LINELEN. */ |
||
4934 | schaersvoo | 28 | |
10 | reyssat | 29 | int ggetline(char buf[]) |
30 | { |
||
12473 | bpr | 31 | int c; |
32 | int i; |
||
33 | for(i=0,c=getchar();i<MAX_LINELEN;i++,c=getchar()) { |
||
34 | if(c=='\n' || c==EOF || c==';') break; |
||
35 | buf[i]=c; |
||
36 | } |
||
37 | buf[i]=0; |
||
38 | if(linecnt!=-100000) linecnt++; |
||
39 | return c; |
||
10 | reyssat | 40 | } |
41 | |||
42 | void setvar(char *p, double v) |
||
43 | { |
||
12473 | bpr | 44 | int i; |
45 | if((strlen(p)>2 && strcmp(p,"animstep")!=0) || !isalpha(*p)) return; |
||
46 | for(i=0;i<varcnt && strcmp(p,vartab[i].name)!=0;i++); |
||
47 | if(i<varcnt) {vartab[i].value=v; return;} |
||
48 | else { |
||
49 | if(varcnt>=MAX_VARS || varnameptr>=varnamebuf+sizeof(varnamebuf)-1) return; |
||
50 | ovlstrcpy(varnameptr,p); |
||
51 | vartab[varcnt].name=varnameptr; vartab[varcnt].value=v; |
||
52 | varnameptr+=strlen(varnameptr)+1; (varcnt)++; |
||
53 | } |
||
10 | reyssat | 54 | } |
55 | |||
7675 | bpr | 56 | /* Points to the end of a name */ |
10 | reyssat | 57 | char *find_name_end(char *p) |
58 | { |
||
12473 | bpr | 59 | int i; |
60 | for(i=0;isalnum(*p) && i<MAX_LINELEN; p++,i++); |
||
61 | return p; |
||
10 | reyssat | 62 | } |
63 | |||
7675 | bpr | 64 | /* Find the beginning of a name */ |
10 | reyssat | 65 | char *find_name_start(char *p) |
66 | { |
||
12473 | bpr | 67 | int i; |
68 | for(i=0; !isalpha(*p) && i<MAX_LINELEN; p++,i++); |
||
69 | return p; |
||
10 | reyssat | 70 | } |
8896 | bpr | 71 | /* on prend les items à partir du n-ieme et on les recopie sur place au debut de la chaine |
72 | de caracteres */ |
||
10 | reyssat | 73 | |
74 | void collapse_item(char *p, int n) |
||
75 | { |
||
12473 | bpr | 76 | int i; |
77 | char *pp; |
||
78 | if(n<1) return; |
||
79 | for(i=1,pp=strchr(p,','); i<n && pp!=NULL; i++,pp=strchr(pp+1,',')); |
||
80 | if(pp==NULL) *p=0; |
||
81 | else ovlstrcpy(p,pp+1); |
||
10 | reyssat | 82 | } |
8897 | bpr | 83 | /* same in Texgif/image.c */ |
10 | reyssat | 84 | int getcolor(int r, int g, int b) |
85 | { |
||
12473 | bpr | 86 | int col; |
87 | if(r>255) r=255; |
||
88 | if(r<0) r=0; |
||
89 | if(g>255) g=255; |
||
90 | if(g<0) g=0; |
||
91 | if(b>255) b=255; |
||
92 | if(b<0) b=0; |
||
93 | col=gdImageColorExact(image, r, g, b); |
||
94 | if(col==-1) col=gdImageColorAllocate(image,r,g,b); |
||
95 | return col; |
||
10 | reyssat | 96 | } |
97 | |||
17574 | bpr | 98 | int tikz_brushColor; |
99 | |||
10 | reyssat | 100 | int widthcolor(int w, int color) |
101 | { |
||
12473 | bpr | 102 | int bg,fg,sh,e; |
103 | /* already allocated */ |
||
104 | if(wimg!=NULL && savew==w && wcolor==color) goto end; |
||
105 | if(wimg!=NULL) gdImageDestroy(wimg); |
||
106 | wimg=gdImageCreate(w,w); |
||
107 | if(wimg==NULL) { |
||
108 | fly_error("width_creation_failure"); return color; |
||
109 | } |
||
110 | bg=gdImageColorAllocate(wimg,255,255,255); |
||
111 | gdImageColorTransparent(wimg,bg); |
||
17574 | bpr | 112 | if (tikz_file) tikz_brushColor=color; |
12473 | bpr | 113 | fg=gdImageColorAllocate(wimg,gdImageRed(image,color), |
7675 | bpr | 114 | gdImageGreen(image,color), |
115 | gdImageBlue(image,color)); |
||
12473 | bpr | 116 | e=w-1;sh=e/3; |
117 | switch(w) { |
||
118 | case 2: { |
||
119 | gdImageFill(wimg,0,0,fg); break; |
||
10 | reyssat | 120 | } |
12473 | bpr | 121 | case 3: { |
122 | gdImageFill(wimg,0,0,fg); |
||
123 | gdImageSetPixel(wimg,2,0,bg);gdImageSetPixel(wimg,2,2,bg); |
||
124 | break; |
||
125 | } |
||
126 | case 4: |
||
127 | case 5: |
||
128 | case 6: |
||
129 | case 7: |
||
130 | case 8: |
||
131 | case 9: |
||
132 | case 10: |
||
133 | case 11: |
||
134 | case 12: { |
||
135 | gdPoint pl[]={{0,sh}, {sh,0}, {e-sh,0}, {e,sh}, |
||
136 | {e,e-sh}, {e-sh,e}, {sh,e}, {0,e-sh}}; |
||
137 | gdImageFilledPolygon(wimg, pl,8,fg); |
||
138 | break; |
||
139 | } |
||
140 | default: { |
||
141 | gdImageArc(wimg,w/2,w/2,w,w,0,360,fg); |
||
142 | gdImageFillToBorder(wimg,w/2,w/2,fg,fg); |
||
143 | break; |
||
144 | } |
||
145 | } |
||
146 | savew=w; wcolor=color; |
||
147 | end: gdImageSetBrush(image,wimg); return gdBrushed; |
||
10 | reyssat | 148 | } |
149 | |||
7675 | bpr | 150 | /* scale coordinates, x then y */ |
10 | reyssat | 151 | void scale(double dbuf[], int ibuf[], int cnt) |
152 | { |
||
12473 | bpr | 153 | int i; double x,y; |
154 | for(i=0;i<cnt*2 && i<MAX_PARMS;i+=2) { |
||
155 | if(transform) { |
||
156 | x=dbuf[i]*matrix[0]+dbuf[i+1]*matrix[1]; |
||
157 | y=dbuf[i]*matrix[2]+dbuf[i+1]*matrix[3]; |
||
10 | reyssat | 158 | } |
12473 | bpr | 159 | else {x=dbuf[i]; y=dbuf[i+1];} |
160 | scale_buf[i]=x+transx; scale_buf[i+1]=y+transy; |
||
161 | ibuf[i]=rint((x-xstart+transx)*xscale); |
||
162 | ibuf[i+1]=rint((y-ystart+transy)*yscale); |
||
163 | if(ibuf[i]<-BOUND) ibuf[i]=-BOUND; |
||
164 | if(ibuf[i]>BOUND) ibuf[i]=BOUND; |
||
165 | if(ibuf[i+1]<-BOUND) ibuf[i+1]=-BOUND; |
||
166 | if(ibuf[i+1]>BOUND) ibuf[i+1]=BOUND; |
||
167 | } |
||
10 | reyssat | 168 | } |
169 | |||
7675 | bpr | 170 | /* scale without displacement */ |
10 | reyssat | 171 | void scale2(double xin, double yin, double *xout, double *yout) |
172 | { |
||
12473 | bpr | 173 | if(transform) { |
174 | *xout=xin*matrix[0]+yin*matrix[1]; |
||
175 | *yout=xin*matrix[2]+yin*matrix[3]; |
||
176 | } |
||
177 | else { |
||
178 | *xout=xin; *yout=yin; |
||
179 | } |
||
180 | *xout*=xscale; *yout*=yscale; |
||
10 | reyssat | 181 | } |