tttables.h 34 KB

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