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 (in_error))
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 (!in_error))
152 allocated = new_allocated;
154 return likely (!in_error);
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 (in_error)) 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 (in_error))
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);
692 /* If language is not set, use default language from locale */
693 if (props.language == HB_LANGUAGE_INVALID) {
694 /* TODO get_default_for_script? using $LANGUAGE */
695 props.language = hb_language_get_default ();
703 * hb_buffer_create: (Xconstructor)
705 * Creates a new #hb_buffer_t with all properties to defaults.
707 * Return value: (transfer full):
708 * A newly allocated #hb_buffer_t with a reference count of 1. The initial
709 * reference count should be released with hb_buffer_destroy() when you are done
710 * using the #hb_buffer_t. This function never returns %NULL. If memory cannot
711 * be allocated, a special #hb_buffer_t object will be returned on which
712 * hb_buffer_allocation_successful() returns %false.
717 hb_buffer_create (void)
721 if (!(buffer = hb_object_create<hb_buffer_t> ()))
722 return hb_buffer_get_empty ();
724 buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
725 buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
733 * hb_buffer_get_empty:
737 * Return value: (transfer full):
742 hb_buffer_get_empty (void)
744 static const hb_buffer_t _hb_buffer_nil = {
745 HB_OBJECT_HEADER_STATIC,
747 const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil),
748 HB_BUFFER_FLAG_DEFAULT,
749 HB_BUFFER_CLUSTER_LEVEL_DEFAULT,
750 HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
751 HB_BUFFER_SCRATCH_FLAG_DEFAULT,
752 HB_BUFFER_MAX_LEN_DEFAULT,
753 HB_BUFFER_MAX_OPS_DEFAULT,
755 HB_BUFFER_CONTENT_TYPE_INVALID,
756 HB_SEGMENT_PROPERTIES_DEFAULT,
758 true, /* have_output */
759 true /* have_positions */
761 /* Zero is good enough for everything else. */
764 return const_cast<hb_buffer_t *> (&_hb_buffer_nil);
768 * hb_buffer_reference: (skip)
769 * @buffer: an #hb_buffer_t.
771 * Increases the reference count on @buffer by one. This prevents @buffer from
772 * being destroyed until a matching call to hb_buffer_destroy() is made.
774 * Return value: (transfer full):
775 * The referenced #hb_buffer_t.
780 hb_buffer_reference (hb_buffer_t *buffer)
782 return hb_object_reference (buffer);
786 * hb_buffer_destroy: (skip)
787 * @buffer: an #hb_buffer_t.
789 * Deallocate the @buffer.
790 * Decreases the reference count on @buffer by one. If the result is zero, then
791 * @buffer and all associated resources are freed. See hb_buffer_reference().
796 hb_buffer_destroy (hb_buffer_t *buffer)
798 if (!hb_object_destroy (buffer)) return;
800 hb_unicode_funcs_destroy (buffer->unicode);
804 if (buffer->message_destroy)
805 buffer->message_destroy (buffer->message_data);
811 * hb_buffer_set_user_data: (skip)
812 * @buffer: an #hb_buffer_t.
825 hb_buffer_set_user_data (hb_buffer_t *buffer,
826 hb_user_data_key_t *key,
828 hb_destroy_func_t destroy,
831 return hb_object_set_user_data (buffer, key, data, destroy, replace);
835 * hb_buffer_get_user_data: (skip)
836 * @buffer: an #hb_buffer_t.
846 hb_buffer_get_user_data (hb_buffer_t *buffer,
847 hb_user_data_key_t *key)
849 return hb_object_get_user_data (buffer, key);
854 * hb_buffer_set_content_type:
855 * @buffer: an #hb_buffer_t.
856 * @content_type: the type of buffer contents to set
858 * Sets the type of @buffer contents, buffers are either empty, contain
859 * characters (before shaping) or glyphs (the result of shaping).
864 hb_buffer_set_content_type (hb_buffer_t *buffer,
865 hb_buffer_content_type_t content_type)
867 buffer->content_type = content_type;
871 * hb_buffer_get_content_type:
872 * @buffer: an #hb_buffer_t.
874 * see hb_buffer_set_content_type().
877 * The type of @buffer contents.
881 hb_buffer_content_type_t
882 hb_buffer_get_content_type (hb_buffer_t *buffer)
884 return buffer->content_type;
889 * hb_buffer_set_unicode_funcs:
890 * @buffer: an #hb_buffer_t.
898 hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
899 hb_unicode_funcs_t *unicode_funcs)
901 if (unlikely (hb_object_is_inert (buffer)))
905 unicode_funcs = hb_unicode_funcs_get_default ();
908 hb_unicode_funcs_reference (unicode_funcs);
909 hb_unicode_funcs_destroy (buffer->unicode);
910 buffer->unicode = unicode_funcs;
914 * hb_buffer_get_unicode_funcs:
915 * @buffer: an #hb_buffer_t.
924 hb_buffer_get_unicode_funcs (hb_buffer_t *buffer)
926 return buffer->unicode;
930 * hb_buffer_set_direction:
931 * @buffer: an #hb_buffer_t.
932 * @direction: the #hb_direction_t of the @buffer
934 * Set the text flow direction of the buffer. No shaping can happen without
935 * setting @buffer direction, and it controls the visual direction for the
936 * output glyphs; for RTL direction the glyphs will be reversed. Many layout
937 * features depend on the proper setting of the direction, for example,
938 * reversing RTL text before shaping, then shaping with LTR direction is not
939 * the same as keeping the text in logical order and shaping with RTL
945 hb_buffer_set_direction (hb_buffer_t *buffer,
946 hb_direction_t direction)
949 if (unlikely (hb_object_is_inert (buffer)))
952 buffer->props.direction = direction;
956 * hb_buffer_get_direction:
957 * @buffer: an #hb_buffer_t.
959 * See hb_buffer_set_direction()
962 * The direction of the @buffer.
967 hb_buffer_get_direction (hb_buffer_t *buffer)
969 return buffer->props.direction;
973 * hb_buffer_set_script:
974 * @buffer: an #hb_buffer_t.
975 * @script: an #hb_script_t to set.
977 * Sets the script of @buffer to @script.
979 * Script is crucial for choosing the proper shaping behaviour for scripts that
980 * require it (e.g. Arabic) and the which OpenType features defined in the font
983 * You can pass one of the predefined #hb_script_t values, or use
984 * hb_script_from_string() or hb_script_from_iso15924_tag() to get the
985 * corresponding script from an ISO 15924 script tag.
990 hb_buffer_set_script (hb_buffer_t *buffer,
993 if (unlikely (hb_object_is_inert (buffer)))
996 buffer->props.script = script;
1000 * hb_buffer_get_script:
1001 * @buffer: an #hb_buffer_t.
1003 * See hb_buffer_set_script().
1006 * The #hb_script_t of the @buffer.
1011 hb_buffer_get_script (hb_buffer_t *buffer)
1013 return buffer->props.script;
1017 * hb_buffer_set_language:
1018 * @buffer: an #hb_buffer_t.
1019 * @language: an hb_language_t to set.
1021 * Sets the language of @buffer to @language.
1023 * Languages are crucial for selecting which OpenType feature to apply to the
1024 * buffer which can result in applying language-specific behaviour. Languages
1025 * are orthogonal to the scripts, and though they are related, they are
1026 * different concepts and should not be confused with each other.
1028 * Use hb_language_from_string() to convert from ISO 639 language codes to
1034 hb_buffer_set_language (hb_buffer_t *buffer,
1035 hb_language_t language)
1037 if (unlikely (hb_object_is_inert (buffer)))
1040 buffer->props.language = language;
1044 * hb_buffer_get_language:
1045 * @buffer: an #hb_buffer_t.
1047 * See hb_buffer_set_language().
1049 * Return value: (transfer none):
1050 * The #hb_language_t of the buffer. Must not be freed by the caller.
1055 hb_buffer_get_language (hb_buffer_t *buffer)
1057 return buffer->props.language;
1061 * hb_buffer_set_segment_properties:
1062 * @buffer: an #hb_buffer_t.
1063 * @props: an #hb_segment_properties_t to use.
1065 * Sets the segment properties of the buffer, a shortcut for calling
1066 * hb_buffer_set_direction(), hb_buffer_set_script() and
1067 * hb_buffer_set_language() individually.
1072 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
1073 const hb_segment_properties_t *props)
1075 if (unlikely (hb_object_is_inert (buffer)))
1078 buffer->props = *props;
1082 * hb_buffer_get_segment_properties:
1083 * @buffer: an #hb_buffer_t.
1084 * @props: (out): the output #hb_segment_properties_t.
1086 * Sets @props to the #hb_segment_properties_t of @buffer.
1091 hb_buffer_get_segment_properties (hb_buffer_t *buffer,
1092 hb_segment_properties_t *props)
1094 *props = buffer->props;
1099 * hb_buffer_set_flags:
1100 * @buffer: an #hb_buffer_t.
1101 * @flags: the buffer flags to set.
1103 * Sets @buffer flags to @flags. See #hb_buffer_flags_t.
1108 hb_buffer_set_flags (hb_buffer_t *buffer,
1109 hb_buffer_flags_t flags)
1111 if (unlikely (hb_object_is_inert (buffer)))
1114 buffer->flags = flags;
1118 * hb_buffer_get_flags:
1119 * @buffer: an #hb_buffer_t.
1121 * See hb_buffer_set_flags().
1124 * The @buffer flags.
1129 hb_buffer_get_flags (hb_buffer_t *buffer)
1131 return buffer->flags;
1135 * hb_buffer_set_cluster_level:
1136 * @buffer: an #hb_buffer_t.
1144 hb_buffer_set_cluster_level (hb_buffer_t *buffer,
1145 hb_buffer_cluster_level_t cluster_level)
1147 if (unlikely (hb_object_is_inert (buffer)))
1150 buffer->cluster_level = cluster_level;
1154 * hb_buffer_get_cluster_level:
1155 * @buffer: an #hb_buffer_t.
1163 hb_buffer_cluster_level_t
1164 hb_buffer_get_cluster_level (hb_buffer_t *buffer)
1166 return buffer->cluster_level;
1171 * hb_buffer_set_replacement_codepoint:
1172 * @buffer: an #hb_buffer_t.
1173 * @replacement: the replacement #hb_codepoint_t
1175 * Sets the #hb_codepoint_t that replaces invalid entries for a given encoding
1176 * when adding text to @buffer.
1178 * Default is %HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
1183 hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
1184 hb_codepoint_t replacement)
1186 if (unlikely (hb_object_is_inert (buffer)))
1189 buffer->replacement = replacement;
1193 * hb_buffer_get_replacement_codepoint:
1194 * @buffer: an #hb_buffer_t.
1196 * See hb_buffer_set_replacement_codepoint().
1199 * The @buffer replacement #hb_codepoint_t.
1204 hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
1206 return buffer->replacement;
1212 * @buffer: an #hb_buffer_t.
1214 * Resets the buffer to its initial status, as if it was just newly created
1215 * with hb_buffer_create().
1220 hb_buffer_reset (hb_buffer_t *buffer)
1226 * hb_buffer_clear_contents:
1227 * @buffer: an #hb_buffer_t.
1229 * Similar to hb_buffer_reset(), but does not clear the Unicode functions and
1230 * the replacement code point.
1235 hb_buffer_clear_contents (hb_buffer_t *buffer)
1241 * hb_buffer_pre_allocate:
1242 * @buffer: an #hb_buffer_t.
1243 * @size: number of items to pre allocate.
1245 * Pre allocates memory for @buffer to fit at least @size number of items.
1248 * %true if @buffer memory allocation succeeded, %false otherwise.
1253 hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
1255 return buffer->ensure (size);
1259 * hb_buffer_allocation_successful:
1260 * @buffer: an #hb_buffer_t.
1262 * Check if allocating memory for the buffer succeeded.
1265 * %true if @buffer memory allocation succeeded, %false otherwise.
1270 hb_buffer_allocation_successful (hb_buffer_t *buffer)
1272 return !buffer->in_error;
1277 * @buffer: an #hb_buffer_t.
1278 * @codepoint: a Unicode code point.
1279 * @cluster: the cluster value of @codepoint.
1281 * Appends a character with the Unicode value of @codepoint to @buffer, and
1282 * gives it the initial cluster value of @cluster. Clusters can be any thing
1283 * the client wants, they are usually used to refer to the index of the
1284 * character in the input text stream and are output in
1285 * #hb_glyph_info_t.cluster field.
1287 * This function does not check the validity of @codepoint, it is up to the
1288 * caller to ensure it is a valid Unicode code point.
1293 hb_buffer_add (hb_buffer_t *buffer,
1294 hb_codepoint_t codepoint,
1295 unsigned int cluster)
1297 buffer->add (codepoint, cluster);
1298 buffer->clear_context (1);
1302 * hb_buffer_set_length:
1303 * @buffer: an #hb_buffer_t.
1304 * @length: the new length of @buffer.
1306 * Similar to hb_buffer_pre_allocate(), but clears any new items added at the
1310 * %true if @buffer memory allocation succeeded, %false otherwise.
1315 hb_buffer_set_length (hb_buffer_t *buffer,
1316 unsigned int length)
1318 if (unlikely (hb_object_is_inert (buffer)))
1321 if (!buffer->ensure (length))
1324 /* Wipe the new space */
1325 if (length > buffer->len) {
1326 memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len));
1327 if (buffer->have_positions)
1328 memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len));
1331 buffer->len = length;
1335 buffer->content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
1336 buffer->clear_context (0);
1338 buffer->clear_context (1);
1344 * hb_buffer_get_length:
1345 * @buffer: an #hb_buffer_t.
1347 * Returns the number of items in the buffer.
1350 * The @buffer length.
1351 * The value valid as long as buffer has not been modified.
1356 hb_buffer_get_length (hb_buffer_t *buffer)
1362 * hb_buffer_get_glyph_infos:
1363 * @buffer: an #hb_buffer_t.
1364 * @length: (out): output array length.
1366 * Returns @buffer glyph information array. Returned pointer
1367 * is valid as long as @buffer contents are not modified.
1369 * Return value: (transfer none) (array length=length):
1370 * The @buffer glyph information array.
1371 * The value valid as long as buffer has not been modified.
1376 hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
1377 unsigned int *length)
1380 *length = buffer->len;
1382 return (hb_glyph_info_t *) buffer->info;
1386 * hb_buffer_get_glyph_positions:
1387 * @buffer: an #hb_buffer_t.
1388 * @length: (out): output length.
1390 * Returns @buffer glyph position array. Returned pointer
1391 * is valid as long as @buffer contents are not modified.
1393 * Return value: (transfer none) (array length=length):
1394 * The @buffer glyph position array.
1395 * The value valid as long as buffer has not been modified.
1399 hb_glyph_position_t *
1400 hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
1401 unsigned int *length)
1403 if (!buffer->have_positions)
1404 buffer->clear_positions ();
1407 *length = buffer->len;
1409 return (hb_glyph_position_t *) buffer->pos;
1413 * hb_glyph_info_get_glyph_flags:
1414 * @info: a #hb_glyph_info_t.
1416 * Returns glyph flags encoded within a #hb_glyph_info_t.
1419 * The #hb_glyph_flags_t encoded within @info.
1424 (hb_glyph_info_get_glyph_flags) (const hb_glyph_info_t *info)
1426 return hb_glyph_info_get_glyph_flags (info);
1430 * hb_buffer_reverse:
1431 * @buffer: an #hb_buffer_t.
1433 * Reverses buffer contents.
1438 hb_buffer_reverse (hb_buffer_t *buffer)
1444 * hb_buffer_reverse_range:
1445 * @buffer: an #hb_buffer_t.
1446 * @start: start index.
1449 * Reverses buffer contents between start to end.
1454 hb_buffer_reverse_range (hb_buffer_t *buffer,
1455 unsigned int start, unsigned int end)
1457 buffer->reverse_range (start, end);
1461 * hb_buffer_reverse_clusters:
1462 * @buffer: an #hb_buffer_t.
1464 * Reverses buffer clusters. That is, the buffer contents are
1465 * reversed, then each cluster (consecutive items having the
1466 * same cluster number) are reversed again.
1471 hb_buffer_reverse_clusters (hb_buffer_t *buffer)
1473 buffer->reverse_clusters ();
1477 * hb_buffer_guess_segment_properties:
1478 * @buffer: an #hb_buffer_t.
1480 * Sets unset buffer segment properties based on buffer Unicode
1481 * contents. If buffer is not empty, it must have content type
1482 * %HB_BUFFER_CONTENT_TYPE_UNICODE.
1484 * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it
1485 * will be set to the Unicode script of the first character in
1486 * the buffer that has a script other than %HB_SCRIPT_COMMON,
1487 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN.
1489 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID),
1490 * it will be set to the natural horizontal direction of the
1491 * buffer script as returned by hb_script_get_horizontal_direction().
1493 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID),
1494 * it will be set to the process's default language as returned by
1495 * hb_language_get_default(). This may change in the future by
1496 * taking buffer script into consideration when choosing a language.
1501 hb_buffer_guess_segment_properties (hb_buffer_t *buffer)
1503 buffer->guess_segment_properties ();
1506 template <typename utf_t>
1508 hb_buffer_add_utf (hb_buffer_t *buffer,
1509 const typename utf_t::codepoint_t *text,
1511 unsigned int item_offset,
1514 typedef typename utf_t::codepoint_t T;
1515 const hb_codepoint_t replacement = buffer->replacement;
1517 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
1518 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1520 if (unlikely (hb_object_is_inert (buffer)))
1523 if (text_length == -1)
1524 text_length = utf_t::strlen (text);
1526 if (item_length == -1)
1527 item_length = text_length - item_offset;
1529 buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
1531 /* If buffer is empty and pre-context provided, install it.
1532 * This check is written this way, to make sure people can
1533 * provide pre-context in one add_utf() call, then provide
1534 * text in a follow-up call. See:
1536 * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13
1538 if (!buffer->len && item_offset > 0)
1540 /* Add pre-context */
1541 buffer->clear_context (0);
1542 const T *prev = text + item_offset;
1543 const T *start = text;
1544 while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH)
1547 prev = utf_t::prev (prev, start, &u, replacement);
1548 buffer->context[0][buffer->context_len[0]++] = u;
1552 const T *next = text + item_offset;
1553 const T *end = next + item_length;
1557 const T *old_next = next;
1558 next = utf_t::next (next, end, &u, replacement);
1559 buffer->add (u, old_next - (const T *) text);
1562 /* Add post-context */
1563 buffer->clear_context (1);
1564 end = text + text_length;
1565 while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH)
1568 next = utf_t::next (next, end, &u, replacement);
1569 buffer->context[1][buffer->context_len[1]++] = u;
1572 buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
1576 * hb_buffer_add_utf8:
1577 * @buffer: an #hb_buffer_t.
1578 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1579 * characters to append.
1580 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1581 * @item_offset: the offset of the first character to add to the @buffer.
1582 * @item_length: the number of characters to add to the @buffer, or -1 for the
1583 * end of @text (assuming it is %NULL terminated).
1585 * See hb_buffer_add_codepoints().
1587 * Replaces invalid UTF-8 characters with the @buffer replacement code point,
1588 * see hb_buffer_set_replacement_codepoint().
1593 hb_buffer_add_utf8 (hb_buffer_t *buffer,
1596 unsigned int item_offset,
1599 hb_buffer_add_utf<hb_utf8_t> (buffer, (const uint8_t *) text, text_length, item_offset, item_length);
1603 * hb_buffer_add_utf16:
1604 * @buffer: an #hb_buffer_t.
1605 * @text: (array length=text_length): an array of UTF-16 characters to append.
1606 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1607 * @item_offset: the offset of the first character to add to the @buffer.
1608 * @item_length: the number of characters to add to the @buffer, or -1 for the
1609 * end of @text (assuming it is %NULL terminated).
1611 * See hb_buffer_add_codepoints().
1613 * Replaces invalid UTF-16 characters with the @buffer replacement code point,
1614 * see hb_buffer_set_replacement_codepoint().
1619 hb_buffer_add_utf16 (hb_buffer_t *buffer,
1620 const uint16_t *text,
1622 unsigned int item_offset,
1625 hb_buffer_add_utf<hb_utf16_t> (buffer, text, text_length, item_offset, item_length);
1629 * hb_buffer_add_utf32:
1630 * @buffer: an #hb_buffer_t.
1631 * @text: (array length=text_length): an array of UTF-32 characters to append.
1632 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1633 * @item_offset: the offset of the first character to add to the @buffer.
1634 * @item_length: the number of characters to add to the @buffer, or -1 for the
1635 * end of @text (assuming it is %NULL terminated).
1637 * See hb_buffer_add_codepoints().
1639 * Replaces invalid UTF-32 characters with the @buffer replacement code point,
1640 * see hb_buffer_set_replacement_codepoint().
1645 hb_buffer_add_utf32 (hb_buffer_t *buffer,
1646 const uint32_t *text,
1648 unsigned int item_offset,
1651 hb_buffer_add_utf<hb_utf32_t<> > (buffer, text, text_length, item_offset, item_length);
1655 * hb_buffer_add_latin1:
1656 * @buffer: an #hb_buffer_t.
1657 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1658 * characters to append.
1659 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1660 * @item_offset: the offset of the first character to add to the @buffer.
1661 * @item_length: the number of characters to add to the @buffer, or -1 for the
1662 * end of @text (assuming it is %NULL terminated).
1664 * Similar to hb_buffer_add_codepoints(), but allows only access to first 256
1665 * Unicode code points that can fit in 8-bit strings.
1667 * <note>Has nothing to do with non-Unicode Latin-1 encoding.</note>
1672 hb_buffer_add_latin1 (hb_buffer_t *buffer,
1673 const uint8_t *text,
1675 unsigned int item_offset,
1678 hb_buffer_add_utf<hb_latin1_t> (buffer, text, text_length, item_offset, item_length);
1682 * hb_buffer_add_codepoints:
1683 * @buffer: a #hb_buffer_t to append characters to.
1684 * @text: (array length=text_length): an array of Unicode code points to append.
1685 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1686 * @item_offset: the offset of the first code point to add to the @buffer.
1687 * @item_length: the number of code points to add to the @buffer, or -1 for the
1688 * end of @text (assuming it is %NULL terminated).
1690 * Appends characters from @text array to @buffer. The @item_offset is the
1691 * position of the first character from @text that will be appended, and
1692 * @item_length is the number of character. When shaping part of a larger text
1693 * (e.g. a run of text from a paragraph), instead of passing just the substring
1694 * corresponding to the run, it is preferable to pass the whole
1695 * paragraph and specify the run start and length as @item_offset and
1696 * @item_length, respectively, to give HarfBuzz the full context to be able,
1697 * for example, to do cross-run Arabic shaping or properly handle combining
1698 * marks at stat of run.
1700 * This function does not check the validity of @text, it is up to the caller
1701 * to ensure it contains a valid Unicode code points.
1706 hb_buffer_add_codepoints (hb_buffer_t *buffer,
1707 const hb_codepoint_t *text,
1709 unsigned int item_offset,
1712 hb_buffer_add_utf<hb_utf32_t<false> > (buffer, text, text_length, item_offset, item_length);
1718 * @buffer: an #hb_buffer_t.
1719 * @source: source #hb_buffer_t.
1720 * @start: start index into source buffer to copy. Use 0 to copy from start of buffer.
1721 * @end: end index into source buffer to copy. Use (unsigned int) -1 to copy to end of buffer.
1723 * Append (part of) contents of another buffer to this buffer.
1728 hb_buffer_append (hb_buffer_t *buffer,
1729 hb_buffer_t *source,
1733 assert (!buffer->have_output && !source->have_output);
1734 assert (buffer->have_positions == source->have_positions ||
1735 !buffer->len || !source->len);
1736 assert (buffer->content_type == source->content_type ||
1737 !buffer->len || !source->len);
1739 if (end > source->len)
1747 buffer->content_type = source->content_type;
1748 if (!buffer->have_positions && source->have_positions)
1749 buffer->clear_positions ();
1751 if (buffer->len + (end - start) < buffer->len) /* Overflows. */
1753 buffer->in_error = true;
1757 unsigned int orig_len = buffer->len;
1758 hb_buffer_set_length (buffer, buffer->len + (end - start));
1759 if (buffer->in_error)
1762 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0]));
1763 if (buffer->have_positions)
1764 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0]));
1769 compare_info_codepoint (const hb_glyph_info_t *pa,
1770 const hb_glyph_info_t *pb)
1772 return (int) pb->codepoint - (int) pa->codepoint;
1776 normalize_glyphs_cluster (hb_buffer_t *buffer,
1781 hb_glyph_position_t *pos = buffer->pos;
1783 /* Total cluster advance */
1784 hb_position_t total_x_advance = 0, total_y_advance = 0;
1785 for (unsigned int i = start; i < end; i++)
1787 total_x_advance += pos[i].x_advance;
1788 total_y_advance += pos[i].y_advance;
1791 hb_position_t x_advance = 0, y_advance = 0;
1792 for (unsigned int i = start; i < end; i++)
1794 pos[i].x_offset += x_advance;
1795 pos[i].y_offset += y_advance;
1797 x_advance += pos[i].x_advance;
1798 y_advance += pos[i].y_advance;
1800 pos[i].x_advance = 0;
1801 pos[i].y_advance = 0;
1806 /* Transfer all cluster advance to the last glyph. */
1807 pos[end - 1].x_advance = total_x_advance;
1808 pos[end - 1].y_advance = total_y_advance;
1810 hb_stable_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start);
1812 /* Transfer all cluster advance to the first glyph. */
1813 pos[start].x_advance += total_x_advance;
1814 pos[start].y_advance += total_y_advance;
1815 for (unsigned int i = start + 1; i < end; i++) {
1816 pos[i].x_offset -= total_x_advance;
1817 pos[i].y_offset -= total_y_advance;
1819 hb_stable_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1);
1824 * hb_buffer_normalize_glyphs:
1825 * @buffer: an #hb_buffer_t.
1827 * Reorders a glyph buffer to have canonical in-cluster glyph order / position.
1828 * The resulting clusters should behave identical to pre-reordering clusters.
1830 * <note>This has nothing to do with Unicode normalization.</note>
1835 hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
1837 assert (buffer->have_positions);
1838 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS ||
1839 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1841 bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
1843 unsigned int count = buffer->len;
1844 if (unlikely (!count)) return;
1845 hb_glyph_info_t *info = buffer->info;
1847 unsigned int start = 0;
1849 for (end = start + 1; end < count; end++)
1850 if (info[start].cluster != info[end].cluster) {
1851 normalize_glyphs_cluster (buffer, start, end, backward);
1854 normalize_glyphs_cluster (buffer, start, end, backward);
1858 hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *))
1860 assert (!have_positions);
1861 for (unsigned int i = start + 1; i < end; i++)
1864 while (j > start && compar (&info[j - 1], &info[i]) > 0)
1868 /* Move item i to occupy place for item j, shift what's in between. */
1869 merge_clusters (j, i + 1);
1871 hb_glyph_info_t t = info[i];
1872 memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t));
1880 * Comparing buffers.
1886 * If dottedcircle_glyph is (hb_codepoint_t) -1 then %HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
1887 * and %HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
1888 * callers if just comparing two buffers is needed.
1892 hb_buffer_diff_flags_t
1893 hb_buffer_diff (hb_buffer_t *buffer,
1894 hb_buffer_t *reference,
1895 hb_codepoint_t dottedcircle_glyph,
1896 unsigned int position_fuzz)
1898 if (buffer->content_type != reference->content_type && buffer->len && reference->len)
1899 return HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH;
1901 hb_buffer_diff_flags_t result = HB_BUFFER_DIFF_FLAG_EQUAL;
1902 bool contains = dottedcircle_glyph != (hb_codepoint_t) -1;
1904 unsigned int count = reference->len;
1906 if (buffer->len != count)
1909 * we can't compare glyph-by-glyph, but we do want to know if there
1910 * are .notdef or dottedcircle glyphs present in the reference buffer
1912 const hb_glyph_info_t *info = reference->info;
1914 for (i = 0; i < count; i++)
1916 if (contains && info[i].codepoint == dottedcircle_glyph)
1917 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1918 if (contains && info[i].codepoint == 0)
1919 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1921 result |= HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH;
1922 return hb_buffer_diff_flags_t (result);
1926 return hb_buffer_diff_flags_t (result);
1928 const hb_glyph_info_t *buf_info = buffer->info;
1929 const hb_glyph_info_t *ref_info = reference->info;
1930 for (unsigned int i = 0; i < count; i++)
1932 if (buf_info->codepoint != ref_info->codepoint)
1933 result |= HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH;
1934 if (buf_info->cluster != ref_info->cluster)
1935 result |= HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH;
1936 if ((buf_info->mask & ~ref_info->mask & HB_GLYPH_FLAG_DEFINED))
1937 result |= HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH;
1938 if (contains && ref_info->codepoint == dottedcircle_glyph)
1939 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1940 if (contains && ref_info->codepoint == 0)
1941 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1946 if (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)
1948 assert (buffer->have_positions);
1949 const hb_glyph_position_t *buf_pos = buffer->pos;
1950 const hb_glyph_position_t *ref_pos = reference->pos;
1951 for (unsigned int i = 0; i < count; i++)
1953 if ((unsigned int) abs (buf_pos->x_advance - ref_pos->x_advance) > position_fuzz ||
1954 (unsigned int) abs (buf_pos->y_advance - ref_pos->y_advance) > position_fuzz ||
1955 (unsigned int) abs (buf_pos->x_offset - ref_pos->x_offset) > position_fuzz ||
1956 (unsigned int) abs (buf_pos->y_offset - ref_pos->y_offset) > position_fuzz)
1958 result |= HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH;
1975 * hb_buffer_set_message_func:
1976 * @buffer: an #hb_buffer_t.
1977 * @func: (closure user_data) (destroy destroy) (scope notified):
1986 hb_buffer_set_message_func (hb_buffer_t *buffer,
1987 hb_buffer_message_func_t func,
1988 void *user_data, hb_destroy_func_t destroy)
1990 if (buffer->message_destroy)
1991 buffer->message_destroy (buffer->message_data);
1994 buffer->message_func = func;
1995 buffer->message_data = user_data;
1996 buffer->message_destroy = destroy;
1998 buffer->message_func = nullptr;
1999 buffer->message_data = nullptr;
2000 buffer->message_destroy = nullptr;
2005 hb_buffer_t::message_impl (hb_font_t *font, const char *fmt, va_list ap)
2008 vsnprintf (buf, sizeof (buf), fmt, ap);
2009 return (bool) this->message_func (this, font, buf, this->message_data);