home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / makefmt.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  6KB  |  246 lines

  1. /*    parseFMT.C    */
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <stdio.h>
  7. #include "parseafm.h"
  8. int debugit=0;
  9. #define dbg if (debugit)
  10. int chrcat(char *s,char c);
  11. int str_ascii(char *s) ;
  12. int writefmt(void);
  13. /*-----------------------------------------------------------------------*/
  14. /* Globals */
  15. FontInfo *fi;
  16. FLAGS myflags = P_ALL;
  17.  
  18. /*-----------------------------------------------------------------------*/
  19.  
  20. char fmtname[80];
  21. main( int argc, char **argv)
  22. {
  23.   char *s;
  24.     char filename[80];
  25.         FILE *fp;
  26.  
  27.     myflags = P_ALL;
  28.  
  29.     strcpy(filename,*(++argv));
  30.     s = strchr(filename,'.');
  31.     if (s!=NULL) *s=0;
  32.     strcpy(fmtname,filename);
  33.     if (strchr(filename,':')!=NULL) strcpy(fmtname,strchr(filename,':')+1);
  34.     strcat(fmtname,".fmt");
  35.     strcat(filename,".afm");
  36.     printf("Processing {%s}, creating {%s} \n",filename,fmtname);
  37.  
  38.     if (!filename[0]) {
  39.       printf ("*** ERROR: can't open. filename is missing.\n",filename );
  40.       return 0;
  41.         }
  42.     printf("Reading ADOBE font metric file {%s} \n ",filename);
  43.     fp = fopen(filename, "r" );
  44.     if (fp == NULL) {
  45.         printf ("*** ERROR: can't find: %s\n", filename );
  46.         perror("");
  47.         exit(1);
  48.     }
  49.  
  50.     switch (parseFile(fp, &fi, myflags)) {
  51.      case parseError:
  52.                printf("*** ERROR: problem in parsing the AFM File.\n");
  53.         exit(1);
  54.         case ok:
  55.             fclose(fp);
  56.             writefmt();
  57.             break;
  58.         case earlyEOF:
  59.             printf("The AFM File ended prematurely.\n");
  60.         exit(1);
  61.             break;
  62.         default:
  63.             break;
  64.     }
  65.     printf("Successful completioin \n");
  66.   exit(0);
  67. }
  68.  
  69. /*-----------------------------------------------------------------------*/
  70. struct xypair {float x,y;} ;
  71. struct allchar {char lig[4],lrep[4],kern[35]; struct xypair kxy[35];
  72. } *ap[256];
  73. /* *ap[256];  */
  74. struct char_data { float wx,wy,x1,y1,x2,y2; } cc ;
  75. struct char_datax { char *kern, *lig, *krep, *lrep; };
  76. struct font_table {
  77.     char *name;
  78.     char *full_name;
  79.     char *file_metric;
  80.     char *file_vector;
  81.     char *file_bitmap;
  82.     struct char_data ( *chr)[256];
  83.     int encoding;        /* 1 = postscript text , 2=postscrip symbol, */
  84.                 /* 3=TEX text, 4=TEX symbol, 5=TEX extensions */
  85.     float space,space_stretch,space_shrink;
  86.     float scale,slant,uposition,uthickness;
  87.     float fx1,fy1,fx2,fy2,caphei,xhei,descender,ascender;
  88. } fnt;
  89. FILE *fmt;
  90. int c1,c2,ll,lk,n;
  91.  
  92. writefmt()
  93. {
  94.     int i = 0,zz;
  95.     double fff;
  96.     char *sss;
  97.     int dec,sgn;
  98.         CharMetricInfo *temp = fi->cmi;
  99.         Ligature *node = temp->ligs;
  100.     PairKernData *pkd = fi->pkd;
  101.     float fval,scl;
  102.     fff = 2;
  103.     sss = (char *) ecvt(fff,2,&dec,&sgn);
  104. #ifdef unix
  105.     fmt = fopen(fmtname,"w");
  106. #else
  107.     fmt = fopen(fmtname,"wb");
  108. #endif
  109.     if (fmt == NULL) {
  110.         perror ("Cant open output file ");
  111.         exit(1);
  112.     }
  113.     fnt.encoding = 1;    /* AdobeStandardEncoding */
  114.         printf("The font name is %s\n", fi->gfi->fontName);
  115.     if (0==strcmp(fi->gfi->encodingScheme,"TEXENCODING")) {
  116.         fnt.encoding = 3;    /* AdobeStandardEncoding */
  117.     }
  118.     if (0==strcmp(fi->gfi->encodingScheme,"AdobeStandardEncoding")) {
  119.         fnt.encoding = 1;    /* AdobeStandardEncoding */
  120.     }
  121.     if (0==strcmp(fi->gfi->encodingScheme,"GLEMARK")) {
  122.         fnt.encoding = 5;
  123.     }
  124.     printf("Encoding scheme {%s} %d \n"
  125.         ,fi->gfi->encodingScheme,fnt.encoding);
  126.     fnt.scale = 1000;
  127.     scl = .001;
  128.     fnt.slant = fi->gfi->italicAngle;
  129.     fnt.uposition = fi->gfi->underlinePosition*scl;
  130.     fnt.uthickness =  fi->gfi->underlineThickness*scl;
  131.     fnt.fx1 = fi->gfi->fontBBox.llx*scl;
  132.     fnt.fy1 = fi->gfi->fontBBox.lly*scl;
  133.     fnt.fx2 = fi->gfi->fontBBox.urx*scl;
  134.     fnt.fy2 = fi->gfi->fontBBox.ury*scl;
  135.     fnt.caphei = fi->gfi->capHeight*scl;
  136.     fnt.xhei = fi->gfi->xHeight*scl;
  137.     fnt.descender = fi->gfi->descender*scl;
  138.     fnt.ascender = fi->gfi->ascender*scl;
  139.  
  140.     temp = fi->cmi;
  141.     zz = 1;
  142.     for (temp=fi->cmi;zz < fi->numOfChars; temp++) {
  143.         zz++;
  144.         if (temp->code==32) {
  145.             fnt.space = temp->wx*scl;
  146.             fnt.space_stretch = fnt.space*.5;
  147.             fnt.space_shrink = fnt.space*.3;
  148.             break;
  149.         }
  150.     }
  151.  
  152.     temp = fi->cmi;
  153.     fwrite(&fnt.encoding,4,16,fmt);
  154.  
  155.     zz = 0;
  156.     for (i = 0; i < 256 ; ++i) {
  157.       if (i<temp->code || zz >= fi->numOfChars ) {
  158.         cc.wx = 0;
  159.         cc.wy = 0;
  160.         cc.x1 = 0;
  161.         cc.x2 = 0;
  162.         cc.y1 = 0;
  163.         cc.y2 = 0;
  164.       } else {
  165.         cc.wx = temp->wx*scl;
  166.         cc.wy = temp->wy*scl;
  167.         cc.x1 = temp->charBBox.llx*scl;
  168.         cc.x2 = temp->charBBox.urx*scl;
  169.         cc.y1 = temp->charBBox.lly*scl;
  170.         cc.y2 = temp->charBBox.ury*scl;
  171.           for (node=temp->ligs;node !=NULL; node = node -> next) {
  172.         if (ap[i]==NULL) ap[i] = calloc(1,sizeof(*ap[i]));
  173.         if (ap[i]==NULL) printf("memory allocation error \n");
  174.             chrcat(ap[i]->lig,str_ascii(node->succ));
  175.             chrcat(ap[i]->lrep,str_ascii(node->lig));
  176.           }
  177.         zz++;
  178.               temp++;
  179.       }
  180.       fwrite(&cc,sizeof(cc),1,fmt);
  181.         } /* for */
  182.     dbg printf("got char %d %d\n",i,zz);
  183.  
  184.     dbg printf("Here comes the pair kerning data ...\n");
  185.     if (fi->numOfPairs != 0) {
  186.       for (i = 0; i < fi->numOfPairs; ++i) {
  187.         c1 = str_ascii(pkd[i].name1);
  188.         c2 = str_ascii(pkd[i].name2);
  189.         if (ap[c1]==NULL) ap[c1] = calloc(1,sizeof(*ap[c1]));
  190.         if (ap[c1]==NULL) printf("memory allocation error \n");
  191.         chrcat(ap[c1]->kern,c2);
  192.         n = strlen(ap[c1]->kern)-1;
  193.         ap[c1]->kxy[n].x = pkd[i].xamt*scl;
  194.         ap[c1]->kxy[n].y = pkd[i].yamt*scl;
  195.       }
  196.     }
  197.  
  198.     for (i=1;i<256;i++) {
  199.         if (ap[i]==NULL) continue;
  200.         ll = strlen(ap[i]->lig);
  201.         lk = strlen(ap[i]->kern);
  202.         if (ll>0 || lk>0) {
  203.             fputc(i,fmt);
  204.             fputc(ll,fmt);
  205.             fwrite(ap[i]->lig,1,ll,fmt);
  206.             fwrite(ap[i]->lrep,1,ll,fmt);
  207.             fputc(lk,fmt);
  208.             fwrite(ap[i]->kern,1,lk,fmt);
  209.             fwrite(ap[i]->kxy,8,lk,fmt);
  210.         }
  211.     }
  212.     fputc(0,fmt);
  213.     fclose(fmt);
  214. }
  215. chrcat(char *s,char c)
  216. {
  217.     int i;
  218.     i = strlen(s);
  219.     *(s+i) = c;
  220. }
  221. int str_ascii(char *s)
  222. {
  223.     int i;
  224.     CharMetricInfo *temp = fi->cmi;
  225.  
  226.     for (i=0;i<fi->numOfChars; ++i) {
  227.         if (strcmp(temp->name,s)==0) {
  228.             return temp->code;
  229.         }
  230.               temp++;
  231.     }
  232.     printf("Failed to find char, fatal error ********* {%s} \n",s);
  233. }
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.