Subversion Repositories wimsdev

Rev

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