home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 12 Font / 12-Font.zip / PFM2AFM.ZIP / pfm2afm.h < prev   
Text File  |  1991-10-09  |  17KB  |  414 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  *  Title:  pfm2afm - Convert Windows .pfm files to .afm files      *
  4.  *                                                                  *
  5.  *  Author: Ken Borgendale   10/9/91                                *
  6.  *                                                                  *
  7.  *  Function:                                                       *
  8.  *      Declare types and constants for pfm2afm.                    *
  9.  *                                                                  *
  10.  *  Copyright:                                                      *
  11.  *      pfm2afm - Copyright (C) IBM Corp., 1991                     *
  12.  *                                                                  *
  13.  *      This code is released for public use as long as the         *
  14.  *      copyright remains intact.  This code is provided asis       *
  15.  *      without any warrenties, express or implied.                 *
  16.  *                                                                  *
  17.  *  Note:                                                           *
  18.  *      1. Be very careful of the packing of the PFM structure.     *
  19.  *         This is a very badly designed data structure.  (I just   *
  20.  *         read it, Microsoft designed it).                         *
  21.  *                                                                  *
  22.  ********************************************************************/
  23.  
  24. /*
  25.  *  Define unsigned types and other compiler sensitive stuff
  26.  */
  27. typedef unsigned char   uchar;
  28. typedef unsigned short  ushort;
  29. typedef unsigned long   ulong;
  30. typedef unsigned int    uint;
  31. #define NEAR near
  32. #define MAINENT _cdecl
  33. #define OPTSEP  '/'
  34. #define PATHSEP ';'
  35.  
  36. /*
  37.  *  Declare Windows .pfm structure.  Many fields are not declared if
  38.  *  they are not used by this program.
  39.  */
  40.  
  41. /*
  42.  * This structure was created with no thought to alignment, so we must
  43.  * set the alignment to character.
  44.  */
  45. #pragma pack(1)
  46. typedef struct pfm_ {
  47.     ushort  vers;
  48.     ulong   len;             /* Total length of .pfm file */
  49.     uchar   copyright[60];   /* Copyright string */
  50.     ushort  type;
  51.     ushort  points;
  52.     ushort  verres;
  53.     ushort  horres;
  54.     ushort  ascent;
  55.     ushort  intleading;
  56.     ushort  extleading;
  57.     uchar   italic;
  58.     uchar   uline;
  59.     uchar   overs;
  60.     ushort  weight;
  61.     uchar   charset;         /* 0=windows, otherwise nomap */
  62.     ushort  pixwidth;        /* Width for mono fonts */
  63.     ushort  pixheight;
  64.     uchar   kind;            /* Lower bit off in mono */
  65.     ushort  avgwidth;        /* Mono if avg=max width */
  66.     ushort  maxwidth;        /* Use to compute bounding box */
  67.     uchar   firstchar;       /* First char in table */
  68.     uchar   lastchar;        /* Last char in table */
  69.     uchar   defchar;
  70.     uchar   brkchar;
  71.     ushort  widthby;
  72.     ulong   device;
  73.     ulong   face;            /* Face name */
  74.     ulong   bits;
  75.     ulong   bitoff;
  76.     ushort  extlen;
  77.     ulong   psext;           /* PostScript extension */
  78.     ulong   chartab;         /* Character width tables */
  79.     ulong   res1;
  80.     ulong   kernpairs;       /* Kerning pairs */
  81.     ulong   res2;
  82.     ulong   fontname;        /* Font name */
  83. } PFM;
  84. #pragma pack()
  85.  
  86. /*
  87.  *  Some metrics from the PostScript extension
  88.  */
  89. typedef struct psx_ {
  90.     uchar   res1[14];
  91.     ushort  capheight;       /* Cap height */
  92.     ushort  xheight;         /* X height */
  93.     ushort  ascender;        /* Ascender */
  94.     ushort  descender;       /* Descender (positive) */
  95. } PSX;
  96.  
  97. /*
  98.  *  Kerning pairs
  99.  */
  100. typedef struct kern_ {
  101.     uchar   first;           /* First character */
  102.     uchar   second;          /* Second character */
  103.     short   kern;            /* Kern distance */
  104. } KERN;
  105.  
  106. /*
  107.  * Translate table from 1004 to psstd.  1004 is an extension of the
  108.  * Windows translate table used in PM.
  109.  */
  110. uchar Win2PSStd[] = {
  111.   0,   0,   0,   0, 197, 198, 199,   0, 202,   0, 205, 206, 207,   0,   0,   0,
  112.   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  113.  32,  33,  34,  35,  36,  37,  38, 169,  40,  41,  42,  43,  44,  45,  46,  47,
  114.  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,
  115.  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,
  116.  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,
  117. 193,  97,  98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
  118. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
  119.   0,   0, 184,   0, 185, 188, 178, 179,  94, 189,   0, 172, 234,   0,   0,   0,
  120.   0,  96,   0, 170, 186,   0, 177, 208, 126,   0,   0, 173, 250,   0,   0,   0,
  121.   0, 161, 162, 163, 168, 165,   0, 167, 200,   0, 227, 171,   0,   0,   0,   0,
  122.   0,   0,   0,   0, 194,   0, 182, 180, 203,   0, 235, 187,   0,   0,   0, 191,
  123.   0,   0,   0,   0,   0,   0, 225,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  124.   0,   0,   0,   0,   0,   0,   0,   0, 233,   0,   0,   0,   0,   0,   0, 251,
  125.   0,   0,   0,   0,   0,   0, 241,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  126.   0,   0,   0,   0,   0,   0,   0,   0, 249,   0,   0,   0,   0,   0,   0,   0,
  127. };
  128.  
  129. /*
  130.  *  Character class.  This is a minor attempt to overcome the problem that
  131.  *  in the pfm file, all unused characters are given the width of space.
  132.  */
  133. uchar WinClass[] = {
  134.     0, 0, 0, 0, 2, 2, 2, 0, 2, 0, 2, 2, 2, 0, 0, 0,   /* 00 */
  135.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   /* 10 */
  136.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* 20 */
  137.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* 30 */
  138.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* 40 */
  139.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* 50 */
  140.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* 60 */
  141.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,   /* 70 */
  142.     0, 0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0,   /* 80 */
  143.     0, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 2,   /* 90 */
  144.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* a0 */
  145.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* b0 */
  146.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* c0 */
  147.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* d0 */
  148.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* e0 */
  149.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   /* f0 */
  150. };
  151.  
  152. /*
  153.  *  Windows chararacter names.  Give a name to the usused locations
  154.  *  for when the all flag is specified.
  155.  */
  156. uchar NEAR * WinChars[] = {
  157.     "W00",              /*   00    */
  158.     "W01",              /*   01    */
  159.     "W02",              /*   02    */
  160.     "W03",              /*   03    */
  161.     "macron",           /*   04    */
  162.     "breve",            /*   05    */
  163.     "dotaccent",        /*   06    */
  164.     "W07",              /*   07    */
  165.     "ring",             /*   08    */
  166.     "W09",              /*   09    */
  167.     "W0a",              /*   0a    */
  168.     "W0b",              /*   0b    */
  169.     "W0c",              /*   0c    */
  170.     "W0d",              /*   0d    */
  171.     "W0e",              /*   0e    */
  172.     "W0f",              /*   0f    */
  173.     "hungarumlaut",     /*   10    */
  174.     "ogonek",           /*   11    */
  175.     "caron",            /*   12    */
  176.     "W13",              /*   13    */
  177.     "W14",              /*   14    */
  178.     "W15",              /*   15    */
  179.     "W16",              /*   16    */
  180.     "W17",              /*   17    */
  181.     "W18",              /*   18    */
  182.     "W19",              /*   19    */
  183.     "W1a",              /*   1a    */
  184.     "W1b",              /*   1b    */
  185.     "W1c",              /*   1c    */
  186.     "W1d",              /*   1d    */
  187.     "W1e",              /*   1e    */
  188.     "W1f",              /*   1f    */
  189.     "space",            /*   20    */
  190.     "exclam",           /*   21    */
  191.     "quotedbl",         /*   22    */
  192.     "numbersign",       /*   23    */
  193.     "dollar",           /*   24    */
  194.     "percent",          /*   25    */
  195.     "ampersand",        /*   26    */
  196.     "quotesingle",      /*   27    */
  197.     "parenleft",        /*   28    */
  198.     "parenright",       /*   29    */
  199.     "asterisk",         /*   2A    */
  200.     "plus",             /*   2B    */
  201.     "comma",            /*   2C    */
  202.     "hyphen",           /*   2D    */
  203.     "period",           /*   2E    */
  204.     "slash",            /*   2F    */
  205.     "zero",             /*   30    */
  206.     "one",              /*   31    */
  207.     "two",              /*   32    */
  208.     "three",            /*   33    */
  209.     "four",             /*   34    */
  210.     "five",             /*   35    */
  211.     "six",              /*   36    */
  212.     "seven",            /*   37    */
  213.     "eight",            /*   38    */
  214.     "nine",             /*   39    */
  215.     "colon",            /*   3A    */
  216.     "semicolon",        /*   3B    */
  217.     "less",             /*   3C    */
  218.     "equal",            /*   3D    */
  219.     "greater",          /*   3E    */
  220.     "question",         /*   3F    */
  221.     "at",               /*   40    */
  222.     "A",                /*   41    */
  223.     "B",                /*   42    */
  224.     "C",                /*   43    */
  225.     "D",                /*   44    */
  226.     "E",                /*   45    */
  227.     "F",                /*   46    */
  228.     "G",                /*   47    */
  229.     "H",                /*   48    */
  230.     "I",                /*   49    */
  231.     "J",                /*   4A    */
  232.     "K",                /*   4B    */
  233.     "L",                /*   4C    */
  234.     "M",                /*   4D    */
  235.     "N",                /*   4E    */
  236.     "O",                /*   4F    */
  237.     "P",                /*   50    */
  238.     "Q",                /*   51    */
  239.     "R",                /*   52    */
  240.     "S",                /*   53    */
  241.     "T",                /*   54    */
  242.     "U",                /*   55    */
  243.     "V",                /*   56    */
  244.     "W",                /*   57    */
  245.     "X",                /*   58    */
  246.     "Y",                /*   59    */
  247.     "Z",                /*   5A    */
  248.     "bracketleft",      /*   5B    */
  249.     "backslash",        /*   5C    */
  250.     "bracketright",     /*   5D    */
  251.     "asciicircum",      /*   5E    */
  252.     "underscore",       /*   5F    */
  253.     "grave",            /*   60    */
  254.     "a",                /*   61    */
  255.     "b",                /*   62    */
  256.     "c",                /*   63    */
  257.     "d",                /*   64    */
  258.     "e",                /*   65    */
  259.     "f",                /*   66    */
  260.     "g",                /*   67    */
  261.     "h",                /*   68    */
  262.     "i",                /*   69    */
  263.     "j",                /*   6A    */
  264.     "k",                /*   6B    */
  265.     "l",                /*   6C    */
  266.     "m",                /*   6D    */
  267.     "n",                /*   6E    */
  268.     "o",                /*   6F    */
  269.     "p",                /*   70    */
  270.     "q",                /*   71    */
  271.     "r",                /*   72    */
  272.     "s",                /*   73    */
  273.     "t",                /*   74    */
  274.     "u",                /*   75    */
  275.     "v",                /*   76    */
  276.     "w",                /*   77    */
  277.     "x",                /*   78    */
  278.     "y",                /*   79    */
  279.     "z",                /*   7A    */
  280.     "braceleft",        /*   7B    */
  281.     "bar",              /*   7C    */
  282.     "braceright",       /*   7D    */
  283.     "asciitilde",       /*   7E    */
  284.     "W7f",              /*   7F    */
  285.     "W80",              /*   80    */
  286.     "W81",              /*   81    */
  287.     "quotesinglbase",   /*   82    */
  288.     "W83",              /*   83    */
  289.     "quotedblbase",     /*   84    */
  290.     "ellipsis",         /*   85    */
  291.     "dagger",           /*   86    */
  292.     "daggerdbl",        /*   87    */
  293.     "asciicircum",      /*   88    */
  294.     "perthousand",      /*   89    */
  295.     "Scaron",           /*   8A    */
  296.     "guilsinglleft",    /*   8B    */
  297.     "OE",               /*   8C    */
  298.     "W8d",              /*   8D    */
  299.     "W8e",              /*   8E    */
  300.     "W8f",              /*   8F    */
  301.     "W90",              /*   90    */
  302.     "quoteleft",        /*   91    */
  303.     "quoteright",       /*   92    */
  304.     "quotedblleft",     /*   93    */
  305.     "quotedblright",    /*   94    */
  306.     "bullet1",          /*   95    */
  307.     "endash",           /*   96    */
  308.     "emdash",           /*   97    */
  309.     "asciitilde",       /*   98    */
  310.     "trademark",        /*   99    */
  311.     "scaron",           /*   9A    */
  312.     "guilsinglright",   /*   9B    */
  313.     "oe",               /*   9C    */
  314.     "W9d",              /*   9D    */
  315.     "W9e",              /*   9E    */
  316.     "Ydieresis",        /*   9F    */
  317.     "reqspace",         /*   A0    */
  318.     "exclamdown",       /*   A1    */
  319.     "cent",             /*   A2    */
  320.     "sterling",         /*   A3    */
  321.     "currency",         /*   A4    */
  322.     "yen",              /*   A5    */
  323.     "brokenbar",        /*   A6    */
  324.     "section",          /*   A7    */
  325.     "dieresis",         /*   A8    */
  326.     "copyright",        /*   A9    */
  327.     "ordfeminine",      /*   AA    */
  328.     "guillemotleft",    /*   AB    */
  329.     "logicalnot",       /*   AC    */
  330.     "syllable",         /*   AD    */
  331.     "registered",       /*   AE    */
  332.     "overbar",          /*   AF    */
  333.     "degree",           /*   B0    */
  334.     "plusminus",        /*   B1    */
  335.     "twosuperior",      /*   B2    */
  336.     "threesuperior",    /*   B3    */
  337.     "acute",            /*   B4    */
  338.     "mu",               /*   B5    */
  339.     "paragraph",        /*   B6    */
  340.     "periodcentered",   /*   B7    */
  341.     "cedilla",          /*   B8    */
  342.     "onesuperior",      /*   B9    */
  343.     "ordmasculine",     /*   BA    */
  344.     "guillemotright",   /*   BB    */
  345.     "onequarter",       /*   BC    */
  346.     "onehalf",          /*   BD    */
  347.     "threequarters",    /*   BE    */
  348.     "questiondown",     /*   BF    */
  349.     "Agrave",           /*   C0    */
  350.     "Aacute",           /*   C1    */
  351.     "Acircumflex",      /*   C2    */
  352.     "Atilde",           /*   C3    */
  353.     "Adieresis",        /*   C4    */
  354.     "Aring",            /*   C5    */
  355.     "AE",               /*   C6    */
  356.     "Ccedilla",         /*   C7    */
  357.     "Egrave",           /*   C8    */
  358.     "Eacute",           /*   C9    */
  359.     "Ecircumflex",      /*   CA    */
  360.     "Edieresis",        /*   CB    */
  361.     "Igrave",           /*   CC    */
  362.     "Iacute",           /*   CD    */
  363.     "Icircumflex",      /*   CE    */
  364.     "Idieresis",        /*   CF    */
  365.     "Eth",              /*   D0    */
  366.     "Ntilde",           /*   D1    */
  367.     "Ograve",           /*   D2    */
  368.     "Oacute",           /*   D3    */
  369.     "Ocircumflex",      /*   D4    */
  370.     "Otilde",           /*   D5    */
  371.     "Odieresis",        /*   D6    */
  372.     "multiply",         /*   D7    */
  373.     "Oslash",           /*   D8    */
  374.     "Ugrave",           /*   D9    */
  375.     "Uacute",           /*   DA    */
  376.     "Ucircumflex",      /*   DB    */
  377.     "Udieresis",        /*   DC    */
  378.     "Yacute",           /*   DD    */
  379.     "Thorn",            /*   DE    */
  380.     "germandbls",       /*   DF    */
  381.     "agrave",           /*   E0    */
  382.     "aacute",           /*   E1    */
  383.     "acircumflex",      /*   E2    */
  384.     "atilde",           /*   E3    */
  385.     "adieresis",        /*   E4    */
  386.     "aring",            /*   E5    */
  387.     "ae",               /*   E6    */
  388.     "ccedilla",         /*   E7    */
  389.     "egrave",           /*   E8    */
  390.     "eacute",           /*   E9    */
  391.     "ecircumflex",      /*   EA    */
  392.     "edieresis",        /*   EB    */
  393.     "igrave",           /*   EC    */
  394.     "iacute",           /*   ED    */
  395.     "icircumflex",      /*   EE    */
  396.     "idieresis",        /*   EF    */
  397.     "eth",              /*   F0    */
  398.     "ntilde",           /*   F1    */
  399.     "ograve",           /*   F2    */
  400.     "oacute",           /*   F3    */
  401.     "ocircumflex",      /*   F4    */
  402.     "otilde",           /*   F5    */
  403.     "odieresis",        /*   F6    */
  404.     "divide",           /*   F7    */
  405.     "oslash",           /*   F8    */
  406.     "ugrave",           /*   F9    */
  407.     "uacute",           /*   FA    */
  408.     "ucircumflex",      /*   FB    */
  409.     "udieresis",        /*   FC    */
  410.     "yacute",           /*   FD    */
  411.     "thorn",            /*   FE    */
  412.     "ydieresis",        /*   FF    */
  413. };
  414.