home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / fbuild.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  5.3 KB  |  218 lines

  1. /*----------------------------------------------------------------------*/
  2. /* This is the font builder for GLE, it runs completely independently    */
  3. /* and only understands the following commands.                */
  4. /*1     AMOVE x y                            */
  5. /*2     ALINE x y                             */
  6. /*3     BEZIER x y x y x y                        */
  7. /*4     CLOSEPATH                            */
  8. /*5     FILL                                */
  9. /*6     STROKE                                */
  10. /*8     SET LWIDTH w                            */
  11. /*7     FILLWHITE   (no newpath )                    */
  12. /*15    DFONT ENDCHAR                             */
  13. /*     DFONT CHAR=nn  or CHAR="A"                     */
  14. /*     DFONT DESIGN=v                             */
  15. /*----------------------------------------------------------------------*/
  16. #define GPRINTDEF
  17. #include "all.h"
  18. #include <math.h>
  19.  
  20. gprint(char *s)
  21. {
  22.     printf("%s",s);
  23. }
  24.  
  25. #define true (!false)
  26. #define false 0
  27. #define gprint printf
  28. int debugit=false;
  29. #define dbg if (debugit==true)
  30. double design,gx,gy;
  31. int thischar;
  32. char inbuff[200],zzz[200];
  33. char source[20];
  34. char *tk[500];
  35. char tkbuff[500];
  36. unsigned char *outbuff;
  37. int outpnt[255];
  38. int nbig,nsmall;
  39. int cx,cy;
  40. int nout;
  41. int sendp(int p);
  42. int sendx(double x);
  43. int sendxy(double x, double y);
  44. int sendxyabs(double x, double y);
  45. int sendi(int ix);
  46. int do_line(void);
  47.  
  48. main(int argc, char **argv)
  49. {
  50. int ntok,f;
  51. static char ostr[90];
  52. double oval;
  53. int plen,cp,otyp,i,j,endp;
  54. int ngtxt=0;
  55. FILE *fptr;
  56. FILE *fout;
  57. char *s;
  58. char space_str[] = " ";
  59. char fname[80];
  60. char outfile[80];
  61.  
  62.     design = 1;
  63.     oval = pow(2.2,3.3);
  64.     token_equal();
  65.     strcpy(fname,*(++argv));
  66.         s = strchr(fname,'.');
  67.         if (s!=NULL) *s = 0;
  68.     strcpy(outfile,fname);
  69.     if (strchr(fname,':')!=NULL) strcpy(outfile,strchr(fname,':')+1);
  70.     strcat(outfile,".fve");
  71.     strcat(fname,".gle");
  72.     printf("Processing {%s}, creating {%s} \n",fname,outfile);
  73.     outbuff = malloc(64000);
  74. #ifdef unix
  75.     fout = fopen(outfile,"w");
  76. #else
  77.     fout = fopen(outfile,"wb");
  78. #endif
  79.     if (fout==NULL) perror("Could not open output file \n");
  80.     fptr = fopen(fname,"r");
  81.     if (fptr==NULL) perror("Could not open input file \n");
  82.     for (i=0;i<500;i++) tk[i] = space_str;
  83.     for (fgets(inbuff,200,fptr);!feof(fptr);fgets(inbuff,200,fptr)) {
  84.         i = strlen(inbuff);
  85. /*         printf("Source | %s",inbuff); */
  86.         token(inbuff,(TOKENS) tk,&ntok,tkbuff);
  87.         do_line();
  88.     }
  89.     printf("\n nbig %d nsmall %d nbytes %d\n\n",nbig,nsmall,nout);
  90.  
  91. /*    for (i=0;i<100;i++) if (outpnt[i]>0) dbg printf("index %d %d ",i,outpnt[i]);*/
  92.     dbg printf("\n\n");
  93.     dbg printf("\n nbig %d nsmall %d nbytes %d\n\n",nbig,nsmall,nout);
  94.  
  95.     for (i=0;i<100;i++) dbg printf("%d ",*(outbuff+i));
  96.     dbg printf("\n nbig %d nsmall %d nbytes %d\n\n",nbig,nsmall,nout);
  97.  
  98.  
  99.     outpnt[0] = nout;
  100.     fwrite(outpnt,sizeof(i),256,fout);
  101.     fwrite(outbuff,1,nout,fout);
  102.     fclose(fout); fclose(fptr);
  103. return 0;
  104. }
  105. /*--------------------------------------------------------------------------*/
  106. #define skipspace if (*tk[ct]==' ') ct++;
  107. do_line()
  108. {
  109.     int ct;
  110.  
  111.     ct = 1;
  112.     if (strcmp(tk[ct],"ALINE")==0)     {
  113.         sendp(2);
  114.         sendxy(gx=atof(tk[2]),gy=atof(tk[3]));
  115.     } else if (strcmp(tk[ct],"RLINE")==0)     {
  116.         sendp(2);
  117.         gx = gx + atof(tk[2]);
  118.         gy = gy + atof(tk[3]);
  119.         sendxy(gx,gy);
  120.     } else if (strcmp(tk[ct],"RMOVE")==0)     {
  121.         sendp(1);
  122.         gx = gx + atof(tk[2]);
  123.         gy = gy + atof(tk[3]);
  124.         sendxyabs(gx,gy);
  125.     } else if (strcmp(tk[ct],"BEZIER")==0) {
  126.         sendp(3);
  127.         sendxy(atof(tk[2]),atof(tk[3]));
  128.         sendxy(atof(tk[4]),atof(tk[5]));
  129.         sendxy(gx=atof(tk[6]),gy=atof(tk[7]));
  130.     } else if (strcmp(tk[ct],"AMOVE")==0) {
  131.         sendp(1);
  132.         sendxyabs(gx=atof(tk[2]),gy=atof(tk[3]));
  133.     } else if (strcmp(tk[ct],"CLOSEPATH")==0)     sendp(4);
  134.     else if (strcmp(tk[ct],"FILL")==0)     sendp(5);
  135.     else if (strcmp(tk[ct],"FILLWHITE")==0) sendp(7);
  136.     else if (strcmp(tk[ct],"STROKE")==0)    sendp(6);
  137.     else if (strcmp(tk[ct],"\n")==0)    ;
  138.     else if (strcmp(tk[ct],"FBY")==0)    ;
  139.     else if (strcmp(tk[ct],"NEWPATH")==0)    ;
  140.     else if (strcmp(tk[ct],"\n")==0)    ;
  141.     else if (strcmp(tk[ct],"!")==0)        ;
  142.     else if (strcmp(tk[ct],"SET")==0)    {
  143.         if (strcmp(tk[2],"LWIDTH")==0) {
  144.             sendp(8); sendx(atof(tk[3]));
  145.         }
  146.     }
  147.     else if (strcmp(tk[ct],"DFONT")==0) {
  148.         ct+=1;
  149.         if (strcmp(tk[ct],"DESIGN")==0)     {
  150.             ct++;ct++;
  151.             design = atof(tk[ct]);
  152.             printf("Design %g \n",design);
  153.         } else if (strcmp(tk[ct],"CHAR")==0) {
  154.             ct++;ct++;
  155.             if (*tk[ct]=='"') thischar = *(tk[ct]+1);
  156.             else thischar = atoi(tk[ct]);
  157.             outpnt[thischar] = nout;
  158.             dbg printf("This char %d {%s} \n",thischar,tk[ct]);
  159.         } else if (strcmp(tk[ct],"ENDCHAR")==0) sendp(15) ;
  160.         else if (strcmp(tk[ct],"WID")==0) ;
  161.         else if (strcmp(tk[ct],"FBY")==0) ;
  162.         else dbg printf("DFONT unknown command {%s} \n",tk[ct]);
  163.     }
  164.     else dbg printf("Unrecoginzed FONT BUILD command {%s} \n",tk[ct]);
  165.     ct++;
  166. }
  167. sendp(int p)
  168. {
  169.     *(outbuff+nout++) = p;
  170. }
  171. int scl(double x);
  172. int scl(double x)
  173. {
  174.      return 1000*x/design;
  175. }
  176. sendxyabs(double x, double y)
  177. {
  178.     cx = scl(x);
  179.     cy = scl(y);
  180.     sendi(cx); sendi(cy);
  181. /*     printf("Move cx cy %d %d %g %g \n",cx,cy,x,y); */
  182. }
  183. sendxy(double x, double y)
  184. {
  185. /*     printf("rove cx cy %d %d %d %d %g %g \n",cx,cy,scl(x),scl(y),x,y); */
  186.     sendi(scl(x)-cx); sendi(scl(y)-cy);
  187.     cx = scl(x);
  188.     cy = scl(y);
  189. }
  190. sendi(int ix)
  191. {
  192.     union jjj {char a[2]; short b;} both;
  193. /*    if (thischar=='i') printf("ix %d \n",ix);
  194. */
  195.     if (ix>120 || ix <-120) {
  196.         both.b = ix;
  197.         *(outbuff+nout++) = 127;
  198.         *(outbuff+nout++) = both.a[0];
  199.         *(outbuff+nout++) = both.a[1];
  200.         nbig++;
  201.     } else { *(outbuff+nout++) = ix;     nsmall++; }
  202. }
  203. sendx(double x)
  204. {
  205.     sendi(scl(x));
  206. }
  207.  
  208. #ifdef unix
  209. #define VAXC 1
  210. #endif
  211. #ifdef VAXC
  212. char *strupr(char *s)
  213. {
  214.     while (*s!=0) {*s = toupper(*s); s++;}
  215.     return s;
  216. }
  217. #endif
  218.