1 /***************************************************************************/
5 /* Basic SFNT/TrueType tables definitions and interface */
6 /* (specification only). */
8 /* Copyright 1996-2015 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. */
61 /* FT_Get_Sfnt_Table */
62 /* FT_Load_Sfnt_Table */
63 /* FT_Sfnt_Table_Info */
65 /* FT_Get_CMap_Language_ID */
66 /* FT_Get_CMap_Format */
68 /* FT_PARAM_TAG_UNPATENTED_HINTING */
70 /*************************************************************************/
73 /*************************************************************************/
79 /* A structure used to model a TrueType font header table. All */
80 /* fields follow the TrueType specification. */
82 typedef struct TT_Header_
84 FT_Fixed Table_Version
;
85 FT_Fixed Font_Revision
;
87 FT_Long CheckSum_Adjust
;
91 FT_UShort Units_Per_EM
;
102 FT_UShort Lowest_Rec_PPEM
;
104 FT_Short Font_Direction
;
105 FT_Short Index_To_Loc_Format
;
106 FT_Short Glyph_Data_Format
;
111 /*************************************************************************/
117 /* A structure used to model a TrueType horizontal header, the `hhea' */
118 /* table, as well as the corresponding horizontal metrics table, */
119 /* i.e., the `hmtx' table. */
122 /* Version :: The table version. */
124 /* Ascender :: The font's ascender, i.e., the distance */
125 /* from the baseline to the top-most of all */
126 /* glyph points found in the font. */
128 /* This value is invalid in many fonts, as */
129 /* it is usually set by the font designer, */
130 /* and often reflects only a portion of the */
131 /* glyphs found in the font (maybe ASCII). */
133 /* You should use the `sTypoAscender' field */
134 /* of the OS/2 table instead if you want */
135 /* the correct one. */
137 /* Descender :: The font's descender, i.e., the distance */
138 /* from the baseline to the bottom-most of */
139 /* all glyph points found in the font. It */
142 /* This value is invalid in many fonts, as */
143 /* it is usually set by the font designer, */
144 /* and often reflects only a portion of the */
145 /* glyphs found in the font (maybe ASCII). */
147 /* You should use the `sTypoDescender' */
148 /* field of the OS/2 table instead if you */
149 /* want the correct one. */
151 /* Line_Gap :: The font's line gap, i.e., the distance */
152 /* to add to the ascender and descender to */
153 /* get the BTB, i.e., the */
154 /* baseline-to-baseline distance for the */
157 /* advance_Width_Max :: This field is the maximum of all advance */
158 /* widths found in the font. It can be */
159 /* used to compute the maximum width of an */
160 /* arbitrary string of text. */
162 /* min_Left_Side_Bearing :: The minimum left side bearing of all */
163 /* glyphs within the font. */
165 /* min_Right_Side_Bearing :: The minimum right side bearing of all */
166 /* glyphs within the font. */
168 /* xMax_Extent :: The maximum horizontal extent (i.e., the */
169 /* `width' of a glyph's bounding box) for */
170 /* all glyphs in the font. */
172 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
173 /* slope of the cursor (slope=rise/run). */
175 /* caret_Slope_Run :: The run coefficient of the cursor's */
178 /* Reserved :: 8~reserved bytes. */
180 /* metric_Data_Format :: Always~0. */
182 /* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */
183 /* table -- this value can be smaller than */
184 /* the total number of glyphs in the font. */
186 /* long_metrics :: A pointer into the `hmtx' table. */
188 /* short_metrics :: A pointer into the `hmtx' table. */
191 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
192 /* be identical except for the names of their fields, */
193 /* which are different. */
195 /* This ensures that a single function in the `ttload' */
196 /* module is able to read both the horizontal and vertical */
199 typedef struct TT_HoriHeader_
206 FT_UShort advance_Width_Max
; /* advance width maximum */
208 FT_Short min_Left_Side_Bearing
; /* minimum left-sb */
209 FT_Short min_Right_Side_Bearing
; /* minimum right-sb */
210 FT_Short xMax_Extent
; /* xmax extents */
211 FT_Short caret_Slope_Rise
;
212 FT_Short caret_Slope_Run
;
213 FT_Short caret_Offset
;
215 FT_Short Reserved
[4];
217 FT_Short metric_Data_Format
;
218 FT_UShort number_Of_HMetrics
;
220 /* The following fields are not defined by the TrueType specification */
221 /* but they are used to connect the metrics header to the relevant */
230 /*************************************************************************/
236 /* A structure used to model a TrueType vertical header, the `vhea' */
237 /* table, as well as the corresponding vertical metrics table, i.e., */
238 /* the `vmtx' table. */
241 /* Version :: The table version. */
243 /* Ascender :: The font's ascender, i.e., the distance */
244 /* from the baseline to the top-most of */
245 /* all glyph points found in the font. */
247 /* This value is invalid in many fonts, as */
248 /* it is usually set by the font designer, */
249 /* and often reflects only a portion of */
250 /* the glyphs found in the font (maybe */
253 /* You should use the `sTypoAscender' */
254 /* field of the OS/2 table instead if you */
255 /* want the correct one. */
257 /* Descender :: The font's descender, i.e., the */
258 /* distance from the baseline to the */
259 /* bottom-most of all glyph points found */
260 /* in the font. It is negative. */
262 /* This value is invalid in many fonts, as */
263 /* it is usually set by the font designer, */
264 /* and often reflects only a portion of */
265 /* the glyphs found in the font (maybe */
268 /* You should use the `sTypoDescender' */
269 /* field of the OS/2 table instead if you */
270 /* want the correct one. */
272 /* Line_Gap :: The font's line gap, i.e., the distance */
273 /* to add to the ascender and descender to */
274 /* get the BTB, i.e., the */
275 /* baseline-to-baseline distance for the */
278 /* advance_Height_Max :: This field is the maximum of all */
279 /* advance heights found in the font. It */
280 /* can be used to compute the maximum */
281 /* height of an arbitrary string of text. */
283 /* min_Top_Side_Bearing :: The minimum top side bearing of all */
284 /* glyphs within the font. */
286 /* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */
287 /* glyphs within the font. */
289 /* yMax_Extent :: The maximum vertical extent (i.e., the */
290 /* `height' of a glyph's bounding box) for */
291 /* all glyphs in the font. */
293 /* caret_Slope_Rise :: The rise coefficient of the cursor's */
294 /* slope of the cursor (slope=rise/run). */
296 /* caret_Slope_Run :: The run coefficient of the cursor's */
299 /* caret_Offset :: The cursor's offset for slanted fonts. */
300 /* This value is `reserved' in vmtx */
303 /* Reserved :: 8~reserved bytes. */
305 /* metric_Data_Format :: Always~0. */
307 /* number_Of_HMetrics :: Number of VMetrics entries in the */
308 /* `vmtx' table -- this value can be */
309 /* smaller than the total number of glyphs */
312 /* long_metrics :: A pointer into the `vmtx' table. */
314 /* short_metrics :: A pointer into the `vmtx' table. */
317 /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
318 /* be identical except for the names of their fields, */
319 /* which are different. */
321 /* This ensures that a single function in the `ttload' */
322 /* module is able to read both the horizontal and vertical */
325 typedef struct TT_VertHeader_
332 FT_UShort advance_Height_Max
; /* advance height maximum */
334 FT_Short min_Top_Side_Bearing
; /* minimum left-sb or top-sb */
335 FT_Short min_Bottom_Side_Bearing
; /* minimum right-sb or bottom-sb */
336 FT_Short yMax_Extent
; /* xmax or ymax extents */
337 FT_Short caret_Slope_Rise
;
338 FT_Short caret_Slope_Run
;
339 FT_Short caret_Offset
;
341 FT_Short Reserved
[4];
343 FT_Short metric_Data_Format
;
344 FT_UShort number_Of_VMetrics
;
346 /* The following fields are not defined by the TrueType specification */
347 /* but they're used to connect the metrics header to the relevant */
348 /* `HMTX' or `VMTX' table. */
356 /*************************************************************************/
362 /* A structure used to model a TrueType OS/2 table. All fields */
363 /* comply to the OpenType specification. */
365 /* Note that we now support old Mac fonts that do not include an OS/2 */
366 /* table. In this case, the `version' field is always set to 0xFFFF. */
368 typedef struct TT_OS2_
370 FT_UShort version
; /* 0x0001 - more or 0xFFFF */
371 FT_Short xAvgCharWidth
;
372 FT_UShort usWeightClass
;
373 FT_UShort usWidthClass
;
375 FT_Short ySubscriptXSize
;
376 FT_Short ySubscriptYSize
;
377 FT_Short ySubscriptXOffset
;
378 FT_Short ySubscriptYOffset
;
379 FT_Short ySuperscriptXSize
;
380 FT_Short ySuperscriptYSize
;
381 FT_Short ySuperscriptXOffset
;
382 FT_Short ySuperscriptYOffset
;
383 FT_Short yStrikeoutSize
;
384 FT_Short yStrikeoutPosition
;
385 FT_Short sFamilyClass
;
389 FT_ULong ulUnicodeRange1
; /* Bits 0-31 */
390 FT_ULong ulUnicodeRange2
; /* Bits 32-63 */
391 FT_ULong ulUnicodeRange3
; /* Bits 64-95 */
392 FT_ULong ulUnicodeRange4
; /* Bits 96-127 */
394 FT_Char achVendID
[4];
396 FT_UShort fsSelection
;
397 FT_UShort usFirstCharIndex
;
398 FT_UShort usLastCharIndex
;
399 FT_Short sTypoAscender
;
400 FT_Short sTypoDescender
;
401 FT_Short sTypoLineGap
;
402 FT_UShort usWinAscent
;
403 FT_UShort usWinDescent
;
405 /* only version 1 and higher: */
407 FT_ULong ulCodePageRange1
; /* Bits 0-31 */
408 FT_ULong ulCodePageRange2
; /* Bits 32-63 */
410 /* only version 2 and higher: */
414 FT_UShort usDefaultChar
;
415 FT_UShort usBreakChar
;
416 FT_UShort usMaxContext
;
418 /* only version 5 and higher: */
420 FT_UShort usLowerOpticalPointSize
; /* in twips (1/20th points) */
421 FT_UShort usUpperOpticalPointSize
; /* in twips (1/20th points) */
426 /*************************************************************************/
432 /* A structure used to model a TrueType PostScript table. All fields */
433 /* comply to the TrueType specification. This structure does not */
434 /* reference the PostScript glyph names, which can be nevertheless */
435 /* accessed with the `ttpost' module. */
437 typedef struct TT_Postscript_
440 FT_Fixed italicAngle
;
441 FT_Short underlinePosition
;
442 FT_Short underlineThickness
;
443 FT_ULong isFixedPitch
;
444 FT_ULong minMemType42
;
445 FT_ULong maxMemType42
;
446 FT_ULong minMemType1
;
447 FT_ULong maxMemType1
;
449 /* Glyph names follow in the file, but we don't */
450 /* load them by default. See the ttpost.c file. */
455 /*************************************************************************/
461 /* A structure used to model a TrueType PCLT table. All fields */
462 /* comply to the TrueType specification. */
464 typedef struct TT_PCLT_
471 FT_UShort TypeFamily
;
474 FT_Char TypeFace
[16];
475 FT_Char CharacterComplement
[8];
477 FT_Char StrokeWeight
;
485 /*************************************************************************/
491 /* The maximum profile is a table containing many max values, which */
492 /* can be used to pre-allocate arrays. This ensures that no memory */
493 /* allocation occurs during a glyph load. */
496 /* version :: The version number. */
498 /* numGlyphs :: The number of glyphs in this TrueType */
501 /* maxPoints :: The maximum number of points in a */
502 /* non-composite TrueType glyph. See also */
503 /* the structure element */
504 /* `maxCompositePoints'. */
506 /* maxContours :: The maximum number of contours in a */
507 /* non-composite TrueType glyph. See also */
508 /* the structure element */
509 /* `maxCompositeContours'. */
511 /* maxCompositePoints :: The maximum number of points in a */
512 /* composite TrueType glyph. See also the */
513 /* structure element `maxPoints'. */
515 /* maxCompositeContours :: The maximum number of contours in a */
516 /* composite TrueType glyph. See also the */
517 /* structure element `maxContours'. */
519 /* maxZones :: The maximum number of zones used for */
522 /* maxTwilightPoints :: The maximum number of points in the */
523 /* twilight zone used for glyph hinting. */
525 /* maxStorage :: The maximum number of elements in the */
526 /* storage area used for glyph hinting. */
528 /* maxFunctionDefs :: The maximum number of function */
529 /* definitions in the TrueType bytecode for */
532 /* maxInstructionDefs :: The maximum number of instruction */
533 /* definitions in the TrueType bytecode for */
536 /* maxStackElements :: The maximum number of stack elements used */
537 /* during bytecode interpretation. */
539 /* maxSizeOfInstructions :: The maximum number of TrueType opcodes */
540 /* used for glyph hinting. */
542 /* maxComponentElements :: The maximum number of simple (i.e., non- */
543 /* composite) glyphs in a composite glyph. */
545 /* maxComponentDepth :: The maximum nesting depth of composite */
549 /* This structure is only used during font loading. */
551 typedef struct TT_MaxProfile_
556 FT_UShort maxContours
;
557 FT_UShort maxCompositePoints
;
558 FT_UShort maxCompositeContours
;
560 FT_UShort maxTwilightPoints
;
561 FT_UShort maxStorage
;
562 FT_UShort maxFunctionDefs
;
563 FT_UShort maxInstructionDefs
;
564 FT_UShort maxStackElements
;
565 FT_UShort maxSizeOfInstructions
;
566 FT_UShort maxComponentElements
;
567 FT_UShort maxComponentDepth
;
572 /*************************************************************************/
578 /* An enumeration used to specify the index of an SFNT table. */
579 /* Used in the @FT_Get_Sfnt_Table API function. */
582 /* FT_SFNT_HEAD :: To access the font's @TT_Header structure. */
584 /* FT_SFNT_MAXP :: To access the font's @TT_MaxProfile structure. */
586 /* FT_SFNT_OS2 :: To access the font's @TT_OS2 structure. */
588 /* FT_SFNT_HHEA :: To access the font's @TT_HoriHeader structure. */
590 /* FT_SFNT_VHEA :: To access the font's @TT_VertHeader struture. */
592 /* FT_SFNT_POST :: To access the font's @TT_Postscript structure. */
594 /* FT_SFNT_PCLT :: To access the font's @TT_PCLT structure. */
596 typedef enum FT_Sfnt_Tag_
610 /* these constants are deprecated; use the corresponding `FT_Sfnt_Tag' */
612 #define ft_sfnt_head FT_SFNT_HEAD
613 #define ft_sfnt_maxp FT_SFNT_MAXP
614 #define ft_sfnt_os2 FT_SFNT_OS2
615 #define ft_sfnt_hhea FT_SFNT_HHEA
616 #define ft_sfnt_vhea FT_SFNT_VHEA
617 #define ft_sfnt_post FT_SFNT_POST
618 #define ft_sfnt_pclt FT_SFNT_PCLT
621 /*************************************************************************/
624 /* FT_Get_Sfnt_Table */
627 /* Return a pointer to a given SFNT table within a face. */
630 /* face :: A handle to the source. */
632 /* tag :: The index of the SFNT table. */
635 /* A type-less pointer to the table. This will be~0 in case of */
636 /* error, or if the corresponding table was not found *OR* loaded */
639 /* Use a typecast according to `tag' to access the structure */
643 /* The table is owned by the face object and disappears with it. */
645 /* This function is only useful to access SFNT tables that are loaded */
646 /* by the sfnt, truetype, and opentype drivers. See @FT_Sfnt_Tag for */
649 /* Here an example how to access the `vhea' table: */
652 /* TT_VertHeader* vert_header; */
656 /* (TT_VertHeader*)FT_Get_Sfnt_Table( face, FT_SFNT_VHEA ); */
660 FT_Get_Sfnt_Table( FT_Face face
,
664 /**************************************************************************
670 * Load any font table into client memory.
674 * A handle to the source face.
677 * The four-byte tag of the table to load. Use the value~0 if you want
678 * to access the whole font file. Otherwise, you can use one of the
679 * definitions found in the @FT_TRUETYPE_TAGS_H file, or forge a new
680 * one with @FT_MAKE_TAG.
683 * The starting offset in the table (or file if tag == 0).
687 * The target buffer address. The client must ensure that the memory
688 * array is big enough to hold the data.
692 * If the `length' parameter is NULL, then try to load the whole table.
693 * Return an error code if it fails.
695 * Else, if `*length' is~0, exit immediately while returning the
696 * table's (or file) full size in it.
698 * Else the number of bytes to read from the table or file, from the
702 * FreeType error code. 0~means success.
705 * If you need to determine the table's length you should first call this
706 * function with `*length' set to~0, as in the following example:
709 * FT_ULong length = 0;
712 * error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length );
713 * if ( error ) { ... table does not exist ... }
715 * buffer = malloc( length );
716 * if ( buffer == NULL ) { ... not enough memory ... }
718 * error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length );
719 * if ( error ) { ... could not load table ... }
722 * Note that structures like @TT_Header or @TT_OS2 can't be used with
723 * this function; they are limited to @FT_Get_Sfnt_Table. Reason is that
724 * those structures depend on the processor architecture, with varying
725 * size (e.g. 32bit vs. 64bit) or order (big endian vs. little endian).
728 FT_EXPORT( FT_Error
)
729 FT_Load_Sfnt_Table( FT_Face face
,
736 /**************************************************************************
742 * Return information on an SFNT table.
746 * A handle to the source face.
749 * The index of an SFNT table. The function returns
750 * FT_Err_Table_Missing for an invalid value.
754 * The name tag of the SFNT table. If the value is NULL, `table_index'
755 * is ignored, and `length' returns the number of SFNT tables in the
760 * The length of the SFNT table (or the number of SFNT tables, depending
764 * FreeType error code. 0~means success.
767 * While parsing fonts, FreeType handles SFNT tables with length zero as
771 FT_EXPORT( FT_Error
)
772 FT_Sfnt_Table_Info( FT_Face face
,
778 /*************************************************************************/
781 /* FT_Get_CMap_Language_ID */
784 /* Return TrueType/sfnt specific cmap language ID. Definitions of */
785 /* language ID values are in `ttnameid.h'. */
789 /* The target charmap. */
792 /* The language ID of `charmap'. If `charmap' doesn't belong to a */
793 /* TrueType/sfnt face, just return~0 as the default value. */
795 /* For a format~14 cmap (to access Unicode IVS), the return value is */
798 FT_EXPORT( FT_ULong
)
799 FT_Get_CMap_Language_ID( FT_CharMap charmap
);
802 /*************************************************************************/
805 /* FT_Get_CMap_Format */
808 /* Return TrueType/sfnt specific cmap format. */
812 /* The target charmap. */
815 /* The format of `charmap'. If `charmap' doesn't belong to a */
816 /* TrueType/sfnt face, return -1. */
819 FT_Get_CMap_Format( FT_CharMap charmap
);
826 #endif /* __TTTABLES_H__ */