summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/src/font/TtfTypes.h
blob: da8d90f1f26eec419d814e5d45aeaa1a915c3ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 2007 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: TtfTypes.h
Responsibility: Tim Eves
Last reviewed: Not yet.

Description:
Provides types required to represent the TTF basic types.
-------------------------------------------------------------------------------*//*:End Ignore*/


//**********************************************************************************************
//	Include files
//**********************************************************************************************
#include "GrPlatform.h"

namespace TtfUtil
{
//**********************************************************************************************
//	Forward declarations
//**********************************************************************************************


//**********************************************************************************************
//	Type declarations
//**********************************************************************************************
typedef gr::data8	uint8;
typedef gr::sdata8	int8;
typedef gr::data16	uint16;
typedef gr::sdata16 	int16;
typedef gr::data32	uint32;
typedef gr::sdata32 	int32;

typedef int16	short_frac;
typedef int32	fixed;
typedef int16	fword;
typedef uint16	ufword;
typedef int16	f2dot14;
typedef uint32	long_date_time[2];

//**********************************************************************************************
//	Constants and enum types
//**********************************************************************************************/
enum
{
	OneFix = 1<<16
};

//**********************************************************************************************
//	Table declarations
//**********************************************************************************************
namespace Sfnt 
{
#pragma pack(1)	// We need this or the structure members aren't alligned 
                     	// correctly.  Fortunately this form of pragma is supposed
                     	// to be recongnised by VS C++ too (at least according to 
                     	// MSDN).

	struct OffsetSubTable
	{
		uint32	scaler_type;
		uint16	num_tables,
			search_range,
			entry_selector,
			range_shift;
		struct Entry
		{
			uint32	tag,
				checksum,
				offset,
				length;
		} table_directory[1];

		enum ScalerType 
		{ 
			TrueTypeMac = 0x74727565U, 
			TrueTypeWin = 0x00010000U,
			Type1   = 0x74797031U
		};
	};



	
	struct CharacterCodeMap
	{
		uint16	version,
			num_subtables;
		struct
		{
			uint16	platform_id,
				platform_specific_id;
			uint32	offset;
		} encoding[1];
	};

	struct CmapSubTable
	{
		uint16	format,
			length,
			language;
	};

	struct CmapSubTableFormat4 : CmapSubTable
	{
		uint16	seg_count_x2,
			search_range,
			entry_selector,
			range_shift,
			end_code[1];
		// There are arrarys after this which need their
		// start positions calculated since end_code is 
		// seg_count uint16s long.
	};

	struct CmapSubTableFormat12
	{
		fixed	format;
		uint32	length,
			language,
			num_groups;
		struct 
		{
			uint32	start_char_code,
				end_char_code,
				start_glyph_id;
		} group[1];
	};



	struct FontHeader
	{
		fixed	version,
			font_revision;
		uint32	check_sum_adjustment,
			magic_number;
		uint16	flags,
			units_per_em;
		long_date_time	created,
				modified;
		fword	x_min,
			y_min,
			x_max,
			y_max;
		uint16	mac_style,
			lowest_rec_ppem;
		int16	font_direction_hint,
			index_to_loc_format,
			glyph_data_format;
		enum 
		{
			MagicNumber = 0x5F0F3CF5, 
			GlypDataFormat = 0
		};
		enum {ShortIndexLocFormat, LongIndexLocFormat};
	};




	struct PostScriptGlyphName
	{
		fixed	format,
			italic_angle;
		fword	underline_position,
			underline_thickness;
		uint32	is_fixed_pitch,
			min_mem_type42,
			max_mem_type42,
			min_mem_type1,
			max_mem_type1;			
		enum 
		{
			Format1  = 0x10000, 
			Format2  = 0x20000,
			Format25 = 0x28000,
			Format3  = 0x30000,
			Format4  = 0x40000
		};
	};
	
	struct PostScriptGlyphName2 : PostScriptGlyphName
	{
		uint16	number_of_glyphs,
			glyph_name_index[1];
	};
	
	struct PostScriptGlyphName25 : PostScriptGlyphName
	{
		uint16	number_of_glyphs;
		int8	offset[1];
	};
	
	struct PostScriptGlyphName3 : PostScriptGlyphName {};
	
	struct PostScriptGlyphName4 : PostScriptGlyphName
	{
		uint16 glyph_to_char_map[1];
	};
	
	
	struct HorizontalHeader
	{
		fixed	version;
		fword	ascent,
			descent,
			line_gap;
		ufword	advance_width_max;
		fword	min_left_side_bearing,
			max_left_side_bearing,
			x_max_element;
		int16	caret_slope_rise,
			caret_slope_run;
		fword	caret_offset;
		int16	reserved[4],
			metric_data_format;
		uint16	num_long_hor_metrics;
	};
	
	struct MaximumProfile
	{
		fixed	version;
		uint16	num_glyphs,
			max_points,
			max_contours,
			max_component_points,
			max_component_contours,
			max_zones,
			max_twilight_points,
			max_storage,
			max_function_defs,
			max_instruction_defs,
			max_stack_elements,
			max_size_of_instructions,
			max_component_elements,
			max_component_depth;
	};


	typedef gr::byte	Panose[10];

	struct Compatibility0
	{
		uint16	version;
		int16	x_avg_char_width;
		uint16	weight_class,
			width_class;
		int16	fs_type,
			y_subscript_x_size,
			y_subscript_y_size,
			y_subscript_x_offset,
			y_subscript_y_offset,
			y_superscript_x_size,
			y_superscript_y_size,
			y_superscript_x_offset,
			y_superscript_y_offset,
			y_strikeout_size,
			y_strikeout_position,
			family_class;
		Panose	panose;
		uint32	unicode_range[4];
		int8	ach_vend_id[4];
		uint16	fs_selection,
			fs_first_char_index,
			fs_last_char_index,	// Acording to Apple's spec this is where v0 should end
			typo_ascender,
			typo_descender,
			type_linegap,
			win_ascent,
			win_descent;
		
		enum 
		{
			Italic    =0x01, 
			Underscore=0x02, 
			Negative  =0x04, 
			Outlined  =0x08, 
			StrikeOut =0x10, 
			Bold      =0x20
		};
	};
	
	struct Compatibility1 : Compatibility0
	{
		uint32	codepage_range[2];
	};
	
	struct Compatibility2 : Compatibility1
	{
    		int16	x_height,
    			cap_height;
    		uint16	default_char,
    			break_char,
    			max_context;
	};
	
	struct Compatibility3 : Compatibility2 {};
	
	typedef Compatibility3	Compatibility;
	
	
	struct NameRecord
	{
		uint16	platform_id,
			platform_specific_id,
			language_id,
			name_id,
			length,
			offset;
		enum	{Unicode, Mactintosh, Reserved, Microsoft};
		enum	
		{
			Copyright, Family, Subfamily, UniqueSubfamily, 
			Fullname, Version, PostScript
		};
	};
	
	struct FontNames
	{
		uint16	format,
			count,
			string_offset;
		NameRecord name_record[1];
	};
	
	
	struct HorizontalMetric
	{
		uint16	advance_width;
		int16	left_side_bearing;
	};
	
	
	struct Glyph
	{
		int16	number_of_contours;
		fword	x_min,
			y_min,
			x_max,
			y_max;
	};
	
	struct SimpleGlyph : Glyph
	{
		uint16	end_pts_of_contours[1];
		enum 
		{
			OnCurve = 0x01,
			XShort  = 0x02,
			YShort  = 0x04,
			Repeat  = 0x08,
			XIsSame = 0x10,
			XIsPos  = 0x10,
			YIsSame = 0x20,
			YIsPos  = 0x20
		};
	};
	
	struct CompoundGlyph : Glyph
	{
		uint16	flags,
			glyph_index;
		enum 
		{
			Arg1Arg2Words   = 0x01,
			ArgsAreXYValues = 0x02,
			RoundXYToGrid   = 0x04,
			HaveScale       = 0x08,
			MoreComponents  = 0x20,
			HaveXAndYScale  = 0x40,
			HaveTwoByTwo    = 0x80,
			HaveInstructions = 0x100,
			UseMyMetrics    = 0x200,
			OverlapCompund  = 0x400,
			ScaledOffset    = 0x800,
			UnscaledOffset  = 0x1000
		};
	};

#pragma pack()
} // end of namespace Sfnt

} // end of namespace TtfUtil