2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010 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
30 #include "hb-buffer-private.hh"
31 #include "hb-utf-private.hh"
37 * @short_description: Input and output buffers
40 * Buffers serve dual role in HarfBuzz; they hold the input characters that are
41 * passed hb_shape(), and after shaping they hold the output glyphs.
45 * hb_segment_properties_equal:
46 * @a: first #hb_segment_properties_t to compare.
47 * @b: second #hb_segment_properties_t to compare.
49 * Checks the equality of two #hb_segment_properties_t's.
52 * %true if all properties of @a equal those of @b, false otherwise.
57 hb_segment_properties_equal (const hb_segment_properties_t *a,
58 const hb_segment_properties_t *b)
60 return a->direction == b->direction &&
61 a->script == b->script &&
62 a->language == b->language &&
63 a->reserved1 == b->reserved1 &&
64 a->reserved2 == b->reserved2;
69 * hb_segment_properties_hash:
70 * @p: #hb_segment_properties_t to hash.
72 * Creates a hash representing @p.
80 hb_segment_properties_hash (const hb_segment_properties_t *p)
82 return (unsigned int) p->direction ^
83 (unsigned int) p->script ^
84 (intptr_t) (p->language);
89 /* Here is how the buffer works internally:
91 * There are two info pointers: info and out_info. They always have
92 * the same allocated size, but different lengths.
94 * As an optimization, both info and out_info may point to the
95 * same piece of memory, which is owned by info. This remains the
96 * case as long as out_len doesn't exceed i at any time.
97 * In that case, swap_buffers() is no-op and the glyph operations operate
100 * As soon as out_info gets longer than info, out_info is moved over
101 * to an alternate buffer (which we reuse the pos buffer for!), and its
102 * current contents (out_len entries) are copied to the new place.
103 * This should all remain transparent to the user. swap_buffers() then
104 * switches info and out_info.
112 hb_buffer_t::enlarge (unsigned int size)
114 if (unlikely (!successful))
116 if (unlikely (size > max_len))
122 unsigned int new_allocated = allocated;
123 hb_glyph_position_t *new_pos = nullptr;
124 hb_glyph_info_t *new_info = nullptr;
125 bool separate_out = out_info != info;
127 if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0]))))
130 while (size >= new_allocated)
131 new_allocated += (new_allocated >> 1) + 32;
133 static_assert ((sizeof (info[0]) == sizeof (pos[0])), "");
134 if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0]))))
137 new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0]));
138 new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0]));
141 if (unlikely (!new_pos || !new_info))
144 if (likely (new_pos))
147 if (likely (new_info))
150 out_info = separate_out ? (hb_glyph_info_t *) pos : info;
151 if (likely (successful))
152 allocated = new_allocated;
154 return likely (successful);
158 hb_buffer_t::make_room_for (unsigned int num_in,
159 unsigned int num_out)
161 if (unlikely (!ensure (out_len + num_out))) return false;
163 if (out_info == info &&
164 out_len + num_out > idx + num_in)
166 assert (have_output);
168 out_info = (hb_glyph_info_t *) pos;
169 memcpy (out_info, info, out_len * sizeof (out_info[0]));
176 hb_buffer_t::shift_forward (unsigned int count)
178 assert (have_output);
179 if (unlikely (!ensure (len + count))) return false;
181 memmove (info + idx + count, info + idx, (len - idx) * sizeof (info[0]));
182 if (idx + count > len)
184 /* Under memory failure we might expose this area. At least
185 * clean it up. Oh well... */
186 memset (info + len, 0, (idx + count - len) * sizeof (info[0]));
194 hb_buffer_t::scratch_buffer_t *
195 hb_buffer_t::get_scratch_buffer (unsigned int *size)
198 have_positions = false;
203 assert ((uintptr_t) pos % sizeof (scratch_buffer_t) == 0);
204 *size = allocated * sizeof (pos[0]) / sizeof (scratch_buffer_t);
205 return (scratch_buffer_t *) (void *) pos;
210 /* HarfBuzz-Internal API */
213 hb_buffer_t::reset (void)
215 if (unlikely (hb_object_is_inert (this)))
218 hb_unicode_funcs_destroy (unicode);
219 unicode = hb_unicode_funcs_get_default ();
220 flags = HB_BUFFER_FLAG_DEFAULT;
221 replacement = HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT;
227 hb_buffer_t::clear (void)
229 if (unlikely (hb_object_is_inert (this)))
232 hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT;
233 props = default_props;
234 scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
236 content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
239 have_positions = false;
248 memset (context, 0, sizeof context);
249 memset (context_len, 0, sizeof context_len);
251 deallocate_var_all ();
255 hb_buffer_t::add (hb_codepoint_t codepoint,
256 unsigned int cluster)
258 hb_glyph_info_t *glyph;
260 if (unlikely (!ensure (len + 1))) return;
264 memset (glyph, 0, sizeof (*glyph));
265 glyph->codepoint = codepoint;
267 glyph->cluster = cluster;
273 hb_buffer_t::add_info (const hb_glyph_info_t &glyph_info)
275 if (unlikely (!ensure (len + 1))) return;
277 info[len] = glyph_info;
284 hb_buffer_t::remove_output (void)
286 if (unlikely (hb_object_is_inert (this)))
290 have_positions = false;
297 hb_buffer_t::clear_output (void)
299 if (unlikely (hb_object_is_inert (this)))
303 have_positions = false;
310 hb_buffer_t::clear_positions (void)
312 if (unlikely (hb_object_is_inert (this)))
316 have_positions = true;
321 memset (pos, 0, sizeof (pos[0]) * len);
325 hb_buffer_t::swap_buffers (void)
327 if (unlikely (!successful)) return;
329 assert (have_output);
332 if (out_info != info)
334 hb_glyph_info_t *tmp_string;
337 out_info = tmp_string;
338 pos = (hb_glyph_position_t *) out_info;
351 hb_buffer_t::replace_glyphs (unsigned int num_in,
352 unsigned int num_out,
353 const uint32_t *glyph_data)
355 if (unlikely (!make_room_for (num_in, num_out))) return;
357 merge_clusters (idx, idx + num_in);
359 hb_glyph_info_t orig_info = info[idx];
360 hb_glyph_info_t *pinfo = &out_info[out_len];
361 for (unsigned int i = 0; i < num_out; i++)
364 pinfo->codepoint = glyph_data[i];
373 hb_buffer_t::output_glyph (hb_codepoint_t glyph_index)
375 if (unlikely (!make_room_for (0, 1))) return;
377 out_info[out_len] = info[idx];
378 out_info[out_len].codepoint = glyph_index;
384 hb_buffer_t::output_info (const hb_glyph_info_t &glyph_info)
386 if (unlikely (!make_room_for (0, 1))) return;
388 out_info[out_len] = glyph_info;
394 hb_buffer_t::copy_glyph (void)
396 if (unlikely (!make_room_for (0, 1))) return;
398 out_info[out_len] = info[idx];
404 hb_buffer_t::move_to (unsigned int i)
412 if (unlikely (!successful))
415 assert (i <= out_len + (len - idx));
419 unsigned int count = i - out_len;
420 if (unlikely (!make_room_for (count, count))) return false;
422 memmove (out_info + out_len, info + idx, count * sizeof (out_info[0]));
426 else if (out_len > i)
428 /* Tricky part: rewinding... */
429 unsigned int count = out_len - i;
431 /* This will blow in our face if memory allocation fails later
432 * in this same lookup... */
433 if (unlikely (idx < count && !shift_forward (count + 32))) return false;
435 assert (idx >= count);
439 memmove (info + idx, out_info + out_len, count * sizeof (out_info[0]));
446 hb_buffer_t::replace_glyph (hb_codepoint_t glyph_index)
448 if (unlikely (out_info != info || out_len != idx)) {
449 if (unlikely (!make_room_for (1, 1))) return;
450 out_info[out_len] = info[idx];
452 out_info[out_len].codepoint = glyph_index;
460 hb_buffer_t::set_masks (hb_mask_t value,
462 unsigned int cluster_start,
463 unsigned int cluster_end)
465 hb_mask_t not_mask = ~mask;
471 if (cluster_start == 0 && cluster_end == (unsigned int)-1) {
472 unsigned int count = len;
473 for (unsigned int i = 0; i < count; i++)
474 info[i].mask = (info[i].mask & not_mask) | value;
478 unsigned int count = len;
479 for (unsigned int i = 0; i < count; i++)
480 if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end)
481 info[i].mask = (info[i].mask & not_mask) | value;
485 hb_buffer_t::reverse_range (unsigned int start,
493 for (i = start, j = end - 1; i < j; i++, j--) {
501 if (have_positions) {
502 for (i = start, j = end - 1; i < j; i++, j--) {
503 hb_glyph_position_t t;
513 hb_buffer_t::reverse (void)
518 reverse_range (0, len);
522 hb_buffer_t::reverse_clusters (void)
524 unsigned int i, start, count, last_cluster;
533 last_cluster = info[0].cluster;
534 for (i = 1; i < count; i++) {
535 if (last_cluster != info[i].cluster) {
536 reverse_range (start, i);
538 last_cluster = info[i].cluster;
541 reverse_range (start, i);
545 hb_buffer_t::merge_clusters_impl (unsigned int start,
548 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
550 unsafe_to_break (start, end);
554 unsigned int cluster = info[start].cluster;
556 for (unsigned int i = start + 1; i < end; i++)
557 cluster = MIN<unsigned int> (cluster, info[i].cluster);
560 while (end < len && info[end - 1].cluster == info[end].cluster)
564 while (idx < start && info[start - 1].cluster == info[start].cluster)
567 /* If we hit the start of buffer, continue in out-buffer. */
569 for (unsigned int i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--)
570 set_cluster (out_info[i - 1], cluster);
572 for (unsigned int i = start; i < end; i++)
573 set_cluster (info[i], cluster);
576 hb_buffer_t::merge_out_clusters (unsigned int start,
579 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
582 if (unlikely (end - start < 2))
585 unsigned int cluster = out_info[start].cluster;
587 for (unsigned int i = start + 1; i < end; i++)
588 cluster = MIN<unsigned int> (cluster, out_info[i].cluster);
591 while (start && out_info[start - 1].cluster == out_info[start].cluster)
595 while (end < out_len && out_info[end - 1].cluster == out_info[end].cluster)
598 /* If we hit the end of out-buffer, continue in buffer. */
600 for (unsigned int i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++)
601 set_cluster (info[i], cluster);
603 for (unsigned int i = start; i < end; i++)
604 set_cluster (out_info[i], cluster);
607 hb_buffer_t::delete_glyph ()
609 /* The logic here is duplicated in hb_ot_hide_default_ignorables(). */
611 unsigned int cluster = info[idx].cluster;
612 if (idx + 1 < len && cluster == info[idx + 1].cluster)
614 /* Cluster survives; do nothing. */
620 /* Merge cluster backward. */
621 if (cluster < out_info[out_len - 1].cluster)
623 unsigned int mask = info[idx].mask;
624 unsigned int old_cluster = out_info[out_len - 1].cluster;
625 for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--)
626 set_cluster (out_info[i - 1], cluster, mask);
633 /* Merge cluster forward. */
634 merge_clusters (idx, idx + 2);
643 hb_buffer_t::unsafe_to_break_impl (unsigned int start, unsigned int end)
645 unsigned int cluster = (unsigned int) -1;
646 cluster = _unsafe_to_break_find_min_cluster (info, start, end, cluster);
647 _unsafe_to_break_set_mask (info, start, end, cluster);
650 hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int end)
654 unsafe_to_break_impl (start, end);
658 assert (start <= out_len);
661 unsigned int cluster = (unsigned int) -1;
662 cluster = _unsafe_to_break_find_min_cluster (out_info, start, out_len, cluster);
663 cluster = _unsafe_to_break_find_min_cluster (info, idx, end, cluster);
664 _unsafe_to_break_set_mask (out_info, start, out_len, cluster);
665 _unsafe_to_break_set_mask (info, idx, end, cluster);
669 hb_buffer_t::guess_segment_properties (void)
671 assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
672 (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
674 /* If script is set to INVALID, guess from buffer contents */
675 if (props.script == HB_SCRIPT_INVALID) {
676 for (unsigned int i = 0; i < len; i++) {
677 hb_script_t script = unicode->script (info[i].codepoint);
678 if (likely (script != HB_SCRIPT_COMMON &&
679 script != HB_SCRIPT_INHERITED &&
680 script != HB_SCRIPT_UNKNOWN)) {
681 props.script = script;
687 /* If direction is set to INVALID, guess from script */
688 if (props.direction == HB_DIRECTION_INVALID) {
689 props.direction = hb_script_get_horizontal_direction (props.script);
690 if (props.direction == HB_DIRECTION_INVALID)
691 props.direction = HB_DIRECTION_LTR;
694 /* If language is not set, use default language from locale */
695 if (props.language == HB_LANGUAGE_INVALID) {
696 /* TODO get_default_for_script? using $LANGUAGE */
697 props.language = hb_language_get_default ();
705 * hb_buffer_create: (Xconstructor)
707 * Creates a new #hb_buffer_t with all properties to defaults.
709 * Return value: (transfer full):
710 * A newly allocated #hb_buffer_t with a reference count of 1. The initial
711 * reference count should be released with hb_buffer_destroy() when you are done
712 * using the #hb_buffer_t. This function never returns %NULL. If memory cannot
713 * be allocated, a special #hb_buffer_t object will be returned on which
714 * hb_buffer_allocation_successful() returns %false.
719 hb_buffer_create (void)
723 if (!(buffer = hb_object_create<hb_buffer_t> ()))
724 return hb_buffer_get_empty ();
726 buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
727 buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
735 * hb_buffer_get_empty:
739 * Return value: (transfer full):
744 hb_buffer_get_empty (void)
746 static const hb_buffer_t _hb_buffer_nil = {
747 HB_OBJECT_HEADER_STATIC,
749 const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil),
750 HB_BUFFER_FLAG_DEFAULT,
751 HB_BUFFER_CLUSTER_LEVEL_DEFAULT,
752 HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
753 HB_BUFFER_SCRATCH_FLAG_DEFAULT,
754 HB_BUFFER_MAX_LEN_DEFAULT,
755 HB_BUFFER_MAX_OPS_DEFAULT,
757 HB_BUFFER_CONTENT_TYPE_INVALID,
758 HB_SEGMENT_PROPERTIES_DEFAULT,
759 false, /* successful */
760 true, /* have_output */
761 true /* have_positions */
763 /* Zero is good enough for everything else. */
766 return const_cast<hb_buffer_t *> (&_hb_buffer_nil);
770 * hb_buffer_reference: (skip)
771 * @buffer: an #hb_buffer_t.
773 * Increases the reference count on @buffer by one. This prevents @buffer from
774 * being destroyed until a matching call to hb_buffer_destroy() is made.
776 * Return value: (transfer full):
777 * The referenced #hb_buffer_t.
782 hb_buffer_reference (hb_buffer_t *buffer)
784 return hb_object_reference (buffer);
788 * hb_buffer_destroy: (skip)
789 * @buffer: an #hb_buffer_t.
791 * Deallocate the @buffer.
792 * Decreases the reference count on @buffer by one. If the result is zero, then
793 * @buffer and all associated resources are freed. See hb_buffer_reference().
798 hb_buffer_destroy (hb_buffer_t *buffer)
800 if (!hb_object_destroy (buffer)) return;
802 hb_unicode_funcs_destroy (buffer->unicode);
806 if (buffer->message_destroy)
807 buffer->message_destroy (buffer->message_data);
813 * hb_buffer_set_user_data: (skip)
814 * @buffer: an #hb_buffer_t.
827 hb_buffer_set_user_data (hb_buffer_t *buffer,
828 hb_user_data_key_t *key,
830 hb_destroy_func_t destroy,
833 return hb_object_set_user_data (buffer, key, data, destroy, replace);
837 * hb_buffer_get_user_data: (skip)
838 * @buffer: an #hb_buffer_t.
848 hb_buffer_get_user_data (hb_buffer_t *buffer,
849 hb_user_data_key_t *key)
851 return hb_object_get_user_data (buffer, key);
856 * hb_buffer_set_content_type:
857 * @buffer: an #hb_buffer_t.
858 * @content_type: the type of buffer contents to set
860 * Sets the type of @buffer contents, buffers are either empty, contain
861 * characters (before shaping) or glyphs (the result of shaping).
866 hb_buffer_set_content_type (hb_buffer_t *buffer,
867 hb_buffer_content_type_t content_type)
869 buffer->content_type = content_type;
873 * hb_buffer_get_content_type:
874 * @buffer: an #hb_buffer_t.
876 * see hb_buffer_set_content_type().
879 * The type of @buffer contents.
883 hb_buffer_content_type_t
884 hb_buffer_get_content_type (hb_buffer_t *buffer)
886 return buffer->content_type;
891 * hb_buffer_set_unicode_funcs:
892 * @buffer: an #hb_buffer_t.
900 hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
901 hb_unicode_funcs_t *unicode_funcs)
903 if (unlikely (hb_object_is_inert (buffer)))
907 unicode_funcs = hb_unicode_funcs_get_default ();
910 hb_unicode_funcs_reference (unicode_funcs);
911 hb_unicode_funcs_destroy (buffer->unicode);
912 buffer->unicode = unicode_funcs;
916 * hb_buffer_get_unicode_funcs:
917 * @buffer: an #hb_buffer_t.
926 hb_buffer_get_unicode_funcs (hb_buffer_t *buffer)
928 return buffer->unicode;
932 * hb_buffer_set_direction:
933 * @buffer: an #hb_buffer_t.
934 * @direction: the #hb_direction_t of the @buffer
936 * Set the text flow direction of the buffer. No shaping can happen without
937 * setting @buffer direction, and it controls the visual direction for the
938 * output glyphs; for RTL direction the glyphs will be reversed. Many layout
939 * features depend on the proper setting of the direction, for example,
940 * reversing RTL text before shaping, then shaping with LTR direction is not
941 * the same as keeping the text in logical order and shaping with RTL
947 hb_buffer_set_direction (hb_buffer_t *buffer,
948 hb_direction_t direction)
951 if (unlikely (hb_object_is_inert (buffer)))
954 buffer->props.direction = direction;
958 * hb_buffer_get_direction:
959 * @buffer: an #hb_buffer_t.
961 * See hb_buffer_set_direction()
964 * The direction of the @buffer.
969 hb_buffer_get_direction (hb_buffer_t *buffer)
971 return buffer->props.direction;
975 * hb_buffer_set_script:
976 * @buffer: an #hb_buffer_t.
977 * @script: an #hb_script_t to set.
979 * Sets the script of @buffer to @script.
981 * Script is crucial for choosing the proper shaping behaviour for scripts that
982 * require it (e.g. Arabic) and the which OpenType features defined in the font
985 * You can pass one of the predefined #hb_script_t values, or use
986 * hb_script_from_string() or hb_script_from_iso15924_tag() to get the
987 * corresponding script from an ISO 15924 script tag.
992 hb_buffer_set_script (hb_buffer_t *buffer,
995 if (unlikely (hb_object_is_inert (buffer)))
998 buffer->props.script = script;
1002 * hb_buffer_get_script:
1003 * @buffer: an #hb_buffer_t.
1005 * See hb_buffer_set_script().
1008 * The #hb_script_t of the @buffer.
1013 hb_buffer_get_script (hb_buffer_t *buffer)
1015 return buffer->props.script;
1019 * hb_buffer_set_language:
1020 * @buffer: an #hb_buffer_t.
1021 * @language: an hb_language_t to set.
1023 * Sets the language of @buffer to @language.
1025 * Languages are crucial for selecting which OpenType feature to apply to the
1026 * buffer which can result in applying language-specific behaviour. Languages
1027 * are orthogonal to the scripts, and though they are related, they are
1028 * different concepts and should not be confused with each other.
1030 * Use hb_language_from_string() to convert from ISO 639 language codes to
1036 hb_buffer_set_language (hb_buffer_t *buffer,
1037 hb_language_t language)
1039 if (unlikely (hb_object_is_inert (buffer)))
1042 buffer->props.language = language;
1046 * hb_buffer_get_language:
1047 * @buffer: an #hb_buffer_t.
1049 * See hb_buffer_set_language().
1051 * Return value: (transfer none):
1052 * The #hb_language_t of the buffer. Must not be freed by the caller.
1057 hb_buffer_get_language (hb_buffer_t *buffer)
1059 return buffer->props.language;
1063 * hb_buffer_set_segment_properties:
1064 * @buffer: an #hb_buffer_t.
1065 * @props: an #hb_segment_properties_t to use.
1067 * Sets the segment properties of the buffer, a shortcut for calling
1068 * hb_buffer_set_direction(), hb_buffer_set_script() and
1069 * hb_buffer_set_language() individually.
1074 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
1075 const hb_segment_properties_t *props)
1077 if (unlikely (hb_object_is_inert (buffer)))
1080 buffer->props = *props;
1084 * hb_buffer_get_segment_properties:
1085 * @buffer: an #hb_buffer_t.
1086 * @props: (out): the output #hb_segment_properties_t.
1088 * Sets @props to the #hb_segment_properties_t of @buffer.
1093 hb_buffer_get_segment_properties (hb_buffer_t *buffer,
1094 hb_segment_properties_t *props)
1096 *props = buffer->props;
1101 * hb_buffer_set_flags:
1102 * @buffer: an #hb_buffer_t.
1103 * @flags: the buffer flags to set.
1105 * Sets @buffer flags to @flags. See #hb_buffer_flags_t.
1110 hb_buffer_set_flags (hb_buffer_t *buffer,
1111 hb_buffer_flags_t flags)
1113 if (unlikely (hb_object_is_inert (buffer)))
1116 buffer->flags = flags;
1120 * hb_buffer_get_flags:
1121 * @buffer: an #hb_buffer_t.
1123 * See hb_buffer_set_flags().
1126 * The @buffer flags.
1131 hb_buffer_get_flags (hb_buffer_t *buffer)
1133 return buffer->flags;
1137 * hb_buffer_set_cluster_level:
1138 * @buffer: an #hb_buffer_t.
1146 hb_buffer_set_cluster_level (hb_buffer_t *buffer,
1147 hb_buffer_cluster_level_t cluster_level)
1149 if (unlikely (hb_object_is_inert (buffer)))
1152 buffer->cluster_level = cluster_level;
1156 * hb_buffer_get_cluster_level:
1157 * @buffer: an #hb_buffer_t.
1165 hb_buffer_cluster_level_t
1166 hb_buffer_get_cluster_level (hb_buffer_t *buffer)
1168 return buffer->cluster_level;
1173 * hb_buffer_set_replacement_codepoint:
1174 * @buffer: an #hb_buffer_t.
1175 * @replacement: the replacement #hb_codepoint_t
1177 * Sets the #hb_codepoint_t that replaces invalid entries for a given encoding
1178 * when adding text to @buffer.
1180 * Default is %HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
1185 hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
1186 hb_codepoint_t replacement)
1188 if (unlikely (hb_object_is_inert (buffer)))
1191 buffer->replacement = replacement;
1195 * hb_buffer_get_replacement_codepoint:
1196 * @buffer: an #hb_buffer_t.
1198 * See hb_buffer_set_replacement_codepoint().
1201 * The @buffer replacement #hb_codepoint_t.
1206 hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
1208 return buffer->replacement;
1214 * @buffer: an #hb_buffer_t.
1216 * Resets the buffer to its initial status, as if it was just newly created
1217 * with hb_buffer_create().
1222 hb_buffer_reset (hb_buffer_t *buffer)
1228 * hb_buffer_clear_contents:
1229 * @buffer: an #hb_buffer_t.
1231 * Similar to hb_buffer_reset(), but does not clear the Unicode functions and
1232 * the replacement code point.
1237 hb_buffer_clear_contents (hb_buffer_t *buffer)
1243 * hb_buffer_pre_allocate:
1244 * @buffer: an #hb_buffer_t.
1245 * @size: number of items to pre allocate.
1247 * Pre allocates memory for @buffer to fit at least @size number of items.
1250 * %true if @buffer memory allocation succeeded, %false otherwise.
1255 hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
1257 return buffer->ensure (size);
1261 * hb_buffer_allocation_successful:
1262 * @buffer: an #hb_buffer_t.
1264 * Check if allocating memory for the buffer succeeded.
1267 * %true if @buffer memory allocation succeeded, %false otherwise.
1272 hb_buffer_allocation_successful (hb_buffer_t *buffer)
1274 return buffer->successful;
1279 * @buffer: an #hb_buffer_t.
1280 * @codepoint: a Unicode code point.
1281 * @cluster: the cluster value of @codepoint.
1283 * Appends a character with the Unicode value of @codepoint to @buffer, and
1284 * gives it the initial cluster value of @cluster. Clusters can be any thing
1285 * the client wants, they are usually used to refer to the index of the
1286 * character in the input text stream and are output in
1287 * #hb_glyph_info_t.cluster field.
1289 * This function does not check the validity of @codepoint, it is up to the
1290 * caller to ensure it is a valid Unicode code point.
1295 hb_buffer_add (hb_buffer_t *buffer,
1296 hb_codepoint_t codepoint,
1297 unsigned int cluster)
1299 buffer->add (codepoint, cluster);
1300 buffer->clear_context (1);
1304 * hb_buffer_set_length:
1305 * @buffer: an #hb_buffer_t.
1306 * @length: the new length of @buffer.
1308 * Similar to hb_buffer_pre_allocate(), but clears any new items added at the
1312 * %true if @buffer memory allocation succeeded, %false otherwise.
1317 hb_buffer_set_length (hb_buffer_t *buffer,
1318 unsigned int length)
1320 if (unlikely (hb_object_is_inert (buffer)))
1323 if (!buffer->ensure (length))
1326 /* Wipe the new space */
1327 if (length > buffer->len) {
1328 memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len));
1329 if (buffer->have_positions)
1330 memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len));
1333 buffer->len = length;
1337 buffer->content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
1338 buffer->clear_context (0);
1340 buffer->clear_context (1);
1346 * hb_buffer_get_length:
1347 * @buffer: an #hb_buffer_t.
1349 * Returns the number of items in the buffer.
1352 * The @buffer length.
1353 * The value valid as long as buffer has not been modified.
1358 hb_buffer_get_length (hb_buffer_t *buffer)
1364 * hb_buffer_get_glyph_infos:
1365 * @buffer: an #hb_buffer_t.
1366 * @length: (out): output array length.
1368 * Returns @buffer glyph information array. Returned pointer
1369 * is valid as long as @buffer contents are not modified.
1371 * Return value: (transfer none) (array length=length):
1372 * The @buffer glyph information array.
1373 * The value valid as long as buffer has not been modified.
1378 hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
1379 unsigned int *length)
1382 *length = buffer->len;
1384 return (hb_glyph_info_t *) buffer->info;
1388 * hb_buffer_get_glyph_positions:
1389 * @buffer: an #hb_buffer_t.
1390 * @length: (out): output length.
1392 * Returns @buffer glyph position array. Returned pointer
1393 * is valid as long as @buffer contents are not modified.
1395 * Return value: (transfer none) (array length=length):
1396 * The @buffer glyph position array.
1397 * The value valid as long as buffer has not been modified.
1401 hb_glyph_position_t *
1402 hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
1403 unsigned int *length)
1405 if (!buffer->have_positions)
1406 buffer->clear_positions ();
1409 *length = buffer->len;
1411 return (hb_glyph_position_t *) buffer->pos;
1415 * hb_glyph_info_get_glyph_flags:
1416 * @info: a #hb_glyph_info_t.
1418 * Returns glyph flags encoded within a #hb_glyph_info_t.
1421 * The #hb_glyph_flags_t encoded within @info.
1426 (hb_glyph_info_get_glyph_flags) (const hb_glyph_info_t *info)
1428 return hb_glyph_info_get_glyph_flags (info);
1432 * hb_buffer_reverse:
1433 * @buffer: an #hb_buffer_t.
1435 * Reverses buffer contents.
1440 hb_buffer_reverse (hb_buffer_t *buffer)
1446 * hb_buffer_reverse_range:
1447 * @buffer: an #hb_buffer_t.
1448 * @start: start index.
1451 * Reverses buffer contents between start to end.
1456 hb_buffer_reverse_range (hb_buffer_t *buffer,
1457 unsigned int start, unsigned int end)
1459 buffer->reverse_range (start, end);
1463 * hb_buffer_reverse_clusters:
1464 * @buffer: an #hb_buffer_t.
1466 * Reverses buffer clusters. That is, the buffer contents are
1467 * reversed, then each cluster (consecutive items having the
1468 * same cluster number) are reversed again.
1473 hb_buffer_reverse_clusters (hb_buffer_t *buffer)
1475 buffer->reverse_clusters ();
1479 * hb_buffer_guess_segment_properties:
1480 * @buffer: an #hb_buffer_t.
1482 * Sets unset buffer segment properties based on buffer Unicode
1483 * contents. If buffer is not empty, it must have content type
1484 * %HB_BUFFER_CONTENT_TYPE_UNICODE.
1486 * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it
1487 * will be set to the Unicode script of the first character in
1488 * the buffer that has a script other than %HB_SCRIPT_COMMON,
1489 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN.
1491 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID),
1492 * it will be set to the natural horizontal direction of the
1493 * buffer script as returned by hb_script_get_horizontal_direction().
1494 * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID,
1495 * then %HB_DIRECTION_LTR is used.
1497 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID),
1498 * it will be set to the process's default language as returned by
1499 * hb_language_get_default(). This may change in the future by
1500 * taking buffer script into consideration when choosing a language.
1505 hb_buffer_guess_segment_properties (hb_buffer_t *buffer)
1507 buffer->guess_segment_properties ();
1510 template <typename utf_t>
1512 hb_buffer_add_utf (hb_buffer_t *buffer,
1513 const typename utf_t::codepoint_t *text,
1515 unsigned int item_offset,
1518 typedef typename utf_t::codepoint_t T;
1519 const hb_codepoint_t replacement = buffer->replacement;
1521 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
1522 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1524 if (unlikely (hb_object_is_inert (buffer)))
1527 if (text_length == -1)
1528 text_length = utf_t::strlen (text);
1530 if (item_length == -1)
1531 item_length = text_length - item_offset;
1533 buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
1535 /* If buffer is empty and pre-context provided, install it.
1536 * This check is written this way, to make sure people can
1537 * provide pre-context in one add_utf() call, then provide
1538 * text in a follow-up call. See:
1540 * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13
1542 if (!buffer->len && item_offset > 0)
1544 /* Add pre-context */
1545 buffer->clear_context (0);
1546 const T *prev = text + item_offset;
1547 const T *start = text;
1548 while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH)
1551 prev = utf_t::prev (prev, start, &u, replacement);
1552 buffer->context[0][buffer->context_len[0]++] = u;
1556 const T *next = text + item_offset;
1557 const T *end = next + item_length;
1561 const T *old_next = next;
1562 next = utf_t::next (next, end, &u, replacement);
1563 buffer->add (u, old_next - (const T *) text);
1566 /* Add post-context */
1567 buffer->clear_context (1);
1568 end = text + text_length;
1569 while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH)
1572 next = utf_t::next (next, end, &u, replacement);
1573 buffer->context[1][buffer->context_len[1]++] = u;
1576 buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
1580 * hb_buffer_add_utf8:
1581 * @buffer: an #hb_buffer_t.
1582 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1583 * characters to append.
1584 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1585 * @item_offset: the offset of the first character to add to the @buffer.
1586 * @item_length: the number of characters to add to the @buffer, or -1 for the
1587 * end of @text (assuming it is %NULL terminated).
1589 * See hb_buffer_add_codepoints().
1591 * Replaces invalid UTF-8 characters with the @buffer replacement code point,
1592 * see hb_buffer_set_replacement_codepoint().
1597 hb_buffer_add_utf8 (hb_buffer_t *buffer,
1600 unsigned int item_offset,
1603 hb_buffer_add_utf<hb_utf8_t> (buffer, (const uint8_t *) text, text_length, item_offset, item_length);
1607 * hb_buffer_add_utf16:
1608 * @buffer: an #hb_buffer_t.
1609 * @text: (array length=text_length): an array of UTF-16 characters to append.
1610 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1611 * @item_offset: the offset of the first character to add to the @buffer.
1612 * @item_length: the number of characters to add to the @buffer, or -1 for the
1613 * end of @text (assuming it is %NULL terminated).
1615 * See hb_buffer_add_codepoints().
1617 * Replaces invalid UTF-16 characters with the @buffer replacement code point,
1618 * see hb_buffer_set_replacement_codepoint().
1623 hb_buffer_add_utf16 (hb_buffer_t *buffer,
1624 const uint16_t *text,
1626 unsigned int item_offset,
1629 hb_buffer_add_utf<hb_utf16_t> (buffer, text, text_length, item_offset, item_length);
1633 * hb_buffer_add_utf32:
1634 * @buffer: an #hb_buffer_t.
1635 * @text: (array length=text_length): an array of UTF-32 characters to append.
1636 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1637 * @item_offset: the offset of the first character to add to the @buffer.
1638 * @item_length: the number of characters to add to the @buffer, or -1 for the
1639 * end of @text (assuming it is %NULL terminated).
1641 * See hb_buffer_add_codepoints().
1643 * Replaces invalid UTF-32 characters with the @buffer replacement code point,
1644 * see hb_buffer_set_replacement_codepoint().
1649 hb_buffer_add_utf32 (hb_buffer_t *buffer,
1650 const uint32_t *text,
1652 unsigned int item_offset,
1655 hb_buffer_add_utf<hb_utf32_t<> > (buffer, text, text_length, item_offset, item_length);
1659 * hb_buffer_add_latin1:
1660 * @buffer: an #hb_buffer_t.
1661 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1662 * characters to append.
1663 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1664 * @item_offset: the offset of the first character to add to the @buffer.
1665 * @item_length: the number of characters to add to the @buffer, or -1 for the
1666 * end of @text (assuming it is %NULL terminated).
1668 * Similar to hb_buffer_add_codepoints(), but allows only access to first 256
1669 * Unicode code points that can fit in 8-bit strings.
1671 * <note>Has nothing to do with non-Unicode Latin-1 encoding.</note>
1676 hb_buffer_add_latin1 (hb_buffer_t *buffer,
1677 const uint8_t *text,
1679 unsigned int item_offset,
1682 hb_buffer_add_utf<hb_latin1_t> (buffer, text, text_length, item_offset, item_length);
1686 * hb_buffer_add_codepoints:
1687 * @buffer: a #hb_buffer_t to append characters to.
1688 * @text: (array length=text_length): an array of Unicode code points to append.
1689 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1690 * @item_offset: the offset of the first code point to add to the @buffer.
1691 * @item_length: the number of code points to add to the @buffer, or -1 for the
1692 * end of @text (assuming it is %NULL terminated).
1694 * Appends characters from @text array to @buffer. The @item_offset is the
1695 * position of the first character from @text that will be appended, and
1696 * @item_length is the number of character. When shaping part of a larger text
1697 * (e.g. a run of text from a paragraph), instead of passing just the substring
1698 * corresponding to the run, it is preferable to pass the whole
1699 * paragraph and specify the run start and length as @item_offset and
1700 * @item_length, respectively, to give HarfBuzz the full context to be able,
1701 * for example, to do cross-run Arabic shaping or properly handle combining
1702 * marks at stat of run.
1704 * This function does not check the validity of @text, it is up to the caller
1705 * to ensure it contains a valid Unicode code points.
1710 hb_buffer_add_codepoints (hb_buffer_t *buffer,
1711 const hb_codepoint_t *text,
1713 unsigned int item_offset,
1716 hb_buffer_add_utf<hb_utf32_t<false> > (buffer, text, text_length, item_offset, item_length);
1722 * @buffer: an #hb_buffer_t.
1723 * @source: source #hb_buffer_t.
1724 * @start: start index into source buffer to copy. Use 0 to copy from start of buffer.
1725 * @end: end index into source buffer to copy. Use (unsigned int) -1 to copy to end of buffer.
1727 * Append (part of) contents of another buffer to this buffer.
1732 hb_buffer_append (hb_buffer_t *buffer,
1733 hb_buffer_t *source,
1737 assert (!buffer->have_output && !source->have_output);
1738 assert (buffer->have_positions == source->have_positions ||
1739 !buffer->len || !source->len);
1740 assert (buffer->content_type == source->content_type ||
1741 !buffer->len || !source->len);
1743 if (end > source->len)
1751 buffer->content_type = source->content_type;
1752 if (!buffer->have_positions && source->have_positions)
1753 buffer->clear_positions ();
1755 if (buffer->len + (end - start) < buffer->len) /* Overflows. */
1757 buffer->successful = false;
1761 unsigned int orig_len = buffer->len;
1762 hb_buffer_set_length (buffer, buffer->len + (end - start));
1763 if (unlikely (!buffer->successful))
1766 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0]));
1767 if (buffer->have_positions)
1768 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0]));
1773 compare_info_codepoint (const hb_glyph_info_t *pa,
1774 const hb_glyph_info_t *pb)
1776 return (int) pb->codepoint - (int) pa->codepoint;
1780 normalize_glyphs_cluster (hb_buffer_t *buffer,
1785 hb_glyph_position_t *pos = buffer->pos;
1787 /* Total cluster advance */
1788 hb_position_t total_x_advance = 0, total_y_advance = 0;
1789 for (unsigned int i = start; i < end; i++)
1791 total_x_advance += pos[i].x_advance;
1792 total_y_advance += pos[i].y_advance;
1795 hb_position_t x_advance = 0, y_advance = 0;
1796 for (unsigned int i = start; i < end; i++)
1798 pos[i].x_offset += x_advance;
1799 pos[i].y_offset += y_advance;
1801 x_advance += pos[i].x_advance;
1802 y_advance += pos[i].y_advance;
1804 pos[i].x_advance = 0;
1805 pos[i].y_advance = 0;
1810 /* Transfer all cluster advance to the last glyph. */
1811 pos[end - 1].x_advance = total_x_advance;
1812 pos[end - 1].y_advance = total_y_advance;
1814 hb_stable_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start);
1816 /* Transfer all cluster advance to the first glyph. */
1817 pos[start].x_advance += total_x_advance;
1818 pos[start].y_advance += total_y_advance;
1819 for (unsigned int i = start + 1; i < end; i++) {
1820 pos[i].x_offset -= total_x_advance;
1821 pos[i].y_offset -= total_y_advance;
1823 hb_stable_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1);
1828 * hb_buffer_normalize_glyphs:
1829 * @buffer: an #hb_buffer_t.
1831 * Reorders a glyph buffer to have canonical in-cluster glyph order / position.
1832 * The resulting clusters should behave identical to pre-reordering clusters.
1834 * <note>This has nothing to do with Unicode normalization.</note>
1839 hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
1841 assert (buffer->have_positions);
1842 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS ||
1843 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1845 bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
1847 unsigned int count = buffer->len;
1848 if (unlikely (!count)) return;
1849 hb_glyph_info_t *info = buffer->info;
1851 unsigned int start = 0;
1853 for (end = start + 1; end < count; end++)
1854 if (info[start].cluster != info[end].cluster) {
1855 normalize_glyphs_cluster (buffer, start, end, backward);
1858 normalize_glyphs_cluster (buffer, start, end, backward);
1862 hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *))
1864 assert (!have_positions);
1865 for (unsigned int i = start + 1; i < end; i++)
1868 while (j > start && compar (&info[j - 1], &info[i]) > 0)
1872 /* Move item i to occupy place for item j, shift what's in between. */
1873 merge_clusters (j, i + 1);
1875 hb_glyph_info_t t = info[i];
1876 memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t));
1884 * Comparing buffers.
1890 * If dottedcircle_glyph is (hb_codepoint_t) -1 then %HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
1891 * and %HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
1892 * callers if just comparing two buffers is needed.
1896 hb_buffer_diff_flags_t
1897 hb_buffer_diff (hb_buffer_t *buffer,
1898 hb_buffer_t *reference,
1899 hb_codepoint_t dottedcircle_glyph,
1900 unsigned int position_fuzz)
1902 if (buffer->content_type != reference->content_type && buffer->len && reference->len)
1903 return HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH;
1905 hb_buffer_diff_flags_t result = HB_BUFFER_DIFF_FLAG_EQUAL;
1906 bool contains = dottedcircle_glyph != (hb_codepoint_t) -1;
1908 unsigned int count = reference->len;
1910 if (buffer->len != count)
1913 * we can't compare glyph-by-glyph, but we do want to know if there
1914 * are .notdef or dottedcircle glyphs present in the reference buffer
1916 const hb_glyph_info_t *info = reference->info;
1918 for (i = 0; i < count; i++)
1920 if (contains && info[i].codepoint == dottedcircle_glyph)
1921 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1922 if (contains && info[i].codepoint == 0)
1923 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1925 result |= HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH;
1926 return hb_buffer_diff_flags_t (result);
1930 return hb_buffer_diff_flags_t (result);
1932 const hb_glyph_info_t *buf_info = buffer->info;
1933 const hb_glyph_info_t *ref_info = reference->info;
1934 for (unsigned int i = 0; i < count; i++)
1936 if (buf_info->codepoint != ref_info->codepoint)
1937 result |= HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH;
1938 if (buf_info->cluster != ref_info->cluster)
1939 result |= HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH;
1940 if ((buf_info->mask & ~ref_info->mask & HB_GLYPH_FLAG_DEFINED))
1941 result |= HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH;
1942 if (contains && ref_info->codepoint == dottedcircle_glyph)
1943 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1944 if (contains && ref_info->codepoint == 0)
1945 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1950 if (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)
1952 assert (buffer->have_positions);
1953 const hb_glyph_position_t *buf_pos = buffer->pos;
1954 const hb_glyph_position_t *ref_pos = reference->pos;
1955 for (unsigned int i = 0; i < count; i++)
1957 if ((unsigned int) abs (buf_pos->x_advance - ref_pos->x_advance) > position_fuzz ||
1958 (unsigned int) abs (buf_pos->y_advance - ref_pos->y_advance) > position_fuzz ||
1959 (unsigned int) abs (buf_pos->x_offset - ref_pos->x_offset) > position_fuzz ||
1960 (unsigned int) abs (buf_pos->y_offset - ref_pos->y_offset) > position_fuzz)
1962 result |= HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH;
1979 * hb_buffer_set_message_func:
1980 * @buffer: an #hb_buffer_t.
1981 * @func: (closure user_data) (destroy destroy) (scope notified):
1990 hb_buffer_set_message_func (hb_buffer_t *buffer,
1991 hb_buffer_message_func_t func,
1992 void *user_data, hb_destroy_func_t destroy)
1994 if (buffer->message_destroy)
1995 buffer->message_destroy (buffer->message_data);
1998 buffer->message_func = func;
1999 buffer->message_data = user_data;
2000 buffer->message_destroy = destroy;
2002 buffer->message_func = nullptr;
2003 buffer->message_data = nullptr;
2004 buffer->message_destroy = nullptr;
2009 hb_buffer_t::message_impl (hb_font_t *font, const char *fmt, va_list ap)
2012 vsnprintf (buf, sizeof (buf), fmt, ap);
2013 return (bool) this->message_func (this, font, buf, this->message_data);