| 1 |
/* ttf.h -- header file that defines the top level abstraction of a True Type font, as |
| 2 |
* well as the usual typedefs in TTF spec. |
| 3 |
* Copyright (C) 1996-1998 Li-Da Lho, All right reserved. |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __TTF_H |
| 7 |
#define __TTF_H |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
/* $Id: ttf.h,v 1.3 1998/07/06 06:07:01 werner Exp $ */ |
| 12 |
|
| 13 |
typedef unsigned char BYTE; |
| 14 |
typedef signed char CHAR; |
| 15 |
typedef unsigned short USHORT; |
| 16 |
typedef signed short SHORT; |
| 17 |
|
| 18 |
|
| 19 |
#if SIZEOF_INT==4 |
| 20 |
typedef unsigned int ULONG; |
| 21 |
typedef signed int LONG; |
| 22 |
#else |
| 23 |
#error "Unsupported size of `int' type!" |
| 24 |
#endif |
| 25 |
|
| 26 |
typedef ULONG Fixed; /* 16.16 fixed point number used for |
| 27 |
* version information */ |
| 28 |
typedef USHORT FUnit; |
| 29 |
typedef SHORT FWord; /* pixel position in the unit of FUnit */ |
| 30 |
typedef USHORT uFWord; |
| 31 |
typedef SHORT F2Dot14; /* 2.14 fixed point number used for |
| 32 |
* unit vectors */ |
| 33 |
typedef LONG F26Dot6; /* 26.6 fixed point number to specify |
| 34 |
* pixel positions */ |
| 35 |
|
| 36 |
BYTE ttfGetBYTE(FILE *fp); |
| 37 |
CHAR ttfGetCHAR(FILE *fp); |
| 38 |
USHORT ttfGetUSHORT(FILE *fp); |
| 39 |
SHORT ttfGetSHORT(FILE *fp); |
| 40 |
ULONG ttfGetULONG(FILE *fp); |
| 41 |
LONG ttfGetLONG(FILE *fp); |
| 42 |
Fixed ttfGetFixed(FILE *fp); |
| 43 |
FUnit ttfGetFUnit(FILE *fp); |
| 44 |
FWord ttfGetFWord(FILE *fp); |
| 45 |
uFWord ttfGetuFWord(FILE *fp); |
| 46 |
F2Dot14 ttfGetF2Dot14(FILE *fp); |
| 47 |
|
| 48 |
/* Read arrays. */ |
| 49 |
void ttfReadUSHORT(USHORT *array, size_t nelem, FILE *fp); |
| 50 |
void ttfReadULONG(ULONG *array, size_t nelem, FILE *fp); |
| 51 |
void ttfReadFWord(FWord *array, size_t nelem, FILE *fp); |
| 52 |
|
| 53 |
/* Allocate and read arrays. */ |
| 54 |
BYTE *ttfMakeBYTE(size_t nelem, FILE *fp); |
| 55 |
USHORT *ttfMakeUSHORT(size_t nelem, FILE *fp); |
| 56 |
SHORT *ttfMakeSHORT(size_t nelem, FILE *fp); |
| 57 |
ULONG *ttfMakeULONG(size_t nelem, FILE *fp); |
| 58 |
LONG *ttfMakeLONG(size_t nelem, FILE *fp); |
| 59 |
|
| 60 |
#include "tables.h" |
| 61 |
#include "gcache.h" |
| 62 |
#include "gstate.h" |
| 63 |
|
| 64 |
typedef struct |
| 65 |
{ |
| 66 |
BYTE opcode; |
| 67 |
BYTE *iStream; |
| 68 |
} |
| 69 |
InstructionDef; |
| 70 |
|
| 71 |
typedef struct |
| 72 |
{ |
| 73 |
BYTE fun; |
| 74 |
BYTE *iStream; |
| 75 |
} |
| 76 |
FunctionDef; |
| 77 |
|
| 78 |
typedef struct |
| 79 |
{ |
| 80 |
/* data for instructions */ |
| 81 |
BYTE *iStream; /* instruction stream */ |
| 82 |
USHORT ip; /* instruction pointer */ |
| 83 |
USHORT insLength; /* instruction length */ |
| 84 |
LONG *StorageArea; /* storage area */ |
| 85 |
LONG *Stack; /* stack */ |
| 86 |
USHORT sp; /* stack pointer */ |
| 87 |
USHORT stklimit; /* stack limit */ |
| 88 |
/* data about point size and resolution */ |
| 89 |
ULONG ppem; /* pixel per em */ |
| 90 |
ULONG xres; /* x resolution in dpi */ |
| 91 |
ULONG yres; /* y resolution in dpi */ |
| 92 |
F26Dot6 pointsize; /* the point size of the font */ |
| 93 |
/* data for grahpics stat and cvt */ |
| 94 |
F26Dot6 *cvt; /* Control value table, scaled form cvt in |
| 95 |
* TTFont */ |
| 96 |
GraphicsState gstate; /* graphics state used for instructions */ |
| 97 |
GraphicsState gstate_init; /* initial graphics state after fpgm and cvt |
| 98 |
* programs are executed */ |
| 99 |
#if 0 |
| 100 |
/* user definded instructions and functions */ |
| 101 |
InstructionDef iDef; /* instruction definitions */ |
| 102 |
FunctionDef fDef; /* function definitions */ |
| 103 |
#endif |
| 104 |
|
| 105 |
int Error_State; /* error state indicate the error */ |
| 106 |
} |
| 107 |
VirtualMachine; |
| 108 |
|
| 109 |
typedef struct |
| 110 |
{ |
| 111 |
/* misc informations */ |
| 112 |
FILE *fp; |
| 113 |
char *ttfname; |
| 114 |
int *refcount; /* how many instances of this font */ |
| 115 |
Fixed version; |
| 116 |
USHORT numTables; /* it seems not necessary to hold all the |
| 117 |
* OffsetTables */ |
| 118 |
ULONG glyphOffset; /* where the glyph table starts */ |
| 119 |
TableDirPtr dir; /* Pointer to Table Directories */ |
| 120 |
EncodingPtr encoding; /* `encoding' is the currently used encoding |
| 121 |
* table */ |
| 122 |
USHORT numCacheElements; /* number of glyph cache elements */ |
| 123 |
|
| 124 |
VirtualMachine vm; /* the virtual machine */ |
| 125 |
|
| 126 |
GlyphCachePtr gcache; /* pointer to glyph cache */ |
| 127 |
|
| 128 |
/* required tables */ |
| 129 |
CMAPPtr cmap; |
| 130 |
HEADPtr head; |
| 131 |
HHEAPtr hhea; |
| 132 |
HMTXPtr hmtx; |
| 133 |
LOCAPtr loca; |
| 134 |
MAXPPtr maxp; |
| 135 |
NAMEPtr name; |
| 136 |
POSTPtr post; |
| 137 |
OS_2Ptr os2; |
| 138 |
|
| 139 |
/* optional tables */ |
| 140 |
FWord *cvt; /* control value table, not scaled yet */ |
| 141 |
USHORT cvtLength; /* number of FWords of CVT */ |
| 142 |
BYTE *fpgm; /* font program */ |
| 143 |
USHORT fpgmLength; /* number of bytes of fpgm */ |
| 144 |
BYTE *prep; /* cvt program */ |
| 145 |
USHORT prepLength; /* number of bytes of prep */ |
| 146 |
|
| 147 |
/* those optional tables seem not to be necessary for a True Type font |
| 148 |
* server */ |
| 149 |
GASPPtr gasp; |
| 150 |
HDMXPtr hdmx; |
| 151 |
KERNPtr kern; |
| 152 |
LTSHPtr ltsh; |
| 153 |
PCLTPtr pclt; |
| 154 |
VDMXPtr vdmx; |
| 155 |
VHEAPtr vhea; |
| 156 |
VMTXPtr vmtx; |
| 157 |
|
| 158 |
/* Additional OpenType Tables */ |
| 159 |
GPOSPtr gpos; |
| 160 |
GSUBPtr gsub; |
| 161 |
} |
| 162 |
TTFont, *TTFontPtr; |
| 163 |
|
| 164 |
TTFontPtr ttfInitFont(char *filename); |
| 165 |
void ttfLoadFont(TTFontPtr font, ULONG offset); |
| 166 |
void ttfFreeFont(TTFontPtr font); |
| 167 |
|
| 168 |
#include "loadtable.h" |
| 169 |
|
| 170 |
#endif /* __TTF_H */ |
| 171 |
|
| 172 |
|
| 173 |
/* end of ttf.h */ |