pub struct FontAtlas {
pub dynamic_texture_atlas_builder: DynamicTextureAtlasBuilder,
pub glyph_to_atlas_index: HashMap<CacheKey, GlyphAtlasLocation>,
pub texture_atlas: Handle<TextureAtlasLayout>,
pub texture: Handle<Image>,
}
Expand description
Rasterized glyphs are cached, stored in, and retrieved from, a FontAtlas
.
A FontAtlas
contains one or more textures, each of which contains one or more glyphs packed into them.
A FontAtlasSet
contains a FontAtlas
for each font size in the same font face.
For the same font face and font size, a glyph will be rasterized differently for different subpixel offsets. In practice, ranges of subpixel offsets are grouped into subpixel bins to limit the number of rasterized glyphs, providing a trade-off between visual quality and performance.
A CacheKey
encodes all of the information of a subpixel-offset glyph and is used to
find that glyphs raster in a TextureAtlas
through its corresponding GlyphAtlasLocation
.
Fields§
§dynamic_texture_atlas_builder: DynamicTextureAtlasBuilder
Used to update the TextureAtlasLayout
.
glyph_to_atlas_index: HashMap<CacheKey, GlyphAtlasLocation>
A mapping between subpixel-offset glyphs and their GlyphAtlasLocation
.
texture_atlas: Handle<TextureAtlasLayout>
The handle to the TextureAtlasLayout
that holds the rasterized glyphs.
texture: Handle<Image>
The texture where this font atlas is located
Implementations§
Source§impl FontAtlas
impl FontAtlas
Sourcepub fn new(
textures: &mut Assets<Image>,
texture_atlases_layout: &mut Assets<TextureAtlasLayout>,
size: UVec2,
font_smoothing: FontSmoothing,
) -> FontAtlas
pub fn new( textures: &mut Assets<Image>, texture_atlases_layout: &mut Assets<TextureAtlasLayout>, size: UVec2, font_smoothing: FontSmoothing, ) -> FontAtlas
Create a new FontAtlas
with the given size, adding it to the appropriate asset collections.
Sourcepub fn get_glyph_index(&self, cache_key: CacheKey) -> Option<GlyphAtlasLocation>
pub fn get_glyph_index(&self, cache_key: CacheKey) -> Option<GlyphAtlasLocation>
Get the GlyphAtlasLocation
for a subpixel-offset glyph.
Sourcepub fn has_glyph(&self, cache_key: CacheKey) -> bool
pub fn has_glyph(&self, cache_key: CacheKey) -> bool
Checks if the given subpixel-offset glyph is contained in this FontAtlas
.
Sourcepub fn add_glyph(
&mut self,
textures: &mut Assets<Image>,
atlas_layouts: &mut Assets<TextureAtlasLayout>,
cache_key: CacheKey,
texture: &Image,
offset: IVec2,
) -> Result<(), TextError>
pub fn add_glyph( &mut self, textures: &mut Assets<Image>, atlas_layouts: &mut Assets<TextureAtlasLayout>, cache_key: CacheKey, texture: &Image, offset: IVec2, ) -> Result<(), TextError>
Add a glyph to the atlas, updating both its texture and layout.
The glyph is represented by glyph
, and its image content is glyph_texture
.
This content is copied into the atlas texture, and the atlas layout is updated
to store the location of that glyph into the atlas.
§Returns
Returns ()
if the glyph is successfully added, or TextError::FailedToAddGlyph
otherwise.
In that case, neither the atlas texture nor the atlas layout are
modified.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FontAtlas
impl !RefUnwindSafe for FontAtlas
impl Send for FontAtlas
impl Sync for FontAtlas
impl Unpin for FontAtlas
impl !UnwindSafe for FontAtlas
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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