Rev 9652 | Rev 11132 | Go to most recent revision | 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 | */ |
||
8177 | bpr | 17 | |
18 | #include <errno.h> |
||
8102 | bpr | 19 | #include "flydraw.h" |
8177 | bpr | 20 | |
8010 | bpr | 21 | /* bug in gdImageFillToBorder */ |
10 | reyssat | 22 | |
8162 | bpr | 23 | void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) |
8076 | bpr | 24 | { |
8156 | bpr | 25 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
8076 | bpr | 26 | gdImageFillToBorder(im,x,y,border,color); |
27 | } |
||
28 | |||
8162 | bpr | 29 | void patchgdImageFill (gdImagePtr im, int x, int y, int color) |
8156 | bpr | 30 | { |
31 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
||
32 | gdImageFill(im,x,y,color); |
||
33 | } |
||
8076 | bpr | 34 | |
8156 | bpr | 35 | |
9651 | georgesk | 36 | #define DASHPIXELS 8 |
37 | |||
38 | void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color); |
||
39 | void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){ |
||
40 | /** |
||
41 | * emulates gdImageDashedLine with gdImageSetStyle and gdImageLine |
||
42 | * GK: As gdImageDashedLine is slightly broken in latest libgd libraries, |
||
43 | * GK: I implemented an emulation named "myDashedLine" |
||
44 | **/ |
||
45 | |||
46 | int styleDashed[DASHPIXELS],i; |
||
47 | for (i=0; i< DASHPIXELS/2; i++) styleDashed[i]=color; |
||
48 | for (; i< DASHPIXELS; i++) styleDashed[i]=gdTransparent; |
||
49 | gdImageSetStyle(im, styleDashed, DASHPIXELS); |
||
50 | gdImageLine(im, x1, y1, x2, y2, gdStyled); |
||
51 | } |
||
52 | |||
53 | |||
7675 | bpr | 54 | /* File opening: with security */ |
10 | reyssat | 55 | FILE *open4read(char *n) |
56 | { |
||
57 | char *p, *p1, *p2, namebuf[2048]; |
||
58 | int t; |
||
59 | FILE *f; |
||
60 | n=find_word_start(n); |
||
61 | if(*n==0) return NULL; |
||
62 | p=getenv("flydraw_filebase"); |
||
63 | p1=n+strlen(n)-4;if(p1<n || strcasecmp(p1,".gif")!=0) t=1; else t=0; |
||
64 | if(p!=NULL && *p!=0) { |
||
7675 | bpr | 65 | char pbuf[MAX_LINELEN+1]; |
66 | snprintf(pbuf,sizeof(pbuf),"%s",p); |
||
67 | p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL; |
||
68 | if(*n=='/' || strstr(n,"..")!=NULL) return NULL; |
||
69 | /* prohibit unusual file/dir names */ |
||
70 | for(p1=p;*p1;p1++) |
||
71 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
||
72 | return NULL; |
||
73 | for(p1=n;*p1;p1++) |
||
74 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
||
75 | return NULL; |
||
76 | f=NULL; |
||
77 | for(p1=p; *p1; p1=find_word_start(p2)) { |
||
78 | p2=find_word_end(p1); |
||
79 | if(*p2) *p2++=0; |
||
80 | snprintf(namebuf,sizeof(namebuf),"%s/%s",p1,n); |
||
81 | f=fopen(namebuf,"r"); if(f!=NULL) goto imgtype; |
||
82 | } |
||
83 | p1=getenv("w_wims_session"); |
||
84 | if(p1!=NULL && strncmp(n,"insert",6)==0) { |
||
85 | snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,n); |
||
86 | f=fopen(namebuf,"r"); |
||
87 | } |
||
10 | reyssat | 88 | } |
89 | else { |
||
7675 | bpr | 90 | snprintf(namebuf,sizeof(namebuf),"%s",n); |
91 | f=fopen(namebuf,"r"); |
||
10 | reyssat | 92 | } |
93 | imgtype: |
||
94 | if(t && f!=NULL) { |
||
7675 | bpr | 95 | char tbuf[1024],sbuf[4096]; |
96 | fclose(f); f=NULL; |
||
97 | p1=getenv("TMPDIR"); if(p1==NULL || *p1==0) p1="."; |
||
98 | snprintf(tbuf,sizeof(tbuf),"%s/drawfile_.gif",p1); |
||
99 | snprintf(sbuf,sizeof(sbuf),"convert %s %s",namebuf,tbuf); |
||
8195 | bpr | 100 | if (system(sbuf)) fly_error("system_failed"); |
7615 | bpr | 101 | f=fopen(tbuf,"r"); |
10 | reyssat | 102 | } |
103 | return f; |
||
104 | } |
||
105 | |||
7675 | bpr | 106 | /* Does nothing; just a comment. */ |
10 | reyssat | 107 | void obj_comment(objparm *pm) |
108 | { |
||
109 | return; |
||
110 | } |
||
111 | |||
7675 | bpr | 112 | /* define image size */ |
10 | reyssat | 113 | void obj_size(objparm *pm) |
114 | { |
||
115 | sizex=rint(pm->pd[0]); sizey=rint(pm->pd[1]); |
||
116 | if(sizex<0 || sizey<0 || sizex>MAX_SIZE || sizey>MAX_SIZE) { |
||
8195 | bpr | 117 | fly_error("bad_size"); return; |
10 | reyssat | 118 | } |
119 | if(image!=NULL) { |
||
8195 | bpr | 120 | fly_error("size_already_defined"); return; |
10 | reyssat | 121 | } |
122 | image=gdImageCreate(sizex,sizey); |
||
8195 | bpr | 123 | if(image==NULL) fly_error("image_creation_failure"); |
10 | reyssat | 124 | else { |
7675 | bpr | 125 | color_white=gdImageColorAllocate(image,255,255,255); |
126 | color_black=gdImageColorAllocate(image,0,0,0); |
||
127 | color_bounder=gdImageColorAllocate(image,1,2,3); |
||
8158 | bpr | 128 | color_frame=gdImageColorAllocate(image,254,254,254); |
10 | reyssat | 129 | } |
130 | } |
||
131 | |||
7675 | bpr | 132 | /* new image */ |
10 | reyssat | 133 | void obj_new(objparm *pm) |
134 | { |
||
135 | if(image) { |
||
7675 | bpr | 136 | gdImageDestroy(image);image=NULL; |
10 | reyssat | 137 | } |
8158 | bpr | 138 | if(pm->pcnt>=2) { obj_size(pm); gdImageRectangle(image,0,0,sizex-1,sizey-1,color_frame);} |
10 | reyssat | 139 | else sizex=sizey=0; |
140 | saved=0; |
||
141 | } |
||
142 | |||
7675 | bpr | 143 | /* new image */ |
10 | reyssat | 144 | void obj_existing(objparm *pm) |
145 | { |
||
146 | FILE *inf; |
||
147 | char *pp; |
||
7615 | bpr | 148 | |
10 | reyssat | 149 | if(image) { |
7675 | bpr | 150 | gdImageDestroy(image);image=NULL; |
10 | reyssat | 151 | } |
152 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
||
153 | inf=open4read(pp); |
||
154 | if(inf==NULL) { |
||
8195 | bpr | 155 | fly_error("file_not_exist"); return; |
10 | reyssat | 156 | } |
157 | image=gdImageCreateFromGif(inf); fclose(inf); |
||
158 | if(image==NULL) { |
||
8195 | bpr | 159 | fly_error("bad_gif"); return; |
10 | reyssat | 160 | } |
161 | sizex=image->sx; sizey=image->sy; |
||
162 | saved=0; |
||
163 | } |
||
164 | |||
7675 | bpr | 165 | /* solid line */ |
10 | reyssat | 166 | void obj_line(objparm *pm) |
167 | { |
||
168 | scale(pm->pd,pm->p,2); |
||
169 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
||
1024 | bpr | 170 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 171 | } |
172 | |||
1024 | bpr | 173 | void _obj_arrow(objparm *pm, int twoside) |
10 | reyssat | 174 | { |
8163 | bpr | 175 | int l,xx,yy; |
176 | gdPoint ii[3]; |
||
10 | reyssat | 177 | double dx,dy,length,dd[6]; |
7615 | bpr | 178 | scale(pm->pd,pm->p,2); |
8163 | bpr | 179 | xx=ii[0].x=pm->p[2];yy=ii[0].y=pm->p[3]; |
10 | reyssat | 180 | l=pm->pd[4];if(l<0) l=0; if(l>200) l=200; |
181 | scale2(pm->pd[0]-pm->pd[2],pm->pd[1]-pm->pd[3],&dx,&dy); |
||
182 | length=sqrt(dx*dx+dy*dy); |
||
183 | if(length<3 || l<5) goto stem; |
||
184 | dd[0]=l*dx/length; dd[1]=l*dy/length; |
||
185 | #define fat 0.27 |
||
186 | dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat; |
||
187 | dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat; |
||
8163 | bpr | 188 | ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y; |
189 | ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y; |
||
190 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
||
191 | xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y; |
||
1024 | bpr | 192 | if(twoside) { |
8163 | bpr | 193 | ii[0].x=pm->p[0]; ii[0].y=pm->p[1]; |
194 | ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y; |
||
195 | ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y; |
||
196 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
||
1024 | bpr | 197 | } |
10 | reyssat | 198 | stem: if(pm->fill) |
9651 | georgesk | 199 | myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
10 | reyssat | 200 | else |
201 | gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
||
1024 | bpr | 202 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 203 | } |
204 | |||
7675 | bpr | 205 | /* Arrow */ |
1024 | bpr | 206 | void obj_arrow(objparm *pm) |
207 | { |
||
208 | _obj_arrow(pm,0); |
||
209 | } |
||
210 | |||
7675 | bpr | 211 | /* 2-sided arrow */ |
1024 | bpr | 212 | void obj_arrow2(objparm *pm) |
213 | { |
||
214 | _obj_arrow(pm,1); |
||
215 | } |
||
216 | |||
7675 | bpr | 217 | /* horizontal line */ |
10 | reyssat | 218 | void obj_hline(objparm *pm) |
219 | { |
||
220 | scale(pm->pd,pm->p,1); |
||
221 | if(pm->fill) |
||
9651 | georgesk | 222 | myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
10 | reyssat | 223 | else |
224 | gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
||
225 | } |
||
226 | |||
7675 | bpr | 227 | /* vertical line */ |
10 | reyssat | 228 | void obj_vline(objparm *pm) |
229 | { |
||
230 | scale(pm->pd,pm->p,1); |
||
231 | if(pm->fill) |
||
9651 | georgesk | 232 | myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
10 | reyssat | 233 | else |
234 | gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
||
235 | } |
||
236 | |||
7675 | bpr | 237 | /* dashed line */ |
10 | reyssat | 238 | void obj_dline(objparm *pm) |
239 | { |
||
240 | scale(pm->pd,pm->p,2); |
||
9652 | georgesk | 241 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], |
242 | pm->color[0]); |
||
10 | reyssat | 243 | } |
244 | |||
7675 | bpr | 245 | /* parallel lines. |
246 | * x1,y1,x2,y2,xv,yv,n,color */ |
||
10 | reyssat | 247 | void obj_parallel(objparm *pm) |
248 | { |
||
249 | int i, n, xi,yi; |
||
250 | double xv,yv; |
||
251 | n=pm->pd[6]; if(n<0) return; if(n>256) n=256; |
||
1122 | bpr | 252 | scale(pm->pd,pm->p,3); |
10 | reyssat | 253 | scale2(pm->pd[4],pm->pd[5],&xv,&yv); |
254 | for(i=0;i<n;i++) { |
||
7675 | bpr | 255 | xi=rint(i*xv); yi=rint(i*yv); |
256 | gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi, |
||
257 | pm->color[0]); |
||
258 | if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx), |
||
259 | scale_buf[1]+i*(scale_buf[5]-transy), |
||
260 | scale_buf[2]+i*(scale_buf[4]-transx), |
||
261 | scale_buf[3]+i*(scale_buf[5]-transy)); |
||
10 | reyssat | 262 | } |
263 | } |
||
264 | |||
7675 | bpr | 265 | /* rectangle */ |
10 | reyssat | 266 | void obj_rect(objparm *pm) |
267 | { |
||
268 | int x1,y1,x2,y2; |
||
269 | scale(pm->pd,pm->p,2); |
||
270 | x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]); |
||
271 | y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]); |
||
272 | if(pm->fill) |
||
273 | gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]); |
||
274 | else |
||
275 | gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]); |
||
1024 | bpr | 276 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 277 | } |
278 | |||
7675 | bpr | 279 | /* square */ |
10 | reyssat | 280 | void obj_square(objparm *pm) |
281 | { |
||
282 | int w,h; |
||
283 | scale(pm->pd,pm->p,1); |
||
284 | w=rint(pm->pd[2]); h=rint(pm->pd[2]); |
||
285 | if(pm->fill) |
||
286 | gdImageFilledRectangle(image,pm->p[0],pm->p[1], |
||
7675 | bpr | 287 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
10 | reyssat | 288 | else |
289 | gdImageRectangle(image,pm->p[0],pm->p[1], |
||
7675 | bpr | 290 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
1024 | bpr | 291 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1], |
7675 | bpr | 292 | scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]); |
10 | reyssat | 293 | } |
294 | |||
7675 | bpr | 295 | /* triangle */ |
10 | reyssat | 296 | void obj_triangle(objparm *pm) |
297 | { |
||
298 | scale(pm->pd,pm->p,3); |
||
299 | if(pm->fill) |
||
300 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
||
301 | else |
||
302 | gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
||
1024 | bpr | 303 | if(vimg_enable) vimg_polyline(scale_buf,3,1); |
10 | reyssat | 304 | } |
305 | |||
7675 | bpr | 306 | /* polygon */ |
10 | reyssat | 307 | void obj_poly(objparm *pm) |
308 | { |
||
309 | int cnt; |
||
310 | cnt=(pm->pcnt)/2; |
||
311 | scale(pm->pd,pm->p,cnt); |
||
312 | if(pm->fill) |
||
313 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
||
314 | else |
||
315 | gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
||
1024 | bpr | 316 | if(vimg_enable) vimg_polyline(scale_buf,cnt,1); |
10 | reyssat | 317 | } |
318 | |||
7675 | bpr | 319 | /* rays */ |
10 | reyssat | 320 | void obj_rays(objparm *pm) |
321 | { |
||
322 | int i, n; |
||
323 | n=(pm->pcnt)/2; |
||
324 | scale(pm->pd,pm->p,n); |
||
1024 | bpr | 325 | for(i=2;i<2*n;i+=2) { |
7675 | bpr | 326 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]); |
327 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1], |
||
328 | scale_buf[i],scale_buf[i+1]); |
||
1024 | bpr | 329 | } |
10 | reyssat | 330 | } |
8414 | bpr | 331 | /* crosshair */ |
332 | void obj_crosshair(objparm *pm) |
||
333 | { |
||
334 | scale(pm->pd,pm->p,2); |
||
335 | gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]); |
||
336 | gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]); |
||
337 | } |
||
338 | /* crosshairs */ |
||
10 | reyssat | 339 | |
8414 | bpr | 340 | void obj_crosshairs(objparm *pm) |
341 | { |
||
342 | int i, n; |
||
343 | n=(pm->pcnt)/2; |
||
344 | scale(pm->pd,pm->p,n); |
||
345 | for(i=0;i<2*n;i+=2) { |
||
346 | gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]); |
||
347 | gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]); |
||
348 | } |
||
349 | } |
||
350 | |||
351 | |||
7675 | bpr | 352 | /* segments */ |
10 | reyssat | 353 | void obj_lines(objparm *pm) |
354 | { |
||
355 | int i, n; |
||
356 | n=(pm->pcnt)/2; |
||
357 | scale(pm->pd,pm->p,n); |
||
7615 | bpr | 358 | for(i=2;i<2*n;i+=2) |
10 | reyssat | 359 | gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
1024 | bpr | 360 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
10 | reyssat | 361 | } |
362 | |||
7675 | bpr | 363 | /* segments */ |
10 | reyssat | 364 | void obj_dlines(objparm *pm) |
365 | { |
||
366 | int i, n; |
||
367 | n=(pm->pcnt)/2; |
||
368 | scale(pm->pd,pm->p,n); |
||
369 | for(i=2;i<2*n;i+=2) |
||
9651 | georgesk | 370 | myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
1024 | bpr | 371 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
10 | reyssat | 372 | } |
373 | |||
7675 | bpr | 374 | /* points */ |
10 | reyssat | 375 | void obj_points(objparm *pm) |
376 | { |
||
377 | int i, n; |
||
378 | n=(pm->pcnt)/2; |
||
379 | scale(pm->pd,pm->p,n); |
||
380 | for(i=0;i<2*n;i+=2) |
||
381 | gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]); |
||
382 | } |
||
383 | |||
7675 | bpr | 384 | /* lattice. |
385 | * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */ |
||
10 | reyssat | 386 | void obj_lattice(objparm *pm) |
387 | { |
||
388 | int n1,n2,i1,i2,xi1,yi1,xi2,yi2; |
||
389 | double xv1,xv2,yv1,yv2; |
||
390 | n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return; |
||
11120 | georgesk | 391 | if(n1>256) n1=256; |
392 | if(n2>256) n2=256; |
||
10 | reyssat | 393 | scale(pm->pd,pm->p,1); |
394 | scale2(pm->pd[2],pm->pd[3],&xv1,&yv1); |
||
395 | scale2(pm->pd[4],pm->pd[5],&xv2,&yv2); |
||
396 | for(i1=0;i1<n1;i1++) { |
||
7675 | bpr | 397 | xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1]; |
398 | for(i2=0;i2<n2;i2++) { |
||
399 | xi2=i2*xv2+xi1;yi2=i2*yv2+yi1; |
||
400 | gdImageSetPixel(image,xi2,yi2,pm->color[0]); |
||
401 | } |
||
10 | reyssat | 402 | } |
403 | } |
||
404 | |||
7675 | bpr | 405 | /* arc */ |
10 | reyssat | 406 | void obj_arc(objparm *pm) |
407 | { |
||
408 | scale(pm->pd,pm->p,1); |
||
409 | pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale); |
||
410 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], |
||
7675 | bpr | 411 | pm->pd[4],pm->pd[5],pm->color[0]); |
1024 | bpr | 412 | if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1], |
7675 | bpr | 413 | 0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]); |
10 | reyssat | 414 | } |
415 | |||
7675 | bpr | 416 | /* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */ |
10 | reyssat | 417 | void obj_ellipse(objparm *pm) |
418 | { |
||
419 | scale(pm->pd,pm->p,1); |
||
420 | pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale); |
||
421 | if(pm->fill) { |
||
7675 | bpr | 422 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360, |
423 | color_bounder); |
||
8162 | bpr | 424 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
7675 | bpr | 425 | color_bounder,pm->color[0]); |
10 | reyssat | 426 | } |
427 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
||
1024 | bpr | 428 | if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]); |
10 | reyssat | 429 | } |
430 | |||
7675 | bpr | 431 | /* Circle */ |
10 | reyssat | 432 | void obj_circle(objparm *pm) |
433 | { |
||
434 | scale(pm->pd,pm->p,1); |
||
435 | pm->p[2]=rint(pm->pd[2]); pm->p[3]=rint(pm->pd[2]); |
||
436 | if(pm->fill) { |
||
7675 | bpr | 437 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360, |
438 | color_bounder); |
||
8162 | bpr | 439 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
7675 | bpr | 440 | color_bounder,pm->color[0]); |
10 | reyssat | 441 | } |
442 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
||
443 | } |
||
444 | |||
7675 | bpr | 445 | /* flood fill */ |
10 | reyssat | 446 | void obj_fill(objparm *pm) |
447 | { |
||
448 | scale(pm->pd,pm->p,1); |
||
8162 | bpr | 449 | patchgdImageFill(image,pm->p[0],pm->p[1],pm->color[0]); |
10 | reyssat | 450 | } |
451 | |||
7675 | bpr | 452 | /* flood fill to border*/ |
10 | reyssat | 453 | void obj_fillb(objparm *pm) |
454 | { |
||
455 | scale(pm->pd,pm->p,1); |
||
8162 | bpr | 456 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1],pm->color[0],pm->color[1]); |
10 | reyssat | 457 | } |
458 | |||
459 | gdImagePtr himg; |
||
460 | |||
461 | int makehatchimage(int x, int y, int px, int py, int col) |
||
462 | { |
||
463 | int c1,c2,r,g,b; |
||
464 | gdImagePtr saveimg; |
||
465 | himg=gdImageCreate(x,y); |
||
466 | c1=gdImageGetPixel(image,px,py); |
||
467 | r=gdImageRed(image,c1); g=gdImageGreen(image,c1); b=gdImageBlue(image,c1); |
||
468 | if(r>=255) r--; else r++; if(g>=255) g--; else g++; if(b>=255) b--; else b++; |
||
469 | c1=gdImageColorAllocate(himg,r,g,b); |
||
470 | r=gdImageRed(image,col); g=gdImageGreen(image,col); b=gdImageBlue(image,col); |
||
471 | c2=gdImageColorAllocate(himg,r,g,b); |
||
472 | if(width>1) { |
||
7675 | bpr | 473 | savew=-1; saveimg=image; |
474 | image=himg; c2=widthcolor(width,c2); image=saveimg; |
||
475 | c2=gdBrushed; savew=-1; |
||
10 | reyssat | 476 | } |
477 | return c2; |
||
478 | } |
||
479 | |||
7675 | bpr | 480 | /* flood fill with hatching */ |
10 | reyssat | 481 | void obj_hatchfill(objparm *pm) |
482 | { |
||
483 | int nx,ny,ax,ay, dir, c; |
||
484 | scale(pm->pd,pm->p,1); |
||
485 | nx=pm->pd[2]; ny=pm->pd[3]; ax=abs(nx); ay=abs(ny); |
||
8195 | bpr | 486 | if(nx==0 && ny==0) {fly_error("bad displacement vector"); return;} |
10 | reyssat | 487 | if((nx>0 && ny>0) || (nx<0 && ny<0)) dir=1; else dir=-1; |
488 | if(ax==0) {ax=100; dir=2;} |
||
489 | if(ay==0) {ay=100; dir=3;} |
||
490 | c=makehatchimage(ax,ay,pm->p[0],pm->p[1],pm->color[0]); |
||
491 | switch(dir) { |
||
7675 | bpr | 492 | case -1: { |
493 | gdImageLine(himg,0,ay-1,ax-1,0,c); |
||
494 | if(width>1) { |
||
495 | gdImageLine(himg,-ax,ay-1,-1,0,c); |
||
496 | gdImageLine(himg,ax,ay-1,2*ax-1,0,c); |
||
497 | gdImageLine(himg,0,-1,ax-1,-ay,c); |
||
498 | gdImageLine(himg,0,2*ay-1,ax-1,ay,c); |
||
499 | } |
||
500 | break; |
||
501 | } |
||
502 | case 1: { |
||
503 | gdImageLine(himg,0,0,ax-1,ay-1,c); |
||
504 | if(width>1) { |
||
505 | gdImageLine(himg,-ax,0,-1,ay-1,c); |
||
506 | gdImageLine(himg,ax,0,2*ax-1,ay-1,c); |
||
507 | gdImageLine(himg,0,-ay,ax-1,-1,c); |
||
508 | gdImageLine(himg,0,ay,ax-1,2*ay-1,c); |
||
509 | } |
||
510 | break; |
||
511 | } |
||
512 | case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break; |
||
513 | case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break; |
||
10 | reyssat | 514 | } |
515 | gdImageSetTile(image,himg); |
||
8162 | bpr | 516 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
10 | reyssat | 517 | gdImageDestroy(himg); |
518 | if(tiled) gdImageSetTile(image,tileimg); |
||
519 | } |
||
520 | |||
7675 | bpr | 521 | /* flood fill with grid */ |
10 | reyssat | 522 | void obj_gridfill(objparm *pm) |
523 | { |
||
524 | int nx,ny, c; |
||
525 | scale(pm->pd,pm->p,1); |
||
526 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
8195 | bpr | 527 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
10 | reyssat | 528 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
529 | gdImageLine(himg,0,ny/2,nx-1,ny/2,c); gdImageLine(himg,nx/2,0,nx/2,ny-1,c); |
||
530 | gdImageSetTile(image,himg); |
||
8162 | bpr | 531 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
10 | reyssat | 532 | gdImageDestroy(himg); |
533 | if(tiled) gdImageSetTile(image,tileimg); |
||
534 | } |
||
535 | |||
7675 | bpr | 536 | /* flood fill with double hatching */ |
10 | reyssat | 537 | void obj_diafill(objparm *pm) |
538 | { |
||
539 | int nx,ny, c; |
||
540 | scale(pm->pd,pm->p,1); |
||
541 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
8195 | bpr | 542 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
10 | reyssat | 543 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
544 | gdImageLine(himg,0,0,nx-1,ny-1,c); gdImageLine(himg,0,ny-1,nx-1,0,c); |
||
545 | gdImageSetTile(image,himg); |
||
8162 | bpr | 546 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
10 | reyssat | 547 | gdImageDestroy(himg); |
548 | if(tiled) gdImageSetTile(image,tileimg); |
||
549 | } |
||
550 | |||
7675 | bpr | 551 | /* flood fill with double hatching */ |
10 | reyssat | 552 | void obj_dotfill(objparm *pm) |
553 | { |
||
554 | int nx,ny, c; |
||
555 | scale(pm->pd,pm->p,1); |
||
556 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
8195 | bpr | 557 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
10 | reyssat | 558 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
559 | gdImageSetPixel(himg,nx/2,ny/2,c); |
||
560 | gdImageSetTile(image,himg); |
||
8162 | bpr | 561 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
10 | reyssat | 562 | gdImageDestroy(himg); |
563 | if(tiled) gdImageSetTile(image,tileimg); |
||
564 | } |
||
565 | |||
566 | struct { |
||
567 | char *name; |
||
568 | gdFontPtr *fpt; |
||
569 | } fonttab[]={ |
||
7675 | bpr | 570 | {"tiny", &gdFontTiny}, |
571 | {"small", &gdFontSmall}, |
||
10 | reyssat | 572 | {"medium",&gdFontMediumBold}, |
7675 | bpr | 573 | {"large", &gdFontLarge}, |
574 | {"giant", &gdFontGiant}, |
||
575 | {"huge", &gdFontGiant} |
||
10 | reyssat | 576 | }; |
577 | |||
578 | #define fonttab_no (sizeof(fonttab)/sizeof(fonttab[0])) |
||
579 | |||
7675 | bpr | 580 | /* string */ |
10 | reyssat | 581 | void obj_string(objparm *pm) |
582 | { |
||
583 | char *pp, *pe, *p2; |
||
584 | int i; |
||
585 | pp=pm->str; pe=strchr(pp,','); if(pe==NULL) { |
||
8195 | bpr | 586 | fly_error("too_few_parms"); return; |
10 | reyssat | 587 | } |
588 | *pe++=0; pp=find_word_start(pp); *find_word_end(pp)=0; |
||
589 | pe=find_word_start(pe); strip_trailing_spaces(pe); |
||
590 | if(*pp) { |
||
7675 | bpr | 591 | for(i=0;i<fonttab_no && strcmp(pp,fonttab[i].name)!=0; i++); |
592 | if(i>=fonttab_no) i=1; |
||
10 | reyssat | 593 | } |
594 | else i=1; |
||
595 | scale(pm->pd,pm->p,1); |
||
596 | if(*pe=='"') { |
||
7675 | bpr | 597 | p2=strchr(pe+1,'"'); |
598 | if(p2 && *(p2+1)==0) {*p2=0; pe++;} |
||
10 | reyssat | 599 | } |
600 | if(pm->fill) |
||
7615 | bpr | 601 | gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe, |
7675 | bpr | 602 | pm->color[0]); |
10 | reyssat | 603 | else |
7615 | bpr | 604 | gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe, |
7675 | bpr | 605 | pm->color[0]); |
10 | reyssat | 606 | } |
607 | |||
7675 | bpr | 608 | /* point */ |
10 | reyssat | 609 | void obj_point(objparm *pm) |
610 | { |
||
611 | scale(pm->pd,pm->p,1); |
||
612 | gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]); |
||
613 | } |
||
614 | |||
7675 | bpr | 615 | /* copy an image file */ |
10 | reyssat | 616 | void obj_copy(objparm *pm) |
617 | { |
||
618 | char *pp; |
||
619 | FILE *inf; |
||
7675 | bpr | 620 | gdImagePtr insimg; |
7615 | bpr | 621 | |
10 | reyssat | 622 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
623 | inf=open4read(pp); |
||
624 | if(inf==NULL) { |
||
8195 | bpr | 625 | fly_error("file_not_exist"); return; |
10 | reyssat | 626 | } |
627 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
628 | if(insimg==NULL) { |
||
8195 | bpr | 629 | fly_error("bad_gif"); return; |
10 | reyssat | 630 | } |
631 | scale(pm->pd,pm->p,1); |
||
7615 | bpr | 632 | if(pm->pd[2]<0 && pm->pd[3]<0 && pm->pd[4]<0 && pm->pd[5]<0) |
10 | reyssat | 633 | gdImageCopy(image,insimg,pm->p[0],pm->p[1],0,0, |
7675 | bpr | 634 | insimg->sx,insimg->sy); |
10 | reyssat | 635 | else |
636 | gdImageCopy(image,insimg,pm->p[0],pm->p[1],pm->pd[2],pm->pd[3], |
||
7675 | bpr | 637 | pm->pd[4]-pm->pd[2],pm->pd[5]-pm->pd[3]); |
10 | reyssat | 638 | gdImageDestroy(insimg); |
639 | } |
||
640 | |||
7675 | bpr | 641 | /* copy an image file, with resizing */ |
10 | reyssat | 642 | void obj_copyresize(objparm *pm) |
643 | { |
||
644 | char *pp; |
||
645 | FILE *inf; |
||
7675 | bpr | 646 | gdImagePtr insimg; |
7615 | bpr | 647 | |
10 | reyssat | 648 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
649 | inf=open4read(pp); |
||
650 | if(inf==NULL) { |
||
8195 | bpr | 651 | fly_error("file_not_found"); return; |
10 | reyssat | 652 | } |
653 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
654 | if(insimg==NULL) { |
||
8195 | bpr | 655 | fly_error("bad_gif"); return; |
10 | reyssat | 656 | } |
657 | scale(pm->pd+4,pm->p+4,2); |
||
7615 | bpr | 658 | if(pm->pd[0]<0 && pm->pd[1]<0 && pm->pd[2]<0 && pm->pd[3]<0) |
10 | reyssat | 659 | gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],0,0, |
7675 | bpr | 660 | pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1, |
661 | insimg->sx,insimg->sy); |
||
10 | reyssat | 662 | else |
663 | gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],pm->pd[0],pm->pd[1], |
||
7675 | bpr | 664 | pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1, |
665 | pm->pd[2]-pm->pd[0]+1,pm->pd[3]-pm->pd[1]+1); |
||
10 | reyssat | 666 | gdImageDestroy(insimg); |
667 | } |
||
668 | |||
7675 | bpr | 669 | /* set brush or tile */ |
10 | reyssat | 670 | void obj_setbrush(objparm *pm) |
671 | { |
||
672 | char *pp; |
||
673 | FILE *inf; |
||
674 | gdImagePtr insimg; |
||
675 | |||
676 | pp=find_word_start(pm->str); *find_word_end(pp)=0; |
||
677 | inf=open4read(pp); if(inf==NULL) { |
||
8195 | bpr | 678 | fly_error("file_not_found"); return; |
10 | reyssat | 679 | } |
680 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
681 | if(insimg==NULL) { |
||
8195 | bpr | 682 | fly_error("bad_gif"); return; |
10 | reyssat | 683 | } |
684 | if(pm->fill) { |
||
7675 | bpr | 685 | gdImageSetTile(image,insimg); tiled=1; tileimg=insimg; |
10 | reyssat | 686 | } |
687 | else { |
||
7675 | bpr | 688 | gdImageSetBrush(image,insimg);brushed=1; brushimg=insimg; |
10 | reyssat | 689 | } |
690 | } |
||
691 | |||
7675 | bpr | 692 | /* kill brush */ |
10 | reyssat | 693 | void obj_killbrush(objparm *pm) |
694 | { |
||
695 | if(brushimg) gdImageDestroy(brushimg); |
||
696 | brushed=0; brushimg=NULL; |
||
697 | } |
||
698 | |||
7675 | bpr | 699 | /* kill tile */ |
10 | reyssat | 700 | void obj_killtile(objparm *pm) |
701 | { |
||
702 | if(tileimg) gdImageDestroy(tileimg); |
||
703 | tiled=0; tileimg=NULL; |
||
704 | } |
||
705 | |||
7675 | bpr | 706 | /* set style */ |
10 | reyssat | 707 | void obj_setstyle(objparm *pm) |
708 | { |
||
709 | int i,t; |
||
710 | t=pm->pcnt/3; if(t<=0) { |
||
8195 | bpr | 711 | fly_error("too_few_parms"); return; |
10 | reyssat | 712 | } |
713 | for(i=0;i<t;i++) { |
||
7675 | bpr | 714 | if(pm->pd[3*i]<0 || pm->pd[3*i+1]<0 || pm->pd[3*i+2]<0) |
715 | pm->p[i]=gdTransparent; |
||
716 | else |
||
717 | pm->p[i]=getcolor(pm->pd[3*i],pm->pd[3*i+1],pm->pd[3*i+2]); |
||
10 | reyssat | 718 | } |
719 | gdImageSetStyle(image,pm->p,t); styled=1; |
||
720 | } |
||
721 | |||
7675 | bpr | 722 | /* kill style */ |
10 | reyssat | 723 | void obj_killstyle(objparm *pm) |
724 | { |
||
725 | styled=0; |
||
726 | } |
||
727 | |||
7675 | bpr | 728 | /* set transparent */ |
10 | reyssat | 729 | void obj_transp(objparm *pm) |
730 | { |
||
731 | gdImageColorTransparent(image,pm->color[0]); |
||
732 | } |
||
733 | |||
7675 | bpr | 734 | /* set interlace */ |
10 | reyssat | 735 | void obj_interlace(objparm *pm) |
736 | { |
||
737 | gdImageInterlace(image,1); |
||
738 | } |
||
739 | |||
7675 | bpr | 740 | /* set linewidth */ |
10 | reyssat | 741 | void obj_linewidth(objparm *pm) |
742 | { |
||
8195 | bpr | 743 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
10 | reyssat | 744 | else width=pm->pd[0]; |
745 | } |
||
746 | |||
8414 | bpr | 747 | /* set crosshairsize */ |
748 | void obj_crosshairsize(objparm *pm) |
||
749 | { |
||
750 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
||
751 | else width2=pm->pd[0]; |
||
752 | } |
||
753 | |||
7675 | bpr | 754 | /* set x range */ |
10 | reyssat | 755 | void obj_xrange(objparm *pm) |
756 | { |
||
757 | double dd; |
||
758 | dd=pm->pd[1]-pm->pd[0]; |
||
759 | xstart=pm->pd[0]; xscale=sizex/dd; |
||
760 | } |
||
761 | |||
7675 | bpr | 762 | /* set y range */ |
10 | reyssat | 763 | void obj_yrange(objparm *pm) |
764 | { |
||
765 | double dd; |
||
766 | dd=pm->pd[1]-pm->pd[0]; |
||
767 | ystart=pm->pd[1]; yscale=-sizey/dd; |
||
768 | } |
||
769 | |||
7675 | bpr | 770 | /* set x et y range */ |
10 | reyssat | 771 | void obj_range(objparm *pm) |
772 | { |
||
773 | double d1,d2; |
||
774 | d1=pm->pd[1]-pm->pd[0]; d2=pm->pd[3]-pm->pd[2]; |
||
775 | xstart=pm->pd[0]; xscale=(sizex-1)/d1; |
||
776 | ystart=pm->pd[3]; yscale=-(sizey-1)/d2; |
||
777 | } |
||
778 | |||
7675 | bpr | 779 | /* set t range */ |
10 | reyssat | 780 | void obj_trange(objparm *pm) |
781 | { |
||
6790 | bpr | 782 | /*double dd; |
783 | dd=pm->pd[1]-pm->pd[0];*/ |
||
10 | reyssat | 784 | tstart=pm->pd[0]; tend=pm->pd[1]; |
785 | tranged=1; |
||
786 | } |
||
787 | |||
7675 | bpr | 788 | /* set tstep (plotting step) */ |
10 | reyssat | 789 | void obj_tstep(objparm *pm) |
790 | { |
||
791 | int dd; |
||
792 | dd=pm->pd[0]; |
||
793 | if(dd<3) { |
||
8195 | bpr | 794 | fly_error("bad_step"); return; |
10 | reyssat | 795 | } |
796 | if(dd>2000) dd=2000; |
||
797 | tstep=dd; |
||
798 | } |
||
799 | |||
7675 | bpr | 800 | /* set plotjump (plot jump break threashold) */ |
10 | reyssat | 801 | void obj_plotjump(objparm *pm) |
802 | { |
||
803 | int dd; |
||
804 | dd=pm->pd[0]; |
||
11120 | georgesk | 805 | if(dd<3) dd=3; |
806 | if(dd>MAX_SIZE) dd=MAX_SIZE; |
||
10 | reyssat | 807 | plotjump=dd; |
808 | } |
||
809 | |||
7675 | bpr | 810 | /* plot a curve, either parametric or explicit */ |
6578 | bpr | 811 | void _obj_plot(objparm *pm,int dash) |
10 | reyssat | 812 | { |
813 | int i,j,n,dist,xx,yy,varpos; |
||
814 | char p1[MAX_LINELEN+1], p2[MAX_LINELEN+1]; |
||
815 | char *varn, *pp; |
||
816 | double dc[2],t,v; |
||
817 | int ic[2],oc[2]; |
||
818 | |||
819 | n=itemnum(pm->str); |
||
820 | if(n<1) { |
||
8195 | bpr | 821 | fly_error("bad_parms"); return; |
10 | reyssat | 822 | } |
823 | fnd_item(pm->str,1,p1); fnd_item(pm->str,2,p2); |
||
824 | if(n==1 && !tranged) v=sizex/xscale/tstep; |
||
825 | else v=(tend-tstart)/tstep; |
||
826 | if(n==1) varn="x"; else varn="t"; |
||
827 | for(pp=varchr(p1,varn); pp; pp=varchr(pp,varn)) { |
||
7675 | bpr | 828 | string_modify(p1,pp,pp+strlen(varn),EV_T); |
829 | pp+=strlen(EV_T); |
||
10 | reyssat | 830 | } |
831 | for(pp=varchr(p2,varn); pp; pp=varchr(pp,varn)) { |
||
7675 | bpr | 832 | string_modify(p2,pp,pp+strlen(varn),EV_T); |
833 | pp+=strlen(EV_T); |
||
10 | reyssat | 834 | } |
835 | varpos=eval_getpos(EV_T); |
||
836 | if(varpos<0) return; /* unknown error */ |
||
837 | evalue_compile(p1); evalue_compile(p2); |
||
1024 | bpr | 838 | if(vimg_enable) vimg_plotstart(); |
10 | reyssat | 839 | for(i=j=0;i<=tstep;i++) { |
7675 | bpr | 840 | if(n==1) { |
841 | if(tranged) t=tstart+i*v; else t=xstart+i*v; |
||
8076 | bpr | 842 | eval_setval(varpos,t); dc[0]=t; dc[1]=strevalue(p1); |
7675 | bpr | 843 | } |
844 | else { |
||
845 | t=tstart+i*v; eval_setval(varpos,t); |
||
8076 | bpr | 846 | dc[0]=strevalue(p1); dc[1]=strevalue(p2); |
7675 | bpr | 847 | } |
8171 | bpr | 848 | if(!isfinite(dc[0]) || !isfinite(dc[1])) ic[0]=ic[1]=-BOUND; |
7675 | bpr | 849 | else scale(dc,ic,1); |
850 | if(vimg_enable) vimg_plot1 (scale_buf[0],scale_buf[1]); |
||
851 | if(j==0) { |
||
852 | gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); j++; |
||
853 | } |
||
854 | else { |
||
855 | xx=ic[0]-oc[0]; yy=ic[1]-oc[1]; |
||
856 | dist=sqrt(xx*xx+yy*yy); |
||
857 | if(dist>0) { |
||
858 | if(dist>plotjump || dist==1) |
||
859 | gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); |
||
860 | else |
||
861 | if ( dash==1) { |
||
862 | gdImageDashedLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]); |
||
863 | } else |
||
864 | {gdImageLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]); } |
||
7615 | bpr | 865 | |
7675 | bpr | 866 | } |
867 | } |
||
868 | memmove(oc,ic,sizeof(oc)); |
||
10 | reyssat | 869 | } |
1024 | bpr | 870 | if(vimg_enable) vimg_plotend(); |
10 | reyssat | 871 | } |
872 | |||
6578 | bpr | 873 | void obj_plot(objparm *pm) { _obj_plot( pm,0) ;} |
874 | void obj_dplot(objparm *pm) { _obj_plot( pm,1) ; } |
||
875 | |||
7675 | bpr | 876 | /* set levelcurve granularity */ |
10 | reyssat | 877 | void obj_levelstep(objparm *pm) |
878 | { |
||
879 | int dd; |
||
880 | dd=pm->pd[0]; |
||
11120 | georgesk | 881 | if(dd<1) return; |
882 | if(dd>16) dd=16; |
||
10 | reyssat | 883 | lstep=dd; |
884 | } |
||
885 | |||
7675 | bpr | 886 | /* level curve */ |
10 | reyssat | 887 | void obj_levelcurve(objparm *pm) |
888 | { |
||
889 | char fn[MAX_LINELEN+1],tc[MAX_LINELEN+1]; |
||
890 | int n,i; |
||
891 | double d; |
||
892 | leveldata *ld; |
||
7615 | bpr | 893 | |
10 | reyssat | 894 | ld=xmalloc(sizeof(leveldata)+16); |
895 | ld->xname="x"; ld->yname="y"; |
||
896 | ld->xsize=sizex; ld->ysize=sizey; ld->datacnt=0; |
||
897 | ld->xrange[0]=xstart; ld->xrange[1]=sizex/xscale+xstart; |
||
898 | ld->yrange[0]=sizey/yscale+ystart; ld->yrange[1]=ystart; |
||
899 | ld->grain=lstep; |
||
900 | fnd_item(pm->str,1,fn); ld->fn=fn; |
||
901 | n=itemnum(pm->str); |
||
902 | if(n<=1) {ld->levelcnt=1; ld->levels[0]=0;} |
||
903 | else { |
||
7675 | bpr | 904 | if(n>LEVEL_LIM+1) n=LEVEL_LIM+1; |
905 | for(i=0;i<n-1;i++) { |
||
906 | fnd_item(pm->str,i+2,tc); |
||
8076 | bpr | 907 | d=strevalue(tc); |
8171 | bpr | 908 | if(isfinite(d)) ld->levels[i]=d; else ld->levels[i]=0; |
7675 | bpr | 909 | } |
910 | ld->levelcnt=n-1; |
||
10 | reyssat | 911 | } |
912 | levelcurve(ld); |
||
913 | for(i=0;i<ld->datacnt;i++) { |
||
7675 | bpr | 914 | gdImageSetPixel(image,ld->xdata[i],ld->ydata[i],pm->color[0]); |
10 | reyssat | 915 | } |
916 | free(ld); |
||
917 | } |
||
918 | |||
7675 | bpr | 919 | /* set animation step */ |
10 | reyssat | 920 | void obj_animstep(objparm *pm) |
921 | { |
||
922 | animstep=pm->pd[0]; |
||
923 | setvar("animstep",pm->pd[0]); |
||
924 | } |
||
925 | |||
7675 | bpr | 926 | /* Starts a line counting */ |
10 | reyssat | 927 | void obj_linecount(objparm *pm) |
928 | { |
||
929 | linecnt=pm->pd[0]; |
||
930 | } |
||
931 | |||
7675 | bpr | 932 | /* marks end of execution */ |
10 | reyssat | 933 | void obj_end(objparm *pm) |
934 | { |
||
8195 | bpr | 935 | fly_error("successful_end_of_execution"); |
10 | reyssat | 936 | } |
937 | |||
7675 | bpr | 938 | /* output */ |
10 | reyssat | 939 | void obj_output(objparm *pm) |
940 | { |
||
941 | char *p, namebuf[1024]; |
||
942 | p=find_word_start(pm->str); *find_word_end(p)=0; |
||
943 | snprintf(namebuf,sizeof(namebuf),"%s",imagefilename); |
||
944 | snprintf(imagefilename,sizeof(imagefilename),"%s",p); |
||
945 | output(); |
||
946 | snprintf(imagefilename,sizeof(imagefilename),"%s",namebuf); |
||
947 | } |
||
948 | |||
7675 | bpr | 949 | /* vimgfile */ |
1024 | bpr | 950 | void obj_vimgfile(objparm *pm) |
951 | { |
||
952 | char *p; |
||
953 | p=find_word_start(pm->str); *find_word_end(p)=0; |
||
954 | snprintf(vimgfilename,sizeof(vimgfilename),"%s",p); |
||
955 | if(vimg_ready) vimg_close(); |
||
956 | } |
||
957 | |||
7675 | bpr | 958 | /* vimg enable/disable */ |
1024 | bpr | 959 | void obj_vimg(objparm *pm) |
960 | { |
||
961 | vimg_enable=pm->pd[0]; |
||
962 | if(vimg_enable>0 && vimg_ready==0) { |
||
7675 | bpr | 963 | vimg_init(); |
1024 | bpr | 964 | } |
965 | } |
||
966 | |||
7675 | bpr | 967 | /* Set affine transformation */ |
10 | reyssat | 968 | void obj_affine(objparm *pm) |
969 | { |
||
970 | int i; |
||
971 | for(i=0;i<4;i++) matrix[i]=pm->pd[i]; |
||
972 | transx=pm->pd[4]; transy=pm->pd[5]; |
||
973 | transform=1; |
||
974 | } |
||
975 | |||
7675 | bpr | 976 | /* Set affine transformation */ |
10 | reyssat | 977 | void obj_rotation(objparm *pm) |
978 | { |
||
979 | double r; |
||
980 | r=M_PI*pm->pd[0]/180; |
||
981 | matrix[0]=matrix[3]=cos(r); |
||
982 | matrix[1]=-sin(r); matrix[2]=sin(r); |
||
983 | transform=1; |
||
984 | } |
||
985 | |||
8419 | bpr | 986 | /* Set linear transformation */ |
10 | reyssat | 987 | void obj_linear(objparm *pm) |
988 | { |
||
989 | int i; |
||
990 | for(i=0;i<4;i++) matrix[i]=pm->pd[i]; |
||
991 | transform=1; |
||
992 | } |
||
993 | |||
8419 | bpr | 994 | /* Set translation transformation */ |
10 | reyssat | 995 | void obj_translation(objparm *pm) |
996 | { |
||
997 | transx=pm->pd[0]; transy=pm->pd[1]; |
||
998 | } |
||
999 | |||
8419 | bpr | 1000 | /* kill affine transformation */ |
10 | reyssat | 1001 | void obj_killaffine(objparm *pm) |
1002 | { |
||
1003 | matrix[0]=matrix[3]=1; |
||
1004 | matrix[1]=matrix[2]=transx=transy=0; |
||
1005 | transform=0; |
||
1006 | } |
||
1007 | |||
8419 | bpr | 1008 | /* kill affine transformation */ |
10 | reyssat | 1009 | void obj_killlinear(objparm *pm) |
1010 | { |
||
1011 | matrix[0]=matrix[3]=1; |
||
1012 | matrix[1]=matrix[2]=0; |
||
1013 | transform=0; |
||
1014 | } |
||
1015 | |||
8419 | bpr | 1016 | /* kill affine transformation */ |
10 | reyssat | 1017 | void obj_killtranslation(objparm *pm) |
1018 | { |
||
1019 | transx=transy=0; |
||
1020 | } |
||
1021 | |||
1022 | /***** Les modifs de Jean-Christophe Leger Fev 2006 *****/ |
||
1023 | |||
7615 | bpr | 1024 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES, une liste de 4 nombres reels pour la matrice */ |
10 | reyssat | 1025 | void obj_setmatrix(objparm *pm) |
1026 | { |
||
1027 | int nummatrix = (int) (pm->pd[0]); |
||
1028 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1029 | fly_error("bad_matrix_number"); |
10 | reyssat | 1030 | return; |
1031 | } |
||
1032 | matrices_pavage[nummatrix][0] = pm->pd[1]; |
||
1033 | matrices_pavage[nummatrix][1] = pm->pd[2]; |
||
1034 | matrices_pavage[nummatrix][2] = pm->pd[3]; |
||
1035 | matrices_pavage[nummatrix][3] = pm->pd[4]; |
||
1036 | } |
||
1037 | |||
7615 | bpr | 1038 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1039 | void obj_resetmatrix(objparm *pm) |
1040 | { |
||
1041 | int nummatrix = (int) (pm->pd[0]); |
||
1042 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1043 | fly_error("bad_matrix_number"); |
10 | reyssat | 1044 | return; |
1045 | } |
||
1046 | matrices_pavage[nummatrix][0] = 1; |
||
1047 | matrices_pavage[nummatrix][1] = 0; |
||
1048 | matrices_pavage[nummatrix][2] = 0; |
||
1049 | matrices_pavage[nummatrix][3] = 1; |
||
1050 | |||
1051 | } |
||
7615 | bpr | 1052 | /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 2 nombres reels pour le vecteur */ |
10 | reyssat | 1053 | void obj_setvector(objparm *pm) |
1054 | { |
||
1055 | int nummatrix = (int) (pm->pd[0]); |
||
1056 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1057 | fly_error("bad_vector_number"); |
10 | reyssat | 1058 | return; |
1059 | } |
||
1060 | vecteurs_pavage[nummatrix][0] = pm->pd[1]; |
||
1061 | vecteurs_pavage[nummatrix][1] = pm->pd[2]; |
||
1062 | } |
||
1063 | |||
7615 | bpr | 1064 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1065 | void obj_resetvector(objparm *pm) |
1066 | { |
||
1067 | int nummatrix = (int) (pm->pd[0]); |
||
1068 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1069 | fly_error("bad_vector_number"); |
10 | reyssat | 1070 | return; |
1071 | } |
||
1072 | vecteurs_pavage[nummatrix][0] = 0; |
||
1073 | vecteurs_pavage[nummatrix][1] = 0; |
||
1074 | } |
||
1075 | |||
7615 | bpr | 1076 | /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 6 nombres reels pour la matrice et le vecteur */ |
10 | reyssat | 1077 | void obj_settransform(objparm *pm) |
1078 | { |
||
1079 | int nummatrix = (int) (pm->pd[0]); |
||
1080 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1081 | fly_error("bad_vector_number"); |
10 | reyssat | 1082 | return; |
1083 | } |
||
1084 | matrices_pavage[nummatrix][0] = pm->pd[1]; |
||
1085 | matrices_pavage[nummatrix][1] = pm->pd[2]; |
||
1086 | matrices_pavage[nummatrix][2] = pm->pd[3]; |
||
1087 | matrices_pavage[nummatrix][3] = pm->pd[4]; |
||
1088 | vecteurs_pavage[nummatrix][0] = pm->pd[5]; |
||
1089 | vecteurs_pavage[nummatrix][1] = pm->pd[6]; |
||
1090 | } |
||
1091 | |||
1092 | |||
7615 | bpr | 1093 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1094 | void obj_resettransform(objparm *pm) |
1095 | { |
||
1096 | int nummatrix = (int) (pm->pd[0]); |
||
1097 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1098 | fly_error("bad_vector_number"); |
10 | reyssat | 1099 | return; |
1100 | } |
||
1101 | vecteurs_pavage[nummatrix][0] = 0; |
||
1102 | vecteurs_pavage[nummatrix][1] = 0; |
||
1103 | matrices_pavage[nummatrix][0] = 1; |
||
1104 | matrices_pavage[nummatrix][1] = 0; |
||
1105 | matrices_pavage[nummatrix][2] = 0; |
||
1106 | matrices_pavage[nummatrix][3] = 1; |
||
1107 | } |
||
1108 | |||
7615 | bpr | 1109 | /* arguments: une liste de 6 nombres reels pour les coordonnees de l'origine et des vecteurs de base */ |
10 | reyssat | 1110 | void obj_setparallelogram(objparm *pm) |
1111 | { |
||
1112 | int i; |
||
1113 | for(i=0;i<6;i++) parallogram_fonda[i]=pm->pd[i]; |
||
1114 | } |
||
1115 | |||
1116 | /* arguments :aucun */ |
||
1117 | void obj_resetparallelogram(objparm *pm) |
||
1118 | { |
||
1119 | parallogram_fonda[0]=0; |
||
1120 | parallogram_fonda[1]=0; |
||
1121 | parallogram_fonda[2]=100; |
||
1122 | parallogram_fonda[3]=0; |
||
1123 | parallogram_fonda[4]=0; |
||
1124 | parallogram_fonda[5]=100; |
||
1125 | } |
||
1126 | |||
1127 | /* argument : la liste des numeros des matrices a faire agir, le nom du fichier de l'image a inclure */ |
||
1128 | void obj_multicopy(objparm *pm) |
||
1129 | { |
||
1130 | char *pp,*pe,*cptr; |
||
1131 | FILE *inf; |
||
7675 | bpr | 1132 | gdImagePtr insimg; |
10 | reyssat | 1133 | int i,j; |
1134 | int imax,jmax; |
||
1135 | int c; /* la couleur reperee */ |
||
1136 | int mat; |
||
1137 | int nummatrices[JC_NB_MATRICES]; |
||
1138 | double pt[2]; /* les coordonnees math. du point repere dans le parallelogramme */ |
||
1139 | double ptr[2]; /* les coordonnees math. du point transforme */ |
||
1140 | int pti[2]; /* les coordonnees img du point a placer sur le canevas */ |
||
1141 | int t; |
||
1142 | /* gestion palette de couleur de l'image a inserer */ |
||
1143 | int colorMap[gdMaxColors]; |
||
1144 | int comptmat=0; /* combien de matrices en tout ? */ |
||
7615 | bpr | 1145 | |
10 | reyssat | 1146 | for (i=0; (i<gdMaxColors); i++) { |
1147 | colorMap[i] = (-1); |
||
1148 | } |
||
1149 | |||
1150 | /* Gestion des parametres la liste est censee finir avec le nom du fichier */ |
||
7615 | bpr | 1151 | t=pm->pcnt-1; /* il faut enlever le nom de fichier ! c'est le nombre de parametres en plus */ |
10 | reyssat | 1152 | pp=find_word_start(pm->str); |
1153 | /* visiblement find_word_start n'arrive pas a trouver le dernier mot dans un contexte ou le nombre de parameters est variable |
||
1154 | * on cherche donc l'emplacement de la derniere virgule: |
||
1155 | * il y en a une car t>0, on retrouve ensuite le debut de mot |
||
1156 | */ |
||
1157 | for(pe=pp;*pe!=0;pe++);/* trouve la fin de la chaine */ |
||
1158 | if(t>0){ |
||
1159 | for(cptr = pe; cptr > pp && *cptr != ','; cptr--); |
||
1160 | pp=find_word_start(cptr+1); |
||
1161 | } |
||
1162 | pe=find_word_end(pp);*pe=0; /* strip junk final */ |
||
1163 | // printf("pp contient %s\n",pp); |
||
1164 | |||
1165 | |||
1166 | inf=open4read(pp); |
||
1167 | if(inf==NULL) { |
||
8195 | bpr | 1168 | fly_error("file_not_exist"); return; |
10 | reyssat | 1169 | } |
1170 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
1171 | if(insimg==NULL) { |
||
8195 | bpr | 1172 | fly_error("bad_gif"); return; |
10 | reyssat | 1173 | } |
1174 | |||
7675 | bpr | 1175 | /* On recupere les numeros des matrices/vecteurs a faire agir, |
1176 | * s'il n'y en a pas, on les fait toutes agir |
||
1177 | */ |
||
10 | reyssat | 1178 | for(i=0;i<t && i< JC_NB_MATRICES;i++) { |
1179 | if(pm->pd[i]>=1 && pm->pd[i]<=JC_NB_MATRICES){ |
||
7675 | bpr | 1180 | nummatrices[comptmat] = pm->pd[i]; |
1181 | comptmat++; |
||
10 | reyssat | 1182 | } |
1183 | } |
||
1184 | if(t<=0){ |
||
1185 | for(i=0;i<JC_NB_MATRICES;i++) { |
||
7675 | bpr | 1186 | nummatrices[i] = i+1; |
10 | reyssat | 1187 | } |
1188 | comptmat=JC_NB_MATRICES; |
||
1189 | } |
||
1190 | |||
7615 | bpr | 1191 | |
10 | reyssat | 1192 | imax = gdImageSX(insimg); |
1193 | jmax = gdImageSY(insimg); |
||
1194 | |||
1195 | for(i=0;i<imax;i++){ |
||
1196 | for(j=0;j<jmax;j++){ |
||
7675 | bpr | 1197 | int nc; |
1198 | c=gdImageGetPixel(insimg,i,j); |
||
1199 | /* Le code suivant est une copie du code dans gdImageCopy Added 7/24/95: support transparent copies */ |
||
1200 | if (gdImageGetTransparent(insimg) != c) { |
||
1201 | /* Have we established a mapping for this color? */ |
||
1202 | if (colorMap[c] == (-1)) { |
||
1203 | /* If it's the same image, mapping is trivial, dans notre cas ca n'arrive jamais... */ |
||
1204 | if (image == insimg) { |
||
1205 | nc = c; |
||
1206 | } else { |
||
1207 | /* First look for an exact match */ |
||
1208 | nc = gdImageColorExact(image, |
||
1209 | insimg->red[c], insimg->green[c], |
||
1210 | insimg->blue[c]); |
||
1211 | } |
||
1212 | if (nc == (-1)) { |
||
1213 | /* No, so try to allocate it */ |
||
1214 | nc = gdImageColorAllocate(image, |
||
1215 | insimg->red[c], insimg->green[c], |
||
1216 | insimg->blue[c]); |
||
1217 | /* If we're out of colors, go for the closest color */ |
||
1218 | if (nc == (-1)) { |
||
1219 | nc = gdImageColorClosest(image, |
||
1220 | insimg->red[c], insimg->green[c], |
||
1221 | insimg->blue[c]); |
||
1222 | } |
||
1223 | } |
||
1224 | colorMap[c] = nc; |
||
1225 | } |
||
10 | reyssat | 1226 | |
7675 | bpr | 1227 | pt[0]= i*(parallogram_fonda[2])/(imax-1)+(jmax-j)*(parallogram_fonda[4])/(jmax-1)+parallogram_fonda[0]; |
1228 | pt[1]= i*(parallogram_fonda[3])/(imax-1)+(jmax-j)*(parallogram_fonda[5])/(jmax-1)+parallogram_fonda[1]; |
||
1229 | for(mat=0;mat<comptmat;mat++){ |
||
1230 | double *matricecourante = matrices_pavage[nummatrices[mat]]; |
||
1231 | double *vecteurcourant = vecteurs_pavage[nummatrices[mat]]; |
||
1232 | ptr[0] = matricecourante[0]*pt[0]+matricecourante[1]*pt[1]+vecteurcourant[0]; |
||
1233 | ptr[1] = matricecourante[2]*pt[0]+matricecourante[3]*pt[1]+vecteurcourant[1]; |
||
1234 | scale(ptr,pti,1); |
||
1235 | gdImageSetPixel(image,pti[0],pti[1],colorMap[c]); |
||
1236 | } |
||
1237 | } |
||
10 | reyssat | 1238 | } |
1239 | } |
||
1240 | gdImageDestroy(insimg); |
||
1241 | } |
||
1242 | |||
1243 | /**** Fin modifs JC Fev 06 ******/ |
||
1244 | |||
7675 | bpr | 1245 | /* get color from value */ |
10 | reyssat | 1246 | int calc_color(char *p, struct objtab *o) |
1247 | { |
||
1248 | int k, cc[3]; |
||
1249 | char buf[MAX_LINELEN+1]; |
||
1250 | for(k=0;k<3;k++) { |
||
7675 | bpr | 1251 | fnd_item(p,k+1,buf); |
8076 | bpr | 1252 | cc[k]=strevalue(buf); |
10 | reyssat | 1253 | } |
1254 | collapse_item(p,3); |
||
1255 | if(cc[0]==-1 && cc[1]==-1 && cc[2]==-255) { |
||
1256 | |||
7675 | bpr | 1257 | if(brushed && o->subst&1) return gdBrushed; |
1258 | else return color_black; |
||
10 | reyssat | 1259 | } |
1260 | if(cc[0]==-1 && cc[1]==-255 && cc[2]==-1) { |
||
7675 | bpr | 1261 | if(styled && o->subst&2) return gdStyled; |
1262 | else return color_black; |
||
10 | reyssat | 1263 | } |
1264 | if(cc[0]==-255 && cc[1]==-1 && cc[2]==-1) { |
||
7675 | bpr | 1265 | if(tiled && o->fill_tag==1) return gdTiled; |
1266 | else return color_black; |
||
10 | reyssat | 1267 | } |
1268 | return getcolor(cc[0],cc[1],cc[2]); |
||
1269 | } |
||
1270 | |||
7675 | bpr | 1271 | /* Routine to parse parameters */ |
10 | reyssat | 1272 | int parse_parms(char *p,objparm *pm,struct objtab *o) |
1273 | { |
||
1274 | char buf[MAX_LINELEN+1]; |
||
1275 | char *p1, *p2; |
||
1276 | int j,t,c,c1,c2; |
||
7615 | bpr | 1277 | |
10 | reyssat | 1278 | c=o->color_pos;c1=c2=0; |
1279 | pm->color[0]=pm->color[1]=0; |
||
11120 | georgesk | 1280 | if(c>0) c1=c; |
1281 | if(c<0) c2=-c; |
||
1282 | c=c1+c2; |
||
10 | reyssat | 1283 | t=itemnum(p);if(t<o->required_parms+3*c) return -1; |
1284 | if(c1>0 && t>o->required_parms+3*c) t=o->required_parms+3*c; |
||
1285 | pm->pcnt=t-3*c; |
||
1286 | if(pm->pcnt>MAX_PARMS) pm->pcnt=MAX_PARMS; |
||
1287 | if(c2>0) { |
||
7675 | bpr | 1288 | for(j=0;j<2 && j<c2; j++) pm->color[j]=calc_color(p,o); |
10 | reyssat | 1289 | } |
1290 | snprintf(buf,sizeof(buf),"%s",p); |
||
1291 | for(j=0, p1=buf; j<pm->pcnt; j++, p1=p2) { |
||
7675 | bpr | 1292 | p2=find_item_end(p1); if(*p2) *p2++=0; |
1293 | p1=find_word_start(p1); |
||
8076 | bpr | 1294 | if(*p1) pm->pd[j]=strevalue(p1); else pm->pd[j]=0; |
8171 | bpr | 1295 | if(!isfinite(pm->pd[j])) { |
7675 | bpr | 1296 | if(j<o->required_parms) return -1; |
1297 | else {pm->pd[j]=0;break;} |
||
1298 | } |
||
10 | reyssat | 1299 | } |
1300 | collapse_item(p,o->required_parms); |
||
1301 | if(c1>0) { |
||
7675 | bpr | 1302 | for(j=0;j<c1 && j<2; j++) pm->color[j]=calc_color(p,o); |
10 | reyssat | 1303 | } |
1304 | if(width>1 && o->subst&1 && pm->color[0]!=gdBrushed |
||
1305 | && pm->color[0]!=gdStyled && pm->color[0]!=gdTiled) { |
||
7675 | bpr | 1306 | pm->color[1]=pm->color[0]; |
1307 | pm->color[0]=widthcolor(width,pm->color[0]); |
||
10 | reyssat | 1308 | } |
1309 | pm->fill=o->fill_tag; |
||
3718 | reyssat | 1310 | ovlstrcpy(pm->str,p); return 0; |
10 | reyssat | 1311 | } |
1312 | |||
8068 | bpr | 1313 | /* Create the struct objparm pm corresponding to the objparm p |
1314 | * Execute a command. Returns 0 if OK. |
||
1315 | */ |
||
10 | reyssat | 1316 | int obj_main(char *p) |
1317 | { |
||
1318 | int i; |
||
1319 | char *pp,*name,*pt; |
||
1320 | char tbuf2[MAX_LINELEN+1]; |
||
1321 | struct objparm pm; |
||
1322 | |||
1323 | p=find_word_start(p); |
||
1324 | if(*p==exec_prefix_char || *p==0) return 0; /* comment */ |
||
1325 | name=p; |
||
1326 | pp=find_name_end(p); |
||
1327 | pt=find_word_start(pp); if(*pt=='=') *pt=' '; |
||
1328 | if(*pt==':' && *(pt+1)=='=') *pt=*(pt+1)=' '; |
||
1329 | pp=find_word_end(p); |
||
1330 | if(*pp!=0) { |
||
7675 | bpr | 1331 | *(pp++)=0; pp=find_word_start(pp); |
10 | reyssat | 1332 | } |
1333 | if(strlen(p)==1 || (strlen(p)==2 && isdigit(*(p+1)))) { |
||
8076 | bpr | 1334 | setvar(p,strevalue(pp)); return 0; |
10 | reyssat | 1335 | } |
8068 | bpr | 1336 | /* search the number of the object */ |
10 | reyssat | 1337 | i=search_list(objtab,obj_no,sizeof(objtab[0]),name); |
1338 | if(i<0) { |
||
8195 | bpr | 1339 | fly_error("bad_cmd"); return 1; |
10 | reyssat | 1340 | } |
1341 | if(image==NULL && (objtab[i].color_pos || objtab[i].required_parms>2)) { |
||
8195 | bpr | 1342 | fly_error("image_not_defined"); return 1; |
10 | reyssat | 1343 | } |
3718 | reyssat | 1344 | ovlstrcpy(tbuf2,pp); |
10 | reyssat | 1345 | if(objtab[i].color_pos || objtab[i].routine==obj_setstyle) { |
7675 | bpr | 1346 | substit(tbuf2); |
10 | reyssat | 1347 | } |
8195 | bpr | 1348 | if(parse_parms(tbuf2,&pm,objtab+i)!=0) fly_error("bad_parms"); |
10 | reyssat | 1349 | else objtab[i].routine(&pm); |
1350 | return 0; |
||
1351 | } |
||
1352 |