Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer {
Show 26 fields pub(crate) flags: BufferFlags, pub(crate) cluster_level: u32, pub(crate) invisible: Option<GlyphId>, pub(crate) not_found_variation_selector: Option<u32>, pub(crate) content_type: Option<ContentType>, pub(crate) direction: Direction, pub(crate) script: Option<Script>, pub(crate) language: Option<Language>, pub(crate) successful: bool, pub(crate) have_output: bool, pub(crate) have_separate_output: bool, pub(crate) have_positions: bool, pub(crate) idx: usize, pub(crate) len: usize, pub(crate) out_len: usize, pub(crate) info: Vec<GlyphInfo>, pub(crate) pos: Vec<GlyphPosition>, pub(crate) context: [[u32; 5]; 2], pub(crate) context_len: [usize; 2], pub(crate) digest: SetDigest, pub(crate) glyph_set: U32Set, pub(crate) allocated_var_bits: u8, pub(crate) serial: u8, pub(crate) scratch_flags: u32, pub(crate) max_len: usize, pub(crate) max_ops: i32,
}
Expand description

A buffer of text to be shaped, and of the glyphs that shaping produces.

This is the unified buffer type, matching HarfBuzz’s hb_buffer_t. It carries a ContentType describing which of the two states it is currently in.

Fields§

§flags: BufferFlags§cluster_level: u32§invisible: Option<GlyphId>§not_found_variation_selector: Option<u32>§content_type: Option<ContentType>§direction: Direction§script: Option<Script>§language: Option<Language>§successful: bool

Allocations successful.

§have_output: bool

Whether we have an output buffer going on.

§have_separate_output: bool§have_positions: bool

Whether we have positions

§idx: usize§len: usize§out_len: usize§info: Vec<GlyphInfo>§pos: Vec<GlyphPosition>§context: [[u32; 5]; 2]§context_len: [usize; 2]§digest: SetDigest§glyph_set: U32Set§allocated_var_bits: u8§serial: u8§scratch_flags: u32§max_len: usize

Maximum allowed len.

§max_ops: i32

Maximum allowed operations.

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Creates a new Buffer.

Source

pub fn clear(&mut self)

Clears the contents of the buffer, retaining its allocation.

This matches HarfBuzz’s hb_buffer_clear_contents.

Source

pub fn reset(&mut self)

Resets the buffer to its default state, clearing its contents along with the flags and cluster level.

Source

pub fn content_type(&self) -> Option<ContentType>

Returns the type of content currently held by the buffer, or None if the buffer is empty or has been cleared.

Source

pub fn set_content_type(&mut self, content_type: Option<ContentType>)

Sets the type of content held by the buffer.

This only relabels the buffer; it never clears it. Shaping sets this to ContentType::Glyphs on its own, so most callers never need it.

Setting it explicitly reinterprets the items already in the buffer, which is occasionally what you want: label a buffer of glyph ids as ContentType::Glyphs to serialize a run that was shaped elsewhere, or label a shaped buffer as ContentType::Unicode to force shape to run over it again.

Source

pub fn len(&self) -> usize

Returns the number of items in the buffer.

Before shaping this is the number of Unicode codepoints; after shaping it is the number of glyphs.

Source

pub fn is_empty(&self) -> bool

Checks that buffer contains no elements. Returns true if the buffer contains no items.

Source

pub fn set_length(&mut self, len: usize) -> bool

Sets the number of items in the buffer.

Growing the buffer fills the new items with zeros. Returns false if the allocation failed, in which case the buffer is left unchanged.

Source

pub fn reserve(&mut self, size: usize) -> bool

Ensures that the buffer can hold at least size items.

Source

pub fn allocation_successful(&self) -> bool

Returns true if every allocation made on this buffer has succeeded.

This goes false when filling the buffer runs out of memory, and when shaping needs more room, more operations or more nesting than the shaper allows.

Source

pub fn push(&mut self, codepoint: u32, cluster: u32)

Appends a codepoint to the buffer with the given cluster value.

This matches HarfBuzz’s hb_buffer_add.

Source

pub fn push_str(&mut self, text: &str)

Appends a string to the buffer.

Cluster values are set to the UTF-8 byte offset of each character.

Source

pub fn push_codepoints(&mut self, codepoints: &[u32])

Appends codepoints with cluster values starting at zero.

Cluster indices restart at zero on each call.

Source

pub fn push_glyph_infos(&mut self, infos: &[GlyphInfo]) -> bool

Appends glyph infos to the buffer.

Source

pub fn set_pre_context(&mut self, text: &str)

Sets the pre-context for this buffer.

Source

pub fn set_pre_context_codepoints(&mut self, codepoints: &[u32])

Sets the pre-context for this buffer from codepoints.

The input is expected to be the Unicode codepoints in reverse order. This matches HarfBuzz’s internal storage of pre-context, and serves as a low-overhead method to pass pre-context from HarfBuzz-HarfRust.

Source

pub fn pre_context_codepoints(&self) -> &[u32]

Returns the pre-context, in the reverse order Buffer::set_pre_context_codepoints takes it.

Source

pub fn set_post_context(&mut self, text: &str)

Sets the post-context for this buffer.

Source

pub fn set_post_context_codepoints(&mut self, codepoints: &[u32])

Sets the post-context for this buffer from codepoints.

Source

pub fn post_context_codepoints(&self) -> &[u32]

Returns the post-context.

Source

pub fn direction(&self) -> Direction

Returns the buffer’s text direction.

Source

pub fn set_direction(&mut self, direction: Direction)

Sets the buffer’s text direction.

Source

pub fn script(&self) -> Option<Script>

Returns the buffer’s ISO 15924 script, or None if it has none.

A buffer with no script is not one whose script is Zzzz: that is a script a caller can ask for, meaning known to be unknown.

Source

pub fn set_script(&mut self, script: Option<Script>)

Sets the buffer’s script from an ISO 15924 tag, or clears it.

Source

pub fn language(&self) -> Option<&Language>

Returns the buffer’s language, or None if it has none.

Source

pub fn set_language(&mut self, language: Option<Language>)

Sets the buffer’s language, or clears it.

Source

pub fn guess_segment_properties(&mut self)

Guesses the direction, script and language of the buffer contents.

Only properties that are still unset are filled in.

Source

pub fn flags(&self) -> BufferFlags

Returns the buffer’s flags.

Source

pub fn set_flags(&mut self, flags: BufferFlags)

Sets the buffer’s flags.

Source

pub fn cluster_level(&self) -> ClusterLevel

Returns the buffer’s cluster level.

Source

pub fn set_cluster_level(&mut self, cluster_level: ClusterLevel)

Sets the buffer’s cluster level.

Source

pub fn invisible_glyph(&self) -> Option<GlyphId>

Returns the glyph used to replace invisible characters, if set.

Source

pub fn set_invisible_glyph(&mut self, glyph: Option<GlyphId>)

Sets the glyph used to replace invisible characters.

Source

pub fn not_found_variation_selector_glyph(&self) -> Option<u32>

Returns the glyph used to replace not-found variation selectors, if set.

Source

pub fn set_not_found_variation_selector_glyph(&mut self, glyph: Option<u32>)

Sets the glyph used to replace not-found variation-selector characters.

A variation selector is not present if there is no glyph in the font for the combination with the previous character. If None then the selector is treated as a default ignorable character. If Some(glyph) then the selector is preserved but replaced with glyph with zero advance to allow callers to know about missing glyph combinations. E.g., fall back to another font.

glyph is taken as is and does not have to be present in the font; any u32 value, even above u16::MAX, is accepted.

Source

pub fn glyph_infos(&self) -> &[GlyphInfo]

Returns the buffer contents.

Before shaping, GlyphInfo::glyph_id holds the input Unicode codepoint rather than a glyph id.

Source

pub fn glyph_infos_mut(&mut self) -> &mut [GlyphInfo]

Returns the buffer contents mutably.

Source

pub fn glyph_positions(&self) -> &[GlyphPosition]

Returns the glyph positions.

Returns an empty slice if the buffer has not been shaped and has no positions allocated. Use glyph_positions_mut to allocate them on demand.

Source

pub fn glyph_positions_mut(&mut self) -> &mut [GlyphPosition]

Returns the glyph positions mutably, allocating and zeroing them if the buffer does not have positions yet.

Source

pub fn reverse(&mut self)

Reverses the buffer contents.

Source

pub fn reverse_range(&mut self, start: usize, end: usize)

Reverses the buffer contents between start and end.

Source

pub fn reverse_clusters(&mut self)

Reverses the buffer contents, keeping the items within each cluster in their original order.

Source

pub fn reset_clusters(&mut self)

Resets the cluster value of each item to its index.

Source

pub fn serialize( &self, font: Option<&ShaperFont<'_, '_>>, flags: SerializeFlags, ) -> String

Serializes the buffer contents into a string.

Source§

impl Buffer

Source

pub(crate) const MAX_LEN_FACTOR: usize = 256

Source

pub(crate) const MAX_LEN_MIN: usize = 65536

Source

pub(crate) const MAX_LEN_DEFAULT: usize = 0x3FFF_FFFF

Source

pub(crate) const MAX_OPS_FACTOR: i32 = 4096

Source

pub(crate) const MAX_OPS_MIN: i32 = 65536

Source

pub(crate) const MAX_OPS_DEFAULT: i32 = 0x1FFF_FFFF

Source

const SMALL_COPY: usize = 16

Below this many elements, copy inline instead of calling memmove: AAT state machines move a couple of glyphs at a time, and the call plus memmove’s size dispatch costs more cycles than the copy.

Source

pub(crate) fn allocate_var(&mut self, shape: buffer_var_shape)

Source

pub(crate) fn try_allocate_var(&mut self, shape: buffer_var_shape) -> bool

Source

pub(crate) fn deallocate_var(&mut self, shape: buffer_var_shape)

Source

pub(crate) fn assert_var(&self, shape: buffer_var_shape)

Source

pub(crate) fn info_slice_mut(&mut self) -> &mut [GlyphInfo]

Source

pub(crate) fn infos_and_positions_mut( &mut self, ) -> (&mut [GlyphInfo], &mut [GlyphPosition])

Returns the glyph infos and positions together, for walking both at once.

Source

pub(crate) fn out_info(&self) -> &[GlyphInfo]

Source

pub(crate) fn out_info_mut(&mut self) -> &mut [GlyphInfo]

Source

pub(crate) fn index_failed(&mut self)

Marks the buffer unsuccessful after an index fell outside it.

Buffer operations skip the out-of-range access but keep their bookkeeping, so shaping loops still advance and then stop on the failure as they do when an allocation fails.

Source

fn set_out_info(&mut self, i: usize, info: GlyphInfo)

Source

fn copy_infos_to_out(&mut self, src: usize, dst: usize, count: usize)

Block-copies info[src..src + count] to out_info[dst..dst + count]. The caller must have made room in the out buffer already. In the shared-array case the destination never starts past the source (dst <= src), which makes the ascending inline copy overlap-safe.

Source

fn try_copy_infos_to_out( &mut self, src: usize, dst: usize, count: usize, ) -> Option<()>

Source

fn copy_out_to_infos(&mut self, src: usize, dst: usize, count: usize)

Block-copies out_info[src..src + count] to info[dst..dst + count]. In the shared-array case the destination never starts before the source (dst >= src), so the inline copy must run descending to keep memmove semantics on overlap.

Source

fn try_copy_out_to_infos( &mut self, src: usize, dst: usize, count: usize, ) -> Option<()>

Source

pub(crate) fn cur(&self, i: usize) -> Option<&GlyphInfo>

Source

pub(crate) fn cur_mut(&mut self, i: usize) -> Option<&mut GlyphInfo>

Source

pub(crate) fn cur_pos_mut(&mut self) -> Option<&mut GlyphPosition>

Source

pub(crate) fn prev(&self) -> Option<&GlyphInfo>

Source

pub(crate) fn prev_mut(&mut self) -> Option<&mut GlyphInfo>

Source

pub(crate) fn update_digest(&mut self)

Source

pub(crate) fn update_glyph_set(&mut self)

Source

pub(crate) fn backtrack_len(&self) -> usize

Source

pub(crate) fn lookahead_len(&self) -> usize

Source

fn next_serial(&mut self) -> u8

Source

pub(crate) fn reverse_groups<F>(&mut self, group: F, merge_clusters: bool)
where F: Fn(&GlyphInfo, &GlyphInfo) -> bool,

Source

pub(crate) fn group_end<F>(&self, start: usize, group: F) -> usize
where F: Fn(&GlyphInfo, &GlyphInfo) -> bool,

Source

pub(crate) fn sync(&mut self) -> bool

Source

pub(crate) fn clear_output(&mut self)

Source

pub(crate) fn clear_positions(&mut self)

Source

pub(crate) fn replace_glyphs( &mut self, num_in: usize, num_out: usize, glyph_data: &[u32], )

Source

pub(crate) fn replace_glyph(&mut self, glyph_index: u32)

Source

pub(crate) fn output_glyph(&mut self, glyph_index: u32)

Source

pub(crate) fn output_info(&mut self, glyph_info: GlyphInfo)

Source

pub(crate) fn copy_glyph(&mut self)

Copies glyph at idx to output but doesn’t advance idx.

Source

fn copy_cur_to_out(&mut self, out: usize)

Copies the current glyph to out_info[out].

Source

fn set_out_glyph(&mut self, out: usize, glyph_index: u32)

Source

pub(crate) fn next_glyph(&mut self)

Copies glyph at idx to output and advance idx.

If there’s no output, just advance idx.

Source

pub(crate) fn next_glyphs(&mut self, n: usize)

Copies n glyphs at idx to output and advance idx.

If there’s no output, just advance idx.

Source

pub(crate) fn skip_glyph(&mut self)

Advance idx without copying to output.

Source

pub(crate) fn set_masks( &mut self, value: u32, mask: u32, cluster_start: u32, cluster_end: u32, )

Source

pub(crate) fn merge_clusters(&mut self, start: usize, end: usize)

Source

fn merge_clusters_impl(&mut self, start: usize, end: usize)

Source

fn try_merge_clusters(&mut self, start: usize, end: usize) -> Option<()>

Source

pub(crate) fn merge_grapheme_clusters(&mut self, start: usize, end: usize)

Source

pub(crate) fn merge_out_clusters(&mut self, start: usize, end: usize)

Source

pub(crate) fn merge_out_grapheme_clusters(&mut self, start: usize, end: usize)

Source

fn merge_out_clusters_impl(&mut self, start: usize, end: usize)

Source

fn try_merge_out_clusters(&mut self, start: usize, end: usize) -> Option<()>

Source

pub(crate) fn delete_glyph(&mut self)

Merge clusters for deleting current glyph, and skip it.

Source

fn merge_deleted_cluster(&mut self) -> Option<()>

Source

pub(crate) fn delete_glyphs_inplace( &mut self, filter: impl Fn(&GlyphInfo) -> bool, )

Source

pub(crate) fn unsafe_to_break( &mut self, start: Option<usize>, end: Option<usize>, )

Source

pub(crate) fn safe_to_insert_tatweel( &mut self, start: Option<usize>, end: Option<usize>, )

Source

fn _set_glyph_flags_impl( &mut self, mask: u32, start: usize, end: usize, interior: bool, from_out_buffer: bool, )

Source

fn set_glyph_flags( &mut self, flags: GlyphFlags, start: Option<usize>, end: Option<usize>, interior: Option<bool>, from_out_buffer: Option<bool>, )

Adds glyph flags in mask to infos with clusters between start and end. The start index will be from out-buffer if from_out_buffer is true. If interior is true, then the cluster having the minimum value is skipped. */

Source

pub(crate) fn unsafe_to_concat( &mut self, start: Option<usize>, end: Option<usize>, )

Source

pub(crate) fn unsafe_to_break_from_outbuffer( &mut self, start: Option<usize>, end: Option<usize>, )

Source

pub(crate) fn unsafe_to_concat_from_outbuffer( &mut self, start: Option<usize>, end: Option<usize>, )

Source

pub(crate) fn move_to(&mut self, i: usize) -> bool

Source

pub(crate) fn ensure(&mut self, size: usize) -> bool

Source

fn enlarge(&mut self, size: usize) -> bool

Source

fn make_room_for(&mut self, num_in: usize, num_out: usize) -> bool

Source

fn shift_forward(&mut self, count: usize) -> bool

Source

fn clear_context(&mut self, side: usize)

Source

pub(crate) fn sort( &mut self, start: usize, end: usize, cmp: impl Fn(&GlyphInfo, &GlyphInfo) -> bool, )

Source

pub(crate) fn set_cluster(info: &mut GlyphInfo, cluster: u32, mask: u32)

Source

pub(crate) fn enter(&mut self)

Source

pub(crate) fn leave(&mut self)

Source

fn _infos_find_min_cluster( &self, info: &[GlyphInfo], start: usize, end: usize, cluster: Option<u32>, ) -> u32

Source

fn _infos_set_glyph_flags( &mut self, out_info: bool, start: usize, end: usize, cluster: u32, mask: u32, )

Source

pub(crate) fn next_syllable(&self, start: usize) -> usize

Source

pub(crate) fn allocate_lig_id(&mut self) -> u8

Source

pub(crate) fn serialize_impl( &self, font: Option<&ShaperFont<'_, '_>>, flags: SerializeFlags, ) -> Result<String, Error>

Source§

impl Buffer

Source

pub(crate) fn allocate_unicode_vars(&mut self)

Source

pub(crate) fn deallocate_unicode_vars(&mut self)

Source

pub(crate) fn assert_unicode_vars(&mut self)

Source

pub(crate) fn allocate_gsubgpos_vars(&mut self)

Source

pub(crate) fn deallocate_gsubgpos_vars(&mut self)

Source

pub(crate) fn assert_gsubgpos_vars(&mut self)

Trait Implementations§

Source§

impl Debug for Buffer

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Buffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.