]> git.donarmstrong.com Git - lilypond.git/blob - ttftool/include/types.h
release commit
[lilypond.git] / ttftool / include / types.h
1 /* Copyright (c) 1997-1998 by Juliusz Chroboczek */
2
3
4 typedef unsigned char BYTE;
5 typedef signed char CHAR;
6 typedef unsigned short USHORT;
7 typedef short SHORT;
8 typedef unsigned long ULONG;
9 typedef long LONG;
10
11 /* Endianness conversions */
12 #ifdef SMALLENDIAN
13 #define H(x) ((SHORT)((((SHORT)(x))&0xFF)<<8)+(((USHORT)(x))>>8))
14 #define UH(x) ((USHORT)((((USHORT)(x))&0xFF)<<8)+(((USHORT)(x))>>8))
15 #define L(x) ((LONG)(((LONG)UH((x)&0xFFFF))<<16)+UH(((ULONG)(x))>>16))
16 #define UL(x) ((ULONG)(((ULONG)UH((x)&0xFFFF))<<16)+UH(((ULONG)(x))>>16))
17 #else
18 #define H(x) ((SHORT)x)
19 #define UH(x) ((USHORT)x)
20 #define L(x) ((LONG)x)
21 #define UL(x) ((ULONG)x)
22 #endif
23
24 #define FIX_H(x) x=H(x)
25 #define FIX_UH(x) x=UH(x)
26 #define FIX_L(x) x=L(x)
27 #define FIX_UL(x) x=UL(x)
28
29 /* We are assuming that the compiler will not pad the following
30  * structures; note that their members are intrinsically properly
31  * aligned.  This will probably break on some machines. */
32
33 typedef struct
34 {
35   SHORT mantissa;
36   USHORT fraction;
37 } Fixed;
38
39 #define FIX_Fixed(x) {(x).mantissa=H((x).mantissa); (x).fraction=UH((x).fraction);}
40
41 typedef struct
42 {
43   BYTE data[8];
44 } longDateTime;
45
46 typedef USHORT uFWord;
47 typedef SHORT FWord;
48 typedef USHORT F2Dot14;
49
50 #define MAKE_ULONG(a,b,c,d) ((ULONG)(((ULONG)(a)<<24)|((b)<<16)|((c)<<8)|(d)))
51
52 /*------------------------------------------------------------*/
53
54 struct OffsetTable
55 {
56   Fixed version;
57   USHORT numTables;
58   USHORT searchRange;
59   USHORT entrySelector;
60   USHORT rangeShift;
61 };
62 #define FIX_OffsetTable(x) \
63   {FIX_Fixed((x).version);\
64    FIX_UH((x).numTables);\
65    FIX_UH((x).searchRange);\
66    FIX_UH((x).entrySelector);}
67
68 struct TableDirectoryEntry
69 {
70   ULONG tag;
71   ULONG checkSum;
72   ULONG offset;
73   ULONG length;
74 };
75 #define FIX_TableDirectoryEntry(x) \
76   {FIX_UL((x).tag); FIX_UL((x).checkSum);\
77    FIX_UL((x).offset); FIX_UL((x).length);}
78
79 /*------------------------------------------------------------*/
80
81 struct HeadTable
82 {
83   Fixed version;
84   Fixed fontRevision;
85   ULONG checkSumAdjustment;
86   ULONG magicNumber;
87   USHORT flags;
88   USHORT unitsPerEm;
89   longDateTime created;
90   longDateTime modified;
91   FWord xMin;
92   FWord yMin;
93   FWord xMax;
94   FWord yMax;
95   USHORT macStyle;
96   USHORT lowestRecPPEM;
97   SHORT fontDirectionHint;
98   SHORT indexToLocFormat;
99   SHORT glyphDataFormat;
100 };
101 #define FIX_HeadTable(x) \
102   {FIX_Fixed((x).version); FIX_Fixed((x).fontRevision);\
103    FIX_UL((x).checkSumAdjustment); FIX_UL((x).magicNumber);\
104    FIX_UH((x).flags); FIX_UH((x).unitsPerEm);\
105    FIX_UH((x).xMin); FIX_UH((x).yMin); FIX_UH((x).xMax); FIX_UH((x).yMax);\
106    FIX_UH((x).macStyle); FIX_UH((x).lowestRecPPEM);\
107    FIX_H((x).fontDirectionHint); FIX_H((x).indexToLocFormat);\
108    FIX_H((x).glyphDataFormat);}
109
110
111 /*------------------------------------------------------------*/
112
113 struct NameRecord
114 {
115   USHORT platformID;
116   USHORT encodingID;
117   USHORT languageID;
118   USHORT nameID;
119   USHORT length;
120   USHORT offset;
121 };
122 #define FIX_NameRecord(x) \
123   {FIX_UH((x).platformID); FIX_UH((x).encodingID); FIX_UH((x).languageID);\
124    FIX_UH((x).nameID); FIX_UH((x).length); FIX_UH((x).offset);}
125
126
127
128 /*------------------------------------------------------------*/
129
130 struct PostTable
131 {
132   Fixed formatType;
133   Fixed italicAngle;
134   FWord underlinePosition;
135   FWord underlineThickness;
136   ULONG isFixedPitch;
137   ULONG minMemType42;
138   ULONG maxMemType42;
139   ULONG minMemType1;
140   ULONG maxMemType1;
141 };
142 #define FIX_PostTable(x) \
143   {FIX_Fixed((x).formatType); FIX_Fixed((x).italicAngle);\
144    FIX_H((x).underlinePosition); FIX_H((x).underlineThickness);\
145    FIX_UL((x).isFixedPitch);\
146    FIX_UL((x).minMemType42); FIX_UL((x).maxMemType42);\
147    FIX_UL((x).minMemType1); FIX_UL((x).maxMemType1); }
148
149 struct GlyphName
150 {
151   int type;
152   union
153   {
154     int index;
155     char *name;
156   } name;
157 };
158
159 /*-----------------------------------------------------------------*/
160 struct HheaTable
161 {
162   Fixed version;
163   FWord Ascender;
164   FWord Descender;
165   FWord LineGap;
166   uFWord advanceWidthMax;
167   FWord minLeftSideBearing;
168   FWord minRightSideBearing;
169   FWord xMaxExtent;
170   SHORT caretSlopeRise;
171   SHORT caretSlopeRun;
172   SHORT reserved[5];
173   SHORT metricDataFormat;
174   USHORT numberOfHMetrics;
175 };
176 #define FIX_HheaTable(x) \
177   {FIX_Fixed((x).version); FIX_H((x).Ascender); FIX_H((x).Descender); FIX_H((x).LineGap);\
178    FIX_UH((x).advanceWidthMax);\
179    FIX_H((x).minLeftSideBearing); FIX_H((x).minRightSideBearing);\
180    FIX_H((x).xMaxExtent); FIX_H((x).caretSlopeRise); FIX_H((x).caretSlopeRun);\
181    FIX_H((x).metricDataFormat); FIX_UH((x).numberOfHMetrics);}
182
183 struct Box
184 {
185   FWord xMin;
186   FWord yMin;
187   FWord xMax;
188   FWord yMax;
189 };
190 #define FIX_Box(x) {FIX_H((x).xMin); FIX_H((x).yMin); FIX_H((x).xMax); FIX_H((x).yMax);}
191
192 typedef struct
193 {
194   uFWord advanceWidth;
195   FWord lsb;
196 } longHorMetric;
197 #define FIX_longHorMetric(x) {FIX_UH((x).advanceWidth); FIX_H((x).lsb);}
198
199 /*------------------------------------------------------------*/
200 struct KernTable
201 {
202   USHORT version;
203   USHORT nTables;
204 };
205 #define FIX_KernTable(x) {FIX_UH((x).version); FIX_UH((x).nTables);}
206
207 struct KernSubTableHeader
208 {
209   USHORT version;
210   USHORT length;
211   USHORT coverage;
212 };
213 #define FIX_KernSubTableHeader(x) \
214   {FIX_UH((x).version); FIX_UH((x).length); FIX_UH((x).coverage);}
215
216
217 #define kernHorizontal 0x0001
218 #define kernMinimum 0x0002
219 #define kernCrossStream 0x0004
220 #define kernOverride 0x0008
221 #define kernFormat(coverage) ((coverage)>>8)
222
223 struct KernSubTable0
224 {
225   USHORT nPairs;
226   USHORT searchRange;
227   USHORT entrySelector;
228   USHORT rangeShift;
229 };
230
231 #define FIX_KernSubTable0(x) \
232   {FIX_UH((x).nPairs); FIX_UH((x).searchRange);\
233    FIX_UH((x).entrySelector); FIX_UH((x).rangeShift);}
234
235 struct KernEntry0
236 {
237   USHORT left;
238   USHORT right;
239   FWord value;
240 };
241 #define FIX_KernEntry0(x) \
242   {FIX_UH((x).left); FIX_UH((x).right); FIX_H((x).value);}
243
244
245 /*------------------------------------------------------------*/
246 /* Hashtables */
247
248 struct hashtable_entry
249 {
250   char *key;
251   int value;
252 };
253
254 struct hashtable_bucket
255 {
256   int size;
257   int nentries;
258   struct hashtable_entry *entries;
259 };
260
261 struct hashtable
262 {
263   int size;
264   struct hashtable_bucket **buckets;
265 };