1 /* Copyright (C) 2001-2003 by George Williams */ 2 /* 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are met: 5 6 * Redistributions of source code must retain the above copyright notice, this 7 * list of conditions and the following disclaimer. 8 9 * Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 13 * The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <stdio.h> /* for NULL */ 29 #include <stdlib.h> /* for free */ 30 #include <limits.h> 31 32 #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4)) 33 #define true 1 34 #define false 0 35 36 #define forever for (;;) 37 38 #if INT_MAX==2147483647 39 typedef int int32; 40 typedef unsigned int uint32; 41 #else 42 typedef long int32; 43 typedef unsigned long uint32; 44 #endif 45 /* I don't know of any systems where the following are not true */ 46 typedef short int16; 47 typedef unsigned short uint16; 48 typedef signed char int8; 49 typedef unsigned char uint8; 50 51 enum style_flags { sf_bold = 1, sf_italic = 2, sf_underline = 4, sf_outline = 8, 52 sf_shadow = 0x10, sf_condense = 0x20, sf_extend = 0x40 }; 53 enum psstyle_flags { psf_bold = 1, psf_italic = 2, psf_outline = 4, 54 psf_shadow = 0x8, psf_condense = 0x10, psf_extend = 0x20 }; 55 56 typedef struct face { 57 char *filename; 58 enum face_type { ft_bdf, ft_ps, ft_ttf } type; /* ttf will include otf */ 59 char *fontname; 60 char *family; 61 int16 style; 62 int16 psstyle; 63 int size; 64 int fixed; 65 short metrics[256]; /* Not computed until NFNT resource dumped, TTF knows once names are read, PS never knows */ 66 int id; /* NFNT, sfnt resource ID */ 67 int ascent, descent, linegap; 68 struct face *next; 69 int xmin, ymin, xmax, ymax; /* Bounding box for a 1em font (fixed 4.12 format) */ 70 } Face; 71 72 typedef struct family { 73 char *familyname; 74 int id; /* FOND resource ID */ 75 int fixed; 76 int ascent, descent, linegap, maxwidth; 77 Face *faces[96]; 78 Face *ttffaces[96]; 79 Face *psfaces[48]; 80 struct family *next; 81 } Family; 82 83 struct resource { 84 uint32 pos; 85 uint8 flags; 86 uint16 id; 87 char *name; 88 uint32 nameloc; 89 uint32 nameptloc; 90 }; 91 92 struct resourcetype { 93 uint32 tag; 94 struct resource *res; 95 uint32 resloc; 96 }; 97 98 struct macbinaryheader { 99 char *macfilename; 100 char *binfilename; /* if macfilename is null and this is set we will figure out macfilename by removing .bin */ 101 uint32 type; 102 uint32 creator; 103 }; 104 105 struct macfont { 106 short fRectWidth; 107 short fRectHeight; 108 short ascent; 109 short descent; 110 short nDescent; 111 short leading; 112 short kernMax; 113 short firstChar; 114 short lastChar; 115 short fontType; 116 short rowWords; 117 short owTLoc; 118 uint16 widmax; 119 Face *face; 120 unsigned short *widths; 121 short *lbearings; 122 unsigned short *locs; 123 unsigned short **rows; 124 unsigned short *idealwidths; /* For the fond */ 125 }; 126 127 extern int getushort(FILE *f); 128 extern long getlong(FILE *f); 129 extern void putshort(int val, FILE *f); 130 extern void putlong(long val, FILE *f); 131 132 /* Postscript */ 133 extern int PSGetNames(Face *face); 134 extern struct resource *PSToResources(FILE *res,Face *face); 135 /* TrueType */ 136 extern int TTFGetNames(Face *face); 137 extern long TTFToResource(FILE *res,Face *face); 138 /* bdf */ 139 extern int BDFGetNames(Face *face); 140 extern long BDFToResource(FILE *res,Face *face); 141