GlyphStore

Struct GlyphStore 

Source
pub struct GlyphStore {
    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_single_preserved_newline: 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.

+- GlyphStore --------------------------------+
|               +---+---+---+---+---+---+---+ |
| 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 GlyphStore. 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: Au

A cache of the advance of the entire glyph store.

§total_characters: usize

The number of characters that correspond to the glyphs in this GlyphStore

§total_word_separators: usize

A cache of the number of word separators in the entire glyph store. See https://drafts.csswg.org/css-text/#word-separator.

§is_whitespace: bool

Whether or not this glyph store contains only glyphs for whitespace.

§ends_with_whitespace: bool

Whether 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_single_preserved_newline: bool

Whether or not this glyph store contains only a single glyph for a single preserved newline.

§is_rtl: bool

Whether or not this GlyphStore has right-to-left text, which has implications about the order of the glyphs in the store.

Implementations§

Source§

impl GlyphStore

Source

pub(crate) fn new(text: &str, 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.

Source

pub(crate) fn with_shaped_glyph_data( font: &Font, 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 GlyphStore 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.

Source

pub fn total_advance(&self) -> Au

Source

pub fn len(&self) -> usize

Return the number of glyphs stored in this GlyphStore.

Source

pub fn is_empty(&self) -> bool

Whether or not this GlyphStore has any glyphs.

Source

pub fn character_count(&self) -> usize

The number of characters (char) from the original string that produced this GlyphStore.

Source

pub fn is_whitespace(&self) -> bool

Whether or not this GlyphStore is entirely whitepsace.

Source

pub fn is_single_preserved_newline(&self) -> bool

Whether or not this GlyphStore is a single preserved newline.

Source

pub fn ends_with_whitespace(&self) -> bool

Whether or not this GlyphStore ends with whitespace.

Source

pub fn total_word_separators(&self) -> usize

The number of word separators in this GlyphStore.

Source

pub fn total_characters(&self) -> usize

The number of characters that were consumed to produce this GlyphStore. Some characters correpond to more than one glyph and some glyphs correspond to more than one character.

Source

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.

Source

fn add_detailed_glyph( &mut self, shaped_glyph: &ShapedGlyph, character: Option<char>, character_count: usize, )

Source

fn extend_previous_glyph_by_character(&mut self)

Source

fn add_glyph_for_current_character( &mut self, shaped_glyph: &ShapedGlyph, options: &ShapingOptions, )

Source

fn ensure_last_glyph_is_detailed(&mut self) -> usize

If the last glyph added to this GlyphStore 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.

Source

pub fn glyphs(&self) -> impl Iterator<Item = GlyphInfo<'_>> + use<'_>

Trait Implementations§

Source§

impl Clone for GlyphStore

Source§

fn clone(&self) -> GlyphStore

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GlyphStore

Source§

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

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

impl<'de> Deserialize<'de> for GlyphStore

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl MallocSizeOf for GlyphStore

Source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
Source§

impl Serialize for GlyphStore

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

impl<T> MaybeSendSync for T