Subversion Repositories wimsdev

Rev

Rev 17599 | Rev 17610 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17599 Rev 17608
Line 17... Line 17...
17
 
17
 
18
#include <errno.h>
18
#include <errno.h>
19
#include "flydraw.h"
19
#include "flydraw.h"
20
 
20
 
21
/* Tikz things */
21
/* Tikz things */
-
 
22
 
-
 
23
static char *tikz_color (int the_color)
-
 
24
{
-
 
25
  static char buf[50];
-
 
26
  int r=gdImageRed(image,the_color);
-
 
27
  int g=gdImageGreen(image,the_color);
-
 
28
  int b=gdImageBlue(image,the_color);
-
 
29
  sprintf(buf, "{rgb,255:red,%i;green,%i;blue,%i}",r,g,b);
-
 
30
  return buf;
-
 
31
}
22
 
32
 
23
static char *tikz_options (int the_color, int the_fill)
33
static char *tikz_options (int the_color, int the_fill)
24
{
34
{
25
  static char buf[100];
35
  static char buf[100];
26
  if (the_color == gdBrushed)
36
  if (the_color == gdBrushed)
27
    the_color = tikz_brushColor;
37
    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);
38
  sprintf (buf, "draw=%s,cap=round",tikz_color(the_color));
32
  if (the_color != tikz_brushColor) strcat(buf, ",thin");
39
  if (the_color != tikz_brushColor) strcat(buf, ",thin");
33
  if (the_fill == -1) strcat(buf, ",dashed");
40
  if (the_fill == -1) strcat(buf, ",dashed");
34
  if (the_fill == 1)
41
  if (the_fill == 1)
35
    sprintf(buf+strlen(buf), ",fill={rgb,255:red,%i;green,%i;blue,%i}",r,g,b);
42
    sprintf(buf+strlen(buf), ",fill=%s", tikz_color(the_color));
36
  return buf;
43
  return buf;
37
}
44
}
38
 
45
 
39
#define flip(y) (sizey-(y))
46
#define flip(y) (sizey-(y))
40
 
47
 
Line 42... Line 49...
42
 
49
 
43
void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
50
void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
44
{
51
{
45
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
52
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
46
  gdImageFillToBorder(im,x,y,border,color);
53
  gdImageFillToBorder(im,x,y,border,color);
47
}
54
}
48
 
55
 
49
void patchgdImageFill (gdImagePtr im, int x, int y, int color)
56
void patchgdImageFill (gdImagePtr im, int x, int y, int color)
50
{
57
{
51
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
58
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
52
  gdImageFill(im,x,y,color);
59
  gdImageFill(im,x,y,color);
53
}
60
}
54
 
-
 
55
 
61
 
56
#define DASHPIXELS 8
62
#define DASHPIXELS 8
57
 
63
 
58
void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){
64
void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){
59
  /**
65
  /**
Line 271... Line 277...
271
  p=find_word_start(pm->str); *find_word_end(p)=0;
277
  p=find_word_start(pm->str); *find_word_end(p)=0;
272
  snprintf(tikzfilename,sizeof(tikzfilename),"%s",p);
278
  snprintf(tikzfilename,sizeof(tikzfilename),"%s",p);
273
  tikz_file=fopen(tikzfilename,"w");
279
  tikz_file=fopen(tikzfilename,"w");
274
  if(!tikz_file)
280
  if(!tikz_file)
275
    fly_error("tikz_nopen");
281
    fly_error("tikz_nopen");
276
  fprintf(tikz_file,"\\documentclass\[11pt]{article}\n\\usepackage{tikz}\n\\begin{document}\n\\begin{tikzpicture}\[scale=0.0254]\n");
282
  fprintf(tikz_file,"\\documentclass\[11pt,a5paper]{article}\n\\usepackage{tikz}\\usepackage{geometry}\\geometry{paperheight=320px,\npaperwidth=320px, \ntop=10px, \nleft=2px, \nbottom=2px, \nright=2px,\n}\\pagestyle{empty}\n\\begin{document}\n\\begin{tikzpicture}\[scale=0.0254]\n");
277
}
283
}
278
 
284
 
279
/* vertical line */
285
/* vertical line */
280
void obj_vline(objparm *pm)
286
void obj_vline(objparm *pm)
281
{
287
{
Line 581... Line 587...
581
 
587
 
582
void tikz_fill(int x, int y, int nx, int ny, int the_color, tfo opt)
588
void tikz_fill(int x, int y, int nx, int ny, int the_color, tfo opt)
583
{
589
{
584
  char *to = tikz_options(the_color,1);
590
  char *to = tikz_options(the_color,1);
585
  int numpix=sizex*sizey, top = 0, a, cy, lx, rx, seed, nt,ct=0, ct2=0;
591
  int numpix=sizex*sizey, top = 0, a, cy, lx, rx, seed, nt,ct=0, ct2=0;
586
  printf("Pixels:%d\n",numpix);
-
 
587
  int *stack = xmalloc(numpix*sizeof(int));
592
  int *stack = xmalloc(numpix*sizeof(int));
588
  int *stack2 = xmalloc(numpix*sizeof(int));
593
  int *stack2 = xmalloc(numpix*sizeof(int));
589
  if (nx==0) nx=1; if (ny==0) ny=1; nt = abs(nx*ny);
594
  if (nx==0) nx=1; if (ny==0) ny=1; nt = abs(nx*ny);
590
  seed = gdImageGetPixel(image,x,y);
595
  seed = gdImageGetPixel(image,x,y);
591
  char *check = xmalloc(numpix);
596
  char *check = xmalloc(numpix);
Line 605... Line 610...
605
      switch(opt)
610
      switch(opt)
606
        {
611
        {
607
        case grille: if(((x%nx)!=(nx/2))&&((y%ny)!=(ny/2))) continue; break;
612
        case grille: if(((x%nx)!=(nx/2))&&((y%ny)!=(ny/2))) continue; break;
608
        case points: if(x%nx!=nx/2||y%ny!=ny/2) continue; break;
613
        case points: if(x%nx!=nx/2||y%ny!=ny/2) continue; break;
609
        case hatch: if(abs((ny*x-nx*y)%nt)!=nt/2) continue; break;
614
        case hatch: if(abs((ny*x-nx*y)%nt)!=nt/2) continue; break;
610
        case dhatch: if((ny*x+nx*y)%nt!=nt/2 && abs((ny*x-nx*y)%nt)!=nt/2) continue; break;
615
        case dhatch: if((ny*x+nx*y)%nt!=nt/2 && abs((ny*x-nx*y)%nt)!=nt/2) continue; break;
611
        default: break;
616
        default: break;
612
        }
617
        }
613
      stack2[ct++]=a;
618
      stack2[ct++]=a;
614
    }
619
    }
615
  free(stack);
620
  free(stack);
Line 802... Line 807...
802
    if(p2 && *(p2+1)==0) {*p2=0; pe++;}
807
    if(p2 && *(p2+1)==0) {*p2=0; pe++;}
803
  }
808
  }
804
  if(pm->fill){
809
  if(pm->fill){
805
    gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
810
    gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
806
        pm->color[0]);
811
        pm->color[0]);
807
    if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) node[font=\\%s,rotate=90] {%s};\n",
812
    if(tikz_file) fprintf(tikz_file,"\\draw (%i,%i) node[font=\\%s,rotate=90,color=%s,anchor=north west,inner sep=0pt] {%s};\n",
808
      tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),fonttab[i].name,(unsigned char*) pe);
813
      pm->p[0],flip(pm->p[1]),fonttab[i].name,tikz_color(pm->color[0]),(unsigned char*) pe);
809
  }
814
  }
810
  else {
815
  else {
811
    gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
816
    gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
812
        pm->color[0]);
817
        pm->color[0]);
813
    if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) node[font=\\%s] {%s};\n",
818
    if(tikz_file) fprintf(tikz_file,"\\draw (%i,%i) node[font=\\%s,color=%s,anchor=north west,inner sep=0pt] {%s};\n",
814
      tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),fonttab[i].name,(unsigned char*) pe);
819
      pm->p[0],flip(pm->p[1]),fonttab[i].name,tikz_color(pm->color[0]),(unsigned char*) pe);
815
  }
820
  }
816
}
821
}
817
/*FIXME; giant does not exist in tikz and ... samething as huge */
822
/*FIXME; giant does not exist in tikz and ... samething as huge */
818
/* point */
823
/* point */
819
void obj_point(objparm *pm)
824
void obj_point(objparm *pm)