Subversion Repositories wimsdev

Rev

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