home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 12 Font / 12-Font.zip / PFMAFM.ZIP / PFM2AFM.C < prev    next >
Text File  |  1991-09-22  |  11KB  |  408 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*                               P F M 2 A F M                               */
  4. /*                                                                           */
  5. /*****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #include "pfm2afm.h"
  11.  
  12. extern const char *charname[];
  13.  
  14. void main (int argc, char *argv[])
  15. {
  16.    PFMHEADER                 pfmhead;
  17.    PFMEXTENSION              pfmextension;
  18.    EXTTEXTMETRIC             ext_text_metric;
  19.    char                      driver[255];
  20.    char                      wfont_name[255];
  21.    char                      psfont_name[255];
  22.    FILE                      *fp;
  23.    WORD                      *ext_tab;
  24.    int                       ext_entries;
  25.    KERNPAIR                  *kernpairs;
  26.    FILE                      *ofp;
  27.    int                       i;
  28.  
  29.    if (argc != 2)
  30.    {
  31.       printf ("Error dude\n");
  32.       exit (EXIT_FAILURE);
  33.    }
  34.  
  35.    if (NULL == (fp = fopen (argv[1], "rb")))
  36.    {
  37.       perror (argv[1]);
  38.       exit (EXIT_FAILURE);
  39.    }
  40.  
  41.    ofp                       =  stdout;
  42.  
  43.    fread (&pfmhead, sizeof (pfmhead), 1, fp);
  44.    fread (&pfmextension, sizeof (pfmextension), 1, fp);
  45.  
  46.    fseek (fp, pfmhead.dfDevice, SEEK_SET);
  47.    fread (driver, 50, 1, fp);
  48.  
  49.    fseek (fp, pfmhead.dfFace, SEEK_SET);
  50.    fread (wfont_name, 50, 1, fp);
  51.  
  52.    fseek (fp, pfmextension.dfExtMetricsOffset, SEEK_SET);
  53.    fread (&ext_text_metric, sizeof (ext_text_metric), 1, fp);
  54.  
  55.    fseek (fp, pfmextension.dfDriverInfo, SEEK_SET);
  56.    fread (psfont_name, 50, 1, fp);
  57.  
  58.    ext_entries    =  pfmhead.dfLastChar - pfmhead.dfFirstChar + 1;
  59.    ext_tab        =  malloc (ext_entries * sizeof (WORD));
  60.    if (ext_tab == NULL)
  61.    {
  62.       perror ("malloc");
  63.       exit (EXIT_FAILURE);
  64.    }
  65.    fseek (fp, pfmextension.dfExtentTable, SEEK_SET);
  66.    fread (ext_tab, sizeof (WORD), ext_entries, fp);
  67.  
  68.    fprintf (ofp, "StartFontMetrics 2.0\n");
  69.    fprintf (ofp, "Comment Generated by pfm2afm Public Domain by Kevin Nickerson 1991\n");
  70.    fprintf (ofp, "FontName %s\n", psfont_name);
  71.    fprintf (ofp, "FullName %s\n", psfont_name);
  72.    fprintf (ofp, "FamilyName %s\n", psfont_name);
  73.    fprintf (ofp, "Weight %s\n", "standard");               /*hm*/
  74.    fprintf (ofp, "Notice This frees you from Windoze\n");
  75.    fprintf (ofp, "ItalicAngle 0.0\n");                     /*hm*/
  76.    fprintf (ofp, "IsFixedPitch false\n");
  77.    fprintf (ofp, "UnderlinePosition -%d\n", ext_text_metric.etmUnderlineOffset);
  78.    fprintf (ofp, "UnderlineThickness %d\n", ext_text_metric.etmUnderlineWidth);
  79.    fprintf (ofp, "Version 001.000\n");                     /*hm*/
  80.    fprintf (ofp, "EncodingScheme AdobeStandardEncoding\n");
  81.    fprintf (ofp, "FontBBox %d %d %d %d\n",
  82.                   0,  ext_text_metric.etmLowerCaseDescent,
  83.                   pfmhead.dfMaxWidth,  ext_text_metric.etmCapHeight );
  84.    fprintf (ofp, "CapHeight %d\n", ext_text_metric.etmCapHeight );
  85.    fprintf (ofp, "XHeight %d\n", ext_text_metric.XHeight);
  86.    fprintf (ofp, "Descender %d\n", ext_text_metric.etmLowerCaseDescent);
  87.    fprintf (ofp, "Ascender %d\n", ext_text_metric.etmCapHeight);
  88.  
  89.  
  90.  
  91.    fprintf (ofp, "StartCharMetrics %d\n", ext_entries);
  92.    for (i = 0; i < ext_entries; i++)
  93.    {
  94.       fprintf (ofp, "C %d ; WX %d ; N %s ; B 0 0 1000 1000 ;\n",
  95.                     i + pfmhead.dfFirstChar,
  96.                     ext_tab[i],
  97.                     charname[i + pfmhead.dfFirstChar]);
  98.    }
  99.  
  100.    fprintf (ofp, "EndCharMetrics\n");
  101.    fprintf (ofp, "StartKernData\n");
  102.    fprintf (ofp, "StartKernPairs %d\n", ext_text_metric.etmKernPairs);
  103.    kernpairs = malloc (ext_text_metric.etmKernPairs * sizeof (KERNPAIR));
  104.    if (kernpairs == NULL)
  105.    {
  106.       perror ("malloc");
  107.       exit (EXIT_FAILURE);
  108.    }
  109.    fseek (fp, pfmextension.dfPairKernTable+2, SEEK_SET);
  110.    fread (kernpairs, sizeof (KERNPAIR), ext_text_metric.etmKernPairs, fp);
  111.    for (i = 0; i < (int) ext_text_metric.etmKernPairs; i++)
  112.    {
  113.       fprintf (ofp, "KPX %s %s %d\n", charname[kernpairs[i].kpPair.each[0]],
  114.                                       charname[kernpairs[i].kpPair.each[1]],
  115.                                       kernpairs[i].kpKernAmount);
  116.    }
  117.    
  118.  
  119.  
  120.    fprintf (ofp, "EndKernPairs\n");
  121.    fprintf (ofp, "EndKernData\n");
  122.    fprintf (ofp, "StartComposites 0\n");
  123.    fprintf (ofp, "EndComposites\n");
  124.    fprintf (ofp, "EndFontMetrics\n");
  125.  
  126.  
  127.    fclose (fp);
  128.    exit (EXIT_SUCCESS);
  129. }
  130.  
  131. /* Quite frankly, this has me puzzled.  The first 127 seem constant,
  132.    but the names of the characters past there seem to change with the
  133.    font.  Some of the fonts give the names in the ascii part.  If so,
  134.    you should use them.  Otherwise, these seem (after looking at a number
  135.    of fonts) to be the correct names. */   
  136.  
  137. static const char *charname[] = 
  138. {
  139. "null",   /* 0*/
  140. "^A",     /* 1*/
  141. "^B",     /* 2*/
  142. "^C",     /* 3*/
  143. "^D",     /* 4*/
  144. "^E",     /* 5*/
  145. "^F",     /* 6*/
  146. "^G",     /* 7*/
  147. "^H",     /* 8*/
  148. "^I",     /* 9*/
  149. "^J",     /*10*/
  150. "^K",     /*11*/
  151. "^L",     /*12*/
  152. "^M",     /*13*/
  153. "^N",     /*14*/
  154. "^O",     /*15*/
  155. "^P",     /*16*/
  156. "^Q",     /*17*/
  157. "^R",     /*18*/
  158. "^S",     /*19*/
  159. "^T",     /*20*/
  160. "^U",     /*21*/
  161. "^V",     /*22*/
  162. "^W",     /*23*/
  163. "^X",     /*24*/
  164. "^Y",     /*25*/
  165. "^Z",     /*26*/
  166. "escape", /*27*/
  167. "28",           /*28*/
  168. "29",           /*29*/
  169. "30",           /*30*/
  170. "31",           /*31*/
  171. "space",        /*32*/
  172. "exclam",       /*33*/
  173. "quotedbl",     /*34*/
  174. "numbersign",   /*35*/
  175. "dollar",       /*36*/ 
  176. "percent",      /*37*/ 
  177. "ampersand",    /*38*/ 
  178. "quoteright",   /*39*/ 
  179. "parenleft",    /*40*/ 
  180. "parenright",   /*41*/ 
  181. "asterisk",     /*42*/
  182. "plus",         /*43*/
  183. "comma",        /*44*/
  184. "hyphen",       /*45*/
  185. "period",       /*46*/
  186. "slash",        /*47*/
  187. "zero",         /*48*/
  188. "one",          /*49*/
  189. "two",          /*50*/
  190. "three",        /*51*/
  191. "four",         /*52*/
  192. "five",         /*53*/
  193. "six",          /*54*/
  194. "seven",        /*55*/
  195. "eight",        /*56*/
  196. "nine",         /*57*/
  197. "colon",        /*58*/ 
  198. "semicolon",    /*59*/ 
  199. "less",         /*60*/
  200. "equal",        /*61*/
  201. "greater",      /*62*/
  202. "question",     /*63*/
  203. "at",           /*64*/
  204. "A",   /*65*/
  205. "B",   /*66*/
  206. "C",   /*67*/
  207. "D",   /*68*/
  208. "E",   /*69*/
  209. "F",   /*70*/
  210. "G",   /*71*/
  211. "H",   /*72*/
  212. "I",   /*73*/
  213. "J",   /*74*/
  214. "K",   /*75*/
  215. "L",   /*76*/
  216. "M",   /*77*/
  217. "N",   /*78*/
  218. "O",   /*79*/
  219. "P",   /*80*/
  220. "Q",   /*81*/
  221. "R",   /*82*/
  222. "S",   /*83*/
  223. "T",   /*84*/
  224. "U",   /*85*/
  225. "V",   /*86*/
  226. "W",   /*87*/
  227. "X",   /*88*/
  228. "Y",   /*89*/
  229. "Z",   /*90*/
  230. "bracketleft",  /*91*/ 
  231. "backslash",    /*92*/ 
  232. "bracketright", /*93*/ 
  233. "asciicircum",  /*94*/ 
  234. "underscore",   /*95*/ 
  235. "grave",        /*96*/ 
  236. "a",  /* 97*/
  237. "b",  /* 98*/
  238. "c",  /* 99*/
  239. "d",  /*100*/
  240. "e",  /*101*/
  241. "f",  /*102*/
  242. "g",  /*103*/
  243. "h",  /*104*/
  244. "i",  /*105*/
  245. "j",  /*106*/
  246. "k",  /*107*/
  247. "l",  /*108*/
  248. "m",  /*109*/
  249. "n",  /*110*/
  250. "o",  /*111*/
  251. "p",  /*112*/
  252. "q",  /*113*/
  253. "r",  /*114*/
  254. "s",  /*115*/
  255. "t",  /*116*/
  256. "u",  /*117*/
  257. "v",  /*118*/
  258. "w",  /*119*/
  259. "x",  /*120*/
  260. "y",  /*121*/
  261. "z",  /*122*/
  262. "braceleft",      /*123*/
  263. "bar",            /*124*/
  264. "braceright",     /*125*/
  265. "asciitilde",     /*126*/
  266. "127",
  267. "grave",          /*128*/
  268. "circumflex",     /*129*/
  269. "tilde",          /*130*/
  270. "dotlessi",       /*131*/
  271. "florin",         /*132*/
  272. "quotedblleft",   /*133*/
  273. "quotedblright",  /*134*/
  274. "guilsinglleft",  /*135*/
  275. "guilsinglright", /*136*/
  276. "fi",             /*137*/
  277. "fl",             /*138*/
  278. "dagger",         /*139*/
  279. "daggerdbl",      /*140*/
  280. "endash",         /*141*/
  281. "bullet",         /*142*/
  282. "breve",          /*143*/
  283. "quotedblbase",   /*144*/
  284. "ellipsis",       /*145*/
  285. "perthousand",    /*146*/
  286. "trademark",      /*147*/
  287. "divide",         /*152*/
  288. "exclamdown",     /*161*/
  289. "cent",           /*162*/
  290. "sterling",       /*163*/
  291. "currency",       /*164*/
  292. "yen",            /*165*/
  293. "section",        /*167*/
  294. "dieresis",       /*168*/
  295. "copyright",      /*169*/
  296. "ordfeminine",    /*170*/
  297. "guillemotleft",  /*171*/
  298. "logicalnot",     /*172*/
  299. "emdash",         /*173*/
  300. "registered",     /*174*/
  301. "ring",           /*176*/
  302. "plusminus",      /*177*/
  303. "twosuperior",    /*178*/
  304. "threesuperior",  /*179*/
  305. "acute",          /*180*/
  306. "mu",             /*181*/
  307. "paragraph",      /*182*/
  308. "periodcentered", /*183*/
  309. "cedilla",        /*184*/
  310. "onesuperior",    /*185*/
  311. "ordmasculine",   /*186*/
  312. "guillemotright", /*187*/
  313. "onequarter",     /*188*/
  314. "onehalf",        /*189*/
  315. "threequarters",  /*190*/
  316. "questiondown",   /*191*/
  317. "Agrave",         /*192*/
  318. "Aacute",      /*193*/
  319. "Acircumflex", /*194*/
  320. "Atilde",      /*195*/
  321. "Adieresis",   /*196*/
  322. "Aring",       /*197*/
  323. "AE",          /*198*/
  324. "Ccedilla",    /*199*/
  325. "Egrave",      /*200*/
  326. "Eacute",      /*201*/
  327. "Ecircumflex", /*202*/
  328. "Edieresis",   /*203*/
  329. "Igrave",      /*204*/
  330. "Iacute",      /*205*/
  331. "Icircumflex", /*206*/
  332. "Idieresis",   /*207*/
  333. "Eth",         /*208*/
  334. "Ntilde",      /*209*/
  335. "Ograve",      /*210*/
  336. "Oacute",      /*211*/
  337. "Ocircumflex", /*212*/
  338. "Otilde",      /*213*/
  339. "Odieresis",   /*214*/
  340. "OE",          /*215*/
  341. "Oslash",      /*216*/
  342. "Ugrave",      /*217*/
  343. "Uacute",      /*218*/
  344. "Ucircumflex", /*219*/
  345. "Udieresis",   /*220*/
  346. "Yacute",      /*221*/
  347. "Thorn",       /*222*/
  348. "germandbls",  /*223*/
  349. "agrave",      /*224*/
  350. "aacute",      /*225*/
  351. "acircumflex", /*226*/
  352. "atilde",      /*227*/
  353. "adieresis",   /*228*/
  354. "aring",       /*229*/
  355. "ae",          /*230*/
  356. "ccedilla",    /*231*/
  357. "egrave",      /*232*/
  358. "eacute",      /*233*/
  359. "ecircumflex", /*234*/
  360. "edieresis",   /*235*/
  361. "igrave",      /*236*/
  362. "iacute",      /*237*/
  363. "icircumflex", /*238*/
  364. "idieresis",   /*239*/
  365. "eth",         /*240*/
  366. "ntilde",      /*241*/
  367. "ograve",      /*242*/
  368. "oacute",      /*243*/
  369. "ocircumflex", /*244*/
  370. "otilde",      /*245*/
  371. "odieresis",   /*246*/
  372. "oe",          /*247*/
  373. "oslash",      /*248*/
  374. "ugrave",      /*249*/
  375. "uacute",      /*250*/
  376. "ucircumflex", /*251*/
  377. "udieresis",   /*252*/
  378. "yacute",      /*253*/
  379. "thorn",       /*254*/
  380. "ydieresis",   /*255*/
  381.  
  382.  
  383. "","","","","","","","","","","","","",
  384. "","","","","","","","","","","","","",
  385. "","","","","","","","","","","","","",
  386. "","","","","","","","","","","","","",
  387. "","","","","","","","","","","","","",
  388. "","","","","","","","","","","","","",
  389. "","","","","","","","","","","","","",
  390. "","","","","","","","","","","","","",
  391. "","","","","","","","","","","","","",
  392. "","","","","","","","","","","","","",
  393. "","","","","","","","","","","","","",
  394. "","","","","","","","","","","","","",
  395. "","","","","","","","","","","","","",
  396. "","","","","","","","","","","","","",
  397. "","","","","","","","","","","","","",
  398. "","","","","","","","","","","","","",
  399. "","","","","","","","","","","","","",
  400. "","","","","","","","","","","","","",
  401. "","","","","","","","","","","","","",
  402. "","","","","","","","","","","","","",
  403. "","","","","","","","","","","","","",
  404. "","","","","","","","","","","","","",
  405. "","","","","","","",""
  406.  
  407. };
  408.