Subversion Repositories wimsdev

Rev

Rev 18133 | 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. /* This file is a temporary patch to tex eps files with extra borders.
  19.  * It cuts the borders in the resulting gif file, so that the font
  20.  * fits tightly in the cadre. libgd is required.
  21.  */
  22.  
  23. #include "flydraw.h"
  24.  
  25. FILE *tikz_file;
  26.  
  27. char imagefilename[1024];
  28. char vimgfilename[1024];
  29. char tikzfilename[1024];
  30. int sizex, sizey, saved;
  31. gdImagePtr image=NULL, brushimg=NULL, tileimg=NULL, wimg=NULL;
  32. int brushed=0, tiled=0, styled=0, width=1, savew=1, wcolor=-1, width2=4;
  33. int dashed,filled,noreset;
  34. int color_white, color_black, color_bounder, color_frame;
  35. int linecnt=-100000;
  36. int tranged=0;
  37. double xscale=1, yscale=1, xstart=0, ystart=0;
  38. double tstart=0, tend=1, tstep=100, plotjump=200;
  39. double animstep=0;
  40. int transform=0;  /* transformation indicator */
  41. double transx=0, transy=0; /* translation vector */
  42. int lstep=4;
  43. ev_variable vartab[MAX_VARS];
  44. char varnamebuf[MAX_VARNAMEBUF], *varnameptr=varnamebuf;
  45. int varcnt;
  46. int vimg=0; /* 0: no vector image output.
  47.              * 1: DXF vector output. */
  48. int vimg_enable=0; /* 0: disable. 1: enable. */
  49. int vimg_ready=0;
  50. FILE *vimgf=NULL;
  51. double scale_buf[MAX_PARMS];
  52. /* les matrices suivantes sont initialisees par la commande setmatrix nummatrix,a11,a12,a21,a22
  53.  * elles sont remises a l'unite par resetmatrix nummatrix
  54.  * la matrice fixant le systeme de coordonnees "mathematiques" dans l'image
  55.  */
  56. matrice matrices_pavage[JC_NB_MATRICES+1];
  57. vecteur vecteurs_pavage[JC_NB_MATRICES+1];
  58.  
  59. /* les coordonnees du parallelograme de pavage = coordonnees "mathematiques"
  60.  * du parallelogramme contenant l'image a recopier on place ces coordonnees
  61.  * avec setparallelogram xs,ys,xu,yu,xv,yu
  62.  * xs,ys=coordonnees math du point 0,0,
  63.  * xu,yu coordonnees math de l'horizontale
  64.  * xv,yv coordonnees math de la verticale
  65.  * ces coordonnees sont remises a leur valeur par defaut par resetparallelogram
  66.  */
  67. double parallogram_fonda[]={0,0,100,0,0,100};
  68.  
  69. /* Write the image */
  70. void output(void)
  71. {
  72.   FILE *out;
  73.  
  74.   if(!image) return;
  75.   if(imagefilename[0]) {
  76.     out=fopen(imagefilename,"wb");
  77.     if(out!=NULL) {gdImageGif(image, out); fclose(out); }
  78.   }
  79.   else gdImageGif(image, stdout);
  80.   saved=1;
  81. }
  82.  
  83. /* substitute variable names by their environment strings
  84.  * The buffer pointed to by p must have enough space
  85.  * (defined by MAX_LINELEN).
  86.  */
  87. char *substit(char *p)
  88. {
  89.   char *pp, *pe;
  90.   char namebuf[MAX_NAMELEN+1];
  91.   int i, l;
  92.  
  93.   pe=strchr(p,'"'); if(pe!=NULL) l=pe-p; else l=MAX_LINELEN;
  94.   for(pp=find_name_start(p); *pp!=0 && pp-p<l;
  95.     pp=find_name_start(pe)) {
  96.     pe=find_name_end(pp);
  97.     if((pp>p && !isspace(*(pp-1)) && *(pp-1)!=',') ||
  98.        (*pe!=0 && !isspace(*pe) && *pe!=',')) continue;
  99.     memmove(namebuf,pp,pe-pp); namebuf[pe-pp]=0;
  100.     i=search_list(nametab,nametab_no,sizeof(nametab[0]),namebuf);
  101.     if(i<0) continue;
  102.     if(nametab[i].type==t_prep && preptab[nametab[i].serial].typ==p_font)
  103.       break;
  104.     if(nametab[i].type==t_color)
  105.       string_modify(p,pp,pe,colortab[nametab[i].serial].def);
  106.   }
  107.   return p;
  108. }
  109.  
  110. void fly_process(void)
  111. {
  112.   char buf[MAX_LINELEN+1];
  113.   int c;
  114.   do {
  115.     c=ggetline(buf); obj_main(buf);
  116.   }
  117.   while(c!=EOF);
  118. }
  119.  
  120. int verify_tables(void) {
  121.   return evaltab_verify();
  122. }
  123.  
  124. int main(int argc, char *argv[])
  125. {
  126.   int i; for (i = 0; i <= JC_NB_MATRICES; i++)
  127.     matrices_pavage [i][0] = matrices_pavage[i][3] = 1;
  128.   substitute=substit;
  129.   ev_varcnt=&varcnt; ev_var=vartab;
  130.   if(argc==2 && strcasecmp(argv[1],"table")==0) {
  131.     if(verify_tables()) {
  132.       printf("Table disorder.\n"); return 1;
  133.     }
  134.     printf("Table orders OK.\n"); return 0;
  135.   }
  136.   vartab[0].name="animstep"; vartab[0].value=0;
  137.   varcnt=1;
  138.   if(argc>1) snprintf(imagefilename,sizeof(imagefilename),"%s",argv[1]);
  139.   else imagefilename[0]=0;
  140.   fly_process();
  141.   if(tikz_file){
  142.     fprintf(tikz_file,"\\end{tikzpicture}\n");
  143.     fclose(tikz_file);
  144.   }
  145.   else
  146.     if(!saved || imagefilename[0]!=0) output();
  147.   if(image) gdImageDestroy(image);
  148.   if(vimg_ready) vimg_close();
  149.   return 0;
  150. }
  151.