Rev 16344 | Rev 17578 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 16344 | Rev 17574 | ||
---|---|---|---|
Line 15... | Line 15... | ||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 | #include <errno.h> |
18 | #include <errno.h> |
19 | #include "flydraw.h" |
19 | #include "flydraw.h" |
- | 20 | ||
- | 21 | /* Tikz things */ |
|
- | 22 | /* the_tiled,gdTiled , int the_tiled*/ |
|
- | 23 | static char *tikz_options (int the_color, int the_fill) |
|
- | 24 | { |
|
- | 25 | static char buf[100]; |
|
- | 26 | if (the_color == gdBrushed) |
|
- | 27 | the_color = tikz_brushColor; |
|
- | 28 | int r=gdImageRed(image,the_color); |
|
- | 29 | int g=gdImageGreen(image,the_color); |
|
- | 30 | int b=gdImageBlue(image,the_color); |
|
- | 31 | sprintf(buf, "draw={rgb,255:red,%i;green,%i;blue,%i},cap=round",r,g,b); |
|
- | 32 | if (the_color != tikz_brushColor) strcat(buf, ",thin"); |
|
- | 33 | if (the_fill == -1) strcat(buf, ",dashed"); |
|
- | 34 | if (the_fill == 1) |
|
- | 35 | sprintf(buf+strlen(buf), ",fill={rgb,255:red,%i;green,%i;blue,%i}",r,g,b); |
|
- | 36 | return buf; |
|
- | 37 | } |
|
- | 38 | ||
- | 39 | #define flip(y) (sizey-(y)) |
|
20 | 40 | ||
21 | /* bug in gdImageFillToBorder */ |
41 | /* bug in gdImageFillToBorder */ |
22 | 42 | ||
23 | void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) |
43 | void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) |
24 | { |
44 | { |
25 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
45 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
26 | gdImageFillToBorder(im,x,y,border,color); |
46 | gdImageFillToBorder(im,x,y,border,color); |
27 | } |
47 | } |
28 | 48 | ||
29 | void patchgdImageFill (gdImagePtr im, int x, int y, int color) |
49 | void patchgdImageFill (gdImagePtr im, int x, int y, int color) |
30 | { |
50 | { |
31 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
51 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
32 | gdImageFill(im,x,y,color); |
52 | gdImageFill(im,x,y,color); |
33 | } |
53 | } |
34 | 54 | ||
35 | 55 | ||
36 | #define DASHPIXELS 8 |
56 | #define DASHPIXELS 8 |
37 | 57 | ||
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){ |
58 | void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){ |
40 | /** |
59 | /** |
41 | * emulates gdImageDashedLine with gdImageSetStyle and gdImageLine |
60 | * emulates gdImageDashedLine with gdImageSetStyle and gdImageLine |
42 | * GK: As gdImageDashedLine is slightly broken in latest libgd libraries, |
61 | * GK: As gdImageDashedLine is slightly broken in latest libgd libraries, |
43 | * GK: I implemented an emulation named "myDashedLine" |
62 | * GK: I implemented an emulation named "myDashedLine" |
Line 48... | Line 67... | ||
48 | for (; i< DASHPIXELS; i++) styleDashed[i]=gdTransparent; |
67 | for (; i< DASHPIXELS; i++) styleDashed[i]=gdTransparent; |
49 | gdImageSetStyle(im, styleDashed, DASHPIXELS); |
68 | gdImageSetStyle(im, styleDashed, DASHPIXELS); |
50 | gdImageLine(im, x1, y1, x2, y2, gdStyled); |
69 | gdImageLine(im, x1, y1, x2, y2, gdStyled); |
51 | } |
70 | } |
52 | 71 | ||
53 | 72 | ||
54 | /* File opening: with security */ |
73 | /* File opening: with security */ |
55 | FILE *open4read(char *n) |
74 | FILE *open4read(char *n) |
56 | { |
75 | { |
57 | char *p, *p1, *p2, namebuf[2048]; |
76 | char *p, *p1, *p2, namebuf[2048]; |
58 | int t; |
77 | int t; |
Line 66... | Line 85... | ||
66 | snprintf(pbuf,sizeof(pbuf),"%s",p); |
85 | snprintf(pbuf,sizeof(pbuf),"%s",p); |
67 | p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL; |
86 | p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL; |
68 | if(*n=='/' || strstr(n,"..")!=NULL) return NULL; |
87 | if(*n=='/' || strstr(n,"..")!=NULL) return NULL; |
69 | /* prohibit unusual file/dir names */ |
88 | /* prohibit unusual file/dir names */ |
70 | for(p1=p;*p1;p1++) |
89 | for(p1=p;*p1;p1++) |
71 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
90 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
72 | return NULL; |
91 | return NULL; |
73 | for(p1=n;*p1;p1++) |
92 | for(p1=n;*p1;p1++) |
74 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
93 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
75 | return NULL; |
94 | return NULL; |
76 | f=NULL; |
95 | f=NULL; |
Line 118... | Line 137... | ||
118 | } |
137 | } |
119 | if(image!=NULL) { |
138 | if(image!=NULL) { |
120 | fly_error("size_already_defined"); return; |
139 | fly_error("size_already_defined"); return; |
121 | } |
140 | } |
122 | image=gdImageCreate(sizex,sizey); |
141 | image=gdImageCreate(sizex,sizey); |
- | 142 | if(tikz_file) fprintf(tikz_file,"\\clip (0,0) rectangle (%i, %i);\n", sizex, sizey); |
|
123 | if(image==NULL) fly_error("image_creation_failure"); |
143 | if(image==NULL) fly_error("image_creation_failure"); |
124 | else { |
144 | else { |
125 | color_white=gdImageColorAllocate(image,255,255,255); |
145 | color_white=gdImageColorAllocate(image,255,255,255); |
126 | color_black=gdImageColorAllocate(image,0,0,0); |
146 | color_black=gdImageColorAllocate(image,0,0,0); |
127 | color_bounder=gdImageColorAllocate(image,1,2,3); |
147 | color_bounder=gdImageColorAllocate(image,1,2,3); |
Line 165... | Line 185... | ||
165 | /* solid line */ |
185 | /* solid line */ |
166 | void obj_line(objparm *pm) |
186 | void obj_line(objparm *pm) |
167 | { |
187 | { |
168 | scale(pm->pd,pm->p,2); |
188 | scale(pm->pd,pm->p,2); |
169 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
189 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
- | 190 | if (tikz_file) |
|
- | 191 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 192 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
|
170 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
193 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
171 | } |
194 | } |
172 | 195 | ||
173 | void _obj_arrow(objparm *pm, int twoside) |
196 | void _obj_arrow(objparm *pm, int twoside) |
174 | { |
197 | { |
Line 197... | Line 220... | ||
197 | } |
220 | } |
198 | stem: if(pm->fill) |
221 | stem: if(pm->fill) |
199 | myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
222 | myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
200 | else |
223 | else |
201 | gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
224 | gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
- | 225 | if(tikz_file) { |
|
- | 226 | if (twoside) fprintf(tikz_file,"\\draw\[%s,<->] (%i,%i) -- (%i,%i);\n", |
|
- | 227 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
|
- | 228 | else fprintf(tikz_file,"\\draw\[%s,->] (%i,%i) -- (%i,%i);\n", |
|
- | 229 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]));} |
|
- | 230 | /*FIXME ne tient pas compte de la largeur de la fleche */ |
|
202 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
231 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
203 | } |
232 | } |
204 | 233 | ||
205 | /* Arrow */ |
234 | /* Arrow */ |
206 | void obj_arrow(objparm *pm) |
235 | void obj_arrow(objparm *pm) |
Line 220... | Line 249... | ||
220 | scale(pm->pd,pm->p,1); |
249 | scale(pm->pd,pm->p,1); |
221 | if(pm->fill) |
250 | if(pm->fill) |
222 | myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
251 | myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
223 | else |
252 | else |
224 | gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
253 | gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
- | 254 | if (tikz_file) |
|
- | 255 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 256 | tikz_options(pm->color[0],pm->fill),0,flip(pm->p[1]),sizex,flip(pm->p[1])); |
|
- | 257 | } |
|
- | 258 | ||
- | 259 | /* tikzfile */ |
|
- | 260 | void obj_tikzfile(objparm *pm) |
|
- | 261 | { |
|
- | 262 | char *p; |
|
- | 263 | if(tikz_file){ |
|
- | 264 | fprintf(tikz_file,"\\end{tikzpicture}\n\\end{document}\n"); |
|
- | 265 | fclose(tikz_file); |
|
- | 266 | } |
|
- | 267 | p=find_word_start(pm->str); *find_word_end(p)=0; |
|
- | 268 | snprintf(tikzfilename,sizeof(tikzfilename),"%s",p); |
|
- | 269 | tikz_file=fopen(tikzfilename,"w"); |
|
- | 270 | if(!tikz_file) |
|
- | 271 | fly_error("tikz_nopen"); |
|
- | 272 | fprintf(tikz_file,"\\documentclass\[11pt]{article}\n\\usepackage{tikz}\n\\begin{document}\n\\begin{tikzpicture}\[scale=0.0254]\n"); |
|
225 | } |
273 | } |
226 | 274 | ||
227 | /* vertical line */ |
275 | /* vertical line */ |
228 | void obj_vline(objparm *pm) |
276 | void obj_vline(objparm *pm) |
229 | { |
277 | { |
230 | scale(pm->pd,pm->p,1); |
278 | scale(pm->pd,pm->p,1); |
231 | if(pm->fill) |
279 | if(pm->fill) |
232 | myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
280 | myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
233 | else |
281 | else |
234 | gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
282 | gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
- | 283 | if (tikz_file) |
|
- | 284 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 285 | tikz_options(pm->color[0],pm->fill),pm->p[0],0,pm->p[0],sizey); |
|
235 | } |
286 | } |
236 | 287 | ||
237 | /* dashed line */ |
288 | /* dashed line */ |
238 | void obj_dline(objparm *pm) |
289 | void obj_dline(objparm *pm) |
239 | { |
290 | { |
240 | scale(pm->pd,pm->p,2); |
291 | scale(pm->pd,pm->p,2); |
241 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]); |
292 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]); |
- | 293 | if (tikz_file) |
|
- | 294 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 295 | tikz_options(pm->color[0],-1), |
|
- | 296 | pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
|
242 | } |
297 | } |
243 | 298 | ||
244 | /* parallel lines. |
299 | /* parallel lines. |
245 | * x1,y1,x2,y2,xv,yv,n,color */ |
300 | * x1,y1,x2,y2,xv,yv,n,color */ |
246 | void obj_parallel(objparm *pm) |
301 | void obj_parallel(objparm *pm) |
247 | { |
302 | { |
248 | int i, n, xi,yi; |
303 | int i, n, xi,yi; |
249 | double xv,yv; |
304 | double xv,yv; |
250 | n=pm->pd[6]; if(n<0) return; if(n>256) n=256; |
305 | n=pm->pd[6]; if(n<0) return; if(n>256) n=256; |
251 | scale(pm->pd,pm->p,3); |
306 | scale(pm->pd,pm->p,3); |
252 | scale2(pm->pd[4],pm->pd[5],&xv,&yv); |
307 | scale2(pm->pd[4],pm->pd[5],&xv,&yv); |
253 | for(i=0;i<n;i++) { |
308 | for(i=0;i<n;i++) { |
254 | xi=rint(i*xv); yi=rint(i*yv); |
309 | xi=rint(i*xv); yi=rint(i*yv); |
255 | gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi, |
310 | gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi, |
256 | pm->color[0]); |
311 | pm->color[0]); |
- | 312 | if (tikz_file) |
|
- | 313 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 314 | tikz_options(pm->color[0],pm->fill), |
|
- | 315 | pm->p[0]+xi,flip(pm->p[1]+yi),pm->p[2]+xi,flip(pm->p[3]+yi)); |
|
257 | if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx), |
316 | if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx), |
258 | scale_buf[1]+i*(scale_buf[5]-transy), |
317 | scale_buf[1]+i*(scale_buf[5]-transy), |
259 | scale_buf[2]+i*(scale_buf[4]-transx), |
318 | scale_buf[2]+i*(scale_buf[4]-transx), |
260 | scale_buf[3]+i*(scale_buf[5]-transy)); |
319 | scale_buf[3]+i*(scale_buf[5]-transy)); |
261 | } |
320 | } |
Line 263... | Line 322... | ||
263 | 322 | ||
264 | /* rectangle */ |
323 | /* rectangle */ |
265 | void obj_rect(objparm *pm) |
324 | void obj_rect(objparm *pm) |
266 | { |
325 | { |
267 | int x1,y1,x2,y2; |
326 | int x1,y1,x2,y2; |
268 | scale(pm->pd,pm->p,2); |
327 | scale(pm->pd,pm->p,2); |
269 | x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]); |
328 | x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]); |
270 | y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]); |
329 | y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]); |
271 | if(pm->fill) |
330 | if(pm->fill) |
272 | gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]); |
331 | gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]); |
273 | else |
332 | else |
274 | gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]); |
333 | gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]); |
- | 334 | if(tikz_file){ |
|
- | 335 | fprintf(tikz_file, |
|
- | 336 | "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n", |
|
- | 337 | tikz_options(pm->color[0],pm->fill),x1,flip(y1),x2,flip(y2)); |
|
- | 338 | } |
|
275 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
339 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
276 | } |
340 | } |
277 | 341 | ||
278 | /* square */ |
342 | /* square */ |
279 | void obj_square(objparm *pm) |
343 | void obj_square(objparm *pm) |
Line 285... | Line 349... | ||
285 | gdImageFilledRectangle(image,pm->p[0],pm->p[1], |
349 | gdImageFilledRectangle(image,pm->p[0],pm->p[1], |
286 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
350 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
287 | else |
351 | else |
288 | gdImageRectangle(image,pm->p[0],pm->p[1], |
352 | gdImageRectangle(image,pm->p[0],pm->p[1], |
289 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
353 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
- | 354 | if(tikz_file){ |
|
- | 355 | fprintf(tikz_file, |
|
- | 356 | "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n", |
|
- | 357 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]), |
|
- | 358 | pm->p[0]+w,flip(pm->p[1]+h)); |
|
- | 359 | } |
|
290 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1], |
360 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1], |
291 | scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]); |
361 | scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]); |
292 | } |
362 | } |
293 | 363 | ||
294 | /* triangle */ |
364 | /* triangle */ |
Line 297... | Line 367... | ||
297 | scale(pm->pd,pm->p,3); |
367 | scale(pm->pd,pm->p,3); |
298 | if(pm->fill) |
368 | if(pm->fill) |
299 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
369 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
300 | else |
370 | else |
301 | gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
371 | gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
- | 372 | if (tikz_file) |
|
- | 373 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
|
- | 374 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]),pm->p[4],flip(pm->p[5])); |
|
302 | if(vimg_enable) vimg_polyline(scale_buf,3,1); |
375 | if(vimg_enable) vimg_polyline(scale_buf,3,1); |
303 | } |
376 | } |
304 | 377 | ||
305 | /* polygon */ |
378 | /* polygon */ |
306 | void obj_poly(objparm *pm) |
379 | void obj_poly(objparm *pm) |
307 | { |
380 | { |
308 | int cnt; |
381 | int cnt,i; |
309 | cnt=(pm->pcnt)/2; |
382 | cnt=(pm->pcnt)/2; |
310 | scale(pm->pd,pm->p,cnt); |
383 | scale(pm->pd,pm->p,cnt); |
311 | if(pm->fill) |
384 | if(pm->fill) |
312 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
385 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
313 | else |
386 | else |
314 | gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
387 | gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
- | 388 | if(tikz_file) |
|
- | 389 | for (i= 0; i<cnt; i++) |
|
- | 390 | fprintf(tikz_file,"\\draw\[%s] (%i,%i)--(%i,%i);\n", |
|
- | 391 | tikz_options(pm->color[0],pm->fill), |
|
- | 392 | pm->p[2*i],flip(pm->p[2*i+1]), |
|
- | 393 | pm->p[2*((i+1)%cnt)],flip(pm->p[2*((i+1)%cnt)+1])); |
|
315 | if(vimg_enable) vimg_polyline(scale_buf,cnt,1); |
394 | if(vimg_enable) vimg_polyline(scale_buf,cnt,1); |
316 | } |
395 | } |
317 | 396 | ||
318 | /* rays */ |
397 | /* rays */ |
319 | void obj_rays(objparm *pm) |
398 | void obj_rays(objparm *pm) |
Line 321... | Line 400... | ||
321 | int i, n; |
400 | int i, n; |
322 | n=(pm->pcnt)/2; |
401 | n=(pm->pcnt)/2; |
323 | scale(pm->pd,pm->p,n); |
402 | scale(pm->pd,pm->p,n); |
324 | for(i=2;i<2*n;i+=2) { |
403 | for(i=2;i<2*n;i+=2) { |
325 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]); |
404 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]); |
- | 405 | if (tikz_file) |
|
- | 406 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 407 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[i],flip(pm->p[i+1])); |
|
326 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1], |
408 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1], |
327 | scale_buf[i],scale_buf[i+1]); |
409 | scale_buf[i],scale_buf[i+1]); |
328 | } |
410 | } |
329 | } |
411 | } |
330 | /* crosshair */ |
412 | /* crosshair */ |
331 | void obj_crosshair(objparm *pm) |
413 | void obj_crosshair(objparm *pm) |
332 | { |
414 | { |
333 | scale(pm->pd,pm->p,2); |
415 | scale(pm->pd,pm->p,2); |
334 | gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]); |
416 | gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]); |
335 | gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]); |
417 | gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]); |
- | 418 | if (tikz_file){ |
|
- | 419 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 420 | tikz_options(pm->color[0],pm->fill),pm->p[0]+width2,flip(pm->p[1]+width2),pm->p[0]-width2,flip(pm->p[1]-width2)); |
|
- | 421 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 422 | tikz_options(pm->color[0],pm->fill),pm->p[0]-width2,flip(pm->p[1]+width2),pm->p[0]+width2,flip(pm->p[1]-width2)); |
|
- | 423 | } |
|
336 | } |
424 | } |
337 | /* crosshairs */ |
425 | /* crosshairs */ |
338 | 426 | ||
339 | void obj_crosshairs(objparm *pm) |
427 | void obj_crosshairs(objparm *pm) |
340 | { |
428 | { |
341 | int i, n; |
429 | int i, n; |
342 | n=(pm->pcnt)/2; |
430 | n=(pm->pcnt)/2; |
343 | scale(pm->pd,pm->p,n); |
431 | scale(pm->pd,pm->p,n); |
344 | for(i=0;i<2*n;i+=2) { |
432 | for(i=0;i<2*n;i+=2) { |
345 | gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]); |
433 | gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]); |
346 | gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]); |
434 | gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]); |
- | 435 | if (tikz_file){ |
|
- | 436 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 437 | tikz_options(pm->color[0],pm->fill),pm->p[i]+width2,flip(pm->p[i+1]+width2),pm->p[i]-width2,flip(pm->p[i+1]-width2)); |
|
- | 438 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 439 | tikz_options(pm->color[0],pm->fill),pm->p[i]-width2,flip(pm->p[i+1]+width2),pm->p[i]+width2,flip(pm->p[i+1]-width2)); |
|
- | 440 | } |
|
347 | } |
441 | } |
348 | } |
442 | } |
349 | 443 | ||
350 | 444 | ||
351 | /* segments */ |
445 | /* segments */ |
352 | void obj_lines(objparm *pm) |
446 | void obj_lines(objparm *pm) |
353 | { |
447 | { |
354 | int i, n; |
448 | int i, n; |
355 | n=(pm->pcnt)/2; |
449 | n=(pm->pcnt)/2; |
356 | scale(pm->pd,pm->p,n); |
450 | scale(pm->pd,pm->p,n); |
357 | for(i=2;i<2*n;i+=2) |
451 | for(i=2;i<2*n;i+=2){ |
358 | gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
452 | gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
- | 453 | if (tikz_file){ |
|
- | 454 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 455 | tikz_options(pm->color[0],pm->fill),pm->p[i-2],flip(pm->p[i-1]),pm->p[i],flip(pm->p[i+1])); |
|
- | 456 | } |
|
359 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
457 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
- | 458 | } |
|
360 | } |
459 | } |
361 | /*segments from x1,y1 to x2,y2, x3,y3 to x4,y4, etc */ |
460 | /*segments from x1,y1 to x2,y2, x3,y3 to x4,y4, etc */ |
362 | void obj_segments(objparm *pm) |
461 | void obj_segments(objparm *pm) |
363 | { |
462 | { |
364 | int i, n; |
463 | int i, n; |
365 | n=(pm->pcnt)/4; |
464 | n=(pm->pcnt)/4; |
366 | scale(pm->pd,pm->p,2*n); |
465 | scale(pm->pd,pm->p,2*n); |
367 | for(i=0;i<4*n;i+=4) |
466 | for(i=0;i<4*n;i+=4){ |
368 | gdImageLine(image,pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],pm->color[0]); |
467 | gdImageLine(image,pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],pm->color[0]); |
- | 468 | if (tikz_file){ |
|
- | 469 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 470 | tikz_options(pm->color[0],pm->fill),pm->p[i],flip(pm->p[i+1]),pm->p[i+2],flip(pm->p[i+3])); |
|
- | 471 | } |
|
- | 472 | } |
|
369 | } |
473 | } |
370 | /* segments */ |
474 | /* segments */ |
371 | void obj_dlines(objparm *pm) |
475 | void obj_dlines(objparm *pm) |
372 | { |
476 | { |
373 | int i, n; |
477 | int i, n; |
374 | n=(pm->pcnt)/2; |
478 | n=(pm->pcnt)/2; |
375 | scale(pm->pd,pm->p,n); |
479 | scale(pm->pd,pm->p,n); |
376 | for(i=2;i<2*n;i+=2) |
480 | for(i=2;i<2*n;i+=2) |
377 | myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
481 | myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
- | 482 | if (tikz_file){ |
|
- | 483 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
|
- | 484 | tikz_options(pm->color[0],pm->fill),pm->p[i-2],flip(pm->p[i-1]),pm->p[i],flip(pm->p[i+1])); |
|
- | 485 | } |
|
378 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
486 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
379 | } |
487 | } |
380 | 488 | ||
381 | /* points */ |
489 | /* points */ |
382 | void obj_points(objparm *pm) |
490 | void obj_points(objparm *pm) |
383 | { |
491 | { |
384 | int i, n; |
492 | int i, n; |
385 | n=(pm->pcnt)/2; |
493 | n=(pm->pcnt)/2; |
386 | scale(pm->pd,pm->p,n); |
494 | scale(pm->pd,pm->p,n); |
387 | for(i=0;i<2*n;i+=2) |
495 | for(i=0;i<2*n;i+=2){ |
388 | gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]); |
496 | gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]); |
- | 497 | if(tikz_file) fprintf(tikz_file, "\\draw\[%s] (%i, %i) circle (0pt);\n", |
|
- | 498 | tikz_options(pm->color[0],pm->fill),pm->p[i],flip(pm->p[i+1])); |
|
- | 499 | } |
|
389 | } |
500 | } |
390 | 501 | ||
391 | /* lattice. |
502 | /* lattice. |
392 | * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */ |
503 | * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */ |
393 | void obj_lattice(objparm *pm) |
504 | void obj_lattice(objparm *pm) |
394 | { |
505 | { |
395 | int n1,n2,i1,i2,xi1,yi1,xi2,yi2; |
506 | int n1,n2,i1,i2,xi1,yi1,xi2,yi2; |
396 | double xv1,xv2,yv1,yv2; |
507 | double xv1,xv2,yv1,yv2; |
397 | n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return; |
508 | n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return; |
398 | if(n1>256) n1=256; |
509 | if(n1>256) n1=256; |
399 | if(n2>256) n2=256; |
510 | if(n2>256) n2=256; |
400 | scale(pm->pd,pm->p,1); |
511 | scale(pm->pd,pm->p,1); |
401 | scale2(pm->pd[2],pm->pd[3],&xv1,&yv1); |
512 | scale2(pm->pd[2],pm->pd[3],&xv1,&yv1); |
402 | scale2(pm->pd[4],pm->pd[5],&xv2,&yv2); |
513 | scale2(pm->pd[4],pm->pd[5],&xv2,&yv2); |
403 | for(i1=0;i1<n1;i1++) { |
514 | for(i1=0;i1<n1;i1++) { |
404 | xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1]; |
515 | xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1]; |
405 | for(i2=0;i2<n2;i2++) { |
516 | for(i2=0;i2<n2;i2++) { |
406 | xi2=i2*xv2+xi1;yi2=i2*yv2+yi1; |
517 | xi2=i2*xv2+xi1;yi2=i2*yv2+yi1; |
407 | gdImageSetPixel(image,xi2,yi2,pm->color[0]); |
518 | gdImageSetPixel(image,xi2,yi2,pm->color[0]); |
- | 519 | if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) circle (0pt);\n", |
|
- | 520 | tikz_options(pm->color[0],0),xi2,flip(yi2)); |
|
408 | } |
521 | } |
409 | } |
522 | } |
410 | } |
523 | } |
411 | 524 | ||
412 | /* arc */ |
525 | /* arc */ |
Line 414... | Line 527... | ||
414 | { |
527 | { |
415 | scale(pm->pd,pm->p,1); |
528 | scale(pm->pd,pm->p,1); |
416 | pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale); |
529 | pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale); |
417 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], |
530 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], |
418 | pm->pd[4],pm->pd[5],pm->color[0]); |
531 | pm->pd[4],pm->pd[5],pm->color[0]); |
- | 532 | if(tikz_file) { |
|
- | 533 | fprintf(tikz_file, |
|
- | 534 | "\\draw\[%s, domain=%f:%f] plot ({%i+%f*cos(\\x)}, {%i+%f*sin(\\x)});\n", |
|
- | 535 | tikz_options(pm->color[0],pm->fill), |
|
- | 536 | pm->pd[4],pm->pd[5],pm->p[0],pm->p[2]*0.5,flip(pm->p[1]),pm->p[3]*(-0.5)); |
|
- | 537 | } |
|
- | 538 | /*FIXME echelle mauvaise*/ |
|
419 | if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1], |
539 | if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1], |
420 | 0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]); |
540 | 0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]); |
421 | } |
541 | } |
422 | 542 | ||
423 | /* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */ |
543 | /* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */ |
Line 430... | Line 550... | ||
430 | color_bounder); |
550 | color_bounder); |
431 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
551 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
432 | color_bounder,pm->color[0]); |
552 | color_bounder,pm->color[0]); |
433 | } |
553 | } |
434 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
554 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
- | 555 | if(tikz_file) fprintf(tikz_file,"\\draw\[%s] (%i,%i) ellipse (%f and %f);\n\n", |
|
- | 556 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2]/2.,pm->p[3]/2.); |
|
435 |
|
557 | if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]); |
436 | } |
558 | } |
437 | 559 | ||
438 | /* Circle */ |
560 | /* Circle */ |
439 | void obj_circle(objparm *pm) |
561 | void obj_circle(objparm *pm) |
440 | { |
562 | { |
Line 445... | Line 567... | ||
445 | color_bounder); |
567 | color_bounder); |
446 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
568 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
447 | color_bounder,pm->color[0]); |
569 | color_bounder,pm->color[0]); |
448 | } |
570 | } |
449 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
571 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
- | 572 | if(tikz_file) fprintf(tikz_file, "\\draw\[%s] (%i, %i) circle (%f);\n", |
|
- | 573 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2]/2.); |
|
450 | } |
574 | } |
451 | 575 | ||
452 | /* flood fill */ |
576 | /* flood fill */ |
453 | void obj_fill(objparm *pm) |
577 | void obj_fill(objparm *pm) |
454 | { |
578 | { |
Line 515... | Line 639... | ||
515 | gdImageLine(himg,0,ay,ax-1,2*ay-1,c); |
639 | gdImageLine(himg,0,ay,ax-1,2*ay-1,c); |
516 | } |
640 | } |
517 | break; |
641 | break; |
518 | } |
642 | } |
519 | case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break; |
643 | case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break; |
520 |
|
644 | case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break; |
521 | } |
645 | } |
522 | gdImageSetTile(image,himg); |
646 | gdImageSetTile(image,himg); |
523 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
647 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
524 | gdImageDestroy(himg); |
648 | gdImageDestroy(himg); |
525 | if(tiled) gdImageSetTile(image,tileimg); |
649 | if(tiled) gdImageSetTile(image,tileimg); |
Line 615... | Line 739... | ||
615 | /* point */ |
739 | /* point */ |
616 | void obj_point(objparm *pm) |
740 | void obj_point(objparm *pm) |
617 | { |
741 | { |
618 | scale(pm->pd,pm->p,1); |
742 | scale(pm->pd,pm->p,1); |
619 | gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]); |
743 | gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]); |
- | 744 | if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) circle (0pt);\n", |
|
- | 745 | tikz_options(pm->color[0],0),pm->p[0],flip(pm->p[1])); |
|
620 | } |
746 | } |
621 | 747 | ||
622 | /* copy an image file */ |
748 | /* copy an image file */ |
623 | void obj_copy(objparm *pm) |
749 | void obj_copy(objparm *pm) |
624 | { |
750 | { |
Line 746... | Line 872... | ||
746 | 872 | ||
747 | /* set linewidth */ |
873 | /* set linewidth */ |
748 | void obj_linewidth(objparm *pm) |
874 | void obj_linewidth(objparm *pm) |
749 | { |
875 | { |
750 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
876 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
751 |
|
877 | width=pm->pd[0]; |
- | 878 | if(tikz_file) fprintf(tikz_file,"\\pgfsetlinewidth{%f}\n",width*0.7); |
|
752 | } |
879 | } |
753 | 880 | ||
754 | /* set crosshairsize */ |
881 | /* set crosshairsize */ |
755 | void obj_crosshairsize(objparm *pm) |
882 | void obj_crosshairsize(objparm *pm) |
756 | { |
883 | { |