Subversion Repositories wimsdev

Rev

Rev 17578 | Rev 17585 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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