| 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 | #ifndef HB_H_IN |
| 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. On the flip side, |
| 80 | * it means that when this flag is not present, |
| 81 | * then it's safe to break the glyph-run at the |
| 82 | * beginning of this cluster, and the two sides |
| 83 | * represent the exact same result one would get |
| 84 | * if breaking input text at the beginning of |
| 85 | * this cluster and shaping the two sides |
| 86 | * separately. This can be used to optimize |
| 87 | * paragraph layout, by avoiding re-shaping |
| 88 | * of each line after line-breaking, or limiting |
| 89 | * the reshaping to a small piece around the |
| 90 | * breaking point only. |
| 91 | * @HB_GLYPH_FLAG_DEFINED: All the currently defined flags. |
| 92 | * |
| 93 | * Since: 1.5.0 |
| 94 | */ |
| 95 | typedef enum { /*< flags >*/ |
| 96 | HB_GLYPH_FLAG_UNSAFE_TO_BREAK = 0x00000001, |
| 97 | |
| 98 | HB_GLYPH_FLAG_DEFINED = 0x00000001 /* OR of all defined flags */ |
| 99 | } hb_glyph_flags_t; |
| 100 | |
| 101 | HB_EXTERN hb_glyph_flags_t |
| 102 | hb_glyph_info_get_glyph_flags (const hb_glyph_info_t *info); |
| 103 | |
| 104 | #define hb_glyph_info_get_glyph_flags(info) \ |
| 105 | ((hb_glyph_flags_t) ((unsigned int) (info)->mask & HB_GLYPH_FLAG_DEFINED)) |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * hb_glyph_position_t: |
| 110 | * @x_advance: how much the line advances after drawing this glyph when setting |
| 111 | * text in horizontal direction. |
| 112 | * @y_advance: how much the line advances after drawing this glyph when setting |
| 113 | * text in vertical direction. |
| 114 | * @x_offset: how much the glyph moves on the X-axis before drawing it, this |
| 115 | * should not affect how much the line advances. |
| 116 | * @y_offset: how much the glyph moves on the Y-axis before drawing it, this |
| 117 | * should not affect how much the line advances. |
| 118 | * |
| 119 | * The #hb_glyph_position_t is the structure that holds the positions of the |
| 120 | * glyph in both horizontal and vertical directions. All positions in |
| 121 | * #hb_glyph_position_t are relative to the current point. |
| 122 | * |
| 123 | */ |
| 124 | typedef struct hb_glyph_position_t { |
| 125 | hb_position_t x_advance; |
| 126 | hb_position_t y_advance; |
| 127 | hb_position_t x_offset; |
| 128 | hb_position_t y_offset; |
| 129 | |
| 130 | /*< private >*/ |
| 131 | hb_var_int_t var; |
| 132 | } hb_glyph_position_t; |
| 133 | |
| 134 | /** |
| 135 | * hb_segment_properties_t: |
| 136 | * @direction: the #hb_direction_t of the buffer, see hb_buffer_set_direction(). |
| 137 | * @script: the #hb_script_t of the buffer, see hb_buffer_set_script(). |
| 138 | * @language: the #hb_language_t of the buffer, see hb_buffer_set_language(). |
| 139 | * |
| 140 | * The structure that holds various text properties of an #hb_buffer_t. Can be |
| 141 | * set and retrieved using hb_buffer_set_segment_properties() and |
| 142 | * hb_buffer_get_segment_properties(), respectively. |
| 143 | */ |
| 144 | typedef struct hb_segment_properties_t { |
| 145 | hb_direction_t direction; |
| 146 | hb_script_t script; |
| 147 | hb_language_t language; |
| 148 | /*< private >*/ |
| 149 | void *reserved1; |
| 150 | void *reserved2; |
| 151 | } hb_segment_properties_t; |
| 152 | |
| 153 | #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \ |
| 154 | HB_SCRIPT_INVALID, \ |
| 155 | HB_LANGUAGE_INVALID, \ |
| 156 | (void *) 0, \ |
| 157 | (void *) 0} |
| 158 | |
| 159 | HB_EXTERN hb_bool_t |
| 160 | hb_segment_properties_equal (const hb_segment_properties_t *a, |
| 161 | const hb_segment_properties_t *b); |
| 162 | |
| 163 | HB_EXTERN unsigned int |
| 164 | hb_segment_properties_hash (const hb_segment_properties_t *p); |
| 165 | |
| 166 | |
| 167 | |
| 168 | /** |
| 169 | * hb_buffer_t: |
| 170 | * |
| 171 | * The main structure holding the input text and its properties before shaping, |
| 172 | * and output glyphs and their information after shaping. |
| 173 | */ |
| 174 | |
| 175 | typedef struct hb_buffer_t hb_buffer_t; |
| 176 | |
| 177 | HB_EXTERN hb_buffer_t * |
| 178 | hb_buffer_create (void); |
| 179 | |
| 180 | HB_EXTERN hb_buffer_t * |
| 181 | hb_buffer_get_empty (void); |
| 182 | |
| 183 | HB_EXTERN hb_buffer_t * |
| 184 | hb_buffer_reference (hb_buffer_t *buffer); |
| 185 | |
| 186 | HB_EXTERN void |
| 187 | hb_buffer_destroy (hb_buffer_t *buffer); |
| 188 | |
| 189 | HB_EXTERN hb_bool_t |
| 190 | hb_buffer_set_user_data (hb_buffer_t *buffer, |
| 191 | hb_user_data_key_t *key, |
| 192 | void * data, |
| 193 | hb_destroy_func_t destroy, |
| 194 | hb_bool_t replace); |
| 195 | |
| 196 | HB_EXTERN void * |
| 197 | hb_buffer_get_user_data (hb_buffer_t *buffer, |
| 198 | hb_user_data_key_t *key); |
| 199 | |
| 200 | |
| 201 | /** |
| 202 | * hb_buffer_content_type_t: |
| 203 | * @HB_BUFFER_CONTENT_TYPE_INVALID: Initial value for new buffer. |
| 204 | * @HB_BUFFER_CONTENT_TYPE_UNICODE: The buffer contains input characters (before shaping). |
| 205 | * @HB_BUFFER_CONTENT_TYPE_GLYPHS: The buffer contains output glyphs (after shaping). |
| 206 | */ |
| 207 | typedef enum { |
| 208 | HB_BUFFER_CONTENT_TYPE_INVALID = 0, |
| 209 | HB_BUFFER_CONTENT_TYPE_UNICODE, |
| 210 | HB_BUFFER_CONTENT_TYPE_GLYPHS |
| 211 | } hb_buffer_content_type_t; |
| 212 | |
| 213 | HB_EXTERN void |
| 214 | hb_buffer_set_content_type (hb_buffer_t *buffer, |
| 215 | hb_buffer_content_type_t content_type); |
| 216 | |
| 217 | HB_EXTERN hb_buffer_content_type_t |
| 218 | hb_buffer_get_content_type (hb_buffer_t *buffer); |
| 219 | |
| 220 | |
| 221 | HB_EXTERN void |
| 222 | hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, |
| 223 | hb_unicode_funcs_t *unicode_funcs); |
| 224 | |
| 225 | HB_EXTERN hb_unicode_funcs_t * |
| 226 | hb_buffer_get_unicode_funcs (hb_buffer_t *buffer); |
| 227 | |
| 228 | HB_EXTERN void |
| 229 | hb_buffer_set_direction (hb_buffer_t *buffer, |
| 230 | hb_direction_t direction); |
| 231 | |
| 232 | HB_EXTERN hb_direction_t |
| 233 | hb_buffer_get_direction (hb_buffer_t *buffer); |
| 234 | |
| 235 | HB_EXTERN void |
| 236 | hb_buffer_set_script (hb_buffer_t *buffer, |
| 237 | hb_script_t script); |
| 238 | |
| 239 | HB_EXTERN hb_script_t |
| 240 | hb_buffer_get_script (hb_buffer_t *buffer); |
| 241 | |
| 242 | HB_EXTERN void |
| 243 | hb_buffer_set_language (hb_buffer_t *buffer, |
| 244 | hb_language_t language); |
| 245 | |
| 246 | |
| 247 | HB_EXTERN hb_language_t |
| 248 | hb_buffer_get_language (hb_buffer_t *buffer); |
| 249 | |
| 250 | HB_EXTERN void |
| 251 | hb_buffer_set_segment_properties (hb_buffer_t *buffer, |
| 252 | const hb_segment_properties_t *props); |
| 253 | |
| 254 | HB_EXTERN void |
| 255 | hb_buffer_get_segment_properties (hb_buffer_t *buffer, |
| 256 | hb_segment_properties_t *props); |
| 257 | |
| 258 | HB_EXTERN void |
| 259 | hb_buffer_guess_segment_properties (hb_buffer_t *buffer); |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * hb_buffer_flags_t: |
| 264 | * @HB_BUFFER_FLAG_DEFAULT: the default buffer flag. |
| 265 | * @HB_BUFFER_FLAG_BOT: flag indicating that special handling of the beginning |
| 266 | * of text paragraph can be applied to this buffer. Should usually |
| 267 | * be set, unless you are passing to the buffer only part |
| 268 | * of the text without the full context. |
| 269 | * @HB_BUFFER_FLAG_EOT: flag indicating that special handling of the end of text |
| 270 | * paragraph can be applied to this buffer, similar to |
| 271 | * @HB_BUFFER_FLAG_BOT. |
| 272 | * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES: |
| 273 | * flag indication that character with Default_Ignorable |
| 274 | * Unicode property should use the corresponding glyph |
| 275 | * from the font, instead of hiding them (done by |
| 276 | * replacing them with the space glyph and zeroing the |
| 277 | * advance width.) This flag takes precedence over |
| 278 | * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES. |
| 279 | * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES: |
| 280 | * flag indication that character with Default_Ignorable |
| 281 | * Unicode property should be removed from glyph string |
| 282 | * instead of hiding them (done by replacing them with the |
| 283 | * space glyph and zeroing the advance width.) |
| 284 | * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES takes |
| 285 | * precedence over this flag. Since: 1.8.0 |
| 286 | * @HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE: |
| 287 | * flag indicating that a dotted circle should |
| 288 | * not be inserted in the rendering of incorrect |
| 289 | * character sequences (such at <0905 093E>). Since: 2.4 |
| 290 | * |
| 291 | * Since: 0.9.20 |
| 292 | */ |
| 293 | typedef enum { /*< flags >*/ |
| 294 | HB_BUFFER_FLAG_DEFAULT = 0x00000000u, |
| 295 | HB_BUFFER_FLAG_BOT = 0x00000001u, /* Beginning-of-text */ |
| 296 | HB_BUFFER_FLAG_EOT = 0x00000002u, /* End-of-text */ |
| 297 | HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004u, |
| 298 | HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES = 0x00000008u, |
| 299 | HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE = 0x00000010u |
| 300 | } hb_buffer_flags_t; |
| 301 | |
| 302 | HB_EXTERN void |
| 303 | hb_buffer_set_flags (hb_buffer_t *buffer, |
| 304 | hb_buffer_flags_t flags); |
| 305 | |
| 306 | HB_EXTERN hb_buffer_flags_t |
| 307 | hb_buffer_get_flags (hb_buffer_t *buffer); |
| 308 | |
| 309 | /** |
| 310 | * hb_buffer_cluster_level_t: |
| 311 | * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES: Return cluster values grouped by graphemes into |
| 312 | * monotone order. |
| 313 | * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS: Return cluster values grouped into monotone order. |
| 314 | * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values. |
| 315 | * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level, |
| 316 | * equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES. |
| 317 | * |
| 318 | * Data type for holding HarfBuzz's clustering behavior options. The cluster level |
| 319 | * dictates one aspect of how HarfBuzz will treat non-base characters |
| 320 | * during shaping. |
| 321 | * |
| 322 | * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base |
| 323 | * characters are merged into the cluster of the base character that precedes them. |
| 324 | * |
| 325 | * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, non-base characters are initially |
| 326 | * assigned their own cluster values, which are not merged into preceding base |
| 327 | * clusters. This allows HarfBuzz to perform additional operations like reorder |
| 328 | * sequences of adjacent marks. |
| 329 | * |
| 330 | * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES is the default, because it maintains |
| 331 | * backward compatibility with older versions of HarfBuzz. New client programs that |
| 332 | * do not need to maintain such backward compatibility are recommended to use |
| 333 | * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS instead of the default. |
| 334 | * |
| 335 | * Since: 0.9.42 |
| 336 | */ |
| 337 | typedef enum { |
| 338 | HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0, |
| 339 | HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1, |
| 340 | HB_BUFFER_CLUSTER_LEVEL_CHARACTERS = 2, |
| 341 | HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES |
| 342 | } hb_buffer_cluster_level_t; |
| 343 | |
| 344 | HB_EXTERN void |
| 345 | hb_buffer_set_cluster_level (hb_buffer_t *buffer, |
| 346 | hb_buffer_cluster_level_t cluster_level); |
| 347 | |
| 348 | HB_EXTERN hb_buffer_cluster_level_t |
| 349 | hb_buffer_get_cluster_level (hb_buffer_t *buffer); |
| 350 | |
| 351 | /** |
| 352 | * HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT: |
| 353 | * |
| 354 | * The default code point for replacing invalid characters in a given encoding. |
| 355 | * Set to U+FFFD REPLACEMENT CHARACTER. |
| 356 | * |
| 357 | * Since: 0.9.31 |
| 358 | */ |
| 359 | #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu |
| 360 | |
| 361 | HB_EXTERN void |
| 362 | hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer, |
| 363 | hb_codepoint_t replacement); |
| 364 | |
| 365 | HB_EXTERN hb_codepoint_t |
| 366 | hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer); |
| 367 | |
| 368 | HB_EXTERN void |
| 369 | hb_buffer_set_invisible_glyph (hb_buffer_t *buffer, |
| 370 | hb_codepoint_t invisible); |
| 371 | |
| 372 | HB_EXTERN hb_codepoint_t |
| 373 | hb_buffer_get_invisible_glyph (hb_buffer_t *buffer); |
| 374 | |
| 375 | |
| 376 | HB_EXTERN void |
| 377 | hb_buffer_reset (hb_buffer_t *buffer); |
| 378 | |
| 379 | HB_EXTERN void |
| 380 | hb_buffer_clear_contents (hb_buffer_t *buffer); |
| 381 | |
| 382 | HB_EXTERN hb_bool_t |
| 383 | hb_buffer_pre_allocate (hb_buffer_t *buffer, |
| 384 | unsigned int size); |
| 385 | |
| 386 | |
| 387 | HB_EXTERN hb_bool_t |
| 388 | hb_buffer_allocation_successful (hb_buffer_t *buffer); |
| 389 | |
| 390 | HB_EXTERN void |
| 391 | hb_buffer_reverse (hb_buffer_t *buffer); |
| 392 | |
| 393 | HB_EXTERN void |
| 394 | hb_buffer_reverse_range (hb_buffer_t *buffer, |
| 395 | unsigned int start, unsigned int end); |
| 396 | |
| 397 | HB_EXTERN void |
| 398 | hb_buffer_reverse_clusters (hb_buffer_t *buffer); |
| 399 | |
| 400 | |
| 401 | /* Filling the buffer in */ |
| 402 | |
| 403 | HB_EXTERN void |
| 404 | hb_buffer_add (hb_buffer_t *buffer, |
| 405 | hb_codepoint_t codepoint, |
| 406 | unsigned int cluster); |
| 407 | |
| 408 | HB_EXTERN void |
| 409 | hb_buffer_add_utf8 (hb_buffer_t *buffer, |
| 410 | const char *text, |
| 411 | int text_length, |
| 412 | unsigned int item_offset, |
| 413 | int item_length); |
| 414 | |
| 415 | HB_EXTERN void |
| 416 | hb_buffer_add_utf16 (hb_buffer_t *buffer, |
| 417 | const uint16_t *text, |
| 418 | int text_length, |
| 419 | unsigned int item_offset, |
| 420 | int item_length); |
| 421 | |
| 422 | HB_EXTERN void |
| 423 | hb_buffer_add_utf32 (hb_buffer_t *buffer, |
| 424 | const uint32_t *text, |
| 425 | int text_length, |
| 426 | unsigned int item_offset, |
| 427 | int item_length); |
| 428 | |
| 429 | HB_EXTERN void |
| 430 | hb_buffer_add_latin1 (hb_buffer_t *buffer, |
| 431 | const uint8_t *text, |
| 432 | int text_length, |
| 433 | unsigned int item_offset, |
| 434 | int item_length); |
| 435 | |
| 436 | HB_EXTERN void |
| 437 | hb_buffer_add_codepoints (hb_buffer_t *buffer, |
| 438 | const hb_codepoint_t *text, |
| 439 | int text_length, |
| 440 | unsigned int item_offset, |
| 441 | int item_length); |
| 442 | |
| 443 | HB_EXTERN void |
| 444 | hb_buffer_append (hb_buffer_t *buffer, |
| 445 | hb_buffer_t *source, |
| 446 | unsigned int start, |
| 447 | unsigned int end); |
| 448 | |
| 449 | HB_EXTERN hb_bool_t |
| 450 | hb_buffer_set_length (hb_buffer_t *buffer, |
| 451 | unsigned int length); |
| 452 | |
| 453 | HB_EXTERN unsigned int |
| 454 | hb_buffer_get_length (hb_buffer_t *buffer); |
| 455 | |
| 456 | /* Getting glyphs out of the buffer */ |
| 457 | |
| 458 | HB_EXTERN hb_glyph_info_t * |
| 459 | hb_buffer_get_glyph_infos (hb_buffer_t *buffer, |
| 460 | unsigned int *length); |
| 461 | |
| 462 | HB_EXTERN hb_glyph_position_t * |
| 463 | hb_buffer_get_glyph_positions (hb_buffer_t *buffer, |
| 464 | unsigned int *length); |
| 465 | |
| 466 | HB_EXTERN hb_bool_t |
| 467 | hb_buffer_has_positions (hb_buffer_t *buffer); |
| 468 | |
| 469 | |
| 470 | HB_EXTERN void |
| 471 | hb_buffer_normalize_glyphs (hb_buffer_t *buffer); |
| 472 | |
| 473 | |
| 474 | /* |
| 475 | * Serialize |
| 476 | */ |
| 477 | |
| 478 | /** |
| 479 | * hb_buffer_serialize_flags_t: |
| 480 | * @HB_BUFFER_SERIALIZE_FLAG_DEFAULT: serialize glyph names, clusters and positions. |
| 481 | * @HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS: do not serialize glyph cluster. |
| 482 | * @HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS: do not serialize glyph position information. |
| 483 | * @HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES: do no serialize glyph name. |
| 484 | * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS: serialize glyph extents. |
| 485 | * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS: serialize glyph flags. Since: 1.5.0 |
| 486 | * @HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES: do not serialize glyph advances, |
| 487 | * glyph offsets will reflect absolute glyph positions. Since: 1.8.0 |
| 488 | * |
| 489 | * Flags that control what glyph information are serialized in hb_buffer_serialize_glyphs(). |
| 490 | * |
| 491 | * Since: 0.9.20 |
| 492 | */ |
| 493 | typedef enum { /*< flags >*/ |
| 494 | HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u, |
| 495 | HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u, |
| 496 | HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u, |
| 497 | HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u, |
| 498 | HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u, |
| 499 | HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS = 0x00000010u, |
| 500 | HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES = 0x00000020u |
| 501 | } hb_buffer_serialize_flags_t; |
| 502 | |
| 503 | /** |
| 504 | * hb_buffer_serialize_format_t: |
| 505 | * @HB_BUFFER_SERIALIZE_FORMAT_TEXT: a human-readable, plain text format. |
| 506 | * @HB_BUFFER_SERIALIZE_FORMAT_JSON: a machine-readable JSON format. |
| 507 | * @HB_BUFFER_SERIALIZE_FORMAT_INVALID: invalid format. |
| 508 | * |
| 509 | * The buffer serialization and de-serialization format used in |
| 510 | * hb_buffer_serialize_glyphs() and hb_buffer_deserialize_glyphs(). |
| 511 | * |
| 512 | * Since: 0.9.2 |
| 513 | */ |
| 514 | typedef enum { |
| 515 | HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'), |
| 516 | HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'), |
| 517 | HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE |
| 518 | } hb_buffer_serialize_format_t; |
| 519 | |
| 520 | HB_EXTERN hb_buffer_serialize_format_t |
| 521 | hb_buffer_serialize_format_from_string (const char *str, int len); |
| 522 | |
| 523 | HB_EXTERN const char * |
| 524 | hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format); |
| 525 | |
| 526 | HB_EXTERN const char ** |
| 527 | hb_buffer_serialize_list_formats (void); |
| 528 | |
| 529 | HB_EXTERN unsigned int |
| 530 | hb_buffer_serialize_glyphs (hb_buffer_t *buffer, |
| 531 | unsigned int start, |
| 532 | unsigned int end, |
| 533 | char *buf, |
| 534 | unsigned int buf_size, |
| 535 | unsigned int *buf_consumed, |
| 536 | hb_font_t *font, |
| 537 | hb_buffer_serialize_format_t format, |
| 538 | hb_buffer_serialize_flags_t flags); |
| 539 | |
| 540 | HB_EXTERN unsigned int |
| 541 | hb_buffer_serialize_unicode (hb_buffer_t *buffer, |
| 542 | unsigned int start, |
| 543 | unsigned int end, |
| 544 | char *buf, |
| 545 | unsigned int buf_size, |
| 546 | unsigned int *buf_consumed, |
| 547 | hb_buffer_serialize_format_t format, |
| 548 | hb_buffer_serialize_flags_t flags); |
| 549 | |
| 550 | HB_EXTERN unsigned int |
| 551 | hb_buffer_serialize (hb_buffer_t *buffer, |
| 552 | unsigned int start, |
| 553 | unsigned int end, |
| 554 | char *buf, |
| 555 | unsigned int buf_size, |
| 556 | unsigned int *buf_consumed, |
| 557 | hb_font_t *font, |
| 558 | hb_buffer_serialize_format_t format, |
| 559 | hb_buffer_serialize_flags_t flags); |
| 560 | |
| 561 | HB_EXTERN hb_bool_t |
| 562 | hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, |
| 563 | const char *buf, |
| 564 | int buf_len, |
| 565 | const char **end_ptr, |
| 566 | hb_font_t *font, |
| 567 | hb_buffer_serialize_format_t format); |
| 568 | |
| 569 | HB_EXTERN hb_bool_t |
| 570 | hb_buffer_deserialize_unicode (hb_buffer_t *buffer, |
| 571 | const char *buf, |
| 572 | int buf_len, |
| 573 | const char **end_ptr, |
| 574 | hb_buffer_serialize_format_t format); |
| 575 | |
| 576 | |
| 577 | |
| 578 | /* |
| 579 | * Compare buffers |
| 580 | */ |
| 581 | |
| 582 | typedef enum { /*< flags >*/ |
| 583 | HB_BUFFER_DIFF_FLAG_EQUAL = 0x0000, |
| 584 | |
| 585 | /* Buffers with different content_type cannot be meaningfully compared |
| 586 | * in any further detail. */ |
| 587 | HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH = 0x0001, |
| 588 | |
| 589 | /* For buffers with differing length, the per-glyph comparison is not |
| 590 | * attempted, though we do still scan reference for dottedcircle / .notdef |
| 591 | * glyphs. */ |
| 592 | HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH = 0x0002, |
| 593 | |
| 594 | /* We want to know if dottedcircle / .notdef glyphs are present in the |
| 595 | * reference, as we may not care so much about other differences in this |
| 596 | * case. */ |
| 597 | HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT = 0x0004, |
| 598 | HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT = 0x0008, |
| 599 | |
| 600 | /* If the buffers have the same length, we compare them glyph-by-glyph |
| 601 | * and report which aspect(s) of the glyph info/position are different. */ |
| 602 | HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH = 0x0010, |
| 603 | HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH = 0x0020, |
| 604 | HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH = 0x0040, |
| 605 | HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH = 0x0080 |
| 606 | |
| 607 | } hb_buffer_diff_flags_t; |
| 608 | |
| 609 | /* Compare the contents of two buffers, report types of differences. */ |
| 610 | HB_EXTERN hb_buffer_diff_flags_t |
| 611 | hb_buffer_diff (hb_buffer_t *buffer, |
| 612 | hb_buffer_t *reference, |
| 613 | hb_codepoint_t dottedcircle_glyph, |
| 614 | unsigned int position_fuzz); |
| 615 | |
| 616 | |
| 617 | /* |
| 618 | * Debugging. |
| 619 | */ |
| 620 | |
| 621 | typedef hb_bool_t (*hb_buffer_message_func_t) (hb_buffer_t *buffer, |
| 622 | hb_font_t *font, |
| 623 | const char *message, |
| 624 | void *user_data); |
| 625 | |
| 626 | HB_EXTERN void |
| 627 | hb_buffer_set_message_func (hb_buffer_t *buffer, |
| 628 | hb_buffer_message_func_t func, |
| 629 | void *user_data, hb_destroy_func_t destroy); |
| 630 | |
| 631 | |
| 632 | HB_END_DECLS |
| 633 | |
| 634 | #endif /* HB_BUFFER_H */ |
| 635 | |