summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-buffer.cc')
-rw-r--r--src/3rdparty/harfbuzz-ng/src/hb-buffer.cc424
1 files changed, 196 insertions, 228 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc b/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc
index 6131c86177..8cad6ab8e6 100644
--- a/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc
+++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc
@@ -37,8 +37,9 @@
* @short_description: Input and output buffers
* @include: hb.h
*
- * Buffers serve dual role in HarfBuzz; they hold the input characters that are
- * passed to hb_shape(), and after shaping they hold the output glyphs.
+ * Buffers serve a dual role in HarfBuzz; before shaping, they hold
+ * the input characters that are passed to hb_shape(), and after
+ * shaping they hold the output glyphs.
**/
@@ -50,7 +51,7 @@
* Checks the equality of two #hb_segment_properties_t's.
*
* Return value:
- * %true if all properties of @a equal those of @b, false otherwise.
+ * %true if all properties of @a equal those of @b, %false otherwise.
*
* Since: 0.9.7
**/
@@ -217,9 +218,6 @@ hb_buffer_t::get_scratch_buffer (unsigned int *size)
void
hb_buffer_t::reset ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
-
hb_unicode_funcs_destroy (unicode);
unicode = hb_unicode_funcs_reference (hb_unicode_funcs_get_default ());
flags = HB_BUFFER_FLAG_DEFAULT;
@@ -232,9 +230,6 @@ hb_buffer_t::reset ()
void
hb_buffer_t::clear ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
-
hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT;
props = default_props;
scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
@@ -289,9 +284,6 @@ hb_buffer_t::add_info (const hb_glyph_info_t &glyph_info)
void
hb_buffer_t::remove_output ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
-
have_output = false;
have_positions = false;
@@ -302,9 +294,6 @@ hb_buffer_t::remove_output ()
void
hb_buffer_t::clear_output ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
-
have_output = true;
have_positions = false;
@@ -315,9 +304,6 @@ hb_buffer_t::clear_output ()
void
hb_buffer_t::clear_positions ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
-
have_output = false;
have_positions = true;
@@ -332,15 +318,19 @@ hb_buffer_t::swap_buffers ()
{
if (unlikely (!successful)) return;
+ assert (idx <= len);
+ if (unlikely (!next_glyphs (len - idx))) return;
+
assert (have_output);
have_output = false;
if (out_info != info)
{
- hb_glyph_info_t *tmp_string;
- tmp_string = info;
+ hb_glyph_info_t *tmp;
+ tmp = info;
info = out_info;
- out_info = tmp_string;
+ out_info = tmp;
+
pos = (hb_glyph_position_t *) out_info;
}
@@ -352,31 +342,6 @@ hb_buffer_t::swap_buffers ()
idx = 0;
}
-
-void
-hb_buffer_t::replace_glyphs (unsigned int num_in,
- unsigned int num_out,
- const uint32_t *glyph_data)
-{
- if (unlikely (!make_room_for (num_in, num_out))) return;
-
- assert (idx + num_in <= len);
-
- merge_clusters (idx, idx + num_in);
-
- hb_glyph_info_t orig_info = info[idx];
- hb_glyph_info_t *pinfo = &out_info[out_len];
- for (unsigned int i = 0; i < num_out; i++)
- {
- *pinfo = orig_info;
- pinfo->codepoint = glyph_data[i];
- pinfo++;
- }
-
- idx += num_in;
- out_len += num_out;
-}
-
bool
hb_buffer_t::move_to (unsigned int i)
{
@@ -438,13 +403,6 @@ hb_buffer_t::set_masks (hb_mask_t value,
if (!mask)
return;
- if (cluster_start == 0 && cluster_end == (unsigned int)-1) {
- unsigned int count = len;
- for (unsigned int i = 0; i < count; i++)
- info[i].mask = (info[i].mask & not_mask) | value;
- return;
- }
-
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end)
@@ -455,27 +413,13 @@ void
hb_buffer_t::reverse_range (unsigned int start,
unsigned int end)
{
- unsigned int i, j;
-
if (end - start < 2)
return;
- for (i = start, j = end - 1; i < j; i++, j--) {
- hb_glyph_info_t t;
-
- t = info[i];
- info[i] = info[j];
- info[j] = t;
- }
+ hb_array_t<hb_glyph_info_t> (info, len).reverse (start, end);
if (have_positions) {
- for (i = start, j = end - 1; i < j; i++, j--) {
- hb_glyph_position_t t;
-
- t = pos[i];
- pos[i] = pos[j];
- pos[j] = t;
- }
+ hb_array_t<hb_glyph_position_t> (pos, len).reverse (start, end);
}
}
@@ -612,7 +556,7 @@ done:
void
hb_buffer_t::unsafe_to_break_impl (unsigned int start, unsigned int end)
{
- unsigned int cluster = (unsigned int) -1;
+ unsigned int cluster = UINT_MAX;
cluster = _unsafe_to_break_find_min_cluster (info, start, end, cluster);
_unsafe_to_break_set_mask (info, start, end, cluster);
}
@@ -628,7 +572,7 @@ hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int en
assert (start <= out_len);
assert (idx <= end);
- unsigned int cluster = (unsigned int) -1;
+ unsigned int cluster = UINT_MAX;
cluster = _unsafe_to_break_find_min_cluster (out_info, start, out_len, cluster);
cluster = _unsafe_to_break_find_min_cluster (info, idx, end, cluster);
_unsafe_to_break_set_mask (out_info, start, out_len, cluster);
@@ -638,8 +582,7 @@ hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int en
void
hb_buffer_t::guess_segment_properties ()
{
- assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
- (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
+ assert_unicode ();
/* If script is set to INVALID, guess from buffer contents */
if (props.script == HB_SCRIPT_INVALID) {
@@ -727,21 +670,21 @@ hb_buffer_create ()
/**
* hb_buffer_get_empty:
*
+ * Fetches an empty #hb_buffer_t.
*
- *
- * Return value: (transfer full):
+ * Return value: (transfer full): The empty buffer
*
* Since: 0.9.2
**/
hb_buffer_t *
hb_buffer_get_empty ()
{
- return const_cast<hb_buffer_t *> (&Null(hb_buffer_t));
+ return const_cast<hb_buffer_t *> (&Null (hb_buffer_t));
}
/**
* hb_buffer_reference: (skip)
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Increases the reference count on @buffer by one. This prevents @buffer from
* being destroyed until a matching call to hb_buffer_destroy() is made.
@@ -759,7 +702,7 @@ hb_buffer_reference (hb_buffer_t *buffer)
/**
* hb_buffer_destroy: (skip)
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Deallocate the @buffer.
* Decreases the reference count on @buffer by one. If the result is zero, then
@@ -786,15 +729,15 @@ hb_buffer_destroy (hb_buffer_t *buffer)
/**
* hb_buffer_set_user_data: (skip)
- * @buffer: an #hb_buffer_t.
- * @key:
- * @data:
- * @destroy:
- * @replace:
+ * @buffer: An #hb_buffer_t
+ * @key: The user-data key
+ * @data: A pointer to the user data
+ * @destroy: (nullable): A callback to call when @data is not needed anymore
+ * @replace: Whether to replace an existing data with the same key
*
+ * Attaches a user-data key/data pair to the specified buffer.
*
- *
- * Return value:
+ * Return value: %true if success, %false otherwise
*
* Since: 0.9.2
**/
@@ -810,12 +753,13 @@ hb_buffer_set_user_data (hb_buffer_t *buffer,
/**
* hb_buffer_get_user_data: (skip)
- * @buffer: an #hb_buffer_t.
- * @key:
+ * @buffer: An #hb_buffer_t
+ * @key: The user-data key to query
*
+ * Fetches the user data associated with the specified key,
+ * attached to the specified buffer.
*
- *
- * Return value:
+ * Return value: (transfer none): A pointer to the user data
*
* Since: 0.9.2
**/
@@ -829,11 +773,11 @@ hb_buffer_get_user_data (hb_buffer_t *buffer,
/**
* hb_buffer_set_content_type:
- * @buffer: an #hb_buffer_t.
- * @content_type: the type of buffer contents to set
+ * @buffer: An #hb_buffer_t
+ * @content_type: The type of buffer contents to set
*
- * Sets the type of @buffer contents, buffers are either empty, contain
- * characters (before shaping) or glyphs (the result of shaping).
+ * Sets the type of @buffer contents. Buffers are either empty, contain
+ * characters (before shaping), or contain glyphs (the result of shaping).
*
* Since: 0.9.5
**/
@@ -846,12 +790,13 @@ hb_buffer_set_content_type (hb_buffer_t *buffer,
/**
* hb_buffer_get_content_type:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
- * see hb_buffer_set_content_type().
+ * Fetches the type of @buffer contents. Buffers are either empty, contain
+ * characters (before shaping), or contain glyphs (the result of shaping).
*
* Return value:
- * The type of @buffer contents.
+ * The type of @buffer contents
*
* Since: 0.9.5
**/
@@ -864,10 +809,11 @@ hb_buffer_get_content_type (hb_buffer_t *buffer)
/**
* hb_buffer_set_unicode_funcs:
- * @buffer: an #hb_buffer_t.
- * @unicode_funcs:
- *
+ * @buffer: An #hb_buffer_t
+ * @unicode_funcs: The Unicode-functions structure
*
+ * Sets the Unicode-functions structure of a buffer to
+ * @unicode_funcs.
*
* Since: 0.9.2
**/
@@ -888,11 +834,11 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
/**
* hb_buffer_get_unicode_funcs:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
+ * Fetches the Unicode-functions structure of a buffer.
*
- *
- * Return value:
+ * Return value: The Unicode-functions structure
*
* Since: 0.9.2
**/
@@ -904,7 +850,7 @@ hb_buffer_get_unicode_funcs (hb_buffer_t *buffer)
/**
* hb_buffer_set_direction:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
* @direction: the #hb_direction_t of the @buffer
*
* Set the text flow direction of the buffer. No shaping can happen without
@@ -930,7 +876,7 @@ hb_buffer_set_direction (hb_buffer_t *buffer,
/**
* hb_buffer_get_direction:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* See hb_buffer_set_direction()
*
@@ -947,8 +893,8 @@ hb_buffer_get_direction (hb_buffer_t *buffer)
/**
* hb_buffer_set_script:
- * @buffer: an #hb_buffer_t.
- * @script: an #hb_script_t to set.
+ * @buffer: An #hb_buffer_t
+ * @script: An #hb_script_t to set.
*
* Sets the script of @buffer to @script.
*
@@ -958,7 +904,7 @@ hb_buffer_get_direction (hb_buffer_t *buffer)
*
* You can pass one of the predefined #hb_script_t values, or use
* hb_script_from_string() or hb_script_from_iso15924_tag() to get the
- * corresponding script from an ISO 15924 script tag.
+ * corresponding script from an ISO 15924 script tag.
*
* Since: 0.9.2
**/
@@ -974,12 +920,12 @@ hb_buffer_set_script (hb_buffer_t *buffer,
/**
* hb_buffer_get_script:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
- * See hb_buffer_set_script().
+ * Fetches the script of @buffer.
*
* Return value:
- * The #hb_script_t of the @buffer.
+ * The #hb_script_t of the @buffer
*
* Since: 0.9.2
**/
@@ -991,8 +937,8 @@ hb_buffer_get_script (hb_buffer_t *buffer)
/**
* hb_buffer_set_language:
- * @buffer: an #hb_buffer_t.
- * @language: an hb_language_t to set.
+ * @buffer: An #hb_buffer_t
+ * @language: An hb_language_t to set
*
* Sets the language of @buffer to @language.
*
@@ -1001,7 +947,7 @@ hb_buffer_get_script (hb_buffer_t *buffer)
* are orthogonal to the scripts, and though they are related, they are
* different concepts and should not be confused with each other.
*
- * Use hb_language_from_string() to convert from BCP 47 language tags to
+ * Use hb_language_from_string() to convert from BCP 47 language tags to
* #hb_language_t.
*
* Since: 0.9.2
@@ -1018,7 +964,7 @@ hb_buffer_set_language (hb_buffer_t *buffer,
/**
* hb_buffer_get_language:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* See hb_buffer_set_language().
*
@@ -1035,8 +981,8 @@ hb_buffer_get_language (hb_buffer_t *buffer)
/**
* hb_buffer_set_segment_properties:
- * @buffer: an #hb_buffer_t.
- * @props: an #hb_segment_properties_t to use.
+ * @buffer: An #hb_buffer_t
+ * @props: An #hb_segment_properties_t to use
*
* Sets the segment properties of the buffer, a shortcut for calling
* hb_buffer_set_direction(), hb_buffer_set_script() and
@@ -1056,8 +1002,8 @@ hb_buffer_set_segment_properties (hb_buffer_t *buffer,
/**
* hb_buffer_get_segment_properties:
- * @buffer: an #hb_buffer_t.
- * @props: (out): the output #hb_segment_properties_t.
+ * @buffer: An #hb_buffer_t
+ * @props: (out): The output #hb_segment_properties_t
*
* Sets @props to the #hb_segment_properties_t of @buffer.
*
@@ -1073,8 +1019,8 @@ hb_buffer_get_segment_properties (hb_buffer_t *buffer,
/**
* hb_buffer_set_flags:
- * @buffer: an #hb_buffer_t.
- * @flags: the buffer flags to set.
+ * @buffer: An #hb_buffer_t
+ * @flags: The buffer flags to set
*
* Sets @buffer flags to @flags. See #hb_buffer_flags_t.
*
@@ -1092,12 +1038,12 @@ hb_buffer_set_flags (hb_buffer_t *buffer,
/**
* hb_buffer_get_flags:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
- * See hb_buffer_set_flags().
+ * Fetches the #hb_buffer_flags_t of @buffer.
*
* Return value:
- * The @buffer flags.
+ * The @buffer flags
*
* Since: 0.9.7
**/
@@ -1109,16 +1055,18 @@ hb_buffer_get_flags (hb_buffer_t *buffer)
/**
* hb_buffer_set_cluster_level:
- * @buffer: an #hb_buffer_t.
- * @cluster_level:
- *
+ * @buffer: An #hb_buffer_t
+ * @cluster_level: The cluster level to set on the buffer
*
+ * Sets the cluster level of a buffer. The #hb_buffer_cluster_level_t
+ * dictates one aspect of how HarfBuzz will treat non-base characters
+ * during shaping.
*
* Since: 0.9.42
**/
void
-hb_buffer_set_cluster_level (hb_buffer_t *buffer,
- hb_buffer_cluster_level_t cluster_level)
+hb_buffer_set_cluster_level (hb_buffer_t *buffer,
+ hb_buffer_cluster_level_t cluster_level)
{
if (unlikely (hb_object_is_immutable (buffer)))
return;
@@ -1128,11 +1076,13 @@ hb_buffer_set_cluster_level (hb_buffer_t *buffer,
/**
* hb_buffer_get_cluster_level:
- * @buffer: an #hb_buffer_t.
- *
+ * @buffer: An #hb_buffer_t
*
+ * Fetches the cluster level of a buffer. The #hb_buffer_cluster_level_t
+ * dictates one aspect of how HarfBuzz will treat non-base characters
+ * during shaping.
*
- * Return value:
+ * Return value: The cluster level of @buffer
*
* Since: 0.9.42
**/
@@ -1145,13 +1095,13 @@ hb_buffer_get_cluster_level (hb_buffer_t *buffer)
/**
* hb_buffer_set_replacement_codepoint:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
* @replacement: the replacement #hb_codepoint_t
*
* Sets the #hb_codepoint_t that replaces invalid entries for a given encoding
* when adding text to @buffer.
*
- * Default is %HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
+ * Default is #HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT.
*
* Since: 0.9.31
**/
@@ -1167,12 +1117,13 @@ hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
/**
* hb_buffer_get_replacement_codepoint:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
- * See hb_buffer_set_replacement_codepoint().
+ * Fetches the #hb_codepoint_t that replaces invalid entries for a given encoding
+ * when adding text to @buffer.
*
* Return value:
- * The @buffer replacement #hb_codepoint_t.
+ * The @buffer replacement #hb_codepoint_t
*
* Since: 0.9.31
**/
@@ -1185,7 +1136,7 @@ hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
/**
* hb_buffer_set_invisible_glyph:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
* @invisible: the invisible #hb_codepoint_t
*
* Sets the #hb_codepoint_t that replaces invisible characters in
@@ -1207,12 +1158,12 @@ hb_buffer_set_invisible_glyph (hb_buffer_t *buffer,
/**
* hb_buffer_get_invisible_glyph:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* See hb_buffer_set_invisible_glyph().
*
* Return value:
- * The @buffer invisible #hb_codepoint_t.
+ * The @buffer invisible #hb_codepoint_t
*
* Since: 2.0.0
**/
@@ -1225,7 +1176,7 @@ hb_buffer_get_invisible_glyph (hb_buffer_t *buffer)
/**
* hb_buffer_reset:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Resets the buffer to its initial status, as if it was just newly created
* with hb_buffer_create().
@@ -1235,12 +1186,15 @@ hb_buffer_get_invisible_glyph (hb_buffer_t *buffer)
void
hb_buffer_reset (hb_buffer_t *buffer)
{
+ if (unlikely (hb_object_is_immutable (buffer)))
+ return;
+
buffer->reset ();
}
/**
* hb_buffer_clear_contents:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Similar to hb_buffer_reset(), but does not clear the Unicode functions and
* the replacement code point.
@@ -1250,18 +1204,21 @@ hb_buffer_reset (hb_buffer_t *buffer)
void
hb_buffer_clear_contents (hb_buffer_t *buffer)
{
+ if (unlikely (hb_object_is_immutable (buffer)))
+ return;
+
buffer->clear ();
}
/**
* hb_buffer_pre_allocate:
- * @buffer: an #hb_buffer_t.
- * @size: number of items to pre allocate.
+ * @buffer: An #hb_buffer_t
+ * @size: Number of items to pre allocate.
*
* Pre allocates memory for @buffer to fit at least @size number of items.
*
* Return value:
- * %true if @buffer memory allocation succeeded, %false otherwise.
+ * %true if @buffer memory allocation succeeded, %false otherwise
*
* Since: 0.9.2
**/
@@ -1273,7 +1230,7 @@ hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
/**
* hb_buffer_allocation_successful:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Check if allocating memory for the buffer succeeded.
*
@@ -1290,9 +1247,9 @@ hb_buffer_allocation_successful (hb_buffer_t *buffer)
/**
* hb_buffer_add:
- * @buffer: an #hb_buffer_t.
- * @codepoint: a Unicode code point.
- * @cluster: the cluster value of @codepoint.
+ * @buffer: An #hb_buffer_t
+ * @codepoint: A Unicode code point.
+ * @cluster: The cluster value of @codepoint.
*
* Appends a character with the Unicode value of @codepoint to @buffer, and
* gives it the initial cluster value of @cluster. Clusters can be any thing
@@ -1316,8 +1273,8 @@ hb_buffer_add (hb_buffer_t *buffer,
/**
* hb_buffer_set_length:
- * @buffer: an #hb_buffer_t.
- * @length: the new length of @buffer.
+ * @buffer: An #hb_buffer_t
+ * @length: The new length of @buffer
*
* Similar to hb_buffer_pre_allocate(), but clears any new items added at the
* end.
@@ -1334,7 +1291,7 @@ hb_buffer_set_length (hb_buffer_t *buffer,
if (unlikely (hb_object_is_immutable (buffer)))
return length == 0;
- if (!buffer->ensure (length))
+ if (unlikely (!buffer->ensure (length)))
return false;
/* Wipe the new space */
@@ -1358,7 +1315,7 @@ hb_buffer_set_length (hb_buffer_t *buffer,
/**
* hb_buffer_get_length:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Returns the number of items in the buffer.
*
@@ -1376,8 +1333,8 @@ hb_buffer_get_length (hb_buffer_t *buffer)
/**
* hb_buffer_get_glyph_infos:
- * @buffer: an #hb_buffer_t.
- * @length: (out): output array length.
+ * @buffer: An #hb_buffer_t
+ * @length: (out): The output-array length.
*
* Returns @buffer glyph information array. Returned pointer
* is valid as long as @buffer contents are not modified.
@@ -1400,8 +1357,8 @@ hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
/**
* hb_buffer_get_glyph_positions:
- * @buffer: an #hb_buffer_t.
- * @length: (out): output length.
+ * @buffer: An #hb_buffer_t
+ * @length: (out): The output length
*
* Returns @buffer glyph position array. Returned pointer
* is valid as long as @buffer contents are not modified.
@@ -1426,13 +1383,32 @@ hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
}
/**
+ * hb_buffer_has_positions:
+ * @buffer: an #hb_buffer_t.
+ *
+ * Returns whether @buffer has glyph position data.
+ * A buffer gains position data when hb_buffer_get_glyph_positions() is called on it,
+ * and cleared of position data when hb_buffer_clear_contents() is called.
+ *
+ * Return value:
+ * %true if the @buffer has position array, %false otherwise.
+ *
+ * Since: 2.7.3
+ **/
+HB_EXTERN hb_bool_t
+hb_buffer_has_positions (hb_buffer_t *buffer)
+{
+ return buffer->have_positions;
+}
+
+/**
* hb_glyph_info_get_glyph_flags:
- * @info: a #hb_glyph_info_t.
+ * @info: a #hb_glyph_info_t
*
* Returns glyph flags encoded within a #hb_glyph_info_t.
*
* Return value:
- * The #hb_glyph_flags_t encoded within @info.
+ * The #hb_glyph_flags_t encoded within @info
*
* Since: 1.5.0
**/
@@ -1444,7 +1420,7 @@ hb_glyph_flags_t
/**
* hb_buffer_reverse:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Reverses buffer contents.
*
@@ -1458,11 +1434,11 @@ hb_buffer_reverse (hb_buffer_t *buffer)
/**
* hb_buffer_reverse_range:
- * @buffer: an #hb_buffer_t.
- * @start: start index.
- * @end: end index.
+ * @buffer: An #hb_buffer_t
+ * @start: start index
+ * @end: end index
*
- * Reverses buffer contents between start to end.
+ * Reverses buffer contents between @start and @end.
*
* Since: 0.9.41
**/
@@ -1475,7 +1451,7 @@ hb_buffer_reverse_range (hb_buffer_t *buffer,
/**
* hb_buffer_reverse_clusters:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Reverses buffer clusters. That is, the buffer contents are
* reversed, then each cluster (consecutive items having the
@@ -1491,24 +1467,24 @@ hb_buffer_reverse_clusters (hb_buffer_t *buffer)
/**
* hb_buffer_guess_segment_properties:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Sets unset buffer segment properties based on buffer Unicode
* contents. If buffer is not empty, it must have content type
- * %HB_BUFFER_CONTENT_TYPE_UNICODE.
+ * #HB_BUFFER_CONTENT_TYPE_UNICODE.
*
- * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it
+ * If buffer script is not set (ie. is #HB_SCRIPT_INVALID), it
* will be set to the Unicode script of the first character in
- * the buffer that has a script other than %HB_SCRIPT_COMMON,
- * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN.
+ * the buffer that has a script other than #HB_SCRIPT_COMMON,
+ * #HB_SCRIPT_INHERITED, and #HB_SCRIPT_UNKNOWN.
*
- * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID),
+ * Next, if buffer direction is not set (ie. is #HB_DIRECTION_INVALID),
* it will be set to the natural horizontal direction of the
* buffer script as returned by hb_script_get_horizontal_direction().
- * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID,
- * then %HB_DIRECTION_LTR is used.
+ * If hb_script_get_horizontal_direction() returns #HB_DIRECTION_INVALID,
+ * then #HB_DIRECTION_LTR is used.
*
- * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID),
+ * Finally, if buffer language is not set (ie. is #HB_LANGUAGE_INVALID),
* it will be set to the process's default language as returned by
* hb_language_get_default(). This may change in the future by
* taking buffer script into consideration when choosing a language.
@@ -1534,8 +1510,7 @@ hb_buffer_add_utf (hb_buffer_t *buffer,
typedef typename utf_t::codepoint_t T;
const hb_codepoint_t replacement = buffer->replacement;
- assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
- (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
+ buffer->assert_unicode ();
if (unlikely (hb_object_is_immutable (buffer)))
return;
@@ -1546,7 +1521,10 @@ hb_buffer_add_utf (hb_buffer_t *buffer,
if (item_length == -1)
item_length = text_length - item_offset;
- buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
+ if (unlikely (item_length < 0 ||
+ item_length > INT_MAX / 8 ||
+ !buffer->ensure (buffer->len + item_length * sizeof (T) / 4)))
+ return;
/* If buffer is empty and pre-context provided, install it.
* This check is written this way, to make sure people can
@@ -1594,12 +1572,12 @@ hb_buffer_add_utf (hb_buffer_t *buffer,
/**
* hb_buffer_add_utf8:
- * @buffer: an #hb_buffer_t.
- * @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
+ * @buffer: An #hb_buffer_t
+ * @text: (array length=text_length) (element-type uint8_t): An array of UTF-8
* characters to append.
- * @text_length: the length of the @text, or -1 if it is %NULL terminated.
- * @item_offset: the offset of the first character to add to the @buffer.
- * @item_length: the number of characters to add to the @buffer, or -1 for the
+ * @text_length: The length of the @text, or -1 if it is %NULL terminated.
+ * @item_offset: The offset of the first character to add to the @buffer.
+ * @item_length: The number of characters to add to the @buffer, or -1 for the
* end of @text (assuming it is %NULL terminated).
*
* See hb_buffer_add_codepoints().
@@ -1621,12 +1599,12 @@ hb_buffer_add_utf8 (hb_buffer_t *buffer,
/**
* hb_buffer_add_utf16:
- * @buffer: an #hb_buffer_t.
- * @text: (array length=text_length): an array of UTF-16 characters to append.
- * @text_length: the length of the @text, or -1 if it is %NULL terminated.
- * @item_offset: the offset of the first character to add to the @buffer.
- * @item_length: the number of characters to add to the @buffer, or -1 for the
- * end of @text (assuming it is %NULL terminated).
+ * @buffer: An #hb_buffer_t
+ * @text: (array length=text_length): An array of UTF-16 characters to append
+ * @text_length: The length of the @text, or -1 if it is %NULL terminated
+ * @item_offset: The offset of the first character to add to the @buffer
+ * @item_length: The number of characters to add to the @buffer, or -1 for the
+ * end of @text (assuming it is %NULL terminated)
*
* See hb_buffer_add_codepoints().
*
@@ -1647,12 +1625,12 @@ hb_buffer_add_utf16 (hb_buffer_t *buffer,
/**
* hb_buffer_add_utf32:
- * @buffer: an #hb_buffer_t.
- * @text: (array length=text_length): an array of UTF-32 characters to append.
- * @text_length: the length of the @text, or -1 if it is %NULL terminated.
- * @item_offset: the offset of the first character to add to the @buffer.
- * @item_length: the number of characters to add to the @buffer, or -1 for the
- * end of @text (assuming it is %NULL terminated).
+ * @buffer: An #hb_buffer_t
+ * @text: (array length=text_length): An array of UTF-32 characters to append
+ * @text_length: The length of the @text, or -1 if it is %NULL terminated
+ * @item_offset: The offset of the first character to add to the @buffer
+ * @item_length: The number of characters to add to the @buffer, or -1 for the
+ * end of @text (assuming it is %NULL terminated)
*
* See hb_buffer_add_codepoints().
*
@@ -1673,13 +1651,13 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer,
/**
* hb_buffer_add_latin1:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
* @text: (array length=text_length) (element-type uint8_t): an array of UTF-8
- * characters to append.
- * @text_length: the length of the @text, or -1 if it is %NULL terminated.
- * @item_offset: the offset of the first character to add to the @buffer.
+ * characters to append
+ * @text_length: the length of the @text, or -1 if it is %NULL terminated
+ * @item_offset: the offset of the first character to add to the @buffer
* @item_length: the number of characters to add to the @buffer, or -1 for the
- * end of @text (assuming it is %NULL terminated).
+ * end of @text (assuming it is %NULL terminated)
*
* Similar to hb_buffer_add_codepoints(), but allows only access to first 256
* Unicode code points that can fit in 8-bit strings.
@@ -1735,10 +1713,10 @@ hb_buffer_add_codepoints (hb_buffer_t *buffer,
/**
* hb_buffer_append:
- * @buffer: an #hb_buffer_t.
- * @source: source #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
+ * @source: source #hb_buffer_t
* @start: start index into source buffer to copy. Use 0 to copy from start of buffer.
- * @end: end index into source buffer to copy. Use (unsigned int) -1 to copy to end of buffer.
+ * @end: end index into source buffer to copy. Use @HB_FEATURE_GLOBAL_END to copy to end of buffer.
*
* Append (part of) contents of another buffer to this buffer.
*
@@ -1763,11 +1741,6 @@ hb_buffer_append (hb_buffer_t *buffer,
if (start == end)
return;
- if (!buffer->len)
- buffer->content_type = source->content_type;
- if (!buffer->have_positions && source->have_positions)
- buffer->clear_positions ();
-
if (buffer->len + (end - start) < buffer->len) /* Overflows. */
{
buffer->successful = false;
@@ -1779,6 +1752,11 @@ hb_buffer_append (hb_buffer_t *buffer,
if (unlikely (!buffer->successful))
return;
+ if (!orig_len)
+ buffer->content_type = source->content_type;
+ if (!buffer->have_positions && source->have_positions)
+ buffer->clear_positions ();
+
memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0]));
if (buffer->have_positions)
memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0]));
@@ -1842,7 +1820,7 @@ normalize_glyphs_cluster (hb_buffer_t *buffer,
/**
* hb_buffer_normalize_glyphs:
- * @buffer: an #hb_buffer_t.
+ * @buffer: An #hb_buffer_t
*
* Reorders a glyph buffer to have canonical in-cluster glyph order / position.
* The resulting clusters should behave identical to pre-reordering clusters.
@@ -1855,23 +1833,13 @@ void
hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
{
assert (buffer->have_positions);
- assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS ||
- (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
- bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
+ buffer->assert_glyphs ();
- unsigned int count = buffer->len;
- if (unlikely (!count)) return;
- hb_glyph_info_t *info = buffer->info;
+ bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
- unsigned int start = 0;
- unsigned int end;
- for (end = start + 1; end < count; end++)
- if (info[start].cluster != info[end].cluster) {
- normalize_glyphs_cluster (buffer, start, end, backward);
- start = end;
- }
- normalize_glyphs_cluster (buffer, start, end, backward);
+ foreach_cluster (buffer, start, end)
+ normalize_glyphs_cluster (buffer, start, end, backward);
}
void
@@ -1907,8 +1875,8 @@ hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_g
* @dottedcircle_glyph: glyph id of U+25CC DOTTED CIRCLE, or (hb_codepont_t) -1.
* @position_fuzz: allowed absolute difference in position values.
*
- * If dottedcircle_glyph is (hb_codepoint_t) -1 then %HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
- * and %HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
+ * If dottedcircle_glyph is (hb_codepoint_t) -1 then #HB_BUFFER_DIFF_FLAG_DOTTED_CIRCLE_PRESENT
+ * and #HB_BUFFER_DIFF_FLAG_NOTDEF_PRESENT are never returned. This should be used by most
* callers if just comparing two buffers is needed.
*
* Since: 1.5.0
@@ -1998,12 +1966,12 @@ hb_buffer_diff (hb_buffer_t *buffer,
#ifndef HB_NO_BUFFER_MESSAGE
/**
* hb_buffer_set_message_func:
- * @buffer: an #hb_buffer_t.
- * @func: (closure user_data) (destroy destroy) (scope notified):
- * @user_data:
- * @destroy:
- *
+ * @buffer: An #hb_buffer_t
+ * @func: (closure user_data) (destroy destroy) (scope notified): Callback function
+ * @user_data: (nullable): Data to pass to @func
+ * @destroy: (nullable): The function to call when @user_data is not needed anymore
*
+ * Sets the implementation function for #hb_buffer_message_func_t.
*
* Since: 1.1.3
**/