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: boolAllocations successful.
have_output: boolWhether we have an output buffer going on.
have_separate_output: bool§have_positions: boolWhether 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: usizeMaximum allowed len.
max_ops: i32Maximum allowed operations.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the contents of the buffer, retaining its allocation.
This matches HarfBuzz’s hb_buffer_clear_contents.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the buffer to its default state, clearing its contents along with the flags and cluster level.
Sourcepub fn content_type(&self) -> Option<ContentType>
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.
Sourcepub fn set_content_type(&mut self, content_type: Option<ContentType>)
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks that buffer contains no elements.
Returns true if the buffer contains no items.
Sourcepub fn set_length(&mut self, len: usize) -> bool
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.
Sourcepub fn reserve(&mut self, size: usize) -> bool
pub fn reserve(&mut self, size: usize) -> bool
Ensures that the buffer can hold at least size items.
Sourcepub fn allocation_successful(&self) -> bool
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.
Sourcepub fn push(&mut self, codepoint: u32, cluster: u32)
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.
Sourcepub fn push_str(&mut self, text: &str)
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.
Sourcepub fn push_codepoints(&mut self, codepoints: &[u32])
pub fn push_codepoints(&mut self, codepoints: &[u32])
Appends codepoints with cluster values starting at zero.
Cluster indices restart at zero on each call.
Sourcepub fn push_glyph_infos(&mut self, infos: &[GlyphInfo]) -> bool
pub fn push_glyph_infos(&mut self, infos: &[GlyphInfo]) -> bool
Appends glyph infos to the buffer.
Sourcepub fn set_pre_context(&mut self, text: &str)
pub fn set_pre_context(&mut self, text: &str)
Sets the pre-context for this buffer.
Sourcepub fn set_pre_context_codepoints(&mut self, codepoints: &[u32])
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.
Sourcepub fn pre_context_codepoints(&self) -> &[u32]
pub fn pre_context_codepoints(&self) -> &[u32]
Returns the pre-context, in the reverse order
Buffer::set_pre_context_codepoints takes it.
Sourcepub fn set_post_context(&mut self, text: &str)
pub fn set_post_context(&mut self, text: &str)
Sets the post-context for this buffer.
Sourcepub fn set_post_context_codepoints(&mut self, codepoints: &[u32])
pub fn set_post_context_codepoints(&mut self, codepoints: &[u32])
Sets the post-context for this buffer from codepoints.
Sourcepub fn post_context_codepoints(&self) -> &[u32]
pub fn post_context_codepoints(&self) -> &[u32]
Returns the post-context.
Sourcepub fn set_direction(&mut self, direction: Direction)
pub fn set_direction(&mut self, direction: Direction)
Sets the buffer’s text direction.
Sourcepub fn script(&self) -> Option<Script>
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.
Sourcepub fn set_script(&mut self, script: Option<Script>)
pub fn set_script(&mut self, script: Option<Script>)
Sets the buffer’s script from an ISO 15924 tag, or clears it.
Sourcepub fn language(&self) -> Option<&Language>
pub fn language(&self) -> Option<&Language>
Returns the buffer’s language, or None if it has none.
Sourcepub fn set_language(&mut self, language: Option<Language>)
pub fn set_language(&mut self, language: Option<Language>)
Sets the buffer’s language, or clears it.
Sourcepub fn guess_segment_properties(&mut self)
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.
Sourcepub fn flags(&self) -> BufferFlags
pub fn flags(&self) -> BufferFlags
Returns the buffer’s flags.
Sourcepub fn set_flags(&mut self, flags: BufferFlags)
pub fn set_flags(&mut self, flags: BufferFlags)
Sets the buffer’s flags.
Sourcepub fn cluster_level(&self) -> ClusterLevel
pub fn cluster_level(&self) -> ClusterLevel
Returns the buffer’s cluster level.
Sourcepub fn set_cluster_level(&mut self, cluster_level: ClusterLevel)
pub fn set_cluster_level(&mut self, cluster_level: ClusterLevel)
Sets the buffer’s cluster level.
Sourcepub fn invisible_glyph(&self) -> Option<GlyphId>
pub fn invisible_glyph(&self) -> Option<GlyphId>
Returns the glyph used to replace invisible characters, if set.
Sourcepub fn set_invisible_glyph(&mut self, glyph: Option<GlyphId>)
pub fn set_invisible_glyph(&mut self, glyph: Option<GlyphId>)
Sets the glyph used to replace invisible characters.
Sourcepub fn not_found_variation_selector_glyph(&self) -> Option<u32>
pub fn not_found_variation_selector_glyph(&self) -> Option<u32>
Returns the glyph used to replace not-found variation selectors, if set.
Sourcepub fn set_not_found_variation_selector_glyph(&mut self, glyph: Option<u32>)
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.
Sourcepub fn glyph_infos(&self) -> &[GlyphInfo]
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.
Sourcepub fn glyph_infos_mut(&mut self) -> &mut [GlyphInfo]
pub fn glyph_infos_mut(&mut self) -> &mut [GlyphInfo]
Returns the buffer contents mutably.
Sourcepub fn glyph_positions(&self) -> &[GlyphPosition]
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.
Sourcepub fn glyph_positions_mut(&mut self) -> &mut [GlyphPosition]
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.
Sourcepub fn reverse_range(&mut self, start: usize, end: usize)
pub fn reverse_range(&mut self, start: usize, end: usize)
Reverses the buffer contents between start and end.
Sourcepub fn reverse_clusters(&mut self)
pub fn reverse_clusters(&mut self)
Reverses the buffer contents, keeping the items within each cluster in their original order.
Sourcepub fn reset_clusters(&mut self)
pub fn reset_clusters(&mut self)
Resets the cluster value of each item to its index.
Sourcepub fn serialize(
&self,
font: Option<&ShaperFont<'_, '_>>,
flags: SerializeFlags,
) -> String
pub fn serialize( &self, font: Option<&ShaperFont<'_, '_>>, flags: SerializeFlags, ) -> String
Serializes the buffer contents into a string.
Source§impl Buffer
impl Buffer
pub(crate) const MAX_LEN_FACTOR: usize = 256
pub(crate) const MAX_LEN_MIN: usize = 65536
pub(crate) const MAX_LEN_DEFAULT: usize = 0x3FFF_FFFF
pub(crate) const MAX_OPS_FACTOR: i32 = 4096
pub(crate) const MAX_OPS_MIN: i32 = 65536
pub(crate) const MAX_OPS_DEFAULT: i32 = 0x1FFF_FFFF
Sourceconst SMALL_COPY: usize = 16
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.
pub(crate) fn allocate_var(&mut self, shape: buffer_var_shape)
pub(crate) fn try_allocate_var(&mut self, shape: buffer_var_shape) -> bool
pub(crate) fn deallocate_var(&mut self, shape: buffer_var_shape)
pub(crate) fn assert_var(&self, shape: buffer_var_shape)
pub(crate) fn info_slice_mut(&mut self) -> &mut [GlyphInfo]
Sourcepub(crate) fn infos_and_positions_mut(
&mut self,
) -> (&mut [GlyphInfo], &mut [GlyphPosition])
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.
pub(crate) fn out_info(&self) -> &[GlyphInfo]
pub(crate) fn out_info_mut(&mut self) -> &mut [GlyphInfo]
Sourcepub(crate) fn index_failed(&mut self)
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.
fn set_out_info(&mut self, i: usize, info: GlyphInfo)
Sourcefn copy_infos_to_out(&mut self, src: usize, dst: usize, count: usize)
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.
fn try_copy_infos_to_out( &mut self, src: usize, dst: usize, count: usize, ) -> Option<()>
Sourcefn copy_out_to_infos(&mut self, src: usize, dst: usize, count: usize)
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.
fn try_copy_out_to_infos( &mut self, src: usize, dst: usize, count: usize, ) -> Option<()>
pub(crate) fn cur(&self, i: usize) -> Option<&GlyphInfo>
pub(crate) fn cur_mut(&mut self, i: usize) -> Option<&mut GlyphInfo>
pub(crate) fn cur_pos_mut(&mut self) -> Option<&mut GlyphPosition>
pub(crate) fn prev(&self) -> Option<&GlyphInfo>
pub(crate) fn prev_mut(&mut self) -> Option<&mut GlyphInfo>
pub(crate) fn update_digest(&mut self)
pub(crate) fn update_glyph_set(&mut self)
pub(crate) fn backtrack_len(&self) -> usize
pub(crate) fn lookahead_len(&self) -> usize
fn next_serial(&mut self) -> u8
pub(crate) fn reverse_groups<F>(&mut self, group: F, merge_clusters: bool)
pub(crate) fn group_end<F>(&self, start: usize, group: F) -> usize
pub(crate) fn sync(&mut self) -> bool
pub(crate) fn clear_output(&mut self)
pub(crate) fn clear_positions(&mut self)
pub(crate) fn replace_glyphs( &mut self, num_in: usize, num_out: usize, glyph_data: &[u32], )
pub(crate) fn replace_glyph(&mut self, glyph_index: u32)
pub(crate) fn output_glyph(&mut self, glyph_index: u32)
pub(crate) fn output_info(&mut self, glyph_info: GlyphInfo)
Sourcepub(crate) fn copy_glyph(&mut self)
pub(crate) fn copy_glyph(&mut self)
Copies glyph at idx to output but doesn’t advance idx.
Sourcefn copy_cur_to_out(&mut self, out: usize)
fn copy_cur_to_out(&mut self, out: usize)
Copies the current glyph to out_info[out].
fn set_out_glyph(&mut self, out: usize, glyph_index: u32)
Sourcepub(crate) fn next_glyph(&mut self)
pub(crate) fn next_glyph(&mut self)
Copies glyph at idx to output and advance idx.
If there’s no output, just advance idx.
Sourcepub(crate) fn next_glyphs(&mut self, n: usize)
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.
Sourcepub(crate) fn skip_glyph(&mut self)
pub(crate) fn skip_glyph(&mut self)
Advance idx without copying to output.
pub(crate) fn set_masks( &mut self, value: u32, mask: u32, cluster_start: u32, cluster_end: u32, )
pub(crate) fn merge_clusters(&mut self, start: usize, end: usize)
fn merge_clusters_impl(&mut self, start: usize, end: usize)
fn try_merge_clusters(&mut self, start: usize, end: usize) -> Option<()>
pub(crate) fn merge_grapheme_clusters(&mut self, start: usize, end: usize)
pub(crate) fn merge_out_clusters(&mut self, start: usize, end: usize)
pub(crate) fn merge_out_grapheme_clusters(&mut self, start: usize, end: usize)
fn merge_out_clusters_impl(&mut self, start: usize, end: usize)
fn try_merge_out_clusters(&mut self, start: usize, end: usize) -> Option<()>
Sourcepub(crate) fn delete_glyph(&mut self)
pub(crate) fn delete_glyph(&mut self)
Merge clusters for deleting current glyph, and skip it.
fn merge_deleted_cluster(&mut self) -> Option<()>
pub(crate) fn delete_glyphs_inplace( &mut self, filter: impl Fn(&GlyphInfo) -> bool, )
pub(crate) fn unsafe_to_break( &mut self, start: Option<usize>, end: Option<usize>, )
pub(crate) fn safe_to_insert_tatweel( &mut self, start: Option<usize>, end: Option<usize>, )
fn _set_glyph_flags_impl( &mut self, mask: u32, start: usize, end: usize, interior: bool, from_out_buffer: bool, )
Sourcefn set_glyph_flags(
&mut self,
flags: GlyphFlags,
start: Option<usize>,
end: Option<usize>,
interior: Option<bool>,
from_out_buffer: Option<bool>,
)
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. */