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.hh"
37 * @short_description: Input and output buffers
40 * Buffers serve dual role in HarfBuzz; they hold the input characters that are
41 * passed to hb_shape(), and after shaping they hold the output glyphs.
46 * hb_segment_properties_equal:
47 * @a: first #hb_segment_properties_t to compare.
48 * @b: second #hb_segment_properties_t to compare.
50 * Checks the equality of two #hb_segment_properties_t's.
53 * %true if all properties of @a equal those of @b, false otherwise.
58 hb_segment_properties_equal (const hb_segment_properties_t *a,
59 const hb_segment_properties_t *b)
61 return a->direction == b->direction &&
62 a->script == b->script &&
63 a->language == b->language &&
64 a->reserved1 == b->reserved1 &&
65 a->reserved2 == b->reserved2;
70 * hb_segment_properties_hash:
71 * @p: #hb_segment_properties_t to hash.
73 * Creates a hash representing @p.
81 hb_segment_properties_hash (const hb_segment_properties_t *p)
83 return (unsigned int) p->direction ^
84 (unsigned int) p->script ^
85 (intptr_t) (p->language);
90 /* Here is how the buffer works internally:
92 * There are two info pointers: info and out_info. They always have
93 * the same allocated size, but different lengths.
95 * As an optimization, both info and out_info may point to the
96 * same piece of memory, which is owned by info. This remains the
97 * case as long as out_len doesn't exceed i at any time.
98 * In that case, swap_buffers() is no-op and the glyph operations operate
101 * As soon as out_info gets longer than info, out_info is moved over
102 * to an alternate buffer (which we reuse the pos buffer for!), and its
103 * current contents (out_len entries) are copied to the new place.
104 * This should all remain transparent to the user. swap_buffers() then
105 * switches info and out_info.
113 hb_buffer_t::enlarge (unsigned int size)
115 if (unlikely (!successful))
117 if (unlikely (size > max_len))
123 unsigned int new_allocated = allocated;
124 hb_glyph_position_t *new_pos = nullptr;
125 hb_glyph_info_t *new_info = nullptr;
126 bool separate_out = out_info != info;
128 if (unlikely (hb_unsigned_mul_overflows (size, sizeof (info[0]))))
131 while (size >= new_allocated)
132 new_allocated += (new_allocated >> 1) + 32;
134 static_assert ((sizeof (info[0]) == sizeof (pos[0])), "");
135 if (unlikely (hb_unsigned_mul_overflows (new_allocated, sizeof (info[0]))))
138 new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0]));
139 new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0]));
142 if (unlikely (!new_pos || !new_info))
145 if (likely (new_pos))
148 if (likely (new_info))
151 out_info = separate_out ? (hb_glyph_info_t *) pos : info;
152 if (likely (successful))
153 allocated = new_allocated;
155 return likely (successful);
159 hb_buffer_t::make_room_for (unsigned int num_in,
160 unsigned int num_out)
162 if (unlikely (!ensure (out_len + num_out))) return false;
164 if (out_info == info &&
165 out_len + num_out > idx + num_in)
167 assert (have_output);
169 out_info = (hb_glyph_info_t *) pos;
170 memcpy (out_info, info, out_len * sizeof (out_info[0]));
177 hb_buffer_t::shift_forward (unsigned int count)
179 assert (have_output);
180 if (unlikely (!ensure (len + count))) return false;
182 memmove (info + idx + count, info + idx, (len - idx) * sizeof (info[0]));
183 if (idx + count > len)
185 /* Under memory failure we might expose this area. At least
186 * clean it up. Oh well...
188 * Ideally, we should at least set Default_Ignorable bits on
189 * these, as well as consistent cluster values. But the former
190 * is layering violation... */
191 memset (info + len, 0, (idx + count - len) * sizeof (info[0]));
199 hb_buffer_t::scratch_buffer_t *
200 hb_buffer_t::get_scratch_buffer (unsigned int *size)
203 have_positions = false;
208 assert ((uintptr_t) pos % sizeof (scratch_buffer_t) == 0);
209 *size = allocated * sizeof (pos[0]) / sizeof (scratch_buffer_t);
210 return (scratch_buffer_t *) (void *) pos;
215 /* HarfBuzz-Internal API */
218 hb_buffer_t::reset ()
220 if (unlikely (hb_object_is_immutable (this)))
223 hb_unicode_funcs_destroy (unicode);
224 unicode = hb_unicode_funcs_reference (hb_unicode_funcs_get_default ());
225 flags = HB_BUFFER_FLAG_DEFAULT;
226 replacement = HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT;
233 hb_buffer_t::clear ()
235 if (unlikely (hb_object_is_immutable (this)))
238 hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT;
239 props = default_props;
240 scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
242 content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
245 have_positions = false;
254 memset (context, 0, sizeof context);
255 memset (context_len, 0, sizeof context_len);
257 deallocate_var_all ();
261 hb_buffer_t::add (hb_codepoint_t codepoint,
262 unsigned int cluster)
264 hb_glyph_info_t *glyph;
266 if (unlikely (!ensure (len + 1))) return;
270 memset (glyph, 0, sizeof (*glyph));
271 glyph->codepoint = codepoint;
273 glyph->cluster = cluster;
279 hb_buffer_t::add_info (const hb_glyph_info_t &glyph_info)
281 if (unlikely (!ensure (len + 1))) return;
283 info[len] = glyph_info;
290 hb_buffer_t::remove_output ()
292 if (unlikely (hb_object_is_immutable (this)))
296 have_positions = false;
303 hb_buffer_t::clear_output ()
305 if (unlikely (hb_object_is_immutable (this)))
309 have_positions = false;
316 hb_buffer_t::clear_positions ()
318 if (unlikely (hb_object_is_immutable (this)))
322 have_positions = true;
327 hb_memset (pos, 0, sizeof (pos[0]) * len);
331 hb_buffer_t::swap_buffers ()
333 if (unlikely (!successful)) return;
335 assert (have_output);
338 if (out_info != info)
340 hb_glyph_info_t *tmp_string;
343 out_info = tmp_string;
344 pos = (hb_glyph_position_t *) out_info;
357 hb_buffer_t::replace_glyphs (unsigned int num_in,
358 unsigned int num_out,
359 const uint32_t *glyph_data)
361 if (unlikely (!make_room_for (num_in, num_out))) return;
363 assert (idx + num_in <= len);
365 merge_clusters (idx, idx + num_in);
367 hb_glyph_info_t orig_info = info[idx];
368 hb_glyph_info_t *pinfo = &out_info[out_len];
369 for (unsigned int i = 0; i < num_out; i++)
372 pinfo->codepoint = glyph_data[i];
381 hb_buffer_t::move_to (unsigned int i)
389 if (unlikely (!successful))
392 assert (i <= out_len + (len - idx));
396 unsigned int count = i - out_len;
397 if (unlikely (!make_room_for (count, count))) return false;
399 memmove (out_info + out_len, info + idx, count * sizeof (out_info[0]));
403 else if (out_len > i)
405 /* Tricky part: rewinding... */
406 unsigned int count = out_len - i;
408 /* This will blow in our face if memory allocation fails later
409 * in this same lookup...
411 * We used to shift with extra 32 items, instead of the 0 below.
412 * But that would leave empty slots in the buffer in case of allocation
413 * failures. Setting to zero for now to avoid other problems (see
414 * comments in shift_forward(). This can cause O(N^2) behavior more
415 * severely than adding 32 empty slots can... */
416 if (unlikely (idx < count && !shift_forward (count + 0))) return false;
418 assert (idx >= count);
422 memmove (info + idx, out_info + out_len, count * sizeof (out_info[0]));
430 hb_buffer_t::set_masks (hb_mask_t value,
432 unsigned int cluster_start,
433 unsigned int cluster_end)
435 hb_mask_t not_mask = ~mask;
441 unsigned int count = len;
442 for (unsigned int i = 0; i < count; i++)
443 if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end)
444 info[i].mask = (info[i].mask & not_mask) | value;
448 hb_buffer_t::reverse_range (unsigned int start,
454 hb_array_t<hb_glyph_info_t> (info, len).reverse (start, end);
456 if (have_positions) {
457 hb_array_t<hb_glyph_position_t> (pos, len).reverse (start, end);
462 hb_buffer_t::reverse ()
467 reverse_range (0, len);
471 hb_buffer_t::reverse_clusters ()
473 unsigned int i, start, count, last_cluster;
482 last_cluster = info[0].cluster;
483 for (i = 1; i < count; i++) {
484 if (last_cluster != info[i].cluster) {
485 reverse_range (start, i);
487 last_cluster = info[i].cluster;
490 reverse_range (start, i);
494 hb_buffer_t::merge_clusters_impl (unsigned int start,
497 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
499 unsafe_to_break (start, end);
503 unsigned int cluster = info[start].cluster;
505 for (unsigned int i = start + 1; i < end; i++)
506 cluster = hb_min (cluster, info[i].cluster);
509 while (end < len && info[end - 1].cluster == info[end].cluster)
513 while (idx < start && info[start - 1].cluster == info[start].cluster)
516 /* If we hit the start of buffer, continue in out-buffer. */
518 for (unsigned int i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--)
519 set_cluster (out_info[i - 1], cluster);
521 for (unsigned int i = start; i < end; i++)
522 set_cluster (info[i], cluster);
525 hb_buffer_t::merge_out_clusters (unsigned int start,
528 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
531 if (unlikely (end - start < 2))
534 unsigned int cluster = out_info[start].cluster;
536 for (unsigned int i = start + 1; i < end; i++)
537 cluster = hb_min (cluster, out_info[i].cluster);
540 while (start && out_info[start - 1].cluster == out_info[start].cluster)
544 while (end < out_len && out_info[end - 1].cluster == out_info[end].cluster)
547 /* If we hit the end of out-buffer, continue in buffer. */
549 for (unsigned int i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++)
550 set_cluster (info[i], cluster);
552 for (unsigned int i = start; i < end; i++)
553 set_cluster (out_info[i], cluster);
556 hb_buffer_t::delete_glyph ()
558 /* The logic here is duplicated in hb_ot_hide_default_ignorables(). */
560 unsigned int cluster = info[idx].cluster;
561 if (idx + 1 < len && cluster == info[idx + 1].cluster)
563 /* Cluster survives; do nothing. */
569 /* Merge cluster backward. */
570 if (cluster < out_info[out_len - 1].cluster)
572 unsigned int mask = info[idx].mask;
573 unsigned int old_cluster = out_info[out_len - 1].cluster;
574 for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--)
575 set_cluster (out_info[i - 1], cluster, mask);
582 /* Merge cluster forward. */
583 merge_clusters (idx, idx + 2);
592 hb_buffer_t::unsafe_to_break_impl (unsigned int start, unsigned int end)
594 unsigned int cluster = UINT_MAX;
595 cluster = _unsafe_to_break_find_min_cluster (info, start, end, cluster);
596 _unsafe_to_break_set_mask (info, start, end, cluster);
599 hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int end)
603 unsafe_to_break_impl (start, end);
607 assert (start <= out_len);
610 unsigned int cluster = UINT_MAX;
611 cluster = _unsafe_to_break_find_min_cluster (out_info, start, out_len, cluster);
612 cluster = _unsafe_to_break_find_min_cluster (info, idx, end, cluster);
613 _unsafe_to_break_set_mask (out_info, start, out_len, cluster);
614 _unsafe_to_break_set_mask (info, idx, end, cluster);
618 hb_buffer_t::guess_segment_properties ()
620 assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
621 (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
623 /* If script is set to INVALID, guess from buffer contents */
624 if (props.script == HB_SCRIPT_INVALID) {
625 for (unsigned int i = 0; i < len; i++) {
626 hb_script_t script = unicode->script (info[i].codepoint);
627 if (likely (script != HB_SCRIPT_COMMON &&
628 script != HB_SCRIPT_INHERITED &&
629 script != HB_SCRIPT_UNKNOWN)) {
630 props.script = script;
636 /* If direction is set to INVALID, guess from script */
637 if (props.direction == HB_DIRECTION_INVALID) {
638 props.direction = hb_script_get_horizontal_direction (props.script);
639 if (props.direction == HB_DIRECTION_INVALID)
640 props.direction = HB_DIRECTION_LTR;
643 /* If language is not set, use default language from locale */
644 if (props.language == HB_LANGUAGE_INVALID) {
645 /* TODO get_default_for_script? using $LANGUAGE */
646 props.language = hb_language_get_default ();
653 DEFINE_NULL_INSTANCE (hb_buffer_t) =
655 HB_OBJECT_HEADER_STATIC,
657 const_cast<hb_unicode_funcs_t *> (&_hb_Null_hb_unicode_funcs_t),
658 HB_BUFFER_FLAG_DEFAULT,
659 HB_BUFFER_CLUSTER_LEVEL_DEFAULT,
660 HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
662 HB_BUFFER_SCRATCH_FLAG_DEFAULT,
663 HB_BUFFER_MAX_LEN_DEFAULT,
664 HB_BUFFER_MAX_OPS_DEFAULT,
666 HB_BUFFER_CONTENT_TYPE_INVALID,
667 HB_SEGMENT_PROPERTIES_DEFAULT,
668 false, /* successful */
669 true, /* have_output */
670 true /* have_positions */
672 /* Zero is good enough for everything else. */
677 * hb_buffer_create: (Xconstructor)
679 * Creates a new #hb_buffer_t with all properties to defaults.
681 * Return value: (transfer full):
682 * A newly allocated #hb_buffer_t with a reference count of 1. The initial
683 * reference count should be released with hb_buffer_destroy() when you are done
684 * using the #hb_buffer_t. This function never returns %NULL. If memory cannot
685 * be allocated, a special #hb_buffer_t object will be returned on which
686 * hb_buffer_allocation_successful() returns %false.
695 if (!(buffer = hb_object_create<hb_buffer_t> ()))
696 return hb_buffer_get_empty ();
698 buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
699 buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
707 * hb_buffer_get_empty:
711 * Return value: (transfer full):
716 hb_buffer_get_empty ()
718 return const_cast<hb_buffer_t *> (&Null (hb_buffer_t));
722 * hb_buffer_reference: (skip)
723 * @buffer: an #hb_buffer_t.
725 * Increases the reference count on @buffer by one. This prevents @buffer from
726 * being destroyed until a matching call to hb_buffer_destroy() is made.
728 * Return value: (transfer full):
729 * The referenced #hb_buffer_t.
734 hb_buffer_reference (hb_buffer_t *buffer)
736 return hb_object_reference (buffer);
740 * hb_buffer_destroy: (skip)
741 * @buffer: an #hb_buffer_t.
743 * Deallocate the @buffer.
744 * Decreases the reference count on @buffer by one. If the result is zero, then
745 * @buffer and all associated resources are freed. See hb_buffer_reference().
750 hb_buffer_destroy (hb_buffer_t *buffer)
752 if (!hb_object_destroy (buffer)) return;
754 hb_unicode_funcs_destroy (buffer->unicode);
758 #ifndef HB_NO_BUFFER_MESSAGE
759 if (buffer->message_destroy)
760 buffer->message_destroy (buffer->message_data);
767 * hb_buffer_set_user_data: (skip)
768 * @buffer: an #hb_buffer_t.
781 hb_buffer_set_user_data (hb_buffer_t *buffer,
782 hb_user_data_key_t *key,
784 hb_destroy_func_t destroy,
787 return hb_object_set_user_data (buffer, key, data, destroy, replace);
791 * hb_buffer_get_user_data: (skip)
792 * @buffer: an #hb_buffer_t.
802 hb_buffer_get_user_data (hb_buffer_t *buffer,
803 hb_user_data_key_t *key)
805 return hb_object_get_user_data (buffer, key);
810 * hb_buffer_set_content_type:
811 * @buffer: an #hb_buffer_t.
812 * @content_type: the type of buffer contents to set
814 * Sets the type of @buffer contents, buffers are either empty, contain
815 * characters (before shaping) or glyphs (the result of shaping).
820 hb_buffer_set_content_type (hb_buffer_t *buffer,
821 hb_buffer_content_type_t content_type)
823 buffer->content_type = content_type;
827 * hb_buffer_get_content_type:
828 * @buffer: an #hb_buffer_t.
830 * see hb_buffer_set_content_type().
833 * The type of @buffer contents.
837 hb_buffer_content_type_t
838 hb_buffer_get_content_type (hb_buffer_t *buffer)
840 return buffer->content_type;
845 * hb_buffer_set_unicode_funcs:
846 * @buffer: an #hb_buffer_t.
854 hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
855 hb_unicode_funcs_t *unicode_funcs)
857 if (unlikely (hb_object_is_immutable (buffer)))
861 unicode_funcs = hb_unicode_funcs_get_default ();
863 hb_unicode_funcs_reference (unicode_funcs);
864 hb_unicode_funcs_destroy (buffer->unicode);
865 buffer->unicode = unicode_funcs;
869 * hb_buffer_get_unicode_funcs:
870 * @buffer: an #hb_buffer_t.
879 hb_buffer_get_unicode_funcs (hb_buffer_t *buffer)
881 return buffer->unicode;
885 * hb_buffer_set_direction:
886 * @buffer: an #hb_buffer_t.
887 * @direction: the #hb_direction_t of the @buffer
889 * Set the text flow direction of the buffer. No shaping can happen without
890 * setting @buffer direction, and it controls the visual direction for the
891 * output glyphs; for RTL direction the glyphs will be reversed. Many layout
892 * features depend on the proper setting of the direction, for example,
893 * reversing RTL text before shaping, then shaping with LTR direction is not
894 * the same as keeping the text in logical order and shaping with RTL
900 hb_buffer_set_direction (hb_buffer_t *buffer,
901 hb_direction_t direction)
904 if (unlikely (hb_object_is_immutable (buffer)))
907 buffer->props.direction = direction;
911 * hb_buffer_get_direction:
912 * @buffer: an #hb_buffer_t.
914 * See hb_buffer_set_direction()
917 * The direction of the @buffer.
922 hb_buffer_get_direction (hb_buffer_t *buffer)
924 return buffer->props.direction;
928 * hb_buffer_set_script:
929 * @buffer: an #hb_buffer_t.
930 * @script: an #hb_script_t to set.
932 * Sets the script of @buffer to @script.
934 * Script is crucial for choosing the proper shaping behaviour for scripts that
935 * require it (e.g. Arabic) and the which OpenType features defined in the font
938 * You can pass one of the predefined #hb_script_t values, or use
939 * hb_script_from_string() or hb_script_from_iso15924_tag() to get the
940 * corresponding script from an ISO 15924 script tag.
945 hb_buffer_set_script (hb_buffer_t *buffer,
948 if (unlikely (hb_object_is_immutable (buffer)))
951 buffer->props.script = script;
955 * hb_buffer_get_script:
956 * @buffer: an #hb_buffer_t.
958 * See hb_buffer_set_script().
961 * The #hb_script_t of the @buffer.
966 hb_buffer_get_script (hb_buffer_t *buffer)
968 return buffer->props.script;
972 * hb_buffer_set_language:
973 * @buffer: an #hb_buffer_t.
974 * @language: an hb_language_t to set.
976 * Sets the language of @buffer to @language.
978 * Languages are crucial for selecting which OpenType feature to apply to the
979 * buffer which can result in applying language-specific behaviour. Languages
980 * are orthogonal to the scripts, and though they are related, they are
981 * different concepts and should not be confused with each other.
983 * Use hb_language_from_string() to convert from BCP 47 language tags to
989 hb_buffer_set_language (hb_buffer_t *buffer,
990 hb_language_t language)
992 if (unlikely (hb_object_is_immutable (buffer)))
995 buffer->props.language = language;
999 * hb_buffer_get_language:
1000 * @buffer: an #hb_buffer_t.
1002 * See hb_buffer_set_language().
1004 * Return value: (transfer none):
1005 * The #hb_language_t of the buffer. Must not be freed by the caller.
1010 hb_buffer_get_language (hb_buffer_t *buffer)
1012 return buffer->props.language;
1016 * hb_buffer_set_segment_properties:
1017 * @buffer: an #hb_buffer_t.
1018 * @props: an #hb_segment_properties_t to use.
1020 * Sets the segment properties of the buffer, a shortcut for calling
1021 * hb_buffer_set_direction(), hb_buffer_set_script() and
1022 * hb_buffer_set_language() individually.
1027 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
1028 const hb_segment_properties_t *props)
1030 if (unlikely (hb_object_is_immutable (buffer)))
1033 buffer->props = *props;
1037 * hb_buffer_get_segment_properties:
1038 * @buffer: an #hb_buffer_t.
1039 * @props: (out): the output #hb_segment_properties_t.
1041 * Sets @props to the #hb_segment_properties_t of @buffer.
1046 hb_buffer_get_segment_properties (hb_buffer_t *buffer,
1047 hb_segment_properties_t *props)
1049 *props = buffer->props;
1054 * hb_buffer_set_flags:
1055 * @buffer: an #hb_buffer_t.
1056 * @flags: the buffer flags to set.
1058 * Sets @buffer flags to @flags. See #hb_buffer_flags_t.
1063 hb_buffer_set_flags (hb_buffer_t *buffer,
1064 hb_buffer_flags_t flags)
1066 if (unlikely (hb_object_is_immutable (buffer)))
1069 buffer->flags = flags;
1073 * hb_buffer_get_flags:
1074 * @buffer: an #hb_buffer_t.
1076 * See hb_buffer_set_flags().
1079 * The @buffer flags.
1084 hb_buffer_get_flags (hb_buffer_t *buffer)
1086 return buffer->flags;
1090 * hb_buffer_set_cluster_level:
1091 * @buffer: an #hb_buffer_t.
1099 hb_buffer_set_cluster_level (hb_buffer_t *buffer,
1100 hb_buffer_cluster_level_t cluster_level)
1102 if (unlikely (hb_object_is_immutable (buffer)))
1105 buffer->cluster_level = cluster_level;
1109 * hb_buffer_get_cluster_level:
1110 * @buffer: an #hb_buffer_t.
1118 hb_buffer_cluster_level_t
1119 hb_buffer_get_cluster_level (hb_buffer_t *buffer)
1121 return buffer->cluster_level;
1126 * hb_buffer_set_replacement_codepoint:
1127 * @buffer: an #hb_buffer_t.
1128 * @replacement: the replacement #hb_codepoint_t
1130 * Sets the #hb_codepoint_t that replaces invalid entries for a given encoding
1131 * when adding text to @buffer.
1133 * Default is %HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
1138 hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
1139 hb_codepoint_t replacement)
1141 if (unlikely (hb_object_is_immutable (buffer)))
1144 buffer->replacement = replacement;
1148 * hb_buffer_get_replacement_codepoint:
1149 * @buffer: an #hb_buffer_t.
1151 * See hb_buffer_set_replacement_codepoint().
1154 * The @buffer replacement #hb_codepoint_t.
1159 hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
1161 return buffer->replacement;
1166 * hb_buffer_set_invisible_glyph:
1167 * @buffer: an #hb_buffer_t.
1168 * @invisible: the invisible #hb_codepoint_t
1170 * Sets the #hb_codepoint_t that replaces invisible characters in
1171 * the shaping result. If set to zero (default), the glyph for the
1172 * U+0020 SPACE character is used. Otherwise, this value is used
1178 hb_buffer_set_invisible_glyph (hb_buffer_t *buffer,
1179 hb_codepoint_t invisible)
1181 if (unlikely (hb_object_is_immutable (buffer)))
1184 buffer->invisible = invisible;
1188 * hb_buffer_get_invisible_glyph:
1189 * @buffer: an #hb_buffer_t.
1191 * See hb_buffer_set_invisible_glyph().
1194 * The @buffer invisible #hb_codepoint_t.
1199 hb_buffer_get_invisible_glyph (hb_buffer_t *buffer)
1201 return buffer->invisible;
1207 * @buffer: an #hb_buffer_t.
1209 * Resets the buffer to its initial status, as if it was just newly created
1210 * with hb_buffer_create().
1215 hb_buffer_reset (hb_buffer_t *buffer)
1221 * hb_buffer_clear_contents:
1222 * @buffer: an #hb_buffer_t.
1224 * Similar to hb_buffer_reset(), but does not clear the Unicode functions and
1225 * the replacement code point.
1230 hb_buffer_clear_contents (hb_buffer_t *buffer)
1236 * hb_buffer_pre_allocate:
1237 * @buffer: an #hb_buffer_t.
1238 * @size: number of items to pre allocate.
1240 * Pre allocates memory for @buffer to fit at least @size number of items.
1243 * %true if @buffer memory allocation succeeded, %false otherwise.
1248 hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
1250 return buffer->ensure (size);
1254 * hb_buffer_allocation_successful:
1255 * @buffer: an #hb_buffer_t.
1257 * Check if allocating memory for the buffer succeeded.
1260 * %true if @buffer memory allocation succeeded, %false otherwise.
1265 hb_buffer_allocation_successful (hb_buffer_t *buffer)
1267 return buffer->successful;
1272 * @buffer: an #hb_buffer_t.
1273 * @codepoint: a Unicode code point.
1274 * @cluster: the cluster value of @codepoint.
1276 * Appends a character with the Unicode value of @codepoint to @buffer, and
1277 * gives it the initial cluster value of @cluster. Clusters can be any thing
1278 * the client wants, they are usually used to refer to the index of the
1279 * character in the input text stream and are output in
1280 * #hb_glyph_info_t.cluster field.
1282 * This function does not check the validity of @codepoint, it is up to the
1283 * caller to ensure it is a valid Unicode code point.
1288 hb_buffer_add (hb_buffer_t *buffer,
1289 hb_codepoint_t codepoint,
1290 unsigned int cluster)
1292 buffer->add (codepoint, cluster);
1293 buffer->clear_context (1);
1297 * hb_buffer_set_length:
1298 * @buffer: an #hb_buffer_t.
1299 * @length: the new length of @buffer.
1301 * Similar to hb_buffer_pre_allocate(), but clears any new items added at the
1305 * %true if @buffer memory allocation succeeded, %false otherwise.
1310 hb_buffer_set_length (hb_buffer_t *buffer,
1311 unsigned int length)
1313 if (unlikely (hb_object_is_immutable (buffer)))
1316 if (!buffer->ensure (length))
1319 /* Wipe the new space */
1320 if (length > buffer->len) {
1321 memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len));
1322 if (buffer->have_positions)
1323 memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len));
1326 buffer->len = length;
1330 buffer->content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
1331 buffer->clear_context (0);
1333 buffer->clear_context (1);
1339 * hb_buffer_get_length:
1340 * @buffer: an #hb_buffer_t.
1342 * Returns the number of items in the buffer.
1345 * The @buffer length.
1346 * The value valid as long as buffer has not been modified.
1351 hb_buffer_get_length (hb_buffer_t *buffer)
1357 * hb_buffer_get_glyph_infos:
1358 * @buffer: an #hb_buffer_t.
1359 * @length: (out): output array length.
1361 * Returns @buffer glyph information array. Returned pointer
1362 * is valid as long as @buffer contents are not modified.
1364 * Return value: (transfer none) (array length=length):
1365 * The @buffer glyph information array.
1366 * The value valid as long as buffer has not been modified.
1371 hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
1372 unsigned int *length)
1375 *length = buffer->len;
1377 return (hb_glyph_info_t *) buffer->info;
1381 * hb_buffer_get_glyph_positions:
1382 * @buffer: an #hb_buffer_t.
1383 * @length: (out): output length.
1385 * Returns @buffer glyph position array. Returned pointer
1386 * is valid as long as @buffer contents are not modified.
1388 * Return value: (transfer none) (array length=length):
1389 * The @buffer glyph position array.
1390 * The value valid as long as buffer has not been modified.
1394 hb_glyph_position_t *
1395 hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
1396 unsigned int *length)
1398 if (!buffer->have_positions)
1399 buffer->clear_positions ();
1402 *length = buffer->len;
1404 return (hb_glyph_position_t *) buffer->pos;
1408 * hb_glyph_info_get_glyph_flags:
1409 * @info: a #hb_glyph_info_t.
1411 * Returns glyph flags encoded within a #hb_glyph_info_t.
1414 * The #hb_glyph_flags_t encoded within @info.
1419 (hb_glyph_info_get_glyph_flags) (const hb_glyph_info_t *info)
1421 return hb_glyph_info_get_glyph_flags (info);
1425 * hb_buffer_reverse:
1426 * @buffer: an #hb_buffer_t.
1428 * Reverses buffer contents.
1433 hb_buffer_reverse (hb_buffer_t *buffer)
1439 * hb_buffer_reverse_range:
1440 * @buffer: an #hb_buffer_t.
1441 * @start: start index.
1444 * Reverses buffer contents between start to end.
1449 hb_buffer_reverse_range (hb_buffer_t *buffer,
1450 unsigned int start, unsigned int end)
1452 buffer->reverse_range (start, end);
1456 * hb_buffer_reverse_clusters:
1457 * @buffer: an #hb_buffer_t.
1459 * Reverses buffer clusters. That is, the buffer contents are
1460 * reversed, then each cluster (consecutive items having the
1461 * same cluster number) are reversed again.
1466 hb_buffer_reverse_clusters (hb_buffer_t *buffer)
1468 buffer->reverse_clusters ();
1472 * hb_buffer_guess_segment_properties:
1473 * @buffer: an #hb_buffer_t.
1475 * Sets unset buffer segment properties based on buffer Unicode
1476 * contents. If buffer is not empty, it must have content type
1477 * %HB_BUFFER_CONTENT_TYPE_UNICODE.
1479 * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it
1480 * will be set to the Unicode script of the first character in
1481 * the buffer that has a script other than %HB_SCRIPT_COMMON,
1482 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN.
1484 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID),
1485 * it will be set to the natural horizontal direction of the
1486 * buffer script as returned by hb_script_get_horizontal_direction().
1487 * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID,
1488 * then %HB_DIRECTION_LTR is used.
1490 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID),
1491 * it will be set to the process's default language as returned by
1492 * hb_language_get_default(). This may change in the future by
1493 * taking buffer script into consideration when choosing a language.
1494 * Note that hb_language_get_default() is NOT threadsafe the first time
1495 * it is called. See documentation for that function for details.
1500 hb_buffer_guess_segment_properties (hb_buffer_t *buffer)
1502 buffer->guess_segment_properties ();
1505 template <typename utf_t>
1507 hb_buffer_add_utf (hb_buffer_t *buffer,
1508 const typename utf_t::codepoint_t *text,
1510 unsigned int item_offset,
1513 typedef typename utf_t::codepoint_t T;
1514 const hb_codepoint_t replacement = buffer->replacement;
1516 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
1517 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1519 if (unlikely (hb_object_is_immutable (buffer)))
1522 if (text_length == -1)
1523 text_length = utf_t::strlen (text);
1525 if (item_length == -1)
1526 item_length = text_length - item_offset;
1528 buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
1530 /* If buffer is empty and pre-context provided, install it.
1531 * This check is written this way, to make sure people can
1532 * provide pre-context in one add_utf() call, then provide
1533 * text in a follow-up call. See:
1535 * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13
1537 if (!buffer->len && item_offset > 0)
1539 /* Add pre-context */
1540 buffer->clear_context (0);
1541 const T *prev = text + item_offset;
1542 const T *start = text;
1543 while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH)
1546 prev = utf_t::prev (prev, start, &u, replacement);
1547 buffer->context[0][buffer->context_len[0]++] = u;
1551 const T *next = text + item_offset;
1552 const T *end = next + item_length;
1556 const T *old_next = next;
1557 next = utf_t::next (next, end, &u, replacement);
1558 buffer->add (u, old_next - (const T *) text);
1561 /* Add post-context */
1562 buffer->clear_context (1);
1563 end = text + text_length;
1564 while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH)
1567 next = utf_t::next (next, end, &u, replacement);
1568 buffer->context[1][buffer->context_len[1]++] = u;
1571 buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
1575 * hb_buffer_add_utf8:
1576 * @buffer: an #hb_buffer_t.
1577 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1578 * characters to append.
1579 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1580 * @item_offset: the offset of the first character to add to the @buffer.
1581 * @item_length: the number of characters to add to the @buffer, or -1 for the
1582 * end of @text (assuming it is %NULL terminated).
1584 * See hb_buffer_add_codepoints().
1586 * Replaces invalid UTF-8 characters with the @buffer replacement code point,
1587 * see hb_buffer_set_replacement_codepoint().
1592 hb_buffer_add_utf8 (hb_buffer_t *buffer,
1595 unsigned int item_offset,
1598 hb_buffer_add_utf<hb_utf8_t> (buffer, (const uint8_t *) text, text_length, item_offset, item_length);
1602 * hb_buffer_add_utf16:
1603 * @buffer: an #hb_buffer_t.
1604 * @text: (array length=text_length): an array of UTF-16 characters to append.
1605 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1606 * @item_offset: the offset of the first character to add to the @buffer.
1607 * @item_length: the number of characters to add to the @buffer, or -1 for the
1608 * end of @text (assuming it is %NULL terminated).
1610 * See hb_buffer_add_codepoints().
1612 * Replaces invalid UTF-16 characters with the @buffer replacement code point,
1613 * see hb_buffer_set_replacement_codepoint().
1618 hb_buffer_add_utf16 (hb_buffer_t *buffer,
1619 const uint16_t *text,
1621 unsigned int item_offset,
1624 hb_buffer_add_utf<hb_utf16_t> (buffer, text, text_length, item_offset, item_length);
1628 * hb_buffer_add_utf32:
1629 * @buffer: an #hb_buffer_t.
1630 * @text: (array length=text_length): an array of UTF-32 characters to append.
1631 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1632 * @item_offset: the offset of the first character to add to the @buffer.
1633 * @item_length: the number of characters to add to the @buffer, or -1 for the
1634 * end of @text (assuming it is %NULL terminated).
1636 * See hb_buffer_add_codepoints().
1638 * Replaces invalid UTF-32 characters with the @buffer replacement code point,
1639 * see hb_buffer_set_replacement_codepoint().
1644 hb_buffer_add_utf32 (hb_buffer_t *buffer,
1645 const uint32_t *text,
1647 unsigned int item_offset,
1650 hb_buffer_add_utf<hb_utf32_t> (buffer, text, text_length, item_offset, item_length);
1654 * hb_buffer_add_latin1:
1655 * @buffer: an #hb_buffer_t.
1656 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1657 * characters to append.
1658 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1659 * @item_offset: the offset of the first character to add to the @buffer.
1660 * @item_length: the number of characters to add to the @buffer, or -1 for the
1661 * end of @text (assuming it is %NULL terminated).
1663 * Similar to hb_buffer_add_codepoints(), but allows only access to first 256
1664 * Unicode code points that can fit in 8-bit strings.
1666 * <note>Has nothing to do with non-Unicode Latin-1 encoding.</note>
1671 hb_buffer_add_latin1 (hb_buffer_t *buffer,
1672 const uint8_t *text,
1674 unsigned int item_offset,
1677 hb_buffer_add_utf<hb_latin1_t> (buffer, text, text_length, item_offset, item_length);
1681 * hb_buffer_add_codepoints:
1682 * @buffer: a #hb_buffer_t to append characters to.
1683 * @text: (array length=text_length): an array of Unicode code points to append.
1684 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1685 * @item_offset: the offset of the first code point to add to the @buffer.
1686 * @item_length: the number of code points to add to the @buffer, or -1 for the
1687 * end of @text (assuming it is %NULL terminated).
1689 * Appends characters from @text array to @buffer. The @item_offset is the
1690 * position of the first character from @text that will be appended, and
1691 * @item_length is the number of character. When shaping part of a larger text
1692 * (e.g. a run of text from a paragraph), instead of passing just the substring
1693 * corresponding to the run, it is preferable to pass the whole
1694 * paragraph and specify the run start and length as @item_offset and
1695 * @item_length, respectively, to give HarfBuzz the full context to be able,
1696 * for example, to do cross-run Arabic shaping or properly handle combining
1697 * marks at stat of run.
1699 * This function does not check the validity of @text, it is up to the caller
1700 * to ensure it contains a valid Unicode code points.
1705 hb_buffer_add_codepoints (hb_buffer_t *buffer,
1706 const hb_codepoint_t *text,
1708 unsigned int item_offset,
1711 hb_buffer_add_utf<hb_utf32_novalidate_t> (buffer, text, text_length, item_offset, item_length);
1717 * @buffer: an #hb_buffer_t.
1718 * @source: source #hb_buffer_t.
1719 * @start: start index into source buffer to copy. Use 0 to copy from start of buffer.
1720 * @end: end index into source buffer to copy. Use @HB_FEATURE_GLOBAL_END to copy to end of buffer.
1722 * Append (part of) contents of another buffer to this buffer.
1727 hb_buffer_append (hb_buffer_t *buffer,
1728 hb_buffer_t *source,
1732 assert (!buffer->have_output && !source->have_output);
1733 assert (buffer->have_positions == source->have_positions ||
1734 !buffer->len || !source->len);
1735 assert (buffer->content_type == source->content_type ||
1736 !buffer->len || !source->len);
1738 if (end > source->len)
1746 buffer->content_type = source->content_type;
1747 if (!buffer->have_positions && source->have_positions)
1748 buffer->clear_positions ();
1750 if (buffer->len + (end - start) < buffer->len) /* Overflows. */
1752 buffer->successful = false;
1756 unsigned int orig_len = buffer->len;
1757 hb_buffer_set_length (buffer, buffer->len + (end - start));
1758 if (unlikely (!buffer->successful))
1761 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0]));
1762 if (buffer->have_positions)
1763 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0]));
1768 compare_info_codepoint (const hb_glyph_info_t *pa,
1769 const hb_glyph_info_t *pb)
1771 return (int) pb->codepoint - (int) pa->codepoint;
1775 normalize_glyphs_cluster (hb_buffer_t *buffer,
1780 hb_glyph_position_t *pos = buffer->pos;
1782 /* Total cluster advance */
1783 hb_position_t total_x_advance = 0, total_y_advance = 0;
1784 for (unsigned int i = start; i < end; i++)
1786 total_x_advance += pos[i].x_advance;
1787 total_y_advance += pos[i].y_advance;
1790 hb_position_t x_advance = 0, y_advance = 0;
1791 for (unsigned int i = start; i < end; i++)
1793 pos[i].x_offset += x_advance;
1794 pos[i].y_offset += y_advance;
1796 x_advance += pos[i].x_advance;
1797 y_advance += pos[i].y_advance;
1799 pos[i].x_advance = 0;
1800 pos[i].y_advance = 0;
1805 /* Transfer all cluster advance to the last glyph. */
1806 pos[end - 1].x_advance = total_x_advance;
1807 pos[end - 1].y_advance = total_y_advance;
1809 hb_stable_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start);
1811 /* Transfer all cluster advance to the first glyph. */
1812 pos[start].x_advance += total_x_advance;
1813 pos[start].y_advance += total_y_advance;
1814 for (unsigned int i = start + 1; i < end; i++) {
1815 pos[i].x_offset -= total_x_advance;
1816 pos[i].y_offset -= total_y_advance;
1818 hb_stable_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1);
1823 * hb_buffer_normalize_glyphs:
1824 * @buffer: an #hb_buffer_t.
1826 * Reorders a glyph buffer to have canonical in-cluster glyph order / position.
1827 * The resulting clusters should behave identical to pre-reordering clusters.
1829 * <note>This has nothing to do with Unicode normalization.</note>
1834 hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
1836 assert (buffer->have_positions);
1837 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS ||
1838 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1840 bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
1842 foreach_cluster (buffer, start, end)
1843 normalize_glyphs_cluster (buffer, start, end, backward);
1847 hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *))
1849 assert (!have_positions);
1850 for (unsigned int i = start + 1; i < end; i++)
1853 while (j > start && compar (&info[j - 1], &info[i]) > 0)
1857 /* Move item i to occupy place for item j, shift what's in between. */
1858 merge_clusters (j, i + 1);
1860 hb_glyph_info_t t = info[i];
1861 memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t));
1869 * Comparing buffers.
1874 * @buffer: a buffer.
1875 * @reference: other buffer to compare to.
1876 * @dottedcircle_glyph: glyph id of U+25CC DOTTED CIRCLE, or (hb_codepont_t) -1.
1877 * @position_fuzz: allowed absolute difference in position values.
1879 * If dottedcircle_glyph is (hb_codepoint_t) -1 then %HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
1880 * and %HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
1881 * callers if just comparing two buffers is needed.
1885 hb_buffer_diff_flags_t
1886 hb_buffer_diff (hb_buffer_t *buffer,
1887 hb_buffer_t *reference,
1888 hb_codepoint_t dottedcircle_glyph,
1889 unsigned int position_fuzz)
1891 if (buffer->content_type != reference->content_type && buffer->len && reference->len)
1892 return HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH;
1894 hb_buffer_diff_flags_t result = HB_BUFFER_DIFF_FLAG_EQUAL;
1895 bool contains = dottedcircle_glyph != (hb_codepoint_t) -1;
1897 unsigned int count = reference->len;
1899 if (buffer->len != count)
1902 * we can't compare glyph-by-glyph, but we do want to know if there
1903 * are .notdef or dottedcircle glyphs present in the reference buffer
1905 const hb_glyph_info_t *info = reference->info;
1907 for (i = 0; i < count; i++)
1909 if (contains && info[i].codepoint == dottedcircle_glyph)
1910 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1911 if (contains && info[i].codepoint == 0)
1912 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1914 result |= HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH;
1915 return hb_buffer_diff_flags_t (result);
1919 return hb_buffer_diff_flags_t (result);
1921 const hb_glyph_info_t *buf_info = buffer->info;
1922 const hb_glyph_info_t *ref_info = reference->info;
1923 for (unsigned int i = 0; i < count; i++)
1925 if (buf_info->codepoint != ref_info->codepoint)
1926 result |= HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH;
1927 if (buf_info->cluster != ref_info->cluster)
1928 result |= HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH;
1929 if ((buf_info->mask & ~ref_info->mask & HB_GLYPH_FLAG_DEFINED))
1930 result |= HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH;
1931 if (contains && ref_info->codepoint == dottedcircle_glyph)
1932 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1933 if (contains && ref_info->codepoint == 0)
1934 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1939 if (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)
1941 assert (buffer->have_positions);
1942 const hb_glyph_position_t *buf_pos = buffer->pos;
1943 const hb_glyph_position_t *ref_pos = reference->pos;
1944 for (unsigned int i = 0; i < count; i++)
1946 if ((unsigned int) abs (buf_pos->x_advance - ref_pos->x_advance) > position_fuzz ||
1947 (unsigned int) abs (buf_pos->y_advance - ref_pos->y_advance) > position_fuzz ||
1948 (unsigned int) abs (buf_pos->x_offset - ref_pos->x_offset) > position_fuzz ||
1949 (unsigned int) abs (buf_pos->y_offset - ref_pos->y_offset) > position_fuzz)
1951 result |= HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH;
1967 #ifndef HB_NO_BUFFER_MESSAGE
1969 * hb_buffer_set_message_func:
1970 * @buffer: an #hb_buffer_t.
1971 * @func: (closure user_data) (destroy destroy) (scope notified):
1980 hb_buffer_set_message_func (hb_buffer_t *buffer,
1981 hb_buffer_message_func_t func,
1982 void *user_data, hb_destroy_func_t destroy)
1984 if (buffer->message_destroy)
1985 buffer->message_destroy (buffer->message_data);
1988 buffer->message_func = func;
1989 buffer->message_data = user_data;
1990 buffer->message_destroy = destroy;
1992 buffer->message_func = nullptr;
1993 buffer->message_data = nullptr;
1994 buffer->message_destroy = nullptr;
1998 hb_buffer_t::message_impl (hb_font_t *font, const char *fmt, va_list ap)
2001 vsnprintf (buf, sizeof (buf), fmt, ap);
2002 return (bool) this->message_func (this, font, buf, this->message_data);