1 /***************************************************************************/
2 /* */
3 /* tttables.h */
4 /* */
5 /* Basic SFNT/TrueType tables definitions and interface */
6 /* (specification only). */
7 /* */
8 /* Copyright 1996-2001 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
16 /* */
17 /***************************************************************************/
20 #ifndef __TTTABLES_H__
21 #define __TTTABLES_H__
24 #include <ft2build.h>
25 #include FT_FREETYPE_H
28 FT_BEGIN_HEADER
30 /*************************************************************************/
31 /* */
32 /* <Section> */
33 /* truetype_tables */
34 /* */
35 /* <Title> */
36 /* TrueType Tables */
37 /* */
38 /* <Abstract> */
39 /* TrueType-specific table types and functions. */
40 /* */
41 /* <Description> */
42 /* This section contains the definition of TrueType-specific tables */
43 /* as well as some routines used to access and process them. */
44 /* */
45 /*************************************************************************/
48 /*************************************************************************/
49 /* */
50 /* <Struct> */
51 /* TT_Header */
52 /* */
53 /* <Description> */
54 /* A structure used to model a TrueType font header table. All */
55 /* fields follow the TrueType specification. */
56 /* */
57 typedef struct TT_Header_
58 {
59 FT_Fixed Table_Version;
60 FT_Fixed Font_Revision;
62 FT_Long CheckSum_Adjust;
63 FT_Long Magic_Number;
65 FT_UShort Flags;
66 FT_UShort Units_Per_EM;
68 FT_Long Created [2];
69 FT_Long Modified[2];
71 FT_Short xMin;
72 FT_Short yMin;
73 FT_Short xMax;
74 FT_Short yMax;
76 FT_UShort Mac_Style;
77 FT_UShort Lowest_Rec_PPEM;
79 FT_Short Font_Direction;
80 FT_Short Index_To_Loc_Format;
81 FT_Short Glyph_Data_Format;
83 } TT_Header;
86 /*************************************************************************/
87 /* */
88 /* <Struct> */
89 /* TT_HoriHeader */
90 /* */
91 /* <Description> */
92 /* A structure used to model a TrueType horizontal header, the `hhea' */
93 /* table, as well as the corresponding horizontal metrics table, */
94 /* i.e., the `hmtx' table. */
95 /* */
96 /* <Fields> */
97 /* Version :: The table version. */
98 /* */
99 /* Ascender :: The font's ascender, i.e., the distance */
100 /* from the baseline to the top-most of all */
101 /* glyph points found in the font. */
102 /* */
103 /* This value is invalid in many fonts, as */
104 /* it is usually set by the font designer, */
105 /* and often reflects only a portion of the */
106 /* glyphs found in the font (maybe ASCII). */
107 /* */
108 /* You should use the `sTypoAscender' field */
109 /* of the OS/2 table instead if you want */
110 /* the correct one. */
111 /* */
112 /* Descender :: The font's descender, i.e., the distance */
113 /* from the baseline to the bottom-most of */
114 /* all glyph points found in the font. It */
115 /* is negative. */
116 /* */
117 /* This value is invalid in many fonts, as */
118 /* it is usually set by the font designer, */
119 /* and often reflects only a portion of the */
120 /* glyphs found in the font (maybe ASCII). */
121 /* */
122 /* You should use the `sTypoDescender' */
123 /* field of the OS/2 table instead if you */
124 /* want the correct one. */
125 /* */
126 /* Line_Gap :: The font's line gap, i.e., the distance */
127 /* to add to the ascender and descender to */
128 /* get the BTB, i.e., the */
129 /* baseline-to-baseline distance for the */
130 /* font. */
131 /* */
132 /* advance_Width_Max :: This field is the maximum of all advance */
133 /* widths found in the font. It can be */
134 /* used to compute the maximum width of an */
135 /* arbitrary string of text. */
136 /* */
137 /* min_Left_Side_Bearing :: The minimum left side bearing of all */
138 /* glyphs within the font. */
139 /* */
140 /* min_Right_Side_Bearing :: The minimum right side bearing of all */
141 /* glyphs within the font. */
142 /* */
143 /* xMax_Extent :: The maximum horizontal extent (i.e., the */
144 /* `width' of a glyph's bounding box) for */
145 /* all glyphs in the font. */
146 /* */
147 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
148 /* slope of the cursor (slope=rise/run). */
149 /* */
150 /* caret_Slope_Run :: The run coefficient of the cursor's */
151 /* slope. */
152 /* */
153 /* Reserved :: 10 reserved bytes. */
154 /* */
155 /* metric_Data_Format :: Always 0. */
156 /* */
157 /* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */
158 /* table -- this value can be smaller than */
159 /* the total number of glyphs in the font. */
160 /* */
161 /* long_metrics :: A pointer into the `hmtx' table. */
162 /* */
163 /* short_metrics :: A pointer into the `hmtx' table. */
164 /* */
165 /* <Note> */
166 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
167 /* be identical except for the names of their fields which */
168 /* are different. */
169 /* */
170 /* This ensures that a single function in the `ttload' */
171 /* module is able to read both the horizontal and vertical */
172 /* headers. */
173 /* */
174 typedef struct TT_HoriHeader_
175 {
176 FT_Fixed Version;
177 FT_Short Ascender;
178 FT_Short Descender;
179 FT_Short Line_Gap;
181 FT_UShort advance_Width_Max; /* advance width maximum */
183 FT_Short min_Left_Side_Bearing; /* minimum left-sb */
184 FT_Short min_Right_Side_Bearing; /* minimum right-sb */
185 FT_Short xMax_Extent; /* xmax extents */
186 FT_Short caret_Slope_Rise;
187 FT_Short caret_Slope_Run;
188 FT_Short caret_Offset;
190 FT_Short Reserved[4];
192 FT_Short metric_Data_Format;
193 FT_UShort number_Of_HMetrics;
195 /* The following fields are not defined by the TrueType specification */
196 /* but they are used to connect the metrics header to the relevant */
197 /* `HMTX' table. */
199 void* long_metrics;
200 void* short_metrics;
202 } TT_HoriHeader;
205 /*************************************************************************/
206 /* */
207 /* <Struct> */
208 /* TT_VertHeader */
209 /* */
210 /* <Description> */
211 /* A structure used to model a TrueType vertical header, the `vhea' */
212 /* table, as well as the corresponding vertical metrics table, i.e., */
213 /* the `vmtx' table. */
214 /* */
215 /* <Fields> */
216 /* Version :: The table version. */
217 /* */
218 /* Ascender :: The font's ascender, i.e., the distance */
219 /* from the baseline to the top-most of */
220 /* all glyph points found in the font. */
221 /* */
222 /* This value is invalid in many fonts, as */
223 /* it is usually set by the font designer, */
224 /* and often reflects only a portion of */
225 /* the glyphs found in the font (maybe */
226 /* ASCII). */
227 /* */
228 /* You should use the `sTypoAscender' */
229 /* field of the OS/2 table instead if you */
230 /* want the correct one. */
231 /* */
232 /* Descender :: The font's descender, i.e., the */
233 /* distance from the baseline to the */
234 /* bottom-most of all glyph points found */
235 /* in the font. It is negative. */
236 /* */
237 /* This value is invalid in many fonts, as */
238 /* it is usually set by the font designer, */
239 /* and often reflects only a portion of */
240 /* the glyphs found in the font (maybe */
241 /* ASCII). */
242 /* */
243 /* You should use the `sTypoDescender' */
244 /* field of the OS/2 table instead if you */
245 /* want the correct one. */
246 /* */
247 /* Line_Gap :: The font's line gap, i.e., the distance */
248 /* to add to the ascender and descender to */
249 /* get the BTB, i.e., the */
250 /* baseline-to-baseline distance for the */
251 /* font. */
252 /* */
253 /* advance_Height_Max :: This field is the maximum of all */
254 /* advance heights found in the font. It */
255 /* can be used to compute the maximum */
256 /* height of an arbitrary string of text. */
257 /* */
258 /* min_Top_Side_Bearing :: The minimum top side bearing of all */
259 /* glyphs within the font. */
260 /* */
261 /* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */
262 /* glyphs within the font. */
263 /* */
264 /* yMax_Extent :: The maximum vertical extent (i.e., the */
265 /* `height' of a glyph's bounding box) for */
266 /* all glyphs in the font. */
267 /* */
268 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
269 /* slope of the cursor (slope=rise/run). */
270 /* */
271 /* caret_Slope_Run :: The run coefficient of the cursor's */
272 /* slope. */
273 /* */
274 /* caret_Offset :: The cursor's offset for slanted fonts. */
275 /* This value is `reserved' in vmtx */
276 /* version 1.0. */
277 /* */
278 /* Reserved :: 8 reserved bytes. */
279 /* */
280 /* metric_Data_Format :: Always 0. */
281 /* */
282 /* number_Of_HMetrics :: Number of VMetrics entries in the */
283 /* `vmtx' table -- this value can be */
284 /* smaller than the total number of glyphs */
285 /* in the font. */
286 /* */
287 /* long_metrics :: A pointer into the `vmtx' table. */
288 /* */
289 /* short_metrics :: A pointer into the `vmtx' table. */
290 /* */
291 /* <Note> */
292 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
293 /* be identical except for the names of their fields which */
294 /* are different. */
295 /* */
296 /* This ensures that a single function in the `ttload' */
297 /* module is able to read both the horizontal and vertical */
298 /* headers. */
299 /* */
300 typedef struct TT_VertHeader_
301 {
302 FT_Fixed Version;
303 FT_Short Ascender;
304 FT_Short Descender;
305 FT_Short Line_Gap;
307 FT_UShort advance_Height_Max; /* advance height maximum */
309 FT_Short min_Top_Side_Bearing; /* minimum left-sb or top-sb */
310 FT_Short min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */
311 FT_Short yMax_Extent; /* xmax or ymax extents */
312 FT_Short caret_Slope_Rise;
313 FT_Short caret_Slope_Run;
314 FT_Short caret_Offset;
316 FT_Short Reserved[4];
318 FT_Short metric_Data_Format;
319 FT_UShort number_Of_VMetrics;
321 /* The following fields are not defined by the TrueType specification */
322 /* but they're used to connect the metrics header to the relevant */
323 /* `HMTX' or `VMTX' table. */
325 void* long_metrics;
326 void* short_metrics;
328 } TT_VertHeader;
331 /*************************************************************************/
332 /* */
333 /* <Struct> */
334 /* TT_OS2 */
335 /* */
336 /* <Description> */
337 /* A structure used to model a TrueType OS/2 table. This is the long */
338 /* table version. All fields comply to the TrueType specification. */
339 /* */
340 /* Note that we now support old Mac fonts which do not include an */
341 /* OS/2 table. In this case, the `version' field is always set to */
342 /* 0xFFFF. */
343 /* */
344 typedef struct TT_OS2_
345 {
346 FT_UShort version; /* 0x0001 - more or 0xFFFF */
347 FT_Short xAvgCharWidth;
348 FT_UShort usWeightClass;
349 FT_UShort usWidthClass;
350 FT_Short fsType;
351 FT_Short ySubscriptXSize;
352 FT_Short ySubscriptYSize;
353 FT_Short ySubscriptXOffset;
354 FT_Short ySubscriptYOffset;
355 FT_Short ySuperscriptXSize;
356 FT_Short ySuperscriptYSize;
357 FT_Short ySuperscriptXOffset;
358 FT_Short ySuperscriptYOffset;
359 FT_Short yStrikeoutSize;
360 FT_Short yStrikeoutPosition;
361 FT_Short sFamilyClass;
363 FT_Byte panose[10];
365 FT_ULong ulUnicodeRange1; /* Bits 0-31 */
366 FT_ULong ulUnicodeRange2; /* Bits 32-63 */
367 FT_ULong ulUnicodeRange3; /* Bits 64-95 */
368 FT_ULong ulUnicodeRange4; /* Bits 96-127 */
370 FT_Char achVendID[4];
372 FT_UShort fsSelection;
373 FT_UShort usFirstCharIndex;
374 FT_UShort usLastCharIndex;
375 FT_Short sTypoAscender;
376 FT_Short sTypoDescender;
377 FT_Short sTypoLineGap;
378 FT_UShort usWinAscent;
379 FT_UShort usWinDescent;
381 /* only version 1 tables: */
383 FT_ULong ulCodePageRange1; /* Bits 0-31 */
384 FT_ULong ulCodePageRange2; /* Bits 32-63 */
386 /* only version 2 tables: */
388 FT_Short sxHeight;
389 FT_Short sCapHeight;
390 FT_UShort usDefaultChar;
391 FT_UShort usBreakChar;
392 FT_UShort usMaxContext;
394 } TT_OS2;
397 /*************************************************************************/
398 /* */
399 /* <Struct> */
400 /* TT_Postscript */
401 /* */
402 /* <Description> */
403 /* A structure used to model a TrueType Postscript table. All fields */
404 /* comply to the TrueType table. This structure does not reference */
405 /* the Postscript glyph names, which can be nevertheless accessed */
406 /* with the `ttpost' module. */
407 /* */
408 typedef struct TT_Postscript_
409 {
410 FT_Fixed FormatType;
411 FT_Fixed italicAngle;
412 FT_Short underlinePosition;
413 FT_Short underlineThickness;
414 FT_ULong isFixedPitch;
415 FT_ULong minMemType42;
416 FT_ULong maxMemType42;
417 FT_ULong minMemType1;
418 FT_ULong maxMemType1;
420 /* Glyph names follow in the file, but we don't */
421 /* load them by default. See the ttpost.c file. */
423 } TT_Postscript;
426 /*************************************************************************/
427 /* */
428 /* <Struct> */
429 /* TT_PCLT */
430 /* */
431 /* <Description> */
432 /* A structure used to model a TrueType PCLT table. All fields */
433 /* comply to the TrueType table. */
434 /* */
435 typedef struct TT_PCLT_
436 {
437 FT_Fixed Version;
438 FT_ULong FontNumber;
439 FT_UShort Pitch;
440 FT_UShort xHeight;
441 FT_UShort Style;
442 FT_UShort TypeFamily;
443 FT_UShort CapHeight;
444 FT_UShort SymbolSet;
445 FT_Char TypeFace[16];
446 FT_Char CharacterComplement[8];
447 FT_Char FileName[6];
448 FT_Char StrokeWeight;
449 FT_Char WidthType;
450 FT_Byte SerifStyle;
451 FT_Byte Reserved;
453 } TT_PCLT;
456 /*************************************************************************/
457 /* */
458 /* <Struct> */
459 /* TT_MaxProfile */
460 /* */
461 /* <Description> */
462 /* The maximum profile is a table containing many max values which */
463 /* can be used to pre-allocate arrays. This ensures that no memory */
464 /* allocation occurs during a glyph load. */
465 /* */
466 /* <Fields> */
467 /* version :: The version number. */
468 /* */
469 /* numGlyphs :: The number of glyphs in this TrueType */
470 /* font. */
471 /* */
472 /* maxPoints :: The maximum number of points in a */
473 /* non-composite TrueType glyph. See also */
474 /* the structure element */
475 /* `maxCompositePoints'. */
476 /* */
477 /* maxContours :: The maximum number of contours in a */
478 /* non-composite TrueType glyph. See also */
479 /* the structure element */
480 /* `maxCompositeContours'. */
481 /* */
482 /* maxCompositePoints :: The maximum number of points in a */
483 /* composite TrueType glyph. See also the */
484 /* structure element `maxPoints'. */
485 /* */
486 /* maxCompositeContours :: The maximum number of contours in a */
487 /* composite TrueType glyph. See also the */
488 /* structure element `maxContours'. */
489 /* */
490 /* maxZones :: The maximum number of zones used for */
491 /* glyph hinting. */
492 /* */
493 /* maxTwilightPoints :: The maximum number of points in the */
494 /* twilight zone used for glyph hinting. */
495 /* */
496 /* maxStorage :: The maximum number of elements in the */
497 /* storage area used for glyph hinting. */
498 /* */
499 /* maxFunctionDefs :: The maximum number of function */
500 /* definitions in the TrueType bytecode for */
501 /* this font. */
502 /* */
503 /* maxInstructionDefs :: The maximum number of instruction */
504 /* definitions in the TrueType bytecode for */
505 /* this font. */
506 /* */
507 /* maxStackElements :: The maximum number of stack elements used */
508 /* during bytecode interpretation. */
509 /* */
510 /* maxSizeOfInstructions :: The maximum number of TrueType opcodes */
511 /* used for glyph hinting. */
512 /* */
513 /* maxComponentElements :: An obscure value related to composite */
514 /* glyphs definitions. */
515 /* */
516 /* maxComponentDepth :: An obscure value related to composite */
517 /* glyphs definitions. Probably the maximum */
518 /* number of simple glyphs in a composite. */
519 /* */
520 /* <Note> */
521 /* This structure is only used during font loading. */
522 /* */
523 typedef struct TT_MaxProfile_
524 {
525 FT_Fixed version;
526 FT_UShort numGlyphs;
527 FT_UShort maxPoints;
528 FT_UShort maxContours;
529 FT_UShort maxCompositePoints;
530 FT_UShort maxCompositeContours;
531 FT_UShort maxZones;
532 FT_UShort maxTwilightPoints;
533 FT_UShort maxStorage;
534 FT_UShort maxFunctionDefs;
535 FT_UShort maxInstructionDefs;
536 FT_UShort maxStackElements;
537 FT_UShort maxSizeOfInstructions;
538 FT_UShort maxComponentElements;
539 FT_UShort maxComponentDepth;
541 } TT_MaxProfile;
544 /* */
546 typedef enum
547 {
548 ft_sfnt_head = 0,
549 ft_sfnt_maxp = 1,
550 ft_sfnt_os2 = 2,
551 ft_sfnt_hhea = 3,
552 ft_sfnt_vhea = 4,
553 ft_sfnt_post = 5,
554 ft_sfnt_pclt = 6,
556 sfnt_max /* don't remove */
558 } FT_Sfnt_Tag;
561 /* internal use only */
562 typedef void*
563 (*FT_Get_Sfnt_Table_Func)( FT_Face face,
564 FT_Sfnt_Tag tag );
567 /*************************************************************************/
568 /* */
569 /* <Function> */
570 /* FT_Get_Sfnt_Table */
571 /* */
572 /* <Description> */
573 /* Returns a pointer to a given SFNT table within a face. */
574 /* */
575 /* <Input> */
576 /* face :: A handle to the source. */
577 /* */
578 /* tag :: The index of the SFNT table. */
579 /* */
580 /* <Return> */
581 /* A type-less pointer to the table. This will be 0 in case of */
582 /* error, or if the corresponding table was not found *OR* loaded */
583 /* from the file. */
584 /* */
585 /* <Note> */
586 /* The table is owned by the face object and disappears with it. */
587 /* */
588 /* This function is only useful to access SFNT tables that are loaded */
589 /* by the sfnt/truetype/opentype drivers. See FT_Sfnt_Tag for a */
590 /* list. */
591 /* */
592 FT_EXPORT( void* )
593 FT_Get_Sfnt_Table( FT_Face face,
594 FT_Sfnt_Tag tag );
597 /* */
600 FT_END_HEADER
602 #endif /* __TTTABLES_H__ */
605 /* END */