sfnt.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /***************************************************************************/
  2. /* */
  3. /* sfnt.h */
  4. /* */
  5. /* High-level `sfnt' driver interface (specification). */
  6. /* */
  7. /* Copyright 1996-2006, 2009, 2012-2013 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #ifndef __SFNT_H__
  18. #define __SFNT_H__
  19. #include <ft2build.h>
  20. #include FT_INTERNAL_DRIVER_H
  21. #include FT_INTERNAL_TRUETYPE_TYPES_H
  22. FT_BEGIN_HEADER
  23. /*************************************************************************/
  24. /* */
  25. /* <FuncType> */
  26. /* TT_Init_Face_Func */
  27. /* */
  28. /* <Description> */
  29. /* First part of the SFNT face object initialization. This finds */
  30. /* the face in a SFNT file or collection, and load its format tag in */
  31. /* face->format_tag. */
  32. /* */
  33. /* <Input> */
  34. /* stream :: The input stream. */
  35. /* */
  36. /* face :: A handle to the target face object. */
  37. /* */
  38. /* face_index :: The index of the TrueType font, if we are opening a */
  39. /* collection. */
  40. /* */
  41. /* num_params :: The number of additional parameters. */
  42. /* */
  43. /* params :: Optional additional parameters. */
  44. /* */
  45. /* <Return> */
  46. /* FreeType error code. 0 means success. */
  47. /* */
  48. /* <Note> */
  49. /* The stream cursor must be at the font file's origin. */
  50. /* */
  51. /* This function recognizes fonts embedded in a `TrueType */
  52. /* collection'. */
  53. /* */
  54. /* Once the format tag has been validated by the font driver, it */
  55. /* should then call the TT_Load_Face_Func() callback to read the rest */
  56. /* of the SFNT tables in the object. */
  57. /* */
  58. typedef FT_Error
  59. (*TT_Init_Face_Func)( FT_Stream stream,
  60. TT_Face face,
  61. FT_Int face_index,
  62. FT_Int num_params,
  63. FT_Parameter* params );
  64. /*************************************************************************/
  65. /* */
  66. /* <FuncType> */
  67. /* TT_Load_Face_Func */
  68. /* */
  69. /* <Description> */
  70. /* Second part of the SFNT face object initialization. This loads */
  71. /* the common SFNT tables (head, OS/2, maxp, metrics, etc.) in the */
  72. /* face object. */
  73. /* */
  74. /* <Input> */
  75. /* stream :: The input stream. */
  76. /* */
  77. /* face :: A handle to the target face object. */
  78. /* */
  79. /* face_index :: The index of the TrueType font, if we are opening a */
  80. /* collection. */
  81. /* */
  82. /* num_params :: The number of additional parameters. */
  83. /* */
  84. /* params :: Optional additional parameters. */
  85. /* */
  86. /* <Return> */
  87. /* FreeType error code. 0 means success. */
  88. /* */
  89. /* <Note> */
  90. /* This function must be called after TT_Init_Face_Func(). */
  91. /* */
  92. typedef FT_Error
  93. (*TT_Load_Face_Func)( FT_Stream stream,
  94. TT_Face face,
  95. FT_Int face_index,
  96. FT_Int num_params,
  97. FT_Parameter* params );
  98. /*************************************************************************/
  99. /* */
  100. /* <FuncType> */
  101. /* TT_Done_Face_Func */
  102. /* */
  103. /* <Description> */
  104. /* A callback used to delete the common SFNT data from a face. */
  105. /* */
  106. /* <Input> */
  107. /* face :: A handle to the target face object. */
  108. /* */
  109. /* <Note> */
  110. /* This function does NOT destroy the face object. */
  111. /* */
  112. typedef void
  113. (*TT_Done_Face_Func)( TT_Face face );
  114. /*************************************************************************/
  115. /* */
  116. /* <FuncType> */
  117. /* TT_Load_Any_Func */
  118. /* */
  119. /* <Description> */
  120. /* Load any font table into client memory. */
  121. /* */
  122. /* <Input> */
  123. /* face :: The face object to look for. */
  124. /* */
  125. /* tag :: The tag of table to load. Use the value 0 if you want */
  126. /* to access the whole font file, else set this parameter */
  127. /* to a valid TrueType table tag that you can forge with */
  128. /* the MAKE_TT_TAG macro. */
  129. /* */
  130. /* offset :: The starting offset in the table (or the file if */
  131. /* tag == 0). */
  132. /* */
  133. /* length :: The address of the decision variable: */
  134. /* */
  135. /* If length == NULL: */
  136. /* Loads the whole table. Returns an error if */
  137. /* `offset' == 0! */
  138. /* */
  139. /* If *length == 0: */
  140. /* Exits immediately; returning the length of the given */
  141. /* table or of the font file, depending on the value of */
  142. /* `tag'. */
  143. /* */
  144. /* If *length != 0: */
  145. /* Loads the next `length' bytes of table or font, */
  146. /* starting at offset `offset' (in table or font too). */
  147. /* */
  148. /* <Output> */
  149. /* buffer :: The address of target buffer. */
  150. /* */
  151. /* <Return> */
  152. /* TrueType error code. 0 means success. */
  153. /* */
  154. typedef FT_Error
  155. (*TT_Load_Any_Func)( TT_Face face,
  156. FT_ULong tag,
  157. FT_Long offset,
  158. FT_Byte *buffer,
  159. FT_ULong* length );
  160. /*************************************************************************/
  161. /* */
  162. /* <FuncType> */
  163. /* TT_Find_SBit_Image_Func */
  164. /* */
  165. /* <Description> */
  166. /* Check whether an embedded bitmap (an `sbit') exists for a given */
  167. /* glyph, at a given strike. */
  168. /* */
  169. /* <Input> */
  170. /* face :: The target face object. */
  171. /* */
  172. /* glyph_index :: The glyph index. */
  173. /* */
  174. /* strike_index :: The current strike index. */
  175. /* */
  176. /* <Output> */
  177. /* arange :: The SBit range containing the glyph index. */
  178. /* */
  179. /* astrike :: The SBit strike containing the glyph index. */
  180. /* */
  181. /* aglyph_offset :: The offset of the glyph data in `EBDT' table. */
  182. /* */
  183. /* <Return> */
  184. /* FreeType error code. 0 means success. Returns */
  185. /* SFNT_Err_Invalid_Argument if no sbit exists for the requested */
  186. /* glyph. */
  187. /* */
  188. typedef FT_Error
  189. (*TT_Find_SBit_Image_Func)( TT_Face face,
  190. FT_UInt glyph_index,
  191. FT_ULong strike_index,
  192. TT_SBit_Range *arange,
  193. TT_SBit_Strike *astrike,
  194. FT_ULong *aglyph_offset );
  195. /*************************************************************************/
  196. /* */
  197. /* <FuncType> */
  198. /* TT_Load_SBit_Metrics_Func */
  199. /* */
  200. /* <Description> */
  201. /* Get the big metrics for a given embedded bitmap. */
  202. /* */
  203. /* <Input> */
  204. /* stream :: The input stream. */
  205. /* */
  206. /* range :: The SBit range containing the glyph. */
  207. /* */
  208. /* <Output> */
  209. /* big_metrics :: A big SBit metrics structure for the glyph. */
  210. /* */
  211. /* <Return> */
  212. /* FreeType error code. 0 means success. */
  213. /* */
  214. /* <Note> */
  215. /* The stream cursor must be positioned at the glyph's offset within */
  216. /* the `EBDT' table before the call. */
  217. /* */
  218. /* If the image format uses variable metrics, the stream cursor is */
  219. /* positioned just after the metrics header in the `EBDT' table on */
  220. /* function exit. */
  221. /* */
  222. typedef FT_Error
  223. (*TT_Load_SBit_Metrics_Func)( FT_Stream stream,
  224. TT_SBit_Range range,
  225. TT_SBit_Metrics metrics );
  226. /*************************************************************************/
  227. /* */
  228. /* <FuncType> */
  229. /* TT_Load_SBit_Image_Func */
  230. /* */
  231. /* <Description> */
  232. /* Load a given glyph sbit image from the font resource. This also */
  233. /* returns its metrics. */
  234. /* */
  235. /* <Input> */
  236. /* face :: */
  237. /* The target face object. */
  238. /* */
  239. /* strike_index :: */
  240. /* The strike index. */
  241. /* */
  242. /* glyph_index :: */
  243. /* The current glyph index. */
  244. /* */
  245. /* load_flags :: */
  246. /* The current load flags. */
  247. /* */
  248. /* stream :: */
  249. /* The input stream. */
  250. /* */
  251. /* <Output> */
  252. /* amap :: */
  253. /* The target pixmap. */
  254. /* */
  255. /* ametrics :: */
  256. /* A big sbit metrics structure for the glyph image. */
  257. /* */
  258. /* <Return> */
  259. /* FreeType error code. 0 means success. Returns an error if no */
  260. /* glyph sbit exists for the index. */
  261. /* */
  262. /* <Note> */
  263. /* The `map.buffer' field is always freed before the glyph is loaded. */
  264. /* */
  265. typedef FT_Error
  266. (*TT_Load_SBit_Image_Func)( TT_Face face,
  267. FT_ULong strike_index,
  268. FT_UInt glyph_index,
  269. FT_UInt load_flags,
  270. FT_Stream stream,
  271. FT_Bitmap *amap,
  272. TT_SBit_MetricsRec *ametrics );
  273. /*************************************************************************/
  274. /* */
  275. /* <FuncType> */
  276. /* TT_Set_SBit_Strike_Func */
  277. /* */
  278. /* <Description> */
  279. /* Select an sbit strike for a given size request. */
  280. /* */
  281. /* <Input> */
  282. /* face :: The target face object. */
  283. /* */
  284. /* req :: The size request. */
  285. /* */
  286. /* <Output> */
  287. /* astrike_index :: The index of the sbit strike. */
  288. /* */
  289. /* <Return> */
  290. /* FreeType error code. 0 means success. Returns an error if no */
  291. /* sbit strike exists for the selected ppem values. */
  292. /* */
  293. typedef FT_Error
  294. (*TT_Set_SBit_Strike_Func)( TT_Face face,
  295. FT_Size_Request req,
  296. FT_ULong* astrike_index );
  297. /*************************************************************************/
  298. /* */
  299. /* <FuncType> */
  300. /* TT_Load_Strike_Metrics_Func */
  301. /* */
  302. /* <Description> */
  303. /* Load the metrics of a given strike. */
  304. /* */
  305. /* <Input> */
  306. /* face :: The target face object. */
  307. /* */
  308. /* strike_index :: The strike index. */
  309. /* */
  310. /* <Output> */
  311. /* metrics :: the metrics of the strike. */
  312. /* */
  313. /* <Return> */
  314. /* FreeType error code. 0 means success. Returns an error if no */
  315. /* such sbit strike exists. */
  316. /* */
  317. typedef FT_Error
  318. (*TT_Load_Strike_Metrics_Func)( TT_Face face,
  319. FT_ULong strike_index,
  320. FT_Size_Metrics* metrics );
  321. /*************************************************************************/
  322. /* */
  323. /* <FuncType> */
  324. /* TT_Get_PS_Name_Func */
  325. /* */
  326. /* <Description> */
  327. /* Get the PostScript glyph name of a glyph. */
  328. /* */
  329. /* <Input> */
  330. /* idx :: The glyph index. */
  331. /* */
  332. /* PSname :: The address of a string pointer. Will be NULL in case */
  333. /* of error, otherwise it is a pointer to the glyph name. */
  334. /* */
  335. /* You must not modify the returned string! */
  336. /* */
  337. /* <Output> */
  338. /* FreeType error code. 0 means success. */
  339. /* */
  340. typedef FT_Error
  341. (*TT_Get_PS_Name_Func)( TT_Face face,
  342. FT_UInt idx,
  343. FT_String** PSname );
  344. /*************************************************************************/
  345. /* */
  346. /* <FuncType> */
  347. /* TT_Load_Metrics_Func */
  348. /* */
  349. /* <Description> */
  350. /* Load a metrics table, which is a table with a horizontal and a */
  351. /* vertical version. */
  352. /* */
  353. /* <Input> */
  354. /* face :: A handle to the target face object. */
  355. /* */
  356. /* stream :: The input stream. */
  357. /* */
  358. /* vertical :: A boolean flag. If set, load the vertical one. */
  359. /* */
  360. /* <Return> */
  361. /* FreeType error code. 0 means success. */
  362. /* */
  363. typedef FT_Error
  364. (*TT_Load_Metrics_Func)( TT_Face face,
  365. FT_Stream stream,
  366. FT_Bool vertical );
  367. /*************************************************************************/
  368. /* */
  369. /* <FuncType> */
  370. /* TT_Get_Metrics_Func */
  371. /* */
  372. /* <Description> */
  373. /* Load the horizontal or vertical header in a face object. */
  374. /* */
  375. /* <Input> */
  376. /* face :: A handle to the target face object. */
  377. /* */
  378. /* stream :: The input stream. */
  379. /* */
  380. /* vertical :: A boolean flag. If set, load vertical metrics. */
  381. /* */
  382. /* <Return> */
  383. /* FreeType error code. 0 means success. */
  384. /* */
  385. typedef FT_Error
  386. (*TT_Get_Metrics_Func)( TT_Face face,
  387. FT_Bool vertical,
  388. FT_UInt gindex,
  389. FT_Short* abearing,
  390. FT_UShort* aadvance );
  391. /*************************************************************************/
  392. /* */
  393. /* <FuncType> */
  394. /* TT_Load_Table_Func */
  395. /* */
  396. /* <Description> */
  397. /* Load a given TrueType table. */
  398. /* */
  399. /* <Input> */
  400. /* face :: A handle to the target face object. */
  401. /* */
  402. /* stream :: The input stream. */
  403. /* */
  404. /* <Return> */
  405. /* FreeType error code. 0 means success. */
  406. /* */
  407. /* <Note> */
  408. /* The function uses `face->goto_table' to seek the stream to the */
  409. /* start of the table, except while loading the font directory. */
  410. /* */
  411. typedef FT_Error
  412. (*TT_Load_Table_Func)( TT_Face face,
  413. FT_Stream stream );
  414. /*************************************************************************/
  415. /* */
  416. /* <FuncType> */
  417. /* TT_Free_Table_Func */
  418. /* */
  419. /* <Description> */
  420. /* Free a given TrueType table. */
  421. /* */
  422. /* <Input> */
  423. /* face :: A handle to the target face object. */
  424. /* */
  425. typedef void
  426. (*TT_Free_Table_Func)( TT_Face face );
  427. /*
  428. * @functype:
  429. * TT_Face_GetKerningFunc
  430. *
  431. * @description:
  432. * Return the horizontal kerning value between two glyphs.
  433. *
  434. * @input:
  435. * face :: A handle to the source face object.
  436. * left_glyph :: The left glyph index.
  437. * right_glyph :: The right glyph index.
  438. *
  439. * @return:
  440. * The kerning value in font units.
  441. */
  442. typedef FT_Int
  443. (*TT_Face_GetKerningFunc)( TT_Face face,
  444. FT_UInt left_glyph,
  445. FT_UInt right_glyph );
  446. /*************************************************************************/
  447. /* */
  448. /* <Struct> */
  449. /* SFNT_Interface */
  450. /* */
  451. /* <Description> */
  452. /* This structure holds pointers to the functions used to load and */
  453. /* free the basic tables that are required in a `sfnt' font file. */
  454. /* */
  455. /* <Fields> */
  456. /* Check the various xxx_Func() descriptions for details. */
  457. /* */
  458. typedef struct SFNT_Interface_
  459. {
  460. TT_Loader_GotoTableFunc goto_table;
  461. TT_Init_Face_Func init_face;
  462. TT_Load_Face_Func load_face;
  463. TT_Done_Face_Func done_face;
  464. FT_Module_Requester get_interface;
  465. TT_Load_Any_Func load_any;
  466. /* these functions are called by `load_face' but they can also */
  467. /* be called from external modules, if there is a need to do so */
  468. TT_Load_Table_Func load_head;
  469. TT_Load_Metrics_Func load_hhea;
  470. TT_Load_Table_Func load_cmap;
  471. TT_Load_Table_Func load_maxp;
  472. TT_Load_Table_Func load_os2;
  473. TT_Load_Table_Func load_post;
  474. TT_Load_Table_Func load_name;
  475. TT_Free_Table_Func free_name;
  476. /* this field was called `load_kerning' up to version 2.1.10 */
  477. TT_Load_Table_Func load_kern;
  478. TT_Load_Table_Func load_gasp;
  479. TT_Load_Table_Func load_pclt;
  480. /* see `ttload.h'; this field was called `load_bitmap_header' up to */
  481. /* version 2.1.10 */
  482. TT_Load_Table_Func load_bhed;
  483. TT_Load_SBit_Image_Func load_sbit_image;
  484. /* see `ttpost.h' */
  485. TT_Get_PS_Name_Func get_psname;
  486. TT_Free_Table_Func free_psnames;
  487. /* starting here, the structure differs from version 2.1.7 */
  488. /* this field was introduced in version 2.1.8, named `get_psname' */
  489. TT_Face_GetKerningFunc get_kerning;
  490. /* new elements introduced after version 2.1.10 */
  491. /* load the font directory, i.e., the offset table and */
  492. /* the table directory */
  493. TT_Load_Table_Func load_font_dir;
  494. TT_Load_Metrics_Func load_hmtx;
  495. TT_Load_Table_Func load_eblc;
  496. TT_Free_Table_Func free_eblc;
  497. TT_Set_SBit_Strike_Func set_sbit_strike;
  498. TT_Load_Strike_Metrics_Func load_strike_metrics;
  499. TT_Get_Metrics_Func get_metrics;
  500. } SFNT_Interface;
  501. /* transitional */
  502. typedef SFNT_Interface* SFNT_Service;
  503. #ifndef FT_CONFIG_OPTION_PIC
  504. #define FT_DEFINE_SFNT_INTERFACE( \
  505. class_, \
  506. goto_table_, \
  507. init_face_, \
  508. load_face_, \
  509. done_face_, \
  510. get_interface_, \
  511. load_any_, \
  512. load_head_, \
  513. load_hhea_, \
  514. load_cmap_, \
  515. load_maxp_, \
  516. load_os2_, \
  517. load_post_, \
  518. load_name_, \
  519. free_name_, \
  520. load_kern_, \
  521. load_gasp_, \
  522. load_pclt_, \
  523. load_bhed_, \
  524. load_sbit_image_, \
  525. get_psname_, \
  526. free_psnames_, \
  527. get_kerning_, \
  528. load_font_dir_, \
  529. load_hmtx_, \
  530. load_eblc_, \
  531. free_eblc_, \
  532. set_sbit_strike_, \
  533. load_strike_metrics_, \
  534. get_metrics_ ) \
  535. static const SFNT_Interface class_ = \
  536. { \
  537. goto_table_, \
  538. init_face_, \
  539. load_face_, \
  540. done_face_, \
  541. get_interface_, \
  542. load_any_, \
  543. load_head_, \
  544. load_hhea_, \
  545. load_cmap_, \
  546. load_maxp_, \
  547. load_os2_, \
  548. load_post_, \
  549. load_name_, \
  550. free_name_, \
  551. load_kern_, \
  552. load_gasp_, \
  553. load_pclt_, \
  554. load_bhed_, \
  555. load_sbit_image_, \
  556. get_psname_, \
  557. free_psnames_, \
  558. get_kerning_, \
  559. load_font_dir_, \
  560. load_hmtx_, \
  561. load_eblc_, \
  562. free_eblc_, \
  563. set_sbit_strike_, \
  564. load_strike_metrics_, \
  565. get_metrics_, \
  566. };
  567. #else /* FT_CONFIG_OPTION_PIC */
  568. #define FT_INTERNAL( a, a_ ) \
  569. clazz->a = a_;
  570. #define FT_DEFINE_SFNT_INTERFACE( \
  571. class_, \
  572. goto_table_, \
  573. init_face_, \
  574. load_face_, \
  575. done_face_, \
  576. get_interface_, \
  577. load_any_, \
  578. load_head_, \
  579. load_hhea_, \
  580. load_cmap_, \
  581. load_maxp_, \
  582. load_os2_, \
  583. load_post_, \
  584. load_name_, \
  585. free_name_, \
  586. load_kern_, \
  587. load_gasp_, \
  588. load_pclt_, \
  589. load_bhed_, \
  590. load_sbit_image_, \
  591. get_psname_, \
  592. free_psnames_, \
  593. get_kerning_, \
  594. load_font_dir_, \
  595. load_hmtx_, \
  596. load_eblc_, \
  597. free_eblc_, \
  598. set_sbit_strike_, \
  599. load_strike_metrics_, \
  600. get_metrics_ ) \
  601. void \
  602. FT_Init_Class_ ## class_( FT_Library library, \
  603. SFNT_Interface* clazz ) \
  604. { \
  605. FT_UNUSED( library ); \
  606. \
  607. clazz->goto_table = goto_table_; \
  608. clazz->init_face = init_face_; \
  609. clazz->load_face = load_face_; \
  610. clazz->done_face = done_face_; \
  611. clazz->get_interface = get_interface_; \
  612. clazz->load_any = load_any_; \
  613. clazz->load_head = load_head_; \
  614. clazz->load_hhea = load_hhea_; \
  615. clazz->load_cmap = load_cmap_; \
  616. clazz->load_maxp = load_maxp_; \
  617. clazz->load_os2 = load_os2_; \
  618. clazz->load_post = load_post_; \
  619. clazz->load_name = load_name_; \
  620. clazz->free_name = free_name_; \
  621. clazz->load_kern = load_kern_; \
  622. clazz->load_gasp = load_gasp_; \
  623. clazz->load_pclt = load_pclt_; \
  624. clazz->load_bhed = load_bhed_; \
  625. clazz->load_sbit_image = load_sbit_image_; \
  626. clazz->get_psname = get_psname_; \
  627. clazz->free_psnames = free_psnames_; \
  628. clazz->get_kerning = get_kerning_; \
  629. clazz->load_font_dir = load_font_dir_; \
  630. clazz->load_hmtx = load_hmtx_; \
  631. clazz->load_eblc = load_eblc_; \
  632. clazz->free_eblc = free_eblc_; \
  633. clazz->set_sbit_strike = set_sbit_strike_; \
  634. clazz->load_strike_metrics = load_strike_metrics_; \
  635. clazz->get_metrics = get_metrics_; \
  636. }
  637. #endif /* FT_CONFIG_OPTION_PIC */
  638. FT_END_HEADER
  639. #endif /* __SFNT_H__ */
  640. /* END */