hb-buffer.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /*
  2. * Copyright © 1998-2004 David Turner and Werner Lemberg
  3. * Copyright © 2004,2007,2009 Red Hat, Inc.
  4. * Copyright © 2011,2012 Google, Inc.
  5. *
  6. * This is part of HarfBuzz, a text shaping library.
  7. *
  8. * Permission is hereby granted, without written agreement and without
  9. * license or royalty fees, to use, copy, modify, and distribute this
  10. * software and its documentation for any purpose, provided that the
  11. * above copyright notice and the following two paragraphs appear in
  12. * all copies of this software.
  13. *
  14. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  15. * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  16. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  17. * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  18. * DAMAGE.
  19. *
  20. * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  21. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  23. * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  24. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  25. *
  26. * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
  27. * Google Author(s): Behdad Esfahbod
  28. */
  29. #if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
  30. #error "Include <hb.h> instead."
  31. #endif
  32. #ifndef HB_BUFFER_H
  33. #define HB_BUFFER_H
  34. #include "hb-common.h"
  35. #include "hb-unicode.h"
  36. #include "hb-font.h"
  37. HB_BEGIN_DECLS
  38. /**
  39. * hb_glyph_info_t:
  40. * @codepoint: either a Unicode code point (before shaping) or a glyph index
  41. * (after shaping).
  42. * @cluster: the index of the character in the original text that corresponds
  43. * to this #hb_glyph_info_t, or whatever the client passes to
  44. * hb_buffer_add(). More than one #hb_glyph_info_t can have the same
  45. * @cluster value, if they resulted from the same character (e.g. one
  46. * to many glyph substitution), and when more than one character gets
  47. * merged in the same glyph (e.g. many to one glyph substitution) the
  48. * #hb_glyph_info_t will have the smallest cluster value of them.
  49. * By default some characters are merged into the same cluster
  50. * (e.g. combining marks have the same cluster as their bases)
  51. * even if they are separate glyphs, hb_buffer_set_cluster_level()
  52. * allow selecting more fine-grained cluster handling.
  53. *
  54. * The #hb_glyph_info_t is the structure that holds information about the
  55. * glyphs and their relation to input text.
  56. */
  57. typedef struct hb_glyph_info_t {
  58. hb_codepoint_t codepoint;
  59. /*< private >*/
  60. hb_mask_t mask;
  61. /*< public >*/
  62. uint32_t cluster;
  63. /*< private >*/
  64. hb_var_int_t var1;
  65. hb_var_int_t var2;
  66. } hb_glyph_info_t;
  67. /**
  68. * hb_glyph_flags_t:
  69. * @HB_GLYPH_FLAG_UNSAFE_TO_BREAK: Indicates that if input text is broken at the
  70. * beginning of the cluster this glyph is part of,
  71. * then both sides need to be re-shaped, as the
  72. * result might be different.
  73. * On the flip side, it means that when this
  74. * flag is not present, then it is safe to break
  75. * the glyph-run at the beginning of this
  76. * cluster, and the two sides will represent the
  77. * exact same result one would get if breaking
  78. * input text at the beginning of this cluster
  79. * and shaping the two sides separately.
  80. * This can be used to optimize paragraph
  81. * layout, by avoiding re-shaping of each line
  82. * after line-breaking.
  83. * @HB_GLYPH_FLAG_UNSAFE_TO_CONCAT: Indicates that if input text is changed on one
  84. * side of the beginning of the cluster this glyph
  85. * is part of, then the shaping results for the
  86. * other side might change.
  87. * Note that the absence of this flag will NOT by
  88. * itself mean that it IS safe to concat text.
  89. * Only two pieces of text both of which clear of
  90. * this flag can be concatenated safely.
  91. * This can be used to optimize paragraph
  92. * layout, by avoiding re-shaping of each line
  93. * after line-breaking, by limiting the
  94. * reshaping to a small piece around the
  95. * breaking positin only, even if the breaking
  96. * position carries the
  97. * #HB_GLYPH_FLAG_UNSAFE_TO_BREAK or when
  98. * hyphenation or other text transformation
  99. * happens at line-break position, in the following
  100. * way:
  101. * 1. Iterate back from the line-break position
  102. * until the first cluster start position that is
  103. * NOT unsafe-to-concat, 2. shape the segment from
  104. * there till the end of line, 3. check whether the
  105. * resulting glyph-run also is clear of the
  106. * unsafe-to-concat at its start-of-text position;
  107. * if it is, just splice it into place and the line
  108. * is shaped; If not, move on to a position further
  109. * back that is clear of unsafe-to-concat and retry
  110. * from there, and repeat.
  111. * At the start of next line a similar algorithm can
  112. * be implemented. That is: 1. Iterate forward from
  113. * the line-break position until the first cluster
  114. * start position that is NOT unsafe-to-concat, 2.
  115. * shape the segment from beginning of the line to
  116. * that position, 3. check whether the resulting
  117. * glyph-run also is clear of the unsafe-to-concat
  118. * at its end-of-text position; if it is, just splice
  119. * it into place and the beginning is shaped; If not,
  120. * move on to a position further forward that is clear
  121. * of unsafe-to-concat and retry up to there, and repeat.
  122. * A slight complication will arise in the
  123. * implementation of the algorithm above,
  124. * because while our buffer API has a way to
  125. * return flags for position corresponding to
  126. * start-of-text, there is currently no position
  127. * corresponding to end-of-text. This limitation
  128. * can be alleviated by shaping more text than needed
  129. * and looking for unsafe-to-concat flag within text
  130. * clusters.
  131. * The #HB_GLYPH_FLAG_UNSAFE_TO_BREAK flag will
  132. * always imply this flag.
  133. * To use this flag, you must enable the buffer flag
  134. * @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT during
  135. * shaping, otherwise the buffer flag will not be
  136. * reliably produced.
  137. * Since: 4.0.0
  138. * @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL: In scripts that use elongation (Arabic,
  139. Mongolian, Syriac, etc.), this flag signifies
  140. that it is safe to insert a U+0640 TATWEEL
  141. character before this cluster for elongation.
  142. This flag does not determine the
  143. script-specific elongation places, but only
  144. when it is safe to do the elongation without
  145. interrupting text shaping.
  146. Since: 5.1.0
  147. * @HB_GLYPH_FLAG_DEFINED: All the currently defined flags.
  148. *
  149. * Flags for #hb_glyph_info_t.
  150. *
  151. * Since: 1.5.0
  152. */
  153. typedef enum { /*< flags >*/
  154. HB_GLYPH_FLAG_UNSAFE_TO_BREAK = 0x00000001,
  155. HB_GLYPH_FLAG_UNSAFE_TO_CONCAT = 0x00000002,
  156. HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL = 0x00000004,
  157. HB_GLYPH_FLAG_DEFINED = 0x00000007 /* OR of all defined flags */
  158. } hb_glyph_flags_t;
  159. HB_EXTERN hb_glyph_flags_t
  160. hb_glyph_info_get_glyph_flags (const hb_glyph_info_t *info);
  161. #define hb_glyph_info_get_glyph_flags(info) \
  162. ((hb_glyph_flags_t) ((unsigned int) (info)->mask & HB_GLYPH_FLAG_DEFINED))
  163. /**
  164. * hb_glyph_position_t:
  165. * @x_advance: how much the line advances after drawing this glyph when setting
  166. * text in horizontal direction.
  167. * @y_advance: how much the line advances after drawing this glyph when setting
  168. * text in vertical direction.
  169. * @x_offset: how much the glyph moves on the X-axis before drawing it, this
  170. * should not affect how much the line advances.
  171. * @y_offset: how much the glyph moves on the Y-axis before drawing it, this
  172. * should not affect how much the line advances.
  173. *
  174. * The #hb_glyph_position_t is the structure that holds the positions of the
  175. * glyph in both horizontal and vertical directions. All positions in
  176. * #hb_glyph_position_t are relative to the current point.
  177. *
  178. */
  179. typedef struct hb_glyph_position_t {
  180. hb_position_t x_advance;
  181. hb_position_t y_advance;
  182. hb_position_t x_offset;
  183. hb_position_t y_offset;
  184. /*< private >*/
  185. hb_var_int_t var;
  186. } hb_glyph_position_t;
  187. /**
  188. * hb_segment_properties_t:
  189. * @direction: the #hb_direction_t of the buffer, see hb_buffer_set_direction().
  190. * @script: the #hb_script_t of the buffer, see hb_buffer_set_script().
  191. * @language: the #hb_language_t of the buffer, see hb_buffer_set_language().
  192. *
  193. * The structure that holds various text properties of an #hb_buffer_t. Can be
  194. * set and retrieved using hb_buffer_set_segment_properties() and
  195. * hb_buffer_get_segment_properties(), respectively.
  196. */
  197. typedef struct hb_segment_properties_t {
  198. hb_direction_t direction;
  199. hb_script_t script;
  200. hb_language_t language;
  201. /*< private >*/
  202. void *reserved1;
  203. void *reserved2;
  204. } hb_segment_properties_t;
  205. /**
  206. * HB_SEGMENT_PROPERTIES_DEFAULT:
  207. *
  208. * The default #hb_segment_properties_t of of freshly created #hb_buffer_t.
  209. */
  210. #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \
  211. HB_SCRIPT_INVALID, \
  212. HB_LANGUAGE_INVALID, \
  213. (void *) 0, \
  214. (void *) 0}
  215. HB_EXTERN hb_bool_t
  216. hb_segment_properties_equal (const hb_segment_properties_t *a,
  217. const hb_segment_properties_t *b);
  218. HB_EXTERN unsigned int
  219. hb_segment_properties_hash (const hb_segment_properties_t *p);
  220. HB_EXTERN void
  221. hb_segment_properties_overlay (hb_segment_properties_t *p,
  222. const hb_segment_properties_t *src);
  223. /**
  224. * hb_buffer_t:
  225. *
  226. * The main structure holding the input text and its properties before shaping,
  227. * and output glyphs and their information after shaping.
  228. */
  229. typedef struct hb_buffer_t hb_buffer_t;
  230. HB_EXTERN hb_buffer_t *
  231. hb_buffer_create (void);
  232. HB_EXTERN hb_buffer_t *
  233. hb_buffer_create_similar (const hb_buffer_t *src);
  234. HB_EXTERN void
  235. hb_buffer_reset (hb_buffer_t *buffer);
  236. HB_EXTERN hb_buffer_t *
  237. hb_buffer_get_empty (void);
  238. HB_EXTERN hb_buffer_t *
  239. hb_buffer_reference (hb_buffer_t *buffer);
  240. HB_EXTERN void
  241. hb_buffer_destroy (hb_buffer_t *buffer);
  242. HB_EXTERN hb_bool_t
  243. hb_buffer_set_user_data (hb_buffer_t *buffer,
  244. hb_user_data_key_t *key,
  245. void * data,
  246. hb_destroy_func_t destroy,
  247. hb_bool_t replace);
  248. HB_EXTERN void *
  249. hb_buffer_get_user_data (const hb_buffer_t *buffer,
  250. hb_user_data_key_t *key);
  251. /**
  252. * hb_buffer_content_type_t:
  253. * @HB_BUFFER_CONTENT_TYPE_INVALID: Initial value for new buffer.
  254. * @HB_BUFFER_CONTENT_TYPE_UNICODE: The buffer contains input characters (before shaping).
  255. * @HB_BUFFER_CONTENT_TYPE_GLYPHS: The buffer contains output glyphs (after shaping).
  256. *
  257. * The type of #hb_buffer_t contents.
  258. */
  259. typedef enum {
  260. HB_BUFFER_CONTENT_TYPE_INVALID = 0,
  261. HB_BUFFER_CONTENT_TYPE_UNICODE,
  262. HB_BUFFER_CONTENT_TYPE_GLYPHS
  263. } hb_buffer_content_type_t;
  264. HB_EXTERN void
  265. hb_buffer_set_content_type (hb_buffer_t *buffer,
  266. hb_buffer_content_type_t content_type);
  267. HB_EXTERN hb_buffer_content_type_t
  268. hb_buffer_get_content_type (const hb_buffer_t *buffer);
  269. HB_EXTERN void
  270. hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
  271. hb_unicode_funcs_t *unicode_funcs);
  272. HB_EXTERN hb_unicode_funcs_t *
  273. hb_buffer_get_unicode_funcs (const hb_buffer_t *buffer);
  274. HB_EXTERN void
  275. hb_buffer_set_direction (hb_buffer_t *buffer,
  276. hb_direction_t direction);
  277. HB_EXTERN hb_direction_t
  278. hb_buffer_get_direction (const hb_buffer_t *buffer);
  279. HB_EXTERN void
  280. hb_buffer_set_script (hb_buffer_t *buffer,
  281. hb_script_t script);
  282. HB_EXTERN hb_script_t
  283. hb_buffer_get_script (const hb_buffer_t *buffer);
  284. HB_EXTERN void
  285. hb_buffer_set_language (hb_buffer_t *buffer,
  286. hb_language_t language);
  287. HB_EXTERN hb_language_t
  288. hb_buffer_get_language (const hb_buffer_t *buffer);
  289. HB_EXTERN void
  290. hb_buffer_set_segment_properties (hb_buffer_t *buffer,
  291. const hb_segment_properties_t *props);
  292. HB_EXTERN void
  293. hb_buffer_get_segment_properties (const hb_buffer_t *buffer,
  294. hb_segment_properties_t *props);
  295. HB_EXTERN void
  296. hb_buffer_guess_segment_properties (hb_buffer_t *buffer);
  297. /**
  298. * hb_buffer_flags_t:
  299. * @HB_BUFFER_FLAG_DEFAULT: the default buffer flag.
  300. * @HB_BUFFER_FLAG_BOT: flag indicating that special handling of the beginning
  301. * of text paragraph can be applied to this buffer. Should usually
  302. * be set, unless you are passing to the buffer only part
  303. * of the text without the full context.
  304. * @HB_BUFFER_FLAG_EOT: flag indicating that special handling of the end of text
  305. * paragraph can be applied to this buffer, similar to
  306. * @HB_BUFFER_FLAG_BOT.
  307. * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES:
  308. * flag indication that character with Default_Ignorable
  309. * Unicode property should use the corresponding glyph
  310. * from the font, instead of hiding them (done by
  311. * replacing them with the space glyph and zeroing the
  312. * advance width.) This flag takes precedence over
  313. * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES.
  314. * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES:
  315. * flag indication that character with Default_Ignorable
  316. * Unicode property should be removed from glyph string
  317. * instead of hiding them (done by replacing them with the
  318. * space glyph and zeroing the advance width.)
  319. * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES takes
  320. * precedence over this flag. Since: 1.8.0
  321. * @HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE:
  322. * flag indicating that a dotted circle should
  323. * not be inserted in the rendering of incorrect
  324. * character sequences (such at <0905 093E>). Since: 2.4.0
  325. * @HB_BUFFER_FLAG_VERIFY:
  326. * flag indicating that the hb_shape() call and its variants
  327. * should perform various verification processes on the results
  328. * of the shaping operation on the buffer. If the verification
  329. * fails, then either a buffer message is sent, if a message
  330. * handler is installed on the buffer, or a message is written
  331. * to standard error. In either case, the shaping result might
  332. * be modified to show the failed output. Since: 3.4.0
  333. * @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT:
  334. * flag indicating that the @HB_GLYPH_FLAG_UNSAFE_TO_CONCAT
  335. * glyph-flag should be produced by the shaper. By default
  336. * it will not be produced since it incurs a cost. Since: 4.0.0
  337. * @HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL:
  338. * flag indicating that the @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL
  339. * glyph-flag should be produced by the shaper. By default
  340. * it will not be produced. Since: 5.1.0
  341. * @HB_BUFFER_FLAG_DEFINED: All currently defined flags: Since: 4.4.0
  342. *
  343. * Flags for #hb_buffer_t.
  344. *
  345. * Since: 0.9.20
  346. */
  347. typedef enum { /*< flags >*/
  348. HB_BUFFER_FLAG_DEFAULT = 0x00000000u,
  349. HB_BUFFER_FLAG_BOT = 0x00000001u, /* Beginning-of-text */
  350. HB_BUFFER_FLAG_EOT = 0x00000002u, /* End-of-text */
  351. HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004u,
  352. HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES = 0x00000008u,
  353. HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE = 0x00000010u,
  354. HB_BUFFER_FLAG_VERIFY = 0x00000020u,
  355. HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT = 0x00000040u,
  356. HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL = 0x00000080u,
  357. HB_BUFFER_FLAG_DEFINED = 0x000000FFu
  358. } hb_buffer_flags_t;
  359. HB_EXTERN void
  360. hb_buffer_set_flags (hb_buffer_t *buffer,
  361. hb_buffer_flags_t flags);
  362. HB_EXTERN hb_buffer_flags_t
  363. hb_buffer_get_flags (const hb_buffer_t *buffer);
  364. /**
  365. * hb_buffer_cluster_level_t:
  366. * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES: Return cluster values grouped by graphemes into
  367. * monotone order.
  368. * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS: Return cluster values grouped into monotone order.
  369. * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values.
  370. * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level,
  371. * equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES.
  372. *
  373. * Data type for holding HarfBuzz's clustering behavior options. The cluster level
  374. * dictates one aspect of how HarfBuzz will treat non-base characters
  375. * during shaping.
  376. *
  377. * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base
  378. * characters are merged into the cluster of the base character that precedes them.
  379. *
  380. * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, non-base characters are initially
  381. * assigned their own cluster values, which are not merged into preceding base
  382. * clusters. This allows HarfBuzz to perform additional operations like reorder
  383. * sequences of adjacent marks.
  384. *
  385. * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES is the default, because it maintains
  386. * backward compatibility with older versions of HarfBuzz. New client programs that
  387. * do not need to maintain such backward compatibility are recommended to use
  388. * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS instead of the default.
  389. *
  390. * Since: 0.9.42
  391. */
  392. typedef enum {
  393. HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0,
  394. HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1,
  395. HB_BUFFER_CLUSTER_LEVEL_CHARACTERS = 2,
  396. HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES
  397. } hb_buffer_cluster_level_t;
  398. HB_EXTERN void
  399. hb_buffer_set_cluster_level (hb_buffer_t *buffer,
  400. hb_buffer_cluster_level_t cluster_level);
  401. HB_EXTERN hb_buffer_cluster_level_t
  402. hb_buffer_get_cluster_level (const hb_buffer_t *buffer);
  403. /**
  404. * HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT:
  405. *
  406. * The default code point for replacing invalid characters in a given encoding.
  407. * Set to U+FFFD REPLACEMENT CHARACTER.
  408. *
  409. * Since: 0.9.31
  410. */
  411. #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu
  412. HB_EXTERN void
  413. hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
  414. hb_codepoint_t replacement);
  415. HB_EXTERN hb_codepoint_t
  416. hb_buffer_get_replacement_codepoint (const hb_buffer_t *buffer);
  417. HB_EXTERN void
  418. hb_buffer_set_invisible_glyph (hb_buffer_t *buffer,
  419. hb_codepoint_t invisible);
  420. HB_EXTERN hb_codepoint_t
  421. hb_buffer_get_invisible_glyph (const hb_buffer_t *buffer);
  422. HB_EXTERN void
  423. hb_buffer_set_not_found_glyph (hb_buffer_t *buffer,
  424. hb_codepoint_t not_found);
  425. HB_EXTERN hb_codepoint_t
  426. hb_buffer_get_not_found_glyph (const hb_buffer_t *buffer);
  427. /*
  428. * Content API.
  429. */
  430. HB_EXTERN void
  431. hb_buffer_clear_contents (hb_buffer_t *buffer);
  432. HB_EXTERN hb_bool_t
  433. hb_buffer_pre_allocate (hb_buffer_t *buffer,
  434. unsigned int size);
  435. HB_EXTERN hb_bool_t
  436. hb_buffer_allocation_successful (hb_buffer_t *buffer);
  437. HB_EXTERN void
  438. hb_buffer_reverse (hb_buffer_t *buffer);
  439. HB_EXTERN void
  440. hb_buffer_reverse_range (hb_buffer_t *buffer,
  441. unsigned int start, unsigned int end);
  442. HB_EXTERN void
  443. hb_buffer_reverse_clusters (hb_buffer_t *buffer);
  444. /* Filling the buffer in */
  445. HB_EXTERN void
  446. hb_buffer_add (hb_buffer_t *buffer,
  447. hb_codepoint_t codepoint,
  448. unsigned int cluster);
  449. HB_EXTERN void
  450. hb_buffer_add_utf8 (hb_buffer_t *buffer,
  451. const char *text,
  452. int text_length,
  453. unsigned int item_offset,
  454. int item_length);
  455. HB_EXTERN void
  456. hb_buffer_add_utf16 (hb_buffer_t *buffer,
  457. const uint16_t *text,
  458. int text_length,
  459. unsigned int item_offset,
  460. int item_length);
  461. HB_EXTERN void
  462. hb_buffer_add_utf32 (hb_buffer_t *buffer,
  463. const uint32_t *text,
  464. int text_length,
  465. unsigned int item_offset,
  466. int item_length);
  467. HB_EXTERN void
  468. hb_buffer_add_latin1 (hb_buffer_t *buffer,
  469. const uint8_t *text,
  470. int text_length,
  471. unsigned int item_offset,
  472. int item_length);
  473. HB_EXTERN void
  474. hb_buffer_add_codepoints (hb_buffer_t *buffer,
  475. const hb_codepoint_t *text,
  476. int text_length,
  477. unsigned int item_offset,
  478. int item_length);
  479. HB_EXTERN void
  480. hb_buffer_append (hb_buffer_t *buffer,
  481. const hb_buffer_t *source,
  482. unsigned int start,
  483. unsigned int end);
  484. HB_EXTERN hb_bool_t
  485. hb_buffer_set_length (hb_buffer_t *buffer,
  486. unsigned int length);
  487. HB_EXTERN unsigned int
  488. hb_buffer_get_length (const hb_buffer_t *buffer);
  489. /* Getting glyphs out of the buffer */
  490. HB_EXTERN hb_glyph_info_t *
  491. hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
  492. unsigned int *length);
  493. HB_EXTERN hb_glyph_position_t *
  494. hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
  495. unsigned int *length);
  496. HB_EXTERN hb_bool_t
  497. hb_buffer_has_positions (hb_buffer_t *buffer);
  498. HB_EXTERN void
  499. hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
  500. /*
  501. * Serialize
  502. */
  503. /**
  504. * hb_buffer_serialize_flags_t:
  505. * @HB_BUFFER_SERIALIZE_FLAG_DEFAULT: serialize glyph names, clusters and positions.
  506. * @HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS: do not serialize glyph cluster.
  507. * @HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS: do not serialize glyph position information.
  508. * @HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES: do no serialize glyph name.
  509. * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS: serialize glyph extents.
  510. * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS: serialize glyph flags. Since: 1.5.0
  511. * @HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES: do not serialize glyph advances,
  512. * glyph offsets will reflect absolute glyph positions. Since: 1.8.0
  513. * @HB_BUFFER_SERIALIZE_FLAG_DEFINED: All currently defined flags. Since: 4.4.0
  514. *
  515. * Flags that control what glyph information are serialized in hb_buffer_serialize_glyphs().
  516. *
  517. * Since: 0.9.20
  518. */
  519. typedef enum { /*< flags >*/
  520. HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u,
  521. HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u,
  522. HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u,
  523. HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u,
  524. HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u,
  525. HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS = 0x00000010u,
  526. HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES = 0x00000020u,
  527. HB_BUFFER_SERIALIZE_FLAG_DEFINED = 0x0000003Fu
  528. } hb_buffer_serialize_flags_t;
  529. /**
  530. * hb_buffer_serialize_format_t:
  531. * @HB_BUFFER_SERIALIZE_FORMAT_TEXT: a human-readable, plain text format.
  532. * @HB_BUFFER_SERIALIZE_FORMAT_JSON: a machine-readable JSON format.
  533. * @HB_BUFFER_SERIALIZE_FORMAT_INVALID: invalid format.
  534. *
  535. * The buffer serialization and de-serialization format used in
  536. * hb_buffer_serialize_glyphs() and hb_buffer_deserialize_glyphs().
  537. *
  538. * Since: 0.9.2
  539. */
  540. typedef enum {
  541. HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'),
  542. HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'),
  543. HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE
  544. } hb_buffer_serialize_format_t;
  545. HB_EXTERN hb_buffer_serialize_format_t
  546. hb_buffer_serialize_format_from_string (const char *str, int len);
  547. HB_EXTERN const char *
  548. hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format);
  549. HB_EXTERN const char **
  550. hb_buffer_serialize_list_formats (void);
  551. HB_EXTERN unsigned int
  552. hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
  553. unsigned int start,
  554. unsigned int end,
  555. char *buf,
  556. unsigned int buf_size,
  557. unsigned int *buf_consumed,
  558. hb_font_t *font,
  559. hb_buffer_serialize_format_t format,
  560. hb_buffer_serialize_flags_t flags);
  561. HB_EXTERN unsigned int
  562. hb_buffer_serialize_unicode (hb_buffer_t *buffer,
  563. unsigned int start,
  564. unsigned int end,
  565. char *buf,
  566. unsigned int buf_size,
  567. unsigned int *buf_consumed,
  568. hb_buffer_serialize_format_t format,
  569. hb_buffer_serialize_flags_t flags);
  570. HB_EXTERN unsigned int
  571. hb_buffer_serialize (hb_buffer_t *buffer,
  572. unsigned int start,
  573. unsigned int end,
  574. char *buf,
  575. unsigned int buf_size,
  576. unsigned int *buf_consumed,
  577. hb_font_t *font,
  578. hb_buffer_serialize_format_t format,
  579. hb_buffer_serialize_flags_t flags);
  580. HB_EXTERN hb_bool_t
  581. hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
  582. const char *buf,
  583. int buf_len,
  584. const char **end_ptr,
  585. hb_font_t *font,
  586. hb_buffer_serialize_format_t format);
  587. HB_EXTERN hb_bool_t
  588. hb_buffer_deserialize_unicode (hb_buffer_t *buffer,
  589. const char *buf,
  590. int buf_len,
  591. const char **end_ptr,
  592. hb_buffer_serialize_format_t format);
  593. /*
  594. * Compare buffers
  595. */
  596. /**
  597. * hb_buffer_diff_flags_t:
  598. * @HB_BUFFER_DIFF_FLAG_EQUAL: equal buffers.
  599. * @HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH: buffers with different
  600. * #hb_buffer_content_type_t.
  601. * @HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH: buffers with differing length.
  602. * @HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT: `.notdef` glyph is present in the
  603. * reference buffer.
  604. * @HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT: dotted circle glyph is present
  605. * in the reference buffer.
  606. * @HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH: difference in #hb_glyph_info_t.codepoint
  607. * @HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH: difference in #hb_glyph_info_t.cluster
  608. * @HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH: difference in #hb_glyph_flags_t.
  609. * @HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH: difference in #hb_glyph_position_t.
  610. *
  611. * Flags from comparing two #hb_buffer_t's.
  612. *
  613. * Buffer with different #hb_buffer_content_type_t cannot be meaningfully
  614. * compared in any further detail.
  615. *
  616. * For buffers with differing length, the per-glyph comparison is not
  617. * attempted, though we do still scan reference buffer for dotted circle and
  618. * `.notdef` glyphs.
  619. *
  620. * If the buffers have the same length, we compare them glyph-by-glyph and
  621. * report which aspect(s) of the glyph info/position are different.
  622. *
  623. * Since: 1.5.0
  624. */
  625. typedef enum { /*< flags >*/
  626. HB_BUFFER_DIFF_FLAG_EQUAL = 0x0000,
  627. /* Buffers with different content_type cannot be meaningfully compared
  628. * in any further detail. */
  629. HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH = 0x0001,
  630. /* For buffers with differing length, the per-glyph comparison is not
  631. * attempted, though we do still scan reference for dottedcircle / .notdef
  632. * glyphs. */
  633. HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH = 0x0002,
  634. /* We want to know if dottedcircle / .notdef glyphs are present in the
  635. * reference, as we may not care so much about other differences in this
  636. * case. */
  637. HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT = 0x0004,
  638. HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT = 0x0008,
  639. /* If the buffers have the same length, we compare them glyph-by-glyph
  640. * and report which aspect(s) of the glyph info/position are different. */
  641. HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH = 0x0010,
  642. HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH = 0x0020,
  643. HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH = 0x0040,
  644. HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH = 0x0080
  645. } hb_buffer_diff_flags_t;
  646. /* Compare the contents of two buffers, report types of differences. */
  647. HB_EXTERN hb_buffer_diff_flags_t
  648. hb_buffer_diff (hb_buffer_t *buffer,
  649. hb_buffer_t *reference,
  650. hb_codepoint_t dottedcircle_glyph,
  651. unsigned int position_fuzz);
  652. /*
  653. * Debugging.
  654. */
  655. /**
  656. * hb_buffer_message_func_t:
  657. * @buffer: An #hb_buffer_t to work upon
  658. * @font: The #hb_font_t the @buffer is shaped with
  659. * @message: `NULL`-terminated message passed to the function
  660. * @user_data: User data pointer passed by the caller
  661. *
  662. * A callback method for #hb_buffer_t. The method gets called with the
  663. * #hb_buffer_t it was set on, the #hb_font_t the buffer is shaped with and a
  664. * message describing what step of the shaping process will be performed.
  665. * Returning `false` from this method will skip this shaping step and move to
  666. * the next one.
  667. *
  668. * Return value: `true` to perform the shaping step, `false` to skip it.
  669. *
  670. * Since: 1.1.3
  671. */
  672. typedef hb_bool_t (*hb_buffer_message_func_t) (hb_buffer_t *buffer,
  673. hb_font_t *font,
  674. const char *message,
  675. void *user_data);
  676. HB_EXTERN void
  677. hb_buffer_set_message_func (hb_buffer_t *buffer,
  678. hb_buffer_message_func_t func,
  679. void *user_data, hb_destroy_func_t destroy);
  680. HB_END_DECLS
  681. #endif /* HB_BUFFER_H */