Subversion Repositories wimsdev

Rev

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