hb-ot-layout.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * Copyright © 2007,2008,2009 Red Hat, Inc.
  3. *
  4. * This is part of HarfBuzz, a text shaping library.
  5. *
  6. * Permission is hereby granted, without written agreement and without
  7. * license or royalty fees, to use, copy, modify, and distribute this
  8. * software and its documentation for any purpose, provided that the
  9. * above copyright notice and the following two paragraphs appear in
  10. * all copies of this software.
  11. *
  12. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  13. * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  14. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  15. * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  16. * DAMAGE.
  17. *
  18. * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  19. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  20. * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  21. * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  22. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  23. *
  24. * Red Hat Author(s): Behdad Esfahbod
  25. */
  26. #if !defined(HB_OT_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
  27. #error "Include <hb-ot.h> instead."
  28. #endif
  29. #ifndef HB_OT_LAYOUT_H
  30. #define HB_OT_LAYOUT_H
  31. #include "hb.h"
  32. #include "hb-ot-name.h"
  33. HB_BEGIN_DECLS
  34. /**
  35. * HB_OT_TAG_BASE:
  36. *
  37. * OpenType [Baseline Table](https://docs.microsoft.com/en-us/typography/opentype/spec/base).
  38. */
  39. #define HB_OT_TAG_BASE HB_TAG('B','A','S','E')
  40. /**
  41. * HB_OT_TAG_GDEF:
  42. *
  43. * OpenType [Glyph Definition Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef).
  44. */
  45. #define HB_OT_TAG_GDEF HB_TAG('G','D','E','F')
  46. /**
  47. * HB_OT_TAG_GSUB:
  48. *
  49. * OpenType [Glyph Substitution Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gsub).
  50. */
  51. #define HB_OT_TAG_GSUB HB_TAG('G','S','U','B')
  52. /**
  53. * HB_OT_TAG_GPOS:
  54. *
  55. * OpenType [Glyph Positioning Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos).
  56. */
  57. #define HB_OT_TAG_GPOS HB_TAG('G','P','O','S')
  58. /**
  59. * HB_OT_TAG_JSTF:
  60. *
  61. * OpenType [Justification Table](https://docs.microsoft.com/en-us/typography/opentype/spec/jstf).
  62. */
  63. #define HB_OT_TAG_JSTF HB_TAG('J','S','T','F')
  64. /*
  65. * Script & Language tags.
  66. */
  67. /**
  68. * HB_OT_TAG_DEFAULT_SCRIPT:
  69. *
  70. * OpenType script tag, `DFLT`, for features that are not script-specific.
  71. *
  72. */
  73. #define HB_OT_TAG_DEFAULT_SCRIPT HB_TAG ('D', 'F', 'L', 'T')
  74. /**
  75. * HB_OT_TAG_DEFAULT_LANGUAGE:
  76. *
  77. * OpenType language tag, `dflt`. Not a valid language tag, but some fonts
  78. * mistakenly use it.
  79. */
  80. #define HB_OT_TAG_DEFAULT_LANGUAGE HB_TAG ('d', 'f', 'l', 't')
  81. /**
  82. * HB_OT_MAX_TAGS_PER_SCRIPT:
  83. *
  84. * Maximum number of OpenType tags that can correspond to a give #hb_script_t.
  85. *
  86. * Since: 2.0.0
  87. **/
  88. #define HB_OT_MAX_TAGS_PER_SCRIPT 3u
  89. /**
  90. * HB_OT_MAX_TAGS_PER_LANGUAGE:
  91. *
  92. * Maximum number of OpenType tags that can correspond to a give #hb_language_t.
  93. *
  94. * Since: 2.0.0
  95. **/
  96. #define HB_OT_MAX_TAGS_PER_LANGUAGE 3u
  97. HB_EXTERN void
  98. hb_ot_tags_from_script_and_language (hb_script_t script,
  99. hb_language_t language,
  100. unsigned int *script_count /* IN/OUT */,
  101. hb_tag_t *script_tags /* OUT */,
  102. unsigned int *language_count /* IN/OUT */,
  103. hb_tag_t *language_tags /* OUT */);
  104. HB_EXTERN hb_script_t
  105. hb_ot_tag_to_script (hb_tag_t tag);
  106. HB_EXTERN hb_language_t
  107. hb_ot_tag_to_language (hb_tag_t tag);
  108. HB_EXTERN void
  109. hb_ot_tags_to_script_and_language (hb_tag_t script_tag,
  110. hb_tag_t language_tag,
  111. hb_script_t *script /* OUT */,
  112. hb_language_t *language /* OUT */);
  113. /*
  114. * GDEF
  115. */
  116. HB_EXTERN hb_bool_t
  117. hb_ot_layout_has_glyph_classes (hb_face_t *face);
  118. /**
  119. * hb_ot_layout_glyph_class_t:
  120. * @HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED: Glyphs not matching the other classifications
  121. * @HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH: Spacing, single characters, capable of accepting marks
  122. * @HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE: Glyphs that represent ligation of multiple characters
  123. * @HB_OT_LAYOUT_GLYPH_CLASS_MARK: Non-spacing, combining glyphs that represent marks
  124. * @HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT: Spacing glyphs that represent part of a single character
  125. *
  126. * The GDEF classes defined for glyphs.
  127. *
  128. **/
  129. typedef enum {
  130. HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0,
  131. HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH = 1,
  132. HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE = 2,
  133. HB_OT_LAYOUT_GLYPH_CLASS_MARK = 3,
  134. HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT = 4
  135. } hb_ot_layout_glyph_class_t;
  136. HB_EXTERN hb_ot_layout_glyph_class_t
  137. hb_ot_layout_get_glyph_class (hb_face_t *face,
  138. hb_codepoint_t glyph);
  139. HB_EXTERN void
  140. hb_ot_layout_get_glyphs_in_class (hb_face_t *face,
  141. hb_ot_layout_glyph_class_t klass,
  142. hb_set_t *glyphs /* OUT */);
  143. /* Not that useful. Provides list of attach points for a glyph that a
  144. * client may want to cache */
  145. HB_EXTERN unsigned int
  146. hb_ot_layout_get_attach_points (hb_face_t *face,
  147. hb_codepoint_t glyph,
  148. unsigned int start_offset,
  149. unsigned int *point_count /* IN/OUT */,
  150. unsigned int *point_array /* OUT */);
  151. /* Ligature caret positions */
  152. HB_EXTERN unsigned int
  153. hb_ot_layout_get_ligature_carets (hb_font_t *font,
  154. hb_direction_t direction,
  155. hb_codepoint_t glyph,
  156. unsigned int start_offset,
  157. unsigned int *caret_count /* IN/OUT */,
  158. hb_position_t *caret_array /* OUT */);
  159. /*
  160. * GSUB/GPOS feature query and enumeration interface
  161. */
  162. /**
  163. * HB_OT_LAYOUT_NO_SCRIPT_INDEX:
  164. *
  165. * Special value for script index indicating unsupported script.
  166. */
  167. #define HB_OT_LAYOUT_NO_SCRIPT_INDEX 0xFFFFu
  168. /**
  169. * HB_OT_LAYOUT_NO_FEATURE_INDEX:
  170. *
  171. * Special value for feature index indicating unsupported feature.
  172. */
  173. #define HB_OT_LAYOUT_NO_FEATURE_INDEX 0xFFFFu
  174. /**
  175. * HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX:
  176. *
  177. * Special value for language index indicating default or unsupported language.
  178. */
  179. #define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX 0xFFFFu
  180. /**
  181. * HB_OT_LAYOUT_NO_VARIATIONS_INDEX:
  182. *
  183. * Special value for variations index indicating unsupported variation.
  184. */
  185. #define HB_OT_LAYOUT_NO_VARIATIONS_INDEX 0xFFFFFFFFu
  186. HB_EXTERN unsigned int
  187. hb_ot_layout_table_get_script_tags (hb_face_t *face,
  188. hb_tag_t table_tag,
  189. unsigned int start_offset,
  190. unsigned int *script_count /* IN/OUT */,
  191. hb_tag_t *script_tags /* OUT */);
  192. HB_EXTERN hb_bool_t
  193. hb_ot_layout_table_find_script (hb_face_t *face,
  194. hb_tag_t table_tag,
  195. hb_tag_t script_tag,
  196. unsigned int *script_index /* OUT */);
  197. HB_EXTERN hb_bool_t
  198. hb_ot_layout_table_select_script (hb_face_t *face,
  199. hb_tag_t table_tag,
  200. unsigned int script_count,
  201. const hb_tag_t *script_tags,
  202. unsigned int *script_index /* OUT */,
  203. hb_tag_t *chosen_script /* OUT */);
  204. HB_EXTERN unsigned int
  205. hb_ot_layout_table_get_feature_tags (hb_face_t *face,
  206. hb_tag_t table_tag,
  207. unsigned int start_offset,
  208. unsigned int *feature_count /* IN/OUT */,
  209. hb_tag_t *feature_tags /* OUT */);
  210. HB_EXTERN unsigned int
  211. hb_ot_layout_script_get_language_tags (hb_face_t *face,
  212. hb_tag_t table_tag,
  213. unsigned int script_index,
  214. unsigned int start_offset,
  215. unsigned int *language_count /* IN/OUT */,
  216. hb_tag_t *language_tags /* OUT */);
  217. HB_EXTERN hb_bool_t
  218. hb_ot_layout_script_select_language (hb_face_t *face,
  219. hb_tag_t table_tag,
  220. unsigned int script_index,
  221. unsigned int language_count,
  222. const hb_tag_t *language_tags,
  223. unsigned int *language_index /* OUT */);
  224. HB_EXTERN hb_bool_t
  225. hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
  226. hb_tag_t table_tag,
  227. unsigned int script_index,
  228. unsigned int language_index,
  229. unsigned int *feature_index /* OUT */);
  230. HB_EXTERN hb_bool_t
  231. hb_ot_layout_language_get_required_feature (hb_face_t *face,
  232. hb_tag_t table_tag,
  233. unsigned int script_index,
  234. unsigned int language_index,
  235. unsigned int *feature_index /* OUT */,
  236. hb_tag_t *feature_tag /* OUT */);
  237. HB_EXTERN unsigned int
  238. hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
  239. hb_tag_t table_tag,
  240. unsigned int script_index,
  241. unsigned int language_index,
  242. unsigned int start_offset,
  243. unsigned int *feature_count /* IN/OUT */,
  244. unsigned int *feature_indexes /* OUT */);
  245. HB_EXTERN unsigned int
  246. hb_ot_layout_language_get_feature_tags (hb_face_t *face,
  247. hb_tag_t table_tag,
  248. unsigned int script_index,
  249. unsigned int language_index,
  250. unsigned int start_offset,
  251. unsigned int *feature_count /* IN/OUT */,
  252. hb_tag_t *feature_tags /* OUT */);
  253. HB_EXTERN hb_bool_t
  254. hb_ot_layout_language_find_feature (hb_face_t *face,
  255. hb_tag_t table_tag,
  256. unsigned int script_index,
  257. unsigned int language_index,
  258. hb_tag_t feature_tag,
  259. unsigned int *feature_index /* OUT */);
  260. HB_EXTERN unsigned int
  261. hb_ot_layout_feature_get_lookups (hb_face_t *face,
  262. hb_tag_t table_tag,
  263. unsigned int feature_index,
  264. unsigned int start_offset,
  265. unsigned int *lookup_count /* IN/OUT */,
  266. unsigned int *lookup_indexes /* OUT */);
  267. HB_EXTERN unsigned int
  268. hb_ot_layout_table_get_lookup_count (hb_face_t *face,
  269. hb_tag_t table_tag);
  270. HB_EXTERN void
  271. hb_ot_layout_collect_features (hb_face_t *face,
  272. hb_tag_t table_tag,
  273. const hb_tag_t *scripts,
  274. const hb_tag_t *languages,
  275. const hb_tag_t *features,
  276. hb_set_t *feature_indexes /* OUT */);
  277. HB_EXTERN void
  278. hb_ot_layout_collect_lookups (hb_face_t *face,
  279. hb_tag_t table_tag,
  280. const hb_tag_t *scripts,
  281. const hb_tag_t *languages,
  282. const hb_tag_t *features,
  283. hb_set_t *lookup_indexes /* OUT */);
  284. HB_EXTERN void
  285. hb_ot_layout_lookup_collect_glyphs (hb_face_t *face,
  286. hb_tag_t table_tag,
  287. unsigned int lookup_index,
  288. hb_set_t *glyphs_before, /* OUT. May be NULL */
  289. hb_set_t *glyphs_input, /* OUT. May be NULL */
  290. hb_set_t *glyphs_after, /* OUT. May be NULL */
  291. hb_set_t *glyphs_output /* OUT. May be NULL */);
  292. /* Variations support */
  293. HB_EXTERN hb_bool_t
  294. hb_ot_layout_table_find_feature_variations (hb_face_t *face,
  295. hb_tag_t table_tag,
  296. const int *coords,
  297. unsigned int num_coords,
  298. unsigned int *variations_index /* out */);
  299. HB_EXTERN unsigned int
  300. hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
  301. hb_tag_t table_tag,
  302. unsigned int feature_index,
  303. unsigned int variations_index,
  304. unsigned int start_offset,
  305. unsigned int *lookup_count /* IN/OUT */,
  306. unsigned int *lookup_indexes /* OUT */);
  307. /*
  308. * GSUB
  309. */
  310. HB_EXTERN hb_bool_t
  311. hb_ot_layout_has_substitution (hb_face_t *face);
  312. HB_EXTERN unsigned
  313. hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face,
  314. unsigned lookup_index,
  315. hb_codepoint_t glyph,
  316. unsigned start_offset,
  317. unsigned *alternate_count /* IN/OUT */,
  318. hb_codepoint_t *alternate_glyphs /* OUT */);
  319. HB_EXTERN hb_bool_t
  320. hb_ot_layout_lookup_would_substitute (hb_face_t *face,
  321. unsigned int lookup_index,
  322. const hb_codepoint_t *glyphs,
  323. unsigned int glyphs_length,
  324. hb_bool_t zero_context);
  325. HB_EXTERN void
  326. hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
  327. unsigned int lookup_index,
  328. hb_set_t *glyphs
  329. /*TODO , hb_bool_t inclusive */);
  330. HB_EXTERN void
  331. hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
  332. const hb_set_t *lookups,
  333. hb_set_t *glyphs);
  334. /*
  335. * GPOS
  336. */
  337. HB_EXTERN hb_bool_t
  338. hb_ot_layout_has_positioning (hb_face_t *face);
  339. /* Optical 'size' feature info. Returns true if found.
  340. * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#size */
  341. HB_EXTERN hb_bool_t
  342. hb_ot_layout_get_size_params (hb_face_t *face,
  343. unsigned int *design_size, /* OUT. May be NULL */
  344. unsigned int *subfamily_id, /* OUT. May be NULL */
  345. hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */
  346. unsigned int *range_start, /* OUT. May be NULL */
  347. unsigned int *range_end /* OUT. May be NULL */);
  348. HB_EXTERN hb_position_t
  349. hb_ot_layout_lookup_get_optical_bound (hb_font_t *font,
  350. unsigned lookup_index,
  351. hb_direction_t direction,
  352. hb_codepoint_t glyph);
  353. /*
  354. * GSUB/GPOS
  355. */
  356. HB_EXTERN hb_bool_t
  357. hb_ot_layout_feature_get_name_ids (hb_face_t *face,
  358. hb_tag_t table_tag,
  359. unsigned int feature_index,
  360. hb_ot_name_id_t *label_id /* OUT. May be NULL */,
  361. hb_ot_name_id_t *tooltip_id /* OUT. May be NULL */,
  362. hb_ot_name_id_t *sample_id /* OUT. May be NULL */,
  363. unsigned int *num_named_parameters /* OUT. May be NULL */,
  364. hb_ot_name_id_t *first_param_id /* OUT. May be NULL */);
  365. HB_EXTERN unsigned int
  366. hb_ot_layout_feature_get_characters (hb_face_t *face,
  367. hb_tag_t table_tag,
  368. unsigned int feature_index,
  369. unsigned int start_offset,
  370. unsigned int *char_count /* IN/OUT. May be NULL */,
  371. hb_codepoint_t *characters /* OUT. May be NULL */);
  372. /*
  373. * BASE
  374. */
  375. /**
  376. * hb_ot_layout_baseline_tag_t:
  377. * @HB_OT_LAYOUT_BASELINE_TAG_ROMAN: The baseline used by alphabetic scripts such as Latin, Cyrillic and Greek.
  378. * In vertical writing mode, the alphabetic baseline for characters rotated 90 degrees clockwise.
  379. * (This would not apply to alphabetic characters that remain upright in vertical writing mode, since these
  380. * characters are not rotated.)
  381. * @HB_OT_LAYOUT_BASELINE_TAG_HANGING: The hanging baseline. In horizontal direction, this is the horizontal
  382. * line from which syllables seem, to hang in Tibetan and other similar scripts. In vertical writing mode,
  383. * for Tibetan (or some other similar script) characters rotated 90 degrees clockwise.
  384. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT: Ideographic character face bottom or left edge,
  385. * if the direction is horizontal or vertical, respectively.
  386. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT: Ideographic character face top or right edge,
  387. * if the direction is horizontal or vertical, respectively.
  388. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL: The center of the ideographic character face. Since: 4.0.0
  389. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT: Ideographic em-box bottom or left edge,
  390. * if the direction is horizontal or vertical, respectively.
  391. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT: Ideographic em-box top or right edge baseline,
  392. * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL: The center of the ideographic em-box. Since: 4.0.0
  393. * if the direction is horizontal or vertical, respectively.
  394. * @HB_OT_LAYOUT_BASELINE_TAG_MATH: The baseline about which mathematical characters are centered.
  395. * In vertical writing mode when mathematical characters rotated 90 degrees clockwise, are centered.
  396. *
  397. * Baseline tags from [Baseline Tags](https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags) registry.
  398. *
  399. * Since: 2.6.0
  400. */
  401. typedef enum {
  402. HB_OT_LAYOUT_BASELINE_TAG_ROMAN = HB_TAG ('r','o','m','n'),
  403. HB_OT_LAYOUT_BASELINE_TAG_HANGING = HB_TAG ('h','a','n','g'),
  404. HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT = HB_TAG ('i','c','f','b'),
  405. HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT = HB_TAG ('i','c','f','t'),
  406. HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL = HB_TAG ('I','c','f','c'),
  407. HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT = HB_TAG ('i','d','e','o'),
  408. HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT = HB_TAG ('i','d','t','p'),
  409. HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL = HB_TAG ('I','d','c','e'),
  410. HB_OT_LAYOUT_BASELINE_TAG_MATH = HB_TAG ('m','a','t','h'),
  411. /*< private >*/
  412. _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
  413. } hb_ot_layout_baseline_tag_t;
  414. HB_EXTERN hb_ot_layout_baseline_tag_t
  415. hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script);
  416. HB_EXTERN hb_bool_t
  417. hb_ot_layout_get_baseline (hb_font_t *font,
  418. hb_ot_layout_baseline_tag_t baseline_tag,
  419. hb_direction_t direction,
  420. hb_tag_t script_tag,
  421. hb_tag_t language_tag,
  422. hb_position_t *coord /* OUT. May be NULL. */);
  423. HB_EXTERN void
  424. hb_ot_layout_get_baseline_with_fallback (hb_font_t *font,
  425. hb_ot_layout_baseline_tag_t baseline_tag,
  426. hb_direction_t direction,
  427. hb_tag_t script_tag,
  428. hb_tag_t language_tag,
  429. hb_position_t *coord /* OUT */);
  430. HB_END_DECLS
  431. #endif /* HB_OT_LAYOUT_H */