tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hb-buffer.h (31540B)


      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 
     30 #if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
     31 #error "Include <hb.h> instead."
     32 #endif
     33 
     34 #ifndef HB_BUFFER_H
     35 #define HB_BUFFER_H
     36 
     37 #include "hb-common.h"
     38 #include "hb-unicode.h"
     39 #include "hb-font.h"
     40 
     41 HB_BEGIN_DECLS
     42 
     43 /**
     44 * hb_glyph_info_t:
     45 * @codepoint: either a Unicode code point (before shaping) or a glyph index
     46 *             (after shaping).
     47 * @cluster: the index of the character in the original text that corresponds
     48 *           to this #hb_glyph_info_t, or whatever the client passes to
     49 *           hb_buffer_add(). More than one #hb_glyph_info_t can have the same
     50 *           @cluster value, if they resulted from the same character (e.g. one
     51 *           to many glyph substitution), and when more than one character gets
     52 *           merged in the same glyph (e.g. many to one glyph substitution) the
     53 *           #hb_glyph_info_t will have the smallest cluster value of them.
     54 *           By default some characters are merged into the same cluster
     55 *           (e.g. combining marks have the same cluster as their bases)
     56 *           even if they are separate glyphs, hb_buffer_set_cluster_level()
     57 *           allow selecting more fine-grained cluster handling.
     58 *
     59 * The #hb_glyph_info_t is the structure that holds information about the
     60 * glyphs and their relation to input text.
     61 */
     62 typedef struct hb_glyph_info_t {
     63  hb_codepoint_t codepoint;
     64  /*< private >*/
     65  hb_mask_t      mask;
     66  /*< public >*/
     67  uint32_t       cluster;
     68 
     69  /*< private >*/
     70  hb_var_int_t   var1;
     71  hb_var_int_t   var2;
     72 } hb_glyph_info_t;
     73 
     74 /**
     75 * hb_glyph_flags_t:
     76 * @HB_GLYPH_FLAG_UNSAFE_TO_BREAK: Indicates that if input text is broken at the
     77 * 				   beginning of the cluster this glyph is part of,
     78 * 				   then both sides need to be re-shaped, as the
     79 * 				   result might be different.
     80 * 				   On the flip side, it means that when this
     81 * 				   flag is not present, then it is safe to break
     82 * 				   the glyph-run at the beginning of this
     83 * 				   cluster, and the two sides will represent the
     84 * 				   exact same result one would get if breaking
     85 * 				   input text at the beginning of this cluster
     86 * 				   and shaping the two sides separately.
     87 * 				   This can be used to optimize paragraph
     88 * 				   layout, by avoiding re-shaping of each line
     89 * 				   after line-breaking.
     90 * @HB_GLYPH_FLAG_UNSAFE_TO_CONCAT: Indicates that if input text is changed on one
     91 * 				   side of the beginning of the cluster this glyph
     92 * 				   is part of, then the shaping results for the
     93 * 				   other side might change.
     94 * 				   Note that the absence of this flag will NOT by
     95 * 				   itself mean that it IS safe to concat text.
     96 * 				   Only two pieces of text both of which clear of
     97 * 				   this flag can be concatenated safely.
     98 * 				   This can be used to optimize paragraph
     99 * 				   layout, by avoiding re-shaping of each line
    100 * 				   after line-breaking, by limiting the
    101 * 				   reshaping to a small piece around the
    102 * 				   breaking position only, even if the breaking
    103 * 				   position carries the
    104 * 				   #HB_GLYPH_FLAG_UNSAFE_TO_BREAK or when
    105 * 				   hyphenation or other text transformation
    106 * 				   happens at line-break position, in the following
    107 * 				   way:
    108 * 				   1. Iterate back from the line-break position
    109 * 				   until the first cluster start position that is
    110 * 				   NOT unsafe-to-concat, 2. shape the segment from
    111 * 				   there till the end of line, 3. check whether the
    112 * 				   resulting glyph-run also is clear of the
    113 * 				   unsafe-to-concat at its start-of-text position;
    114 * 				   if it is, just splice it into place and the line
    115 * 				   is shaped; If not, move on to a position further
    116 * 				   back that is clear of unsafe-to-concat and retry
    117 * 				   from there, and repeat.
    118 * 				   At the start of next line a similar algorithm can
    119 * 				   be implemented. That is: 1. Iterate forward from
    120 * 				   the line-break position until the first cluster
    121 * 				   start position that is NOT unsafe-to-concat, 2.
    122 * 				   shape the segment from beginning of the line to
    123 * 				   that position, 3. check whether the resulting
    124 * 				   glyph-run also is clear of the unsafe-to-concat
    125 * 				   at its end-of-text position; if it is, just splice
    126 * 				   it into place and the beginning is shaped; If not,
    127 * 				   move on to a position further forward that is clear
    128 * 				   of unsafe-to-concat and retry up to there, and repeat.
    129 * 				   A slight complication will arise in the
    130 * 				   implementation of the algorithm above,
    131 * 				   because while our buffer API has a way to
    132 * 				   return flags for position corresponding to
    133 * 				   start-of-text, there is currently no position
    134 * 				   corresponding to end-of-text.  This limitation
    135 * 				   can be alleviated by shaping more text than needed
    136 * 				   and looking for unsafe-to-concat flag within text
    137 * 				   clusters.
    138 * 				   The #HB_GLYPH_FLAG_UNSAFE_TO_BREAK flag will
    139 * 				   always imply this flag.
    140 *				   To use this flag, you must enable the buffer flag
    141 *				   @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT during
    142 *				   shaping, otherwise the buffer flag will not be
    143 *				   reliably produced.
    144 * 				   Since: 4.0.0
    145 * @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL: In scripts that use elongation (Arabic,
    146 			   Mongolian, Syriac, etc.), this flag signifies
    147 			   that it is safe to insert a U+0640 TATWEEL
    148 			   character before this cluster for elongation.
    149 			   This flag does not determine the
    150 			   script-specific elongation places, but only
    151 			   when it is safe to do the elongation without
    152 			   interrupting text shaping.
    153 			   Since: 5.1.0
    154 * @HB_GLYPH_FLAG_DEFINED: All the currently defined flags.
    155 *
    156 * Flags for #hb_glyph_info_t.
    157 *
    158 * Since: 1.5.0
    159 */
    160 typedef enum { /*< flags >*/
    161  HB_GLYPH_FLAG_UNSAFE_TO_BREAK			= 0x00000001,
    162  HB_GLYPH_FLAG_UNSAFE_TO_CONCAT		= 0x00000002,
    163  HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL		= 0x00000004,
    164 
    165  HB_GLYPH_FLAG_DEFINED				= 0x00000007 /* OR of all defined flags */
    166 } hb_glyph_flags_t;
    167 
    168 HB_EXTERN hb_glyph_flags_t
    169 hb_glyph_info_get_glyph_flags (const hb_glyph_info_t *info);
    170 
    171 #define hb_glyph_info_get_glyph_flags(info) \
    172 ((hb_glyph_flags_t) ((unsigned int) (info)->mask & HB_GLYPH_FLAG_DEFINED))
    173 
    174 
    175 /**
    176 * hb_glyph_position_t:
    177 * @x_advance: how much the line advances after drawing this glyph when setting
    178 *             text in horizontal direction.
    179 * @y_advance: how much the line advances after drawing this glyph when setting
    180 *             text in vertical direction.
    181 * @x_offset: how much the glyph moves on the X-axis before drawing it, this
    182 *            should not affect how much the line advances.
    183 * @y_offset: how much the glyph moves on the Y-axis before drawing it, this
    184 *            should not affect how much the line advances.
    185 *
    186 * The #hb_glyph_position_t is the structure that holds the positions of the
    187 * glyph in both horizontal and vertical directions. All positions in
    188 * #hb_glyph_position_t are relative to the current point.
    189 *
    190 */
    191 typedef struct hb_glyph_position_t {
    192  hb_position_t  x_advance;
    193  hb_position_t  y_advance;
    194  hb_position_t  x_offset;
    195  hb_position_t  y_offset;
    196 
    197  /*< private >*/
    198  hb_var_int_t   var;
    199 } hb_glyph_position_t;
    200 
    201 /**
    202 * hb_segment_properties_t:
    203 * @direction: the #hb_direction_t of the buffer, see hb_buffer_set_direction().
    204 * @script: the #hb_script_t of the buffer, see hb_buffer_set_script().
    205 * @language: the #hb_language_t of the buffer, see hb_buffer_set_language().
    206 *
    207 * The structure that holds various text properties of an #hb_buffer_t. Can be
    208 * set and retrieved using hb_buffer_set_segment_properties() and
    209 * hb_buffer_get_segment_properties(), respectively.
    210 */
    211 typedef struct hb_segment_properties_t {
    212  hb_direction_t  direction;
    213  hb_script_t     script;
    214  hb_language_t   language;
    215  /*< private >*/
    216  void           *reserved1;
    217  void           *reserved2;
    218 } hb_segment_properties_t;
    219 
    220 /**
    221 * HB_SEGMENT_PROPERTIES_DEFAULT:
    222 *
    223 * The default #hb_segment_properties_t of of freshly created #hb_buffer_t.
    224 */
    225 #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \
    226 			       HB_SCRIPT_INVALID, \
    227 			       HB_LANGUAGE_INVALID, \
    228 			       (void *) 0, \
    229 			       (void *) 0}
    230 
    231 HB_EXTERN hb_bool_t
    232 hb_segment_properties_equal (const hb_segment_properties_t *a,
    233 		     const hb_segment_properties_t *b);
    234 
    235 HB_EXTERN unsigned int
    236 hb_segment_properties_hash (const hb_segment_properties_t *p);
    237 
    238 HB_EXTERN void
    239 hb_segment_properties_overlay (hb_segment_properties_t *p,
    240 		       const hb_segment_properties_t *src);
    241 
    242 
    243 /**
    244 * hb_buffer_t:
    245 *
    246 * The main structure holding the input text and its properties before shaping,
    247 * and output glyphs and their information after shaping.
    248 */
    249 
    250 typedef struct hb_buffer_t hb_buffer_t;
    251 
    252 HB_EXTERN hb_buffer_t *
    253 hb_buffer_create (void);
    254 
    255 HB_EXTERN hb_buffer_t *
    256 hb_buffer_create_similar (const hb_buffer_t *src);
    257 
    258 HB_EXTERN void
    259 hb_buffer_reset (hb_buffer_t *buffer);
    260 
    261 
    262 HB_EXTERN hb_buffer_t *
    263 hb_buffer_get_empty (void);
    264 
    265 HB_EXTERN hb_buffer_t *
    266 hb_buffer_reference (hb_buffer_t *buffer);
    267 
    268 HB_EXTERN void
    269 hb_buffer_destroy (hb_buffer_t *buffer);
    270 
    271 HB_EXTERN hb_bool_t
    272 hb_buffer_set_user_data (hb_buffer_t        *buffer,
    273 		 hb_user_data_key_t *key,
    274 		 void *              data,
    275 		 hb_destroy_func_t   destroy,
    276 		 hb_bool_t           replace);
    277 
    278 HB_EXTERN void *
    279 hb_buffer_get_user_data (const hb_buffer_t  *buffer,
    280 		 hb_user_data_key_t *key);
    281 
    282 
    283 /**
    284 * hb_buffer_content_type_t:
    285 * @HB_BUFFER_CONTENT_TYPE_INVALID: Initial value for new buffer.
    286 * @HB_BUFFER_CONTENT_TYPE_UNICODE: The buffer contains input characters (before shaping).
    287 * @HB_BUFFER_CONTENT_TYPE_GLYPHS: The buffer contains output glyphs (after shaping).
    288 *
    289 * The type of #hb_buffer_t contents.
    290 */
    291 typedef enum {
    292  HB_BUFFER_CONTENT_TYPE_INVALID = 0,
    293  HB_BUFFER_CONTENT_TYPE_UNICODE,
    294  HB_BUFFER_CONTENT_TYPE_GLYPHS
    295 } hb_buffer_content_type_t;
    296 
    297 HB_EXTERN void
    298 hb_buffer_set_content_type (hb_buffer_t              *buffer,
    299 		    hb_buffer_content_type_t  content_type);
    300 
    301 HB_EXTERN hb_buffer_content_type_t
    302 hb_buffer_get_content_type (const hb_buffer_t *buffer);
    303 
    304 
    305 HB_EXTERN void
    306 hb_buffer_set_unicode_funcs (hb_buffer_t        *buffer,
    307 		     hb_unicode_funcs_t *unicode_funcs);
    308 
    309 HB_EXTERN hb_unicode_funcs_t *
    310 hb_buffer_get_unicode_funcs (const hb_buffer_t  *buffer);
    311 
    312 HB_EXTERN void
    313 hb_buffer_set_direction (hb_buffer_t    *buffer,
    314 		 hb_direction_t  direction);
    315 
    316 HB_EXTERN hb_direction_t
    317 hb_buffer_get_direction (const hb_buffer_t *buffer);
    318 
    319 HB_EXTERN void
    320 hb_buffer_set_script (hb_buffer_t *buffer,
    321 	      hb_script_t  script);
    322 
    323 HB_EXTERN hb_script_t
    324 hb_buffer_get_script (const hb_buffer_t *buffer);
    325 
    326 HB_EXTERN void
    327 hb_buffer_set_language (hb_buffer_t   *buffer,
    328 		hb_language_t  language);
    329 
    330 
    331 HB_EXTERN hb_language_t
    332 hb_buffer_get_language (const hb_buffer_t *buffer);
    333 
    334 HB_EXTERN void
    335 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
    336 			  const hb_segment_properties_t *props);
    337 
    338 HB_EXTERN void
    339 hb_buffer_get_segment_properties (const hb_buffer_t *buffer,
    340 			  hb_segment_properties_t *props);
    341 
    342 HB_EXTERN void
    343 hb_buffer_guess_segment_properties (hb_buffer_t *buffer);
    344 
    345 
    346 /**
    347 * hb_buffer_flags_t:
    348 * @HB_BUFFER_FLAG_DEFAULT: the default buffer flag.
    349 * @HB_BUFFER_FLAG_BOT: flag indicating that special handling of the beginning
    350 *                      of text paragraph can be applied to this buffer. Should usually
    351 *                      be set, unless you are passing to the buffer only part
    352 *                      of the text without the full context.
    353 * @HB_BUFFER_FLAG_EOT: flag indicating that special handling of the end of text
    354 *                      paragraph can be applied to this buffer, similar to
    355 *                      @HB_BUFFER_FLAG_BOT.
    356 * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES:
    357 *                      flag indication that character with Default_Ignorable
    358 *                      Unicode property should use the corresponding glyph
    359 *                      from the font, instead of hiding them (done by
    360 *                      replacing them with the space glyph and zeroing the
    361 *                      advance width.)  This flag takes precedence over
    362 *                      @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES.
    363 * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES:
    364 *                      flag indication that character with Default_Ignorable
    365 *                      Unicode property should be removed from glyph string
    366 *                      instead of hiding them (done by replacing them with the
    367 *                      space glyph and zeroing the advance width.)
    368 *                      @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES takes
    369 *                      precedence over this flag. Since: 1.8.0
    370 * @HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE:
    371 *                      flag indicating that a dotted circle should
    372 *                      not be inserted in the rendering of incorrect
    373 *                      character sequences (such at <0905 093E>). Since: 2.4.0
    374 * @HB_BUFFER_FLAG_VERIFY:
    375 *                      flag indicating that the hb_shape() call and its variants
    376 *                      should perform various verification processes on the results
    377 *                      of the shaping operation on the buffer.  If the verification
    378 *                      fails, then either a buffer message is sent, if a message
    379 *                      handler is installed on the buffer, or a message is written
    380 *                      to standard error.  In either case, the shaping result might
    381 *                      be modified to show the failed output. Since: 3.4.0
    382 * @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT:
    383 *                      flag indicating that the @HB_GLYPH_FLAG_UNSAFE_TO_CONCAT
    384 *                      glyph-flag should be produced by the shaper. By default
    385 *                      it will not be produced since it incurs a cost. Since: 4.0.0
    386 * @HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL:
    387 *                      flag indicating that the @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL
    388 *                      glyph-flag should be produced by the shaper. By default
    389 *                      it will not be produced. Since: 5.1.0
    390 * @HB_BUFFER_FLAG_DEFINED: All currently defined flags: Since: 4.4.0
    391 *
    392 * Flags for #hb_buffer_t.
    393 *
    394 * Since: 0.9.20
    395 */
    396 typedef enum { /*< flags >*/
    397  HB_BUFFER_FLAG_DEFAULT			= 0x00000000u,
    398  HB_BUFFER_FLAG_BOT				= 0x00000001u, /* Beginning-of-text */
    399  HB_BUFFER_FLAG_EOT				= 0x00000002u, /* End-of-text */
    400  HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES	= 0x00000004u,
    401  HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES	= 0x00000008u,
    402  HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE	= 0x00000010u,
    403  HB_BUFFER_FLAG_VERIFY				= 0x00000020u,
    404  HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT	= 0x00000040u,
    405  HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL	= 0x00000080u,
    406 
    407  HB_BUFFER_FLAG_DEFINED			= 0x000000FFu
    408 } hb_buffer_flags_t;
    409 
    410 HB_EXTERN void
    411 hb_buffer_set_flags (hb_buffer_t       *buffer,
    412 	     hb_buffer_flags_t  flags);
    413 
    414 HB_EXTERN hb_buffer_flags_t
    415 hb_buffer_get_flags (const hb_buffer_t *buffer);
    416 
    417 /**
    418 * hb_buffer_cluster_level_t:
    419 * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES: Return cluster values grouped by graphemes into
    420 *   monotone order.
    421 * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS: Return cluster values grouped into monotone order.
    422 * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values.
    423 * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level,
    424 *   equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES.
    425 * @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES: Only group clusters, but don't enforce monotone order.
    426 *
    427 * Data type for holding HarfBuzz's clustering behavior options. The cluster level
    428 * dictates one aspect of how HarfBuzz will treat non-base characters
    429 * during shaping.
    430 *
    431 * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base
    432 * characters are merged into the cluster of the base character that precedes them.
    433 * There is also cluster merging every time the clusters will otherwise become non-monotone.
    434 *
    435 * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, non-base characters are initially
    436 * assigned their own cluster values, which are not merged into preceding base
    437 * clusters. This allows HarfBuzz to perform additional operations like reorder
    438 * sequences of adjacent marks. The output is still monotone, but the cluster
    439 * values are more granular.
    440 *
    441 * In @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, non-base characters are assigned their
    442 * own cluster values, which are not merged into preceding base clusters. Moreover,
    443 * the cluster values are not merged into monotone order. This is the most granular
    444 * cluster level, and it is useful for clients that need to know the exact cluster
    445 * values of each character, but is harder to use for clients, since clusters
    446 * might appear in any order.
    447 *
    448 * In @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES, non-base characters are merged into the
    449 * cluster of the base character that precedes them. This is similar to the Unicode
    450 * Grapheme Cluster algorithm, but it is not exactly the same. The output is
    451 * not forced to be monotone. This is useful for clients that want to use HarfBuzz
    452 * as a cheap implementation of the Unicode Grapheme Cluster algorithm.
    453 *
    454 * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES is the default, because it maintains
    455 * backward compatibility with older versions of HarfBuzz. New client programs that
    456 * do not need to maintain such backward compatibility are recommended to use
    457 * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS instead of the default.
    458 *
    459 * Since: 0.9.42
    460 */
    461 typedef enum {
    462  HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES	= 0,
    463  HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS	= 1,
    464  HB_BUFFER_CLUSTER_LEVEL_CHARACTERS		= 2,
    465  HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES		= 3,
    466  HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES
    467 } hb_buffer_cluster_level_t;
    468 
    469 /**
    470 * HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE:
    471 * @level: #hb_buffer_cluster_level_t to test
    472 *
    473 * Tests whether a cluster level groups cluster values into monotone order.
    474 * Requires that the level be valid.
    475 *
    476 * Since: 11.0.0
    477 */
    478 #define HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE(level) \
    479 ((bool) ((1u << (unsigned) (level)) & \
    480 	 ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \
    481 	  (1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS))))
    482 
    483 /**
    484 * HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES:
    485 * @level: #hb_buffer_cluster_level_t to test
    486 *
    487 * Tests whether a cluster level groups cluster values by graphemes. Requires
    488 * that the level be valid.
    489 *
    490 * Since: 11.0.0
    491 */
    492 #define HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES(level) \
    493 ((bool) ((1u << (unsigned) (level)) & \
    494 	 ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \
    495 	  (1u << HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES))))
    496 
    497 /**
    498 * HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS
    499 * @level: #hb_buffer_cluster_level_t to test
    500 *
    501 * Tests whether a cluster level does not group cluster values by graphemes.
    502 * Requires that the level be valid.
    503 *
    504 * Since: 11.0.0
    505 */
    506 #define HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS(level) \
    507 ((bool) ((1u << (unsigned) (level)) & \
    508 	 ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARCATERS) | \
    509 	  (1u << HB_BUFFER_CLUSTER_LEVEL_CHARACTERS))))
    510 
    511 HB_EXTERN void
    512 hb_buffer_set_cluster_level (hb_buffer_t               *buffer,
    513 		     hb_buffer_cluster_level_t  cluster_level);
    514 
    515 HB_EXTERN hb_buffer_cluster_level_t
    516 hb_buffer_get_cluster_level (const hb_buffer_t *buffer);
    517 
    518 /**
    519 * HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT:
    520 *
    521 * The default code point for replacing invalid characters in a given encoding.
    522 * Set to U+FFFD REPLACEMENT CHARACTER.
    523 *
    524 * Since: 0.9.31
    525 */
    526 #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu
    527 
    528 HB_EXTERN void
    529 hb_buffer_set_replacement_codepoint (hb_buffer_t    *buffer,
    530 			     hb_codepoint_t  replacement);
    531 
    532 HB_EXTERN hb_codepoint_t
    533 hb_buffer_get_replacement_codepoint (const hb_buffer_t *buffer);
    534 
    535 HB_EXTERN void
    536 hb_buffer_set_invisible_glyph (hb_buffer_t    *buffer,
    537 		       hb_codepoint_t  invisible);
    538 
    539 HB_EXTERN hb_codepoint_t
    540 hb_buffer_get_invisible_glyph (const hb_buffer_t *buffer);
    541 
    542 HB_EXTERN void
    543 hb_buffer_set_not_found_glyph (hb_buffer_t    *buffer,
    544 		       hb_codepoint_t  not_found);
    545 
    546 HB_EXTERN hb_codepoint_t
    547 hb_buffer_get_not_found_glyph (const hb_buffer_t *buffer);
    548 
    549 HB_EXTERN void
    550 hb_buffer_set_not_found_variation_selector_glyph (hb_buffer_t    *buffer,
    551 					  hb_codepoint_t  not_found_variation_selector);
    552 
    553 HB_EXTERN hb_codepoint_t
    554 hb_buffer_get_not_found_variation_selector_glyph (const hb_buffer_t *buffer);
    555 
    556 HB_EXTERN void
    557 hb_buffer_set_random_state (hb_buffer_t    *buffer,
    558 		    unsigned        state);
    559 
    560 HB_EXTERN unsigned
    561 hb_buffer_get_random_state (const hb_buffer_t *buffer);
    562 
    563 /*
    564 * Content API.
    565 */
    566 
    567 HB_EXTERN void
    568 hb_buffer_clear_contents (hb_buffer_t *buffer);
    569 
    570 HB_EXTERN hb_bool_t
    571 hb_buffer_pre_allocate (hb_buffer_t  *buffer,
    572 		unsigned int  size);
    573 
    574 
    575 HB_EXTERN hb_bool_t
    576 hb_buffer_allocation_successful (hb_buffer_t  *buffer);
    577 
    578 HB_EXTERN void
    579 hb_buffer_reverse (hb_buffer_t *buffer);
    580 
    581 HB_EXTERN void
    582 hb_buffer_reverse_range (hb_buffer_t *buffer,
    583 		 unsigned int start, unsigned int end);
    584 
    585 HB_EXTERN void
    586 hb_buffer_reverse_clusters (hb_buffer_t *buffer);
    587 
    588 
    589 /* Filling the buffer in */
    590 
    591 HB_EXTERN void
    592 hb_buffer_add (hb_buffer_t    *buffer,
    593        hb_codepoint_t  codepoint,
    594        unsigned int    cluster);
    595 
    596 HB_EXTERN void
    597 hb_buffer_add_utf8 (hb_buffer_t  *buffer,
    598 	    const char   *text,
    599 	    int           text_length,
    600 	    unsigned int  item_offset,
    601 	    int           item_length);
    602 
    603 HB_EXTERN void
    604 hb_buffer_add_utf16 (hb_buffer_t    *buffer,
    605 	     const uint16_t *text,
    606 	     int             text_length,
    607 	     unsigned int    item_offset,
    608 	     int             item_length);
    609 
    610 HB_EXTERN void
    611 hb_buffer_add_utf32 (hb_buffer_t    *buffer,
    612 	     const uint32_t *text,
    613 	     int             text_length,
    614 	     unsigned int    item_offset,
    615 	     int             item_length);
    616 
    617 HB_EXTERN void
    618 hb_buffer_add_latin1 (hb_buffer_t   *buffer,
    619 	      const uint8_t *text,
    620 	      int            text_length,
    621 	      unsigned int   item_offset,
    622 	      int            item_length);
    623 
    624 HB_EXTERN void
    625 hb_buffer_add_codepoints (hb_buffer_t          *buffer,
    626 		  const hb_codepoint_t *text,
    627 		  int                   text_length,
    628 		  unsigned int          item_offset,
    629 		  int                   item_length);
    630 
    631 HB_EXTERN void
    632 hb_buffer_append (hb_buffer_t *buffer,
    633 	  const hb_buffer_t *source,
    634 	  unsigned int start,
    635 	  unsigned int end);
    636 
    637 HB_EXTERN hb_bool_t
    638 hb_buffer_set_length (hb_buffer_t  *buffer,
    639 	      unsigned int  length);
    640 
    641 HB_EXTERN unsigned int
    642 hb_buffer_get_length (const hb_buffer_t *buffer);
    643 
    644 /* Getting glyphs out of the buffer */
    645 
    646 HB_EXTERN hb_glyph_info_t *
    647 hb_buffer_get_glyph_infos (hb_buffer_t  *buffer,
    648 		   unsigned int *length);
    649 
    650 HB_EXTERN hb_glyph_position_t *
    651 hb_buffer_get_glyph_positions (hb_buffer_t  *buffer,
    652 		       unsigned int *length);
    653 
    654 HB_EXTERN hb_bool_t
    655 hb_buffer_has_positions (hb_buffer_t  *buffer);
    656 
    657 
    658 HB_EXTERN void
    659 hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
    660 
    661 
    662 /*
    663 * Serialize
    664 */
    665 
    666 /**
    667 * hb_buffer_serialize_flags_t:
    668 * @HB_BUFFER_SERIALIZE_FLAG_DEFAULT: serialize glyph names, clusters and positions.
    669 * @HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS: do not serialize glyph cluster.
    670 * @HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS: do not serialize glyph position information.
    671 * @HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES: do no serialize glyph name.
    672 * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS: serialize glyph extents.
    673 * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS: serialize glyph flags. Since: 1.5.0
    674 * @HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES: do not serialize glyph advances,
    675 *  glyph offsets will reflect absolute glyph positions. Since: 1.8.0
    676 * @HB_BUFFER_SERIALIZE_FLAG_DEFINED: All currently defined flags. Since: 4.4.0
    677 *
    678 * Flags that control what glyph information are serialized in hb_buffer_serialize_glyphs().
    679 *
    680 * Since: 0.9.20
    681 */
    682 typedef enum { /*< flags >*/
    683  HB_BUFFER_SERIALIZE_FLAG_DEFAULT		= 0x00000000u,
    684  HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS		= 0x00000001u,
    685  HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS		= 0x00000002u,
    686  HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES	= 0x00000004u,
    687  HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS	= 0x00000008u,
    688  HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS		= 0x00000010u,
    689  HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES		= 0x00000020u,
    690 
    691  HB_BUFFER_SERIALIZE_FLAG_DEFINED		= 0x0000003Fu
    692 } hb_buffer_serialize_flags_t;
    693 
    694 /**
    695 * hb_buffer_serialize_format_t:
    696 * @HB_BUFFER_SERIALIZE_FORMAT_TEXT: a human-readable, plain text format.
    697 * @HB_BUFFER_SERIALIZE_FORMAT_JSON: a machine-readable JSON format.
    698 * @HB_BUFFER_SERIALIZE_FORMAT_INVALID: invalid format.
    699 *
    700 * The buffer serialization and de-serialization format used in
    701 * hb_buffer_serialize_glyphs() and hb_buffer_deserialize_glyphs().
    702 *
    703 * Since: 0.9.2
    704 */
    705 typedef enum {
    706  HB_BUFFER_SERIALIZE_FORMAT_TEXT	= HB_TAG('T','E','X','T'),
    707  HB_BUFFER_SERIALIZE_FORMAT_JSON	= HB_TAG('J','S','O','N'),
    708  HB_BUFFER_SERIALIZE_FORMAT_INVALID	= HB_TAG_NONE
    709 } hb_buffer_serialize_format_t;
    710 
    711 HB_EXTERN hb_buffer_serialize_format_t
    712 hb_buffer_serialize_format_from_string (const char *str, int len);
    713 
    714 HB_EXTERN const char *
    715 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format);
    716 
    717 HB_EXTERN const char **
    718 hb_buffer_serialize_list_formats (void);
    719 
    720 HB_EXTERN unsigned int
    721 hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
    722 		    unsigned int start,
    723 		    unsigned int end,
    724 		    char *buf,
    725 		    unsigned int buf_size,
    726 		    unsigned int *buf_consumed,
    727 		    hb_font_t *font,
    728 		    hb_buffer_serialize_format_t format,
    729 		    hb_buffer_serialize_flags_t flags);
    730 
    731 HB_EXTERN unsigned int
    732 hb_buffer_serialize_unicode (hb_buffer_t *buffer,
    733 		     unsigned int start,
    734 		     unsigned int end,
    735 		     char *buf,
    736 		     unsigned int buf_size,
    737 		     unsigned int *buf_consumed,
    738 		     hb_buffer_serialize_format_t format,
    739 		     hb_buffer_serialize_flags_t flags);
    740 
    741 HB_EXTERN unsigned int
    742 hb_buffer_serialize (hb_buffer_t *buffer,
    743 	     unsigned int start,
    744 	     unsigned int end,
    745 	     char *buf,
    746 	     unsigned int buf_size,
    747 	     unsigned int *buf_consumed,
    748 	     hb_font_t *font,
    749 	     hb_buffer_serialize_format_t format,
    750 	     hb_buffer_serialize_flags_t flags);
    751 
    752 HB_EXTERN hb_bool_t
    753 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
    754 		      const char *buf,
    755 		      int buf_len,
    756 		      const char **end_ptr,
    757 		      hb_font_t *font,
    758 		      hb_buffer_serialize_format_t format);
    759 
    760 HB_EXTERN hb_bool_t
    761 hb_buffer_deserialize_unicode (hb_buffer_t *buffer,
    762 		       const char *buf,
    763 		       int buf_len,
    764 		       const char **end_ptr,
    765 		       hb_buffer_serialize_format_t format);
    766 
    767 
    768 
    769 /*
    770 * Compare buffers
    771 */
    772 
    773 /**
    774 * hb_buffer_diff_flags_t:
    775 * @HB_BUFFER_DIFF_FLAG_EQUAL: equal buffers.
    776 * @HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH: buffers with different
    777 *     #hb_buffer_content_type_t.
    778 * @HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH: buffers with differing length.
    779 * @HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT: `.notdef` glyph is present in the
    780 *     reference buffer.
    781 * @HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT: dotted circle glyph is present
    782 *     in the reference buffer.
    783 * @HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH: difference in #hb_glyph_info_t.codepoint
    784 * @HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH: difference in #hb_glyph_info_t.cluster
    785 * @HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH: difference in #hb_glyph_flags_t.
    786 * @HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH: difference in #hb_glyph_position_t.
    787 *
    788 * Flags from comparing two #hb_buffer_t's.
    789 *
    790 * Buffer with different #hb_buffer_content_type_t cannot be meaningfully
    791 * compared in any further detail.
    792 *
    793 * For buffers with differing length, the per-glyph comparison is not
    794 * attempted, though we do still scan reference buffer for dotted circle and
    795 * `.notdef` glyphs.
    796 *
    797 * If the buffers have the same length, we compare them glyph-by-glyph and
    798 * report which aspect(s) of the glyph info/position are different.
    799 *
    800 * Since: 1.5.0
    801 */
    802 typedef enum { /*< flags >*/
    803  HB_BUFFER_DIFF_FLAG_EQUAL			= 0x0000,
    804 
    805  /* Buffers with different content_type cannot be meaningfully compared
    806   * in any further detail. */
    807  HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH	= 0x0001,
    808 
    809  /* For buffers with differing length, the per-glyph comparison is not
    810   * attempted, though we do still scan reference for dottedcircle / .notdef
    811   * glyphs. */
    812  HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH		= 0x0002,
    813 
    814  /* We want to know if dottedcircle / .notdef glyphs are present in the
    815   * reference, as we may not care so much about other differences in this
    816   * case. */
    817  HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT		= 0x0004,
    818  HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT	= 0x0008,
    819 
    820  /* If the buffers have the same length, we compare them glyph-by-glyph
    821   * and report which aspect(s) of the glyph info/position are different. */
    822  HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH	= 0x0010,
    823  HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH		= 0x0020,
    824  HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH	= 0x0040,
    825  HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH		= 0x0080
    826 
    827 } hb_buffer_diff_flags_t;
    828 
    829 /* Compare the contents of two buffers, report types of differences. */
    830 HB_EXTERN hb_buffer_diff_flags_t
    831 hb_buffer_diff (hb_buffer_t *buffer,
    832 	hb_buffer_t *reference,
    833 	hb_codepoint_t dottedcircle_glyph,
    834 	unsigned int position_fuzz);
    835 
    836 
    837 /*
    838 * Tracing.
    839 */
    840 
    841 /**
    842 * hb_buffer_message_func_t:
    843 * @buffer: An #hb_buffer_t to work upon
    844 * @font: The #hb_font_t the @buffer is shaped with
    845 * @message: `NULL`-terminated message passed to the function
    846 * @user_data: User data pointer passed by the caller
    847 *
    848 * A callback method for #hb_buffer_t. The method gets called with the
    849 * #hb_buffer_t it was set on, the #hb_font_t the buffer is shaped with and a
    850 * message describing what step of the shaping process will be performed.
    851 * Returning `false` from this method will skip this shaping step and move to
    852 * the next one.
    853 *
    854 * Return value: `true` to perform the shaping step, `false` to skip it.
    855 *
    856 * Since: 1.1.3
    857 */
    858 typedef hb_bool_t	(*hb_buffer_message_func_t)	(hb_buffer_t *buffer,
    859 						 hb_font_t   *font,
    860 						 const char  *message,
    861 						 void        *user_data);
    862 
    863 HB_EXTERN void
    864 hb_buffer_set_message_func (hb_buffer_t *buffer,
    865 		    hb_buffer_message_func_t func,
    866 		    void *user_data, hb_destroy_func_t destroy);
    867 
    868 
    869 HB_END_DECLS
    870 
    871 #endif /* HB_BUFFER_H */