1 /***************************************************************************/
5 /* Basic SFNT/TrueType tables definitions and interface */
6 /* (specification only). */
8 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2008, 2009 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
17 /***************************************************************************/
20 #ifndef __TTTABLES_H__
21 #define __TTTABLES_H__
25 #include FT_FREETYPE_H
28 #error "freetype.h of FreeType 1 has been loaded!"
29 #error "Please fix the directory search order for header files"
30 #error "so that freetype.h of FreeType 2 is found first."
36 /*************************************************************************/
45 /* TrueType specific table types and functions. */
48 /* This section contains the definition of TrueType-specific tables */
49 /* as well as some routines used to access and process them. */
51 /*************************************************************************/
54 /*************************************************************************/
60 /* A structure used to model a TrueType font header table. All */
61 /* fields follow the TrueType specification. */
63 typedef struct TT_Header_
65 FT_Fixed Table_Version
;
66 FT_Fixed Font_Revision
;
68 FT_Long CheckSum_Adjust
;
72 FT_UShort Units_Per_EM
;
83 FT_UShort Lowest_Rec_PPEM
;
85 FT_Short Font_Direction
;
86 FT_Short Index_To_Loc_Format
;
87 FT_Short Glyph_Data_Format
;
92 /*************************************************************************/
98 /* A structure used to model a TrueType horizontal header, the `hhea' */
99 /* table, as well as the corresponding horizontal metrics table, */
100 /* i.e., the `hmtx' table. */
103 /* Version :: The table version. */
105 /* Ascender :: The font's ascender, i.e., the distance */
106 /* from the baseline to the top-most of all */
107 /* glyph points found in the font. */
109 /* This value is invalid in many fonts, as */
110 /* it is usually set by the font designer, */
111 /* and often reflects only a portion of the */
112 /* glyphs found in the font (maybe ASCII). */
114 /* You should use the `sTypoAscender' field */
115 /* of the OS/2 table instead if you want */
116 /* the correct one. */
118 /* Descender :: The font's descender, i.e., the distance */
119 /* from the baseline to the bottom-most of */
120 /* all glyph points found in the font. It */
123 /* This value is invalid in many fonts, as */
124 /* it is usually set by the font designer, */
125 /* and often reflects only a portion of the */
126 /* glyphs found in the font (maybe ASCII). */
128 /* You should use the `sTypoDescender' */
129 /* field of the OS/2 table instead if you */
130 /* want the correct one. */
132 /* Line_Gap :: The font's line gap, i.e., the distance */
133 /* to add to the ascender and descender to */
134 /* get the BTB, i.e., the */
135 /* baseline-to-baseline distance for the */
138 /* advance_Width_Max :: This field is the maximum of all advance */
139 /* widths found in the font. It can be */
140 /* used to compute the maximum width of an */
141 /* arbitrary string of text. */
143 /* min_Left_Side_Bearing :: The minimum left side bearing of all */
144 /* glyphs within the font. */
146 /* min_Right_Side_Bearing :: The minimum right side bearing of all */
147 /* glyphs within the font. */
149 /* xMax_Extent :: The maximum horizontal extent (i.e., the */
150 /* `width' of a glyph's bounding box) for */
151 /* all glyphs in the font. */
153 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
154 /* slope of the cursor (slope=rise/run). */
156 /* caret_Slope_Run :: The run coefficient of the cursor's */
159 /* Reserved :: 8~reserved bytes. */
161 /* metric_Data_Format :: Always~0. */
163 /* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */
164 /* table -- this value can be smaller than */
165 /* the total number of glyphs in the font. */
167 /* long_metrics :: A pointer into the `hmtx' table. */
169 /* short_metrics :: A pointer into the `hmtx' table. */
172 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
173 /* be identical except for the names of their fields which */
176 /* This ensures that a single function in the `ttload' */
177 /* module is able to read both the horizontal and vertical */
180 typedef struct TT_HoriHeader_
187 FT_UShort advance_Width_Max
; /* advance width maximum */
189 FT_Short min_Left_Side_Bearing
; /* minimum left-sb */
190 FT_Short min_Right_Side_Bearing
; /* minimum right-sb */
191 FT_Short xMax_Extent
; /* xmax extents */
192 FT_Short caret_Slope_Rise
;
193 FT_Short caret_Slope_Run
;
194 FT_Short caret_Offset
;
196 FT_Short Reserved
[4];
198 FT_Short metric_Data_Format
;
199 FT_UShort number_Of_HMetrics
;
201 /* The following fields are not defined by the TrueType specification */
202 /* but they are used to connect the metrics header to the relevant */
211 /*************************************************************************/
217 /* A structure used to model a TrueType vertical header, the `vhea' */
218 /* table, as well as the corresponding vertical metrics table, i.e., */
219 /* the `vmtx' table. */
222 /* Version :: The table version. */
224 /* Ascender :: The font's ascender, i.e., the distance */
225 /* from the baseline to the top-most of */
226 /* all glyph points found in the font. */
228 /* This value is invalid in many fonts, as */
229 /* it is usually set by the font designer, */
230 /* and often reflects only a portion of */
231 /* the glyphs found in the font (maybe */
234 /* You should use the `sTypoAscender' */
235 /* field of the OS/2 table instead if you */
236 /* want the correct one. */
238 /* Descender :: The font's descender, i.e., the */
239 /* distance from the baseline to the */
240 /* bottom-most of all glyph points found */
241 /* in the font. It is negative. */
243 /* This value is invalid in many fonts, as */
244 /* it is usually set by the font designer, */
245 /* and often reflects only a portion of */
246 /* the glyphs found in the font (maybe */
249 /* You should use the `sTypoDescender' */
250 /* field of the OS/2 table instead if you */
251 /* want the correct one. */
253 /* Line_Gap :: The font's line gap, i.e., the distance */
254 /* to add to the ascender and descender to */
255 /* get the BTB, i.e., the */
256 /* baseline-to-baseline distance for the */
259 /* advance_Height_Max :: This field is the maximum of all */
260 /* advance heights found in the font. It */
261 /* can be used to compute the maximum */
262 /* height of an arbitrary string of text. */
264 /* min_Top_Side_Bearing :: The minimum top side bearing of all */
265 /* glyphs within the font. */
267 /* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */
268 /* glyphs within the font. */
270 /* yMax_Extent :: The maximum vertical extent (i.e., the */
271 /* `height' of a glyph's bounding box) for */
272 /* all glyphs in the font. */
274 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
275 /* slope of the cursor (slope=rise/run). */
277 /* caret_Slope_Run :: The run coefficient of the cursor's */
280 /* caret_Offset :: The cursor's offset for slanted fonts. */
281 /* This value is `reserved' in vmtx */
284 /* Reserved :: 8~reserved bytes. */
286 /* metric_Data_Format :: Always~0. */
288 /* number_Of_HMetrics :: Number of VMetrics entries in the */
289 /* `vmtx' table -- this value can be */
290 /* smaller than the total number of glyphs */
293 /* long_metrics :: A pointer into the `vmtx' table. */
295 /* short_metrics :: A pointer into the `vmtx' table. */
298 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
299 /* be identical except for the names of their fields which */
302 /* This ensures that a single function in the `ttload' */
303 /* module is able to read both the horizontal and vertical */
306 typedef struct TT_VertHeader_
313 FT_UShort advance_Height_Max
; /* advance height maximum */
315 FT_Short min_Top_Side_Bearing
; /* minimum left-sb or top-sb */
316 FT_Short min_Bottom_Side_Bearing
; /* minimum right-sb or bottom-sb */
317 FT_Short yMax_Extent
; /* xmax or ymax extents */
318 FT_Short caret_Slope_Rise
;
319 FT_Short caret_Slope_Run
;
320 FT_Short caret_Offset
;
322 FT_Short Reserved
[4];
324 FT_Short metric_Data_Format
;
325 FT_UShort number_Of_VMetrics
;
327 /* The following fields are not defined by the TrueType specification */
328 /* but they're used to connect the metrics header to the relevant */
329 /* `HMTX' or `VMTX' table. */
337 /*************************************************************************/
343 /* A structure used to model a TrueType OS/2 table. This is the long */
344 /* table version. All fields comply to the TrueType specification. */
346 /* Note that we now support old Mac fonts which do not include an */
347 /* OS/2 table. In this case, the `version' field is always set to */
350 typedef struct TT_OS2_
352 FT_UShort version
; /* 0x0001 - more or 0xFFFF */
353 FT_Short xAvgCharWidth
;
354 FT_UShort usWeightClass
;
355 FT_UShort usWidthClass
;
357 FT_Short ySubscriptXSize
;
358 FT_Short ySubscriptYSize
;
359 FT_Short ySubscriptXOffset
;
360 FT_Short ySubscriptYOffset
;
361 FT_Short ySuperscriptXSize
;
362 FT_Short ySuperscriptYSize
;
363 FT_Short ySuperscriptXOffset
;
364 FT_Short ySuperscriptYOffset
;
365 FT_Short yStrikeoutSize
;
366 FT_Short yStrikeoutPosition
;
367 FT_Short sFamilyClass
;
371 FT_ULong ulUnicodeRange1
; /* Bits 0-31 */
372 FT_ULong ulUnicodeRange2
; /* Bits 32-63 */
373 FT_ULong ulUnicodeRange3
; /* Bits 64-95 */
374 FT_ULong ulUnicodeRange4
; /* Bits 96-127 */
376 FT_Char achVendID
[4];
378 FT_UShort fsSelection
;
379 FT_UShort usFirstCharIndex
;
380 FT_UShort usLastCharIndex
;
381 FT_Short sTypoAscender
;
382 FT_Short sTypoDescender
;
383 FT_Short sTypoLineGap
;
384 FT_UShort usWinAscent
;
385 FT_UShort usWinDescent
;
387 /* only version 1 tables: */
389 FT_ULong ulCodePageRange1
; /* Bits 0-31 */
390 FT_ULong ulCodePageRange2
; /* Bits 32-63 */
392 /* only version 2 tables: */
396 FT_UShort usDefaultChar
;
397 FT_UShort usBreakChar
;
398 FT_UShort usMaxContext
;
403 /*************************************************************************/
409 /* A structure used to model a TrueType PostScript table. All fields */
410 /* comply to the TrueType specification. This structure does not */
411 /* reference the PostScript glyph names, which can be nevertheless */
412 /* accessed with the `ttpost' module. */
414 typedef struct TT_Postscript_
417 FT_Fixed italicAngle
;
418 FT_Short underlinePosition
;
419 FT_Short underlineThickness
;
420 FT_ULong isFixedPitch
;
421 FT_ULong minMemType42
;
422 FT_ULong maxMemType42
;
423 FT_ULong minMemType1
;
424 FT_ULong maxMemType1
;
426 /* Glyph names follow in the file, but we don't */
427 /* load them by default. See the ttpost.c file. */
432 /*************************************************************************/
438 /* A structure used to model a TrueType PCLT table. All fields */
439 /* comply to the TrueType specification. */
441 typedef struct TT_PCLT_
448 FT_UShort TypeFamily
;
451 FT_Char TypeFace
[16];
452 FT_Char CharacterComplement
[8];
454 FT_Char StrokeWeight
;
462 /*************************************************************************/
468 /* The maximum profile is a table containing many max values which */
469 /* can be used to pre-allocate arrays. This ensures that no memory */
470 /* allocation occurs during a glyph load. */
473 /* version :: The version number. */
475 /* numGlyphs :: The number of glyphs in this TrueType */
478 /* maxPoints :: The maximum number of points in a */
479 /* non-composite TrueType glyph. See also */
480 /* the structure element */
481 /* `maxCompositePoints'. */
483 /* maxContours :: The maximum number of contours in a */
484 /* non-composite TrueType glyph. See also */
485 /* the structure element */
486 /* `maxCompositeContours'. */
488 /* maxCompositePoints :: The maximum number of points in a */
489 /* composite TrueType glyph. See also the */
490 /* structure element `maxPoints'. */
492 /* maxCompositeContours :: The maximum number of contours in a */
493 /* composite TrueType glyph. See also the */
494 /* structure element `maxContours'. */
496 /* maxZones :: The maximum number of zones used for */
499 /* maxTwilightPoints :: The maximum number of points in the */
500 /* twilight zone used for glyph hinting. */
502 /* maxStorage :: The maximum number of elements in the */
503 /* storage area used for glyph hinting. */
505 /* maxFunctionDefs :: The maximum number of function */
506 /* definitions in the TrueType bytecode for */
509 /* maxInstructionDefs :: The maximum number of instruction */
510 /* definitions in the TrueType bytecode for */
513 /* maxStackElements :: The maximum number of stack elements used */
514 /* during bytecode interpretation. */
516 /* maxSizeOfInstructions :: The maximum number of TrueType opcodes */
517 /* used for glyph hinting. */
519 /* maxComponentElements :: The maximum number of simple (i.e., non- */
520 /* composite) glyphs in a composite glyph. */
522 /* maxComponentDepth :: The maximum nesting depth of composite */
526 /* This structure is only used during font loading. */
528 typedef struct TT_MaxProfile_
533 FT_UShort maxContours
;
534 FT_UShort maxCompositePoints
;
535 FT_UShort maxCompositeContours
;
537 FT_UShort maxTwilightPoints
;
538 FT_UShort maxStorage
;
539 FT_UShort maxFunctionDefs
;
540 FT_UShort maxInstructionDefs
;
541 FT_UShort maxStackElements
;
542 FT_UShort maxSizeOfInstructions
;
543 FT_UShort maxComponentElements
;
544 FT_UShort maxComponentDepth
;
549 /*************************************************************************/
555 /* An enumeration used to specify the index of an SFNT table. */
556 /* Used in the @FT_Get_Sfnt_Table API function. */
558 typedef enum FT_Sfnt_Tag_
568 sfnt_max
/* internal end mark */
575 /*************************************************************************/
578 /* FT_Get_Sfnt_Table */
581 /* Return a pointer to a given SFNT table within a face. */
584 /* face :: A handle to the source. */
586 /* tag :: The index of the SFNT table. */
589 /* A type-less pointer to the table. This will be~0 in case of */
590 /* error, or if the corresponding table was not found *OR* loaded */
594 /* The table is owned by the face object and disappears with it. */
596 /* This function is only useful to access SFNT tables that are loaded */
597 /* by the sfnt, truetype, and opentype drivers. See @FT_Sfnt_Tag for */
601 FT_Get_Sfnt_Table( FT_Face face
,
605 /**************************************************************************
611 * Load any font table into client memory.
615 * A handle to the source face.
618 * The four-byte tag of the table to load. Use the value~0 if you want
619 * to access the whole font file. Otherwise, you can use one of the
620 * definitions found in the @FT_TRUETYPE_TAGS_H file, or forge a new
621 * one with @FT_MAKE_TAG.
624 * The starting offset in the table (or file if tag == 0).
628 * The target buffer address. The client must ensure that the memory
629 * array is big enough to hold the data.
633 * If the `length' parameter is NULL, then try to load the whole table.
634 * Return an error code if it fails.
636 * Else, if `*length' is~0, exit immediately while returning the
637 * table's (or file) full size in it.
639 * Else the number of bytes to read from the table or file, from the
643 * FreeType error code. 0~means success.
646 * If you need to determine the table's length you should first call this
647 * function with `*length' set to~0, as in the following example:
650 * FT_ULong length = 0;
653 * error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length );
654 * if ( error ) { ... table does not exist ... }
656 * buffer = malloc( length );
657 * if ( buffer == NULL ) { ... not enough memory ... }
659 * error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length );
660 * if ( error ) { ... could not load table ... }
663 FT_EXPORT( FT_Error
)
664 FT_Load_Sfnt_Table( FT_Face face
,
671 /**************************************************************************
677 * Return information on an SFNT table.
681 * A handle to the source face.
684 * The index of an SFNT table. The function returns
685 * FT_Err_Table_Missing for an invalid value.
689 * The name tag of the SFNT table.
692 * The length of the SFNT table.
695 * FreeType error code. 0~means success.
698 * SFNT tables with length zero are treated as missing.
701 FT_EXPORT( FT_Error
)
702 FT_Sfnt_Table_Info( FT_Face face
,
708 /*************************************************************************/
711 /* FT_Get_CMap_Language_ID */
714 /* Return TrueType/sfnt specific cmap language ID. Definitions of */
715 /* language ID values are in `freetype/ttnameid.h'. */
719 /* The target charmap. */
722 /* The language ID of `charmap'. If `charmap' doesn't belong to a */
723 /* TrueType/sfnt face, just return~0 as the default value. */
725 FT_EXPORT( FT_ULong
)
726 FT_Get_CMap_Language_ID( FT_CharMap charmap
);
729 /*************************************************************************/
732 /* FT_Get_CMap_Format */
735 /* Return TrueType/sfnt specific cmap format. */
739 /* The target charmap. */
742 /* The format of `charmap'. If `charmap' doesn't belong to a */
743 /* TrueType/sfnt face, return -1. */
746 FT_Get_CMap_Format( FT_CharMap charmap
);
753 #endif /* __TTTABLES_H__ */