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 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 if (cluster_start == 0 && cluster_end == (unsigned int)-1) {
442 unsigned int count = len;
443 for (unsigned int i = 0; i < count; i++)
444 info[i].mask = (info[i].mask & not_mask) | value;
448 unsigned int count = len;
449 for (unsigned int i = 0; i < count; i++)
450 if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end)
451 info[i].mask = (info[i].mask & not_mask) | value;
455 hb_buffer_t::reverse_range (unsigned int start,
463 for (i = start, j = end - 1; i < j; i++, j--) {
471 if (have_positions) {
472 for (i = start, j = end - 1; i < j; i++, j--) {
473 hb_glyph_position_t t;
483 hb_buffer_t::reverse ()
488 reverse_range (0, len);
492 hb_buffer_t::reverse_clusters ()
494 unsigned int i, start, count, last_cluster;
503 last_cluster = info[0].cluster;
504 for (i = 1; i < count; i++) {
505 if (last_cluster != info[i].cluster) {
506 reverse_range (start, i);
508 last_cluster = info[i].cluster;
511 reverse_range (start, i);
515 hb_buffer_t::merge_clusters_impl (unsigned int start,
518 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
520 unsafe_to_break (start, end);
524 unsigned int cluster = info[start].cluster;
526 for (unsigned int i = start + 1; i < end; i++)
527 cluster = MIN<unsigned int> (cluster, info[i].cluster);
530 while (end < len && info[end - 1].cluster == info[end].cluster)
534 while (idx < start && info[start - 1].cluster == info[start].cluster)
537 /* If we hit the start of buffer, continue in out-buffer. */
539 for (unsigned int i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--)
540 set_cluster (out_info[i - 1], cluster);
542 for (unsigned int i = start; i < end; i++)
543 set_cluster (info[i], cluster);
546 hb_buffer_t::merge_out_clusters (unsigned int start,
549 if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)
552 if (unlikely (end - start < 2))
555 unsigned int cluster = out_info[start].cluster;
557 for (unsigned int i = start + 1; i < end; i++)
558 cluster = MIN<unsigned int> (cluster, out_info[i].cluster);
561 while (start && out_info[start - 1].cluster == out_info[start].cluster)
565 while (end < out_len && out_info[end - 1].cluster == out_info[end].cluster)
568 /* If we hit the end of out-buffer, continue in buffer. */
570 for (unsigned int i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++)
571 set_cluster (info[i], cluster);
573 for (unsigned int i = start; i < end; i++)
574 set_cluster (out_info[i], cluster);
577 hb_buffer_t::delete_glyph ()
579 /* The logic here is duplicated in hb_ot_hide_default_ignorables(). */
581 unsigned int cluster = info[idx].cluster;
582 if (idx + 1 < len && cluster == info[idx + 1].cluster)
584 /* Cluster survives; do nothing. */
590 /* Merge cluster backward. */
591 if (cluster < out_info[out_len - 1].cluster)
593 unsigned int mask = info[idx].mask;
594 unsigned int old_cluster = out_info[out_len - 1].cluster;
595 for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--)
596 set_cluster (out_info[i - 1], cluster, mask);
603 /* Merge cluster forward. */
604 merge_clusters (idx, idx + 2);
613 hb_buffer_t::unsafe_to_break_impl (unsigned int start, unsigned int end)
615 unsigned int cluster = (unsigned int) -1;
616 cluster = _unsafe_to_break_find_min_cluster (info, start, end, cluster);
617 _unsafe_to_break_set_mask (info, start, end, cluster);
620 hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int end)
624 unsafe_to_break_impl (start, end);
628 assert (start <= out_len);
631 unsigned int cluster = (unsigned int) -1;
632 cluster = _unsafe_to_break_find_min_cluster (out_info, start, out_len, cluster);
633 cluster = _unsafe_to_break_find_min_cluster (info, idx, end, cluster);
634 _unsafe_to_break_set_mask (out_info, start, out_len, cluster);
635 _unsafe_to_break_set_mask (info, idx, end, cluster);
639 hb_buffer_t::guess_segment_properties ()
641 assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
642 (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
644 /* If script is set to INVALID, guess from buffer contents */
645 if (props.script == HB_SCRIPT_INVALID) {
646 for (unsigned int i = 0; i < len; i++) {
647 hb_script_t script = unicode->script (info[i].codepoint);
648 if (likely (script != HB_SCRIPT_COMMON &&
649 script != HB_SCRIPT_INHERITED &&
650 script != HB_SCRIPT_UNKNOWN)) {
651 props.script = script;
657 /* If direction is set to INVALID, guess from script */
658 if (props.direction == HB_DIRECTION_INVALID) {
659 props.direction = hb_script_get_horizontal_direction (props.script);
660 if (props.direction == HB_DIRECTION_INVALID)
661 props.direction = HB_DIRECTION_LTR;
664 /* If language is not set, use default language from locale */
665 if (props.language == HB_LANGUAGE_INVALID) {
666 /* TODO get_default_for_script? using $LANGUAGE */
667 props.language = hb_language_get_default ();
674 DEFINE_NULL_INSTANCE (hb_buffer_t) =
676 HB_OBJECT_HEADER_STATIC,
678 const_cast<hb_unicode_funcs_t *> (&_hb_Null_hb_unicode_funcs_t),
679 HB_BUFFER_FLAG_DEFAULT,
680 HB_BUFFER_CLUSTER_LEVEL_DEFAULT,
681 HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
683 HB_BUFFER_SCRATCH_FLAG_DEFAULT,
684 HB_BUFFER_MAX_LEN_DEFAULT,
685 HB_BUFFER_MAX_OPS_DEFAULT,
687 HB_BUFFER_CONTENT_TYPE_INVALID,
688 HB_SEGMENT_PROPERTIES_DEFAULT,
689 false, /* successful */
690 true, /* have_output */
691 true /* have_positions */
693 /* Zero is good enough for everything else. */
698 * hb_buffer_create: (Xconstructor)
700 * Creates a new #hb_buffer_t with all properties to defaults.
702 * Return value: (transfer full):
703 * A newly allocated #hb_buffer_t with a reference count of 1. The initial
704 * reference count should be released with hb_buffer_destroy() when you are done
705 * using the #hb_buffer_t. This function never returns %NULL. If memory cannot
706 * be allocated, a special #hb_buffer_t object will be returned on which
707 * hb_buffer_allocation_successful() returns %false.
716 if (!(buffer = hb_object_create<hb_buffer_t> ()))
717 return hb_buffer_get_empty ();
719 buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
720 buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
728 * hb_buffer_get_empty:
732 * Return value: (transfer full):
737 hb_buffer_get_empty ()
739 return const_cast<hb_buffer_t *> (&Null(hb_buffer_t));
743 * hb_buffer_reference: (skip)
744 * @buffer: an #hb_buffer_t.
746 * Increases the reference count on @buffer by one. This prevents @buffer from
747 * being destroyed until a matching call to hb_buffer_destroy() is made.
749 * Return value: (transfer full):
750 * The referenced #hb_buffer_t.
755 hb_buffer_reference (hb_buffer_t *buffer)
757 return hb_object_reference (buffer);
761 * hb_buffer_destroy: (skip)
762 * @buffer: an #hb_buffer_t.
764 * Deallocate the @buffer.
765 * Decreases the reference count on @buffer by one. If the result is zero, then
766 * @buffer and all associated resources are freed. See hb_buffer_reference().
771 hb_buffer_destroy (hb_buffer_t *buffer)
773 if (!hb_object_destroy (buffer)) return;
775 hb_unicode_funcs_destroy (buffer->unicode);
779 if (buffer->message_destroy)
780 buffer->message_destroy (buffer->message_data);
786 * hb_buffer_set_user_data: (skip)
787 * @buffer: an #hb_buffer_t.
800 hb_buffer_set_user_data (hb_buffer_t *buffer,
801 hb_user_data_key_t *key,
803 hb_destroy_func_t destroy,
806 return hb_object_set_user_data (buffer, key, data, destroy, replace);
810 * hb_buffer_get_user_data: (skip)
811 * @buffer: an #hb_buffer_t.
821 hb_buffer_get_user_data (hb_buffer_t *buffer,
822 hb_user_data_key_t *key)
824 return hb_object_get_user_data (buffer, key);
829 * hb_buffer_set_content_type:
830 * @buffer: an #hb_buffer_t.
831 * @content_type: the type of buffer contents to set
833 * Sets the type of @buffer contents, buffers are either empty, contain
834 * characters (before shaping) or glyphs (the result of shaping).
839 hb_buffer_set_content_type (hb_buffer_t *buffer,
840 hb_buffer_content_type_t content_type)
842 buffer->content_type = content_type;
846 * hb_buffer_get_content_type:
847 * @buffer: an #hb_buffer_t.
849 * see hb_buffer_set_content_type().
852 * The type of @buffer contents.
856 hb_buffer_content_type_t
857 hb_buffer_get_content_type (hb_buffer_t *buffer)
859 return buffer->content_type;
864 * hb_buffer_set_unicode_funcs:
865 * @buffer: an #hb_buffer_t.
873 hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
874 hb_unicode_funcs_t *unicode_funcs)
876 if (unlikely (hb_object_is_immutable (buffer)))
880 unicode_funcs = hb_unicode_funcs_get_default ();
882 hb_unicode_funcs_reference (unicode_funcs);
883 hb_unicode_funcs_destroy (buffer->unicode);
884 buffer->unicode = unicode_funcs;
888 * hb_buffer_get_unicode_funcs:
889 * @buffer: an #hb_buffer_t.
898 hb_buffer_get_unicode_funcs (hb_buffer_t *buffer)
900 return buffer->unicode;
904 * hb_buffer_set_direction:
905 * @buffer: an #hb_buffer_t.
906 * @direction: the #hb_direction_t of the @buffer
908 * Set the text flow direction of the buffer. No shaping can happen without
909 * setting @buffer direction, and it controls the visual direction for the
910 * output glyphs; for RTL direction the glyphs will be reversed. Many layout
911 * features depend on the proper setting of the direction, for example,
912 * reversing RTL text before shaping, then shaping with LTR direction is not
913 * the same as keeping the text in logical order and shaping with RTL
919 hb_buffer_set_direction (hb_buffer_t *buffer,
920 hb_direction_t direction)
923 if (unlikely (hb_object_is_immutable (buffer)))
926 buffer->props.direction = direction;
930 * hb_buffer_get_direction:
931 * @buffer: an #hb_buffer_t.
933 * See hb_buffer_set_direction()
936 * The direction of the @buffer.
941 hb_buffer_get_direction (hb_buffer_t *buffer)
943 return buffer->props.direction;
947 * hb_buffer_set_script:
948 * @buffer: an #hb_buffer_t.
949 * @script: an #hb_script_t to set.
951 * Sets the script of @buffer to @script.
953 * Script is crucial for choosing the proper shaping behaviour for scripts that
954 * require it (e.g. Arabic) and the which OpenType features defined in the font
957 * You can pass one of the predefined #hb_script_t values, or use
958 * hb_script_from_string() or hb_script_from_iso15924_tag() to get the
959 * corresponding script from an ISO 15924 script tag.
964 hb_buffer_set_script (hb_buffer_t *buffer,
967 if (unlikely (hb_object_is_immutable (buffer)))
970 buffer->props.script = script;
974 * hb_buffer_get_script:
975 * @buffer: an #hb_buffer_t.
977 * See hb_buffer_set_script().
980 * The #hb_script_t of the @buffer.
985 hb_buffer_get_script (hb_buffer_t *buffer)
987 return buffer->props.script;
991 * hb_buffer_set_language:
992 * @buffer: an #hb_buffer_t.
993 * @language: an hb_language_t to set.
995 * Sets the language of @buffer to @language.
997 * Languages are crucial for selecting which OpenType feature to apply to the
998 * buffer which can result in applying language-specific behaviour. Languages
999 * are orthogonal to the scripts, and though they are related, they are
1000 * different concepts and should not be confused with each other.
1002 * Use hb_language_from_string() to convert from BCP 47 language tags to
1008 hb_buffer_set_language (hb_buffer_t *buffer,
1009 hb_language_t language)
1011 if (unlikely (hb_object_is_immutable (buffer)))
1014 buffer->props.language = language;
1018 * hb_buffer_get_language:
1019 * @buffer: an #hb_buffer_t.
1021 * See hb_buffer_set_language().
1023 * Return value: (transfer none):
1024 * The #hb_language_t of the buffer. Must not be freed by the caller.
1029 hb_buffer_get_language (hb_buffer_t *buffer)
1031 return buffer->props.language;
1035 * hb_buffer_set_segment_properties:
1036 * @buffer: an #hb_buffer_t.
1037 * @props: an #hb_segment_properties_t to use.
1039 * Sets the segment properties of the buffer, a shortcut for calling
1040 * hb_buffer_set_direction(), hb_buffer_set_script() and
1041 * hb_buffer_set_language() individually.
1046 hb_buffer_set_segment_properties (hb_buffer_t *buffer,
1047 const hb_segment_properties_t *props)
1049 if (unlikely (hb_object_is_immutable (buffer)))
1052 buffer->props = *props;
1056 * hb_buffer_get_segment_properties:
1057 * @buffer: an #hb_buffer_t.
1058 * @props: (out): the output #hb_segment_properties_t.
1060 * Sets @props to the #hb_segment_properties_t of @buffer.
1065 hb_buffer_get_segment_properties (hb_buffer_t *buffer,
1066 hb_segment_properties_t *props)
1068 *props = buffer->props;
1073 * hb_buffer_set_flags:
1074 * @buffer: an #hb_buffer_t.
1075 * @flags: the buffer flags to set.
1077 * Sets @buffer flags to @flags. See #hb_buffer_flags_t.
1082 hb_buffer_set_flags (hb_buffer_t *buffer,
1083 hb_buffer_flags_t flags)
1085 if (unlikely (hb_object_is_immutable (buffer)))
1088 buffer->flags = flags;
1092 * hb_buffer_get_flags:
1093 * @buffer: an #hb_buffer_t.
1095 * See hb_buffer_set_flags().
1098 * The @buffer flags.
1103 hb_buffer_get_flags (hb_buffer_t *buffer)
1105 return buffer->flags;
1109 * hb_buffer_set_cluster_level:
1110 * @buffer: an #hb_buffer_t.
1118 hb_buffer_set_cluster_level (hb_buffer_t *buffer,
1119 hb_buffer_cluster_level_t cluster_level)
1121 if (unlikely (hb_object_is_immutable (buffer)))
1124 buffer->cluster_level = cluster_level;
1128 * hb_buffer_get_cluster_level:
1129 * @buffer: an #hb_buffer_t.
1137 hb_buffer_cluster_level_t
1138 hb_buffer_get_cluster_level (hb_buffer_t *buffer)
1140 return buffer->cluster_level;
1145 * hb_buffer_set_replacement_codepoint:
1146 * @buffer: an #hb_buffer_t.
1147 * @replacement: the replacement #hb_codepoint_t
1149 * Sets the #hb_codepoint_t that replaces invalid entries for a given encoding
1150 * when adding text to @buffer.
1152 * Default is %HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
1157 hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
1158 hb_codepoint_t replacement)
1160 if (unlikely (hb_object_is_immutable (buffer)))
1163 buffer->replacement = replacement;
1167 * hb_buffer_get_replacement_codepoint:
1168 * @buffer: an #hb_buffer_t.
1170 * See hb_buffer_set_replacement_codepoint().
1173 * The @buffer replacement #hb_codepoint_t.
1178 hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
1180 return buffer->replacement;
1185 * hb_buffer_set_invisible_glyph:
1186 * @buffer: an #hb_buffer_t.
1187 * @invisible: the invisible #hb_codepoint_t
1189 * Sets the #hb_codepoint_t that replaces invisible characters in
1190 * the shaping result. If set to zero (default), the glyph for the
1191 * U+0020 SPACE character is used. Otherwise, this value is used
1197 hb_buffer_set_invisible_glyph (hb_buffer_t *buffer,
1198 hb_codepoint_t invisible)
1200 if (unlikely (hb_object_is_immutable (buffer)))
1203 buffer->invisible = invisible;
1207 * hb_buffer_get_invisible_glyph:
1208 * @buffer: an #hb_buffer_t.
1210 * See hb_buffer_set_invisible_glyph().
1213 * The @buffer invisible #hb_codepoint_t.
1218 hb_buffer_get_invisible_glyph (hb_buffer_t *buffer)
1220 return buffer->invisible;
1226 * @buffer: an #hb_buffer_t.
1228 * Resets the buffer to its initial status, as if it was just newly created
1229 * with hb_buffer_create().
1234 hb_buffer_reset (hb_buffer_t *buffer)
1240 * hb_buffer_clear_contents:
1241 * @buffer: an #hb_buffer_t.
1243 * Similar to hb_buffer_reset(), but does not clear the Unicode functions and
1244 * the replacement code point.
1249 hb_buffer_clear_contents (hb_buffer_t *buffer)
1255 * hb_buffer_pre_allocate:
1256 * @buffer: an #hb_buffer_t.
1257 * @size: number of items to pre allocate.
1259 * Pre allocates memory for @buffer to fit at least @size number of items.
1262 * %true if @buffer memory allocation succeeded, %false otherwise.
1267 hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
1269 return buffer->ensure (size);
1273 * hb_buffer_allocation_successful:
1274 * @buffer: an #hb_buffer_t.
1276 * Check if allocating memory for the buffer succeeded.
1279 * %true if @buffer memory allocation succeeded, %false otherwise.
1284 hb_buffer_allocation_successful (hb_buffer_t *buffer)
1286 return buffer->successful;
1291 * @buffer: an #hb_buffer_t.
1292 * @codepoint: a Unicode code point.
1293 * @cluster: the cluster value of @codepoint.
1295 * Appends a character with the Unicode value of @codepoint to @buffer, and
1296 * gives it the initial cluster value of @cluster. Clusters can be any thing
1297 * the client wants, they are usually used to refer to the index of the
1298 * character in the input text stream and are output in
1299 * #hb_glyph_info_t.cluster field.
1301 * This function does not check the validity of @codepoint, it is up to the
1302 * caller to ensure it is a valid Unicode code point.
1307 hb_buffer_add (hb_buffer_t *buffer,
1308 hb_codepoint_t codepoint,
1309 unsigned int cluster)
1311 buffer->add (codepoint, cluster);
1312 buffer->clear_context (1);
1316 * hb_buffer_set_length:
1317 * @buffer: an #hb_buffer_t.
1318 * @length: the new length of @buffer.
1320 * Similar to hb_buffer_pre_allocate(), but clears any new items added at the
1324 * %true if @buffer memory allocation succeeded, %false otherwise.
1329 hb_buffer_set_length (hb_buffer_t *buffer,
1330 unsigned int length)
1332 if (unlikely (hb_object_is_immutable (buffer)))
1335 if (!buffer->ensure (length))
1338 /* Wipe the new space */
1339 if (length > buffer->len) {
1340 memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len));
1341 if (buffer->have_positions)
1342 memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len));
1345 buffer->len = length;
1349 buffer->content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
1350 buffer->clear_context (0);
1352 buffer->clear_context (1);
1358 * hb_buffer_get_length:
1359 * @buffer: an #hb_buffer_t.
1361 * Returns the number of items in the buffer.
1364 * The @buffer length.
1365 * The value valid as long as buffer has not been modified.
1370 hb_buffer_get_length (hb_buffer_t *buffer)
1376 * hb_buffer_get_glyph_infos:
1377 * @buffer: an #hb_buffer_t.
1378 * @length: (out): output array length.
1380 * Returns @buffer glyph information array. Returned pointer
1381 * is valid as long as @buffer contents are not modified.
1383 * Return value: (transfer none) (array length=length):
1384 * The @buffer glyph information array.
1385 * The value valid as long as buffer has not been modified.
1390 hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
1391 unsigned int *length)
1394 *length = buffer->len;
1396 return (hb_glyph_info_t *) buffer->info;
1400 * hb_buffer_get_glyph_positions:
1401 * @buffer: an #hb_buffer_t.
1402 * @length: (out): output length.
1404 * Returns @buffer glyph position array. Returned pointer
1405 * is valid as long as @buffer contents are not modified.
1407 * Return value: (transfer none) (array length=length):
1408 * The @buffer glyph position array.
1409 * The value valid as long as buffer has not been modified.
1413 hb_glyph_position_t *
1414 hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
1415 unsigned int *length)
1417 if (!buffer->have_positions)
1418 buffer->clear_positions ();
1421 *length = buffer->len;
1423 return (hb_glyph_position_t *) buffer->pos;
1427 * hb_glyph_info_get_glyph_flags:
1428 * @info: a #hb_glyph_info_t.
1430 * Returns glyph flags encoded within a #hb_glyph_info_t.
1433 * The #hb_glyph_flags_t encoded within @info.
1438 (hb_glyph_info_get_glyph_flags) (const hb_glyph_info_t *info)
1440 return hb_glyph_info_get_glyph_flags (info);
1444 * hb_buffer_reverse:
1445 * @buffer: an #hb_buffer_t.
1447 * Reverses buffer contents.
1452 hb_buffer_reverse (hb_buffer_t *buffer)
1458 * hb_buffer_reverse_range:
1459 * @buffer: an #hb_buffer_t.
1460 * @start: start index.
1463 * Reverses buffer contents between start to end.
1468 hb_buffer_reverse_range (hb_buffer_t *buffer,
1469 unsigned int start, unsigned int end)
1471 buffer->reverse_range (start, end);
1475 * hb_buffer_reverse_clusters:
1476 * @buffer: an #hb_buffer_t.
1478 * Reverses buffer clusters. That is, the buffer contents are
1479 * reversed, then each cluster (consecutive items having the
1480 * same cluster number) are reversed again.
1485 hb_buffer_reverse_clusters (hb_buffer_t *buffer)
1487 buffer->reverse_clusters ();
1491 * hb_buffer_guess_segment_properties:
1492 * @buffer: an #hb_buffer_t.
1494 * Sets unset buffer segment properties based on buffer Unicode
1495 * contents. If buffer is not empty, it must have content type
1496 * %HB_BUFFER_CONTENT_TYPE_UNICODE.
1498 * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it
1499 * will be set to the Unicode script of the first character in
1500 * the buffer that has a script other than %HB_SCRIPT_COMMON,
1501 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN.
1503 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID),
1504 * it will be set to the natural horizontal direction of the
1505 * buffer script as returned by hb_script_get_horizontal_direction().
1506 * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID,
1507 * then %HB_DIRECTION_LTR is used.
1509 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID),
1510 * it will be set to the process's default language as returned by
1511 * hb_language_get_default(). This may change in the future by
1512 * taking buffer script into consideration when choosing a language.
1513 * Note that hb_language_get_default() is NOT threadsafe the first time
1514 * it is called. See documentation for that function for details.
1519 hb_buffer_guess_segment_properties (hb_buffer_t *buffer)
1521 buffer->guess_segment_properties ();
1524 template <typename utf_t>
1526 hb_buffer_add_utf (hb_buffer_t *buffer,
1527 const typename utf_t::codepoint_t *text,
1529 unsigned int item_offset,
1532 typedef typename utf_t::codepoint_t T;
1533 const hb_codepoint_t replacement = buffer->replacement;
1535 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
1536 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1538 if (unlikely (hb_object_is_immutable (buffer)))
1541 if (text_length == -1)
1542 text_length = utf_t::strlen (text);
1544 if (item_length == -1)
1545 item_length = text_length - item_offset;
1547 buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
1549 /* If buffer is empty and pre-context provided, install it.
1550 * This check is written this way, to make sure people can
1551 * provide pre-context in one add_utf() call, then provide
1552 * text in a follow-up call. See:
1554 * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13
1556 if (!buffer->len && item_offset > 0)
1558 /* Add pre-context */
1559 buffer->clear_context (0);
1560 const T *prev = text + item_offset;
1561 const T *start = text;
1562 while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH)
1565 prev = utf_t::prev (prev, start, &u, replacement);
1566 buffer->context[0][buffer->context_len[0]++] = u;
1570 const T *next = text + item_offset;
1571 const T *end = next + item_length;
1575 const T *old_next = next;
1576 next = utf_t::next (next, end, &u, replacement);
1577 buffer->add (u, old_next - (const T *) text);
1580 /* Add post-context */
1581 buffer->clear_context (1);
1582 end = text + text_length;
1583 while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH)
1586 next = utf_t::next (next, end, &u, replacement);
1587 buffer->context[1][buffer->context_len[1]++] = u;
1590 buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
1594 * hb_buffer_add_utf8:
1595 * @buffer: an #hb_buffer_t.
1596 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1597 * characters to append.
1598 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1599 * @item_offset: the offset of the first character to add to the @buffer.
1600 * @item_length: the number of characters to add to the @buffer, or -1 for the
1601 * end of @text (assuming it is %NULL terminated).
1603 * See hb_buffer_add_codepoints().
1605 * Replaces invalid UTF-8 characters with the @buffer replacement code point,
1606 * see hb_buffer_set_replacement_codepoint().
1611 hb_buffer_add_utf8 (hb_buffer_t *buffer,
1614 unsigned int item_offset,
1617 hb_buffer_add_utf<hb_utf8_t> (buffer, (const uint8_t *) text, text_length, item_offset, item_length);
1621 * hb_buffer_add_utf16:
1622 * @buffer: an #hb_buffer_t.
1623 * @text: (array length=text_length): an array of UTF-16 characters to append.
1624 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1625 * @item_offset: the offset of the first character to add to the @buffer.
1626 * @item_length: the number of characters to add to the @buffer, or -1 for the
1627 * end of @text (assuming it is %NULL terminated).
1629 * See hb_buffer_add_codepoints().
1631 * Replaces invalid UTF-16 characters with the @buffer replacement code point,
1632 * see hb_buffer_set_replacement_codepoint().
1637 hb_buffer_add_utf16 (hb_buffer_t *buffer,
1638 const uint16_t *text,
1640 unsigned int item_offset,
1643 hb_buffer_add_utf<hb_utf16_t> (buffer, text, text_length, item_offset, item_length);
1647 * hb_buffer_add_utf32:
1648 * @buffer: an #hb_buffer_t.
1649 * @text: (array length=text_length): an array of UTF-32 characters to append.
1650 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1651 * @item_offset: the offset of the first character to add to the @buffer.
1652 * @item_length: the number of characters to add to the @buffer, or -1 for the
1653 * end of @text (assuming it is %NULL terminated).
1655 * See hb_buffer_add_codepoints().
1657 * Replaces invalid UTF-32 characters with the @buffer replacement code point,
1658 * see hb_buffer_set_replacement_codepoint().
1663 hb_buffer_add_utf32 (hb_buffer_t *buffer,
1664 const uint32_t *text,
1666 unsigned int item_offset,
1669 hb_buffer_add_utf<hb_utf32_t> (buffer, text, text_length, item_offset, item_length);
1673 * hb_buffer_add_latin1:
1674 * @buffer: an #hb_buffer_t.
1675 * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
1676 * characters to append.
1677 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1678 * @item_offset: the offset of the first character to add to the @buffer.
1679 * @item_length: the number of characters to add to the @buffer, or -1 for the
1680 * end of @text (assuming it is %NULL terminated).
1682 * Similar to hb_buffer_add_codepoints(), but allows only access to first 256
1683 * Unicode code points that can fit in 8-bit strings.
1685 * <note>Has nothing to do with non-Unicode Latin-1 encoding.</note>
1690 hb_buffer_add_latin1 (hb_buffer_t *buffer,
1691 const uint8_t *text,
1693 unsigned int item_offset,
1696 hb_buffer_add_utf<hb_latin1_t> (buffer, text, text_length, item_offset, item_length);
1700 * hb_buffer_add_codepoints:
1701 * @buffer: a #hb_buffer_t to append characters to.
1702 * @text: (array length=text_length): an array of Unicode code points to append.
1703 * @text_length: the length of the @text, or -1 if it is %NULL terminated.
1704 * @item_offset: the offset of the first code point to add to the @buffer.
1705 * @item_length: the number of code points to add to the @buffer, or -1 for the
1706 * end of @text (assuming it is %NULL terminated).
1708 * Appends characters from @text array to @buffer. The @item_offset is the
1709 * position of the first character from @text that will be appended, and
1710 * @item_length is the number of character. When shaping part of a larger text
1711 * (e.g. a run of text from a paragraph), instead of passing just the substring
1712 * corresponding to the run, it is preferable to pass the whole
1713 * paragraph and specify the run start and length as @item_offset and
1714 * @item_length, respectively, to give HarfBuzz the full context to be able,
1715 * for example, to do cross-run Arabic shaping or properly handle combining
1716 * marks at stat of run.
1718 * This function does not check the validity of @text, it is up to the caller
1719 * to ensure it contains a valid Unicode code points.
1724 hb_buffer_add_codepoints (hb_buffer_t *buffer,
1725 const hb_codepoint_t *text,
1727 unsigned int item_offset,
1730 hb_buffer_add_utf<hb_utf32_novalidate_t> (buffer, text, text_length, item_offset, item_length);
1736 * @buffer: an #hb_buffer_t.
1737 * @source: source #hb_buffer_t.
1738 * @start: start index into source buffer to copy. Use 0 to copy from start of buffer.
1739 * @end: end index into source buffer to copy. Use (unsigned int) -1 to copy to end of buffer.
1741 * Append (part of) contents of another buffer to this buffer.
1746 hb_buffer_append (hb_buffer_t *buffer,
1747 hb_buffer_t *source,
1751 assert (!buffer->have_output && !source->have_output);
1752 assert (buffer->have_positions == source->have_positions ||
1753 !buffer->len || !source->len);
1754 assert (buffer->content_type == source->content_type ||
1755 !buffer->len || !source->len);
1757 if (end > source->len)
1765 buffer->content_type = source->content_type;
1766 if (!buffer->have_positions && source->have_positions)
1767 buffer->clear_positions ();
1769 if (buffer->len + (end - start) < buffer->len) /* Overflows. */
1771 buffer->successful = false;
1775 unsigned int orig_len = buffer->len;
1776 hb_buffer_set_length (buffer, buffer->len + (end - start));
1777 if (unlikely (!buffer->successful))
1780 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0]));
1781 if (buffer->have_positions)
1782 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0]));
1787 compare_info_codepoint (const hb_glyph_info_t *pa,
1788 const hb_glyph_info_t *pb)
1790 return (int) pb->codepoint - (int) pa->codepoint;
1794 normalize_glyphs_cluster (hb_buffer_t *buffer,
1799 hb_glyph_position_t *pos = buffer->pos;
1801 /* Total cluster advance */
1802 hb_position_t total_x_advance = 0, total_y_advance = 0;
1803 for (unsigned int i = start; i < end; i++)
1805 total_x_advance += pos[i].x_advance;
1806 total_y_advance += pos[i].y_advance;
1809 hb_position_t x_advance = 0, y_advance = 0;
1810 for (unsigned int i = start; i < end; i++)
1812 pos[i].x_offset += x_advance;
1813 pos[i].y_offset += y_advance;
1815 x_advance += pos[i].x_advance;
1816 y_advance += pos[i].y_advance;
1818 pos[i].x_advance = 0;
1819 pos[i].y_advance = 0;
1824 /* Transfer all cluster advance to the last glyph. */
1825 pos[end - 1].x_advance = total_x_advance;
1826 pos[end - 1].y_advance = total_y_advance;
1828 hb_stable_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start);
1830 /* Transfer all cluster advance to the first glyph. */
1831 pos[start].x_advance += total_x_advance;
1832 pos[start].y_advance += total_y_advance;
1833 for (unsigned int i = start + 1; i < end; i++) {
1834 pos[i].x_offset -= total_x_advance;
1835 pos[i].y_offset -= total_y_advance;
1837 hb_stable_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1);
1842 * hb_buffer_normalize_glyphs:
1843 * @buffer: an #hb_buffer_t.
1845 * Reorders a glyph buffer to have canonical in-cluster glyph order / position.
1846 * The resulting clusters should behave identical to pre-reordering clusters.
1848 * <note>This has nothing to do with Unicode normalization.</note>
1853 hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
1855 assert (buffer->have_positions);
1856 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS ||
1857 (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
1859 bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
1861 unsigned int count = buffer->len;
1862 if (unlikely (!count)) return;
1863 hb_glyph_info_t *info = buffer->info;
1865 unsigned int start = 0;
1867 for (end = start + 1; end < count; end++)
1868 if (info[start].cluster != info[end].cluster) {
1869 normalize_glyphs_cluster (buffer, start, end, backward);
1872 normalize_glyphs_cluster (buffer, start, end, backward);
1876 hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *))
1878 assert (!have_positions);
1879 for (unsigned int i = start + 1; i < end; i++)
1882 while (j > start && compar (&info[j - 1], &info[i]) > 0)
1886 /* Move item i to occupy place for item j, shift what's in between. */
1887 merge_clusters (j, i + 1);
1889 hb_glyph_info_t t = info[i];
1890 memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t));
1898 * Comparing buffers.
1903 * @buffer: a buffer.
1904 * @reference: other buffer to compare to.
1905 * @dottedcircle_glyph: glyph id of U+25CC DOTTED CIRCLE, or (hb_codepont_t) -1.
1906 * @position_fuzz: allowed absolute difference in position values.
1908 * If dottedcircle_glyph is (hb_codepoint_t) -1 then %HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
1909 * and %HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
1910 * callers if just comparing two buffers is needed.
1914 hb_buffer_diff_flags_t
1915 hb_buffer_diff (hb_buffer_t *buffer,
1916 hb_buffer_t *reference,
1917 hb_codepoint_t dottedcircle_glyph,
1918 unsigned int position_fuzz)
1920 if (buffer->content_type != reference->content_type && buffer->len && reference->len)
1921 return HB_BUFFER_DIFF_FLAG_CONTENT_TYPE_MISMATCH;
1923 hb_buffer_diff_flags_t result = HB_BUFFER_DIFF_FLAG_EQUAL;
1924 bool contains = dottedcircle_glyph != (hb_codepoint_t) -1;
1926 unsigned int count = reference->len;
1928 if (buffer->len != count)
1931 * we can't compare glyph-by-glyph, but we do want to know if there
1932 * are .notdef or dottedcircle glyphs present in the reference buffer
1934 const hb_glyph_info_t *info = reference->info;
1936 for (i = 0; i < count; i++)
1938 if (contains && info[i].codepoint == dottedcircle_glyph)
1939 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1940 if (contains && info[i].codepoint == 0)
1941 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1943 result |= HB_BUFFER_DIFF_FLAG_LENGTH_MISMATCH;
1944 return hb_buffer_diff_flags_t (result);
1948 return hb_buffer_diff_flags_t (result);
1950 const hb_glyph_info_t *buf_info = buffer->info;
1951 const hb_glyph_info_t *ref_info = reference->info;
1952 for (unsigned int i = 0; i < count; i++)
1954 if (buf_info->codepoint != ref_info->codepoint)
1955 result |= HB_BUFFER_DIFF_FLAG_CODEPOINT_MISMATCH;
1956 if (buf_info->cluster != ref_info->cluster)
1957 result |= HB_BUFFER_DIFF_FLAG_CLUSTER_MISMATCH;
1958 if ((buf_info->mask & ~ref_info->mask & HB_GLYPH_FLAG_DEFINED))
1959 result |= HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH;
1960 if (contains && ref_info->codepoint == dottedcircle_glyph)
1961 result |= HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT;
1962 if (contains && ref_info->codepoint == 0)
1963 result |= HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT;
1968 if (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)
1970 assert (buffer->have_positions);
1971 const hb_glyph_position_t *buf_pos = buffer->pos;
1972 const hb_glyph_position_t *ref_pos = reference->pos;
1973 for (unsigned int i = 0; i < count; i++)
1975 if ((unsigned int) abs (buf_pos->x_advance - ref_pos->x_advance) > position_fuzz ||
1976 (unsigned int) abs (buf_pos->y_advance - ref_pos->y_advance) > position_fuzz ||
1977 (unsigned int) abs (buf_pos->x_offset - ref_pos->x_offset) > position_fuzz ||
1978 (unsigned int) abs (buf_pos->y_offset - ref_pos->y_offset) > position_fuzz)
1980 result |= HB_BUFFER_DIFF_FLAG_POSITION_MISMATCH;
1997 * hb_buffer_set_message_func:
1998 * @buffer: an #hb_buffer_t.
1999 * @func: (closure user_data) (destroy destroy) (scope notified):
2008 hb_buffer_set_message_func (hb_buffer_t *buffer,
2009 hb_buffer_message_func_t func,
2010 void *user_data, hb_destroy_func_t destroy)
2012 if (buffer->message_destroy)
2013 buffer->message_destroy (buffer->message_data);
2016 buffer->message_func = func;
2017 buffer->message_data = user_data;
2018 buffer->message_destroy = destroy;
2020 buffer->message_func = nullptr;
2021 buffer->message_data = nullptr;
2022 buffer->message_destroy = nullptr;
2027 hb_buffer_t::message_impl (hb_font_t *font, const char *fmt, va_list ap)
2030 vsnprintf (buf, sizeof (buf), fmt, ap);
2031 return (bool) this->message_func (this, font, buf, this->message_data);