Skip to main content

GlyphAtlas

Struct GlyphAtlas 

Source
pub struct GlyphAtlas { /* private fields */ }
Expand description

A static FontChain plus the char -> slot map for its grid-packed atlas.

Every glyph of every font in the chain is uploaded once; a character maps to a flat slot, which is the font’s base offset in the atlas plus that font’s own glyph index. A renderer never sees characters past this point: resolve hands back a u16 that goes straight into an instance buffer.

Implementations§

Source§

impl GlyphAtlas

Source

pub fn new(fonts: FontChain<'static>, glyph_size: (u8, u8)) -> Self

An atlas over a static font chain, whose slots are assigned back to back in chain order.

glyph_size is the cell size every font in fonts agrees on. Pass what FontChain::glyph_size returned, and reject a chain it returned None for: a grid has one cell size, so a chain whose fonts disagree has no atlas geometry to build.

Source

pub const fn cell_size(&self) -> (u32, u32)

Glyph cell size in unscaled pixels.

Source

pub const fn space_slot(&self) -> u16

The atlas slot of the space glyph, or 0 for a chain with no space glyph at all.

Only ever used for cells that draw no glyph (a backend still needs some slot in the instance it writes), so a chain without a space still renders correctly.

Source

pub fn slot_count(&self) -> u32

The total number of glyph slots the chain occupies in the atlas.

Compare against MAX_SLOTS before building: a chain past that has glyphs resolve cannot name.

Source

pub const fn fonts(&self) -> &FontChain<'static>

The backing font chain.

Source

pub fn data(&self) -> AtlasData

The full coverage buffer to upload, built fresh each call.

Not cached: a backend uploads it once at resource creation and, on some platforms, again after a lost device, which is rare enough that holding a second copy of the atlas for the renderer’s whole life costs more than rebuilding it.

Source

pub fn resolve(&self, ch: char) -> Option<u16>

Resolves ch to its atlas slot, or None when no font in the chain can draw it, not even as the substituted solid block, in which case the caller draws no glyph for that cell.

§Panics

Does not panic. The u16 cast cannot truncate for a chain whose slot_count is within MAX_SLOTS, which a backend’s builder is expected to have checked.

Trait Implementations§

Source§

impl Clone for GlyphAtlas

Source§

fn clone(&self) -> GlyphAtlas

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GlyphAtlas

Source§

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

Formats the value using the given formatter. 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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,