2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009 Red Hat, Inc.
4 * Copyright © 2011,2012 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
26 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
27 * Google Author(s): Behdad Esfahbod
31 #error "Include <hb.h> instead."
37 #include "hb-common.h"
38 #include "hb-unicode.h"
45 * @codepoint: either a Unicode code point (before shaping) or a glyph index
48 * @cluster: the index of the character in the original text that corresponds
49 * to this #hb_glyph_info_t, or whatever the client passes to
50 * hb_buffer_add(). More than one #hb_glyph_info_t can have the same
51 * @cluster value, if they resulted from the same character (e.g. one
52 * to many glyph substitution), and when more than one character gets
53 * merged in the same glyph (e.g. many to one glyph substitution) the
54 * #hb_glyph_info_t will have the smallest cluster value of them.
55 * By default some characters are merged into the same cluster
56 * (e.g. combining marks have the same cluster as their bases)
57 * even if they are separate glyphs, hb_buffer_set_cluster_level()
58 * allow selecting more fine-grained cluster handling.
60 * The #hb_glyph_info_t is the structure that holds information about the
61 * glyphs and their relation to input text.
64 typedef struct hb_glyph_info_t {
65 hb_codepoint_t codepoint;
66 hb_mask_t mask; /* Holds hb_glyph_flags_t after hb_shape(), plus other things. */
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.
92 typedef enum { /*< flags >*/
93 HB_GLYPH_FLAG_UNSAFE_TO_BREAK = 0x00000001,
95 HB_GLYPH_FLAG_DEFINED = 0x00000001 /* OR of all defined flags */
98 HB_EXTERN hb_glyph_flags_t
99 hb_glyph_info_get_glyph_flags (const hb_glyph_info_t *info);
101 #define hb_glyph_info_get_glyph_flags(info) \
102 ((hb_glyph_flags_t) ((unsigned int) (info)->mask & HB_GLYPH_FLAG_DEFINED))
106 * hb_glyph_position_t:
107 * @x_advance: how much the line advances after drawing this glyph when setting
108 * text in horizontal direction.
109 * @y_advance: how much the line advances after drawing this glyph when setting
110 * text in vertical direction.
111 * @x_offset: how much the glyph moves on the X-axis before drawing it, this
112 * should not affect how much the line advances.
113 * @y_offset: how much the glyph moves on the Y-axis before drawing it, this
114 * should not affect how much the line advances.
116 * The #hb_glyph_position_t is the structure that holds the positions of the
117 * glyph in both horizontal and vertical directions. All positions in
118 * #hb_glyph_position_t are relative to the current point.
121 typedef struct hb_glyph_position_t {
122 hb_position_t x_advance;
123 hb_position_t y_advance;
124 hb_position_t x_offset;
125 hb_position_t y_offset;
129 } hb_glyph_position_t;
132 * hb_segment_properties_t:
133 * @direction: the #hb_direction_t of the buffer, see hb_buffer_set_direction().
134 * @script: the #hb_script_t of the buffer, see hb_buffer_set_script().
135 * @language: the #hb_language_t of the buffer, see hb_buffer_set_language().
137 * The structure that holds various text properties of an #hb_buffer_t. Can be
138 * set and retrieved using hb_buffer_set_segment_properties() and
139 * hb_buffer_get_segment_properties(), respectively.
141 typedef struct hb_segment_properties_t {
142 hb_direction_t direction;
144 hb_language_t language;
148 } hb_segment_properties_t;
150 #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \
152 HB_LANGUAGE_INVALID, \
157 hb_segment_properties_equal (const hb_segment_properties_t *a,
158 const hb_segment_properties_t *b);
160 HB_EXTERN unsigned int
161 hb_segment_properties_hash (const hb_segment_properties_t *p);
168 * The main structure holding the input text and its properties before shaping,
169 * and output glyphs and their information after shaping.
172 typedef struct hb_buffer_t hb_buffer_t;
174 HB_EXTERN hb_buffer_t *
175 hb_buffer_create (void);
177 HB_EXTERN hb_buffer_t *
178 hb_buffer_get_empty (void);
180 HB_EXTERN hb_buffer_t *
181 hb_buffer_reference (hb_buffer_t *buffer);
184 hb_buffer_destroy (hb_buffer_t *buffer);
187 hb_buffer_set_user_data (hb_buffer_t *buffer,
188 hb_user_data_key_t *key,
190 hb_destroy_func_t destroy,
194 hb_buffer_get_user_data (hb_buffer_t *buffer,
195 hb_user_data_key_t *key);
199 * hb_buffer_content_type_t:
200 * @HB_BUFFER_CONTENT_TYPE_INVALID: Initial value for new buffer.
201 * @HB_BUFFER_CONTENT_TYPE_UNICODE: The buffer contains input characters (before shaping).
202 * @HB_BUFFER_CONTENT_TYPE_GLYPHS: The buffer contains output glyphs (after shaping).
205 HB_BUFFER_CONTENT_TYPE_INVALID = 0,
206 HB_BUFFER_CONTENT_TYPE_UNICODE,
207 HB_BUFFER_CONTENT_TYPE_GLYPHS
208 } hb_buffer_content_type_t;
211 hb_buffer_set_content_type (hb_buffer_t *buffer,
212 hb_buffer_content_type_t content_type);
214 HB_EXTERN hb_buffer_content_type_t
215 hb_buffer_get_content_type (hb_buffer_t *buffer);
219 hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
220 hb_unicode_funcs_t *unicode_funcs);
222 HB_EXTERN hb_unicode_funcs_t *
223 hb_buffer_get_unicode_funcs (hb_buffer_t *buffer);
226 hb_buffer_set_direction (hb_buffer_t *buffer,
227 hb_direction_t direction);
229 HB_EXTERN hb_direction_t
230 hb_buffer_get_direction (hb_buffer_t *buffer);
233 hb_buffer_set_script (hb_buffer_t *buffer,
236 HB_EXTERN hb_script_t
237 hb_buffer_get_script (hb_buffer_t *buffer);
240 hb_buffer_set_language (hb_buffer_t *buffer,
241 hb_language_t language);
244 HB_EXTERN hb_language_t
245 hb_buffer_get_language (hb_buffer_t *buffer);
248 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
249 const hb_segment_properties_t *props);
252 hb_buffer_get_segment_properties (hb_buffer_t *buffer,
253 hb_segment_properties_t *props);
256 hb_buffer_guess_segment_properties (hb_buffer_t *buffer);
261 * @HB_BUFFER_FLAG_DEFAULT: the default buffer flag.
262 * @HB_BUFFER_FLAG_BOT: flag indicating that special handling of the beginning
263 * of text paragraph can be applied to this buffer. Should usually
264 * be set, unless you are passing to the buffer only part
265 * of the text without the full context.
266 * @HB_BUFFER_FLAG_EOT: flag indicating that special handling of the end of text
267 * paragraph can be applied to this buffer, similar to
268 * @HB_BUFFER_FLAG_BOT.
269 * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES:
270 * flag indication that character with Default_Ignorable
271 * Unicode property should use the corresponding glyph
272 * from the font, instead of hiding them (done by
273 * replacing them with the space glyph and zeroing the
274 * advance width.) This flag takes precedence over
275 * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES.
276 * @HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES:
277 * flag indication that character with Default_Ignorable
278 * Unicode property should be removed from glyph string
279 * instead of hiding them (done by replacing them with the
280 * space glyph and zeroing the advance width.)
281 * @HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES takes
282 * precedence over this flag. Since: 1.8.0
286 typedef enum { /*< flags >*/
287 HB_BUFFER_FLAG_DEFAULT = 0x00000000u,
288 HB_BUFFER_FLAG_BOT = 0x00000001u, /* Beginning-of-text */
289 HB_BUFFER_FLAG_EOT = 0x00000002u, /* End-of-text */
290 HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004u,
291 HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES = 0x00000008u
295 hb_buffer_set_flags (hb_buffer_t *buffer,
296 hb_buffer_flags_t flags);
298 HB_EXTERN hb_buffer_flags_t
299 hb_buffer_get_flags (hb_buffer_t *buffer);
305 HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0,
306 HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1,
307 HB_BUFFER_CLUSTER_LEVEL_CHARACTERS = 2,
308 HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES
309 } hb_buffer_cluster_level_t;
312 hb_buffer_set_cluster_level (hb_buffer_t *buffer,
313 hb_buffer_cluster_level_t cluster_level);
315 HB_EXTERN hb_buffer_cluster_level_t
316 hb_buffer_get_cluster_level (hb_buffer_t *buffer);
319 * HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT:
321 * The default code point for replacing invalid characters in a given encoding.
322 * Set to U+FFFD REPLACEMENT CHARACTER.
326 #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu
329 hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
330 hb_codepoint_t replacement);
332 HB_EXTERN hb_codepoint_t
333 hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer);
337 hb_buffer_reset (hb_buffer_t *buffer);
340 hb_buffer_clear_contents (hb_buffer_t *buffer);
343 hb_buffer_pre_allocate (hb_buffer_t *buffer,
348 hb_buffer_allocation_successful (hb_buffer_t *buffer);
351 hb_buffer_reverse (hb_buffer_t *buffer);
354 hb_buffer_reverse_range (hb_buffer_t *buffer,
355 unsigned int start, unsigned int end);
358 hb_buffer_reverse_clusters (hb_buffer_t *buffer);
361 /* Filling the buffer in */
364 hb_buffer_add (hb_buffer_t *buffer,
365 hb_codepoint_t codepoint,
366 unsigned int cluster);
369 hb_buffer_add_utf8 (hb_buffer_t *buffer,
372 unsigned int item_offset,
376 hb_buffer_add_utf16 (hb_buffer_t *buffer,
377 const uint16_t *text,
379 unsigned int item_offset,
383 hb_buffer_add_utf32 (hb_buffer_t *buffer,
384 const uint32_t *text,
386 unsigned int item_offset,
390 hb_buffer_add_latin1 (hb_buffer_t *buffer,
393 unsigned int item_offset,
397 hb_buffer_add_codepoints (hb_buffer_t *buffer,
398 const hb_codepoint_t *text,
400 unsigned int item_offset,
404 hb_buffer_append (hb_buffer_t *buffer,
410 hb_buffer_set_length (hb_buffer_t *buffer,
411 unsigned int length);
413 HB_EXTERN unsigned int
414 hb_buffer_get_length (hb_buffer_t *buffer);
416 /* Getting glyphs out of the buffer */
418 HB_EXTERN hb_glyph_info_t *
419 hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
420 unsigned int *length);
422 HB_EXTERN hb_glyph_position_t *
423 hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
424 unsigned int *length);
428 hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
436 * hb_buffer_serialize_flags_t:
437 * @HB_BUFFER_SERIALIZE_FLAG_DEFAULT: serialize glyph names, clusters and positions.
438 * @HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS: do not serialize glyph cluster.
439 * @HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS: do not serialize glyph position information.
440 * @HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES: do no serialize glyph name.
441 * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS: serialize glyph extents.
442 * @HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS: serialize glyph flags. Since: 1.5.0
443 * @HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES: do not serialize glyph advances,
444 * glyph offsets will reflect absolute glyph positions. Since: 1.8.0
446 * Flags that control what glyph information are serialized in hb_buffer_serialize_glyphs().
450 typedef enum { /*< flags >*/
451 HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u,
452 HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u,
453 HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u,
454 HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u,
455 HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u,
456 HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS = 0x00000010u,
457 HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES = 0x00000020u
458 } hb_buffer_serialize_flags_t;
461 * hb_buffer_serialize_format_t:
462 * @HB_BUFFER_SERIALIZE_FORMAT_TEXT: a human-readable, plain text format.
463 * @HB_BUFFER_SERIALIZE_FORMAT_JSON: a machine-readable JSON format.
464 * @HB_BUFFER_SERIALIZE_FORMAT_INVALID: invalid format.
466 * The buffer serialization and de-serialization format used in
467 * hb_buffer_serialize_glyphs() and hb_buffer_deserialize_glyphs().
472 HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'),
473 HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'),
474 HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE
475 } hb_buffer_serialize_format_t;
477 HB_EXTERN hb_buffer_serialize_format_t
478 hb_buffer_serialize_format_from_string (const char *str, int len);
480 HB_EXTERN const char *
481 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format);
483 HB_EXTERN const char **
484 hb_buffer_serialize_list_formats (void);
486 HB_EXTERN unsigned int
487 hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
491 unsigned int buf_size,
492 unsigned int *buf_consumed,
494 hb_buffer_serialize_format_t format,
495 hb_buffer_serialize_flags_t flags);
498 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
501 const char **end_ptr,
503 hb_buffer_serialize_format_t format);
510 typedef enum { /*< flags >*/
511 HB_BUFFER_DIFF_FLAG_EQUAL = 0x0000,
513 /* Buffers with different content_type cannot be meaningfully compared
514 * in any further detail. */
515 HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH = 0x0001,
517 /* For buffers with differing length, the per-glyph comparison is not
518 * attempted, though we do still scan reference for dottedcircle / .notdef
520 HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH = 0x0002,
522 /* We want to know if dottedcircle / .notdef glyphs are present in the
523 * reference, as we may not care so much about other differences in this
525 HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT = 0x0004,
526 HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT = 0x0008,
528 /* If the buffers have the same length, we compare them glyph-by-glyph
529 * and report which aspect(s) of the glyph info/position are different. */
530 HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH = 0x0010,
531 HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH = 0x0020,
532 HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH = 0x0040,
533 HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH = 0x0080
535 } hb_buffer_diff_flags_t;
537 /* Compare the contents of two buffers, report types of differences. */
538 HB_EXTERN hb_buffer_diff_flags_t
539 hb_buffer_diff (hb_buffer_t *buffer,
540 hb_buffer_t *reference,
541 hb_codepoint_t dottedcircle_glyph,
542 unsigned int position_fuzz);
549 typedef hb_bool_t (*hb_buffer_message_func_t) (hb_buffer_t *buffer,
555 hb_buffer_set_message_func (hb_buffer_t *buffer,
556 hb_buffer_message_func_t func,
557 void *user_data, hb_destroy_func_t destroy);
562 #endif /* HB_BUFFER_H */