pub struct ShapedText {
glyphs: Vec<GlyphEntry>,
detailed_glyphs: Vec<DetailedGlyphEntry>,
total_advance: Au,
total_characters: usize,
total_word_separators: usize,
is_whitespace: bool,
ends_with_whitespace: bool,
is_rtl: bool,
}Expand description
Stores the glyph data belonging to a text run.
Simple glyphs are stored inline in the entry_buffer, detailed glyphs are
stored as pointers into the detail_store.
+- ShapedText --------------------------------+
| +---+---+---+---+---+---+---+ |
| entry_buffer: | | s | | s | | s | s | | d = detailed
| +-|-+---+-|-+---+-|-+---+---+ | s = simple
| | | | |
| | +---+-------+ |
| | | |
| +-V-+-V-+ |
| detail_store: | d | d | |
| +---+---+ |
+---------------------------------------------+Fields§
§glyphs: Vec<GlyphEntry>A collection of GlyphEntrys within the ShapedText. Each GlyphEntry
maybe simple or detailed. When detailed, there will be a corresponding entry
in Self::detailed_glyphs.
detailed_glyphs: Vec<DetailedGlyphEntry>A vector of glyphs that cannot fit within a single GlyphEntry or that
correspond to 0 or more than 1 character in the original string.
total_advance: AuA cache of the advance of the entire glyph store.
total_characters: usizeThe number of characters that correspond to the glyphs in this ShapedText
total_word_separators: usizeA cache of the number of word separators in the entire glyph store. See https://drafts.csswg.org/css-text/#word-separator.
is_whitespace: boolWhether or not this glyph store contains only glyphs for whitespace.
ends_with_whitespace: boolWhether or not this glyph store ends with whitespace glyphs.
Typically whitespace glyphs are placed in a separate store,
but that may not be the case with white-space: break-spaces.
is_rtl: boolWhether or not this ShapedText has right-to-left text, which has implications
about the order of the glyphs in the store.
Implementations§
Source§impl ShapedText
impl ShapedText
Sourcepub(crate) fn new(length: usize, options: &ShapingOptions) -> Self
pub(crate) fn new(length: usize, options: &ShapingOptions) -> Self
Initializes the glyph store with the given capacity, but doesn’t actually add any glyphs.
Use the add_* methods to store glyph data.
Sourcepub(crate) fn with_shaped_glyph_data(
text: &str,
options: &ShapingOptions,
shaped_glyph_data: &impl GlyphShapingResult,
) -> Self
pub(crate) fn with_shaped_glyph_data( text: &str, options: &ShapingOptions, shaped_glyph_data: &impl GlyphShapingResult, ) -> Self
This constructor turns shaping output from HarfBuzz into a glyph run to be
used by layout. The idea here is that we add each glyph to the ShapedText
and track to which characters from the original string each glyph
corresponds. HarfBuzz will either give us glyphs that correspond to
characters left-to-right or right-to-left. Each character can produce
multiple glyphs and multiple characters can produce one glyph. HarfBuzz just
guarantees that the resulting character offsets are in monotone order.
pub fn total_advance(&self) -> Au
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of glyphs stored in this ShapedText.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether or not this ShapedText has any glyphs.
Sourcepub fn character_count(&self) -> usize
pub fn character_count(&self) -> usize
The number of characters (char) from the original string that produced this
ShapedText.
Sourcepub fn is_whitespace(&self) -> bool
pub fn is_whitespace(&self) -> bool
Whether or not this ShapedText is entirely white space.
Sourcepub fn ends_with_whitespace(&self) -> bool
pub fn ends_with_whitespace(&self) -> bool
Whether or not this ShapedText ends with whitespace.
Sourcepub fn total_word_separators(&self) -> usize
pub fn total_word_separators(&self) -> usize
The number of word separators in this ShapedText.
Sourcepub fn total_characters(&self) -> usize
pub fn total_characters(&self) -> usize
The number of characters that were consumed to produce this ShapedText. Some
characters correspond to more than one glyph and some glyphs correspond to more than
one character.
Sourcepub(crate) fn add_glyph(&mut self, character: char, glyph: &ShapedGlyph)
pub(crate) fn add_glyph(&mut self, character: char, glyph: &ShapedGlyph)
Adds glyph that corresponds to a single character (as far we know) in the originating string.
fn add_detailed_glyph( &mut self, shaped_glyph: &ShapedGlyph, character: Option<char>, character_count: usize, )
fn extend_previous_glyph_by_character(&mut self)
fn add_glyph_for_current_character( &mut self, shaped_glyph: &ShapedGlyph, options: &ShapingOptions, )
Sourcefn ensure_last_glyph_is_detailed(&mut self) -> usize
fn ensure_last_glyph_is_detailed(&mut self) -> usize
If the last glyph added to this ShapedText was a simple glyph, convert it to a
detailed one. In either case, return the index into Self::detailed_glyphs for
the most recently added glyph.
pub fn glyphs(&self) -> impl Iterator<Item = GlyphInfo<'_>> + use<'_>
Trait Implementations§
Source§impl Clone for ShapedText
impl Clone for ShapedText
Source§fn clone(&self) -> ShapedText
fn clone(&self) -> ShapedText
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShapedText
impl Debug for ShapedText
Source§impl<'de> Deserialize<'de> for ShapedText
impl<'de> Deserialize<'de> for ShapedText
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl MallocSizeOf for ShapedText
impl MallocSizeOf for ShapedText
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl Freeze for ShapedText
impl RefUnwindSafe for ShapedText
impl Send for ShapedText
impl Sync for ShapedText
impl Unpin for ShapedText
impl UnwindSafe for ShapedText
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more