pub struct Fonts { /* private fields */ }egui only.Expand description
The collection of fonts used by epaint.
Required in order to paint text. Create one and reuse. Cheap to clone.
Each Fonts comes with a font atlas textures that needs to be used when painting.
If you are using egui, use egui::Context::set_fonts and egui::Context::fonts.
You need to call Self::begin_pass once per viewport pass, and
Self::font_image_delta once every frame.
Implementations§
Source§impl Fonts
impl Fonts
Sourcepub fn new(options: TextOptions, definitions: FontDefinitions) -> Fonts
pub fn new(options: TextOptions, definitions: FontDefinitions) -> Fonts
Sourcepub fn with_glyph_rasterizer(self, glyph_rasterizer: GlyphRasterizer) -> Fonts
pub fn with_glyph_rasterizer(self, glyph_rasterizer: GlyphRasterizer) -> Fonts
Also use this glyph rasterizer, e.g. the browser on web, or for custom glyphs.
See GlyphRasterizer.
Sourcepub fn add_glyph_rasterizer(
&mut self,
glyph_rasterizer: GlyphRasterizer,
) -> bool
pub fn add_glyph_rasterizer( &mut self, glyph_rasterizer: GlyphRasterizer, ) -> bool
Also use this glyph rasterizer, e.g. the browser on web, or for custom glyphs.
Adding a rasterizer whose GlyphRasterizer::key is already installed is a no-op,
so this is safe to call every frame.
Returns true if it was added.
See GlyphRasterizer.
Sourcepub fn set_glyph_rasterizers(&mut self, glyph_rasterizers: Vec<GlyphRasterizer>)
pub fn set_glyph_rasterizers(&mut self, glyph_rasterizers: Vec<GlyphRasterizer>)
Replace all GlyphRasterizers.
Pass an empty list to only use the installed fonts.
Sourcepub fn with_font_providers(
self,
font_providers: Vec<Arc<dyn FontProvider>>,
) -> Fonts
pub fn with_font_providers( self, font_providers: Vec<Arc<dyn FontProvider>>, ) -> Fonts
Ask these for fonts, after the FontDefinitions.
The providers are asked in order, and the first font found is used.
Sourcepub fn discovered_fonts(&self) -> &[FontInsert]
pub fn discovered_fonts(&self) -> &[FontInsert]
The fonts discovered by the FontProviders so far, in the order they were found.
These are not part of Self::definitions.
Sourcepub fn with_missing_glyph_policy(self, policy: MissingGlyphPolicy) -> Fonts
pub fn with_missing_glyph_policy(self, policy: MissingGlyphPolicy) -> Fonts
What to do with characters that nothing can draw. See MissingGlyphPolicy.
Sourcepub fn set_missing_glyph_policy(&mut self, policy: MissingGlyphPolicy)
pub fn set_missing_glyph_policy(&mut self, policy: MissingGlyphPolicy)
What to do with characters that nothing can draw. See MissingGlyphPolicy.
Sourcepub fn missing_glyph_policy(&self) -> MissingGlyphPolicy
pub fn missing_glyph_policy(&self) -> MissingGlyphPolicy
See MissingGlyphPolicy.
Sourcepub fn begin_pass(&mut self, options: TextOptions, viewport_key: ViewportKey)
pub fn begin_pass(&mut self, options: TextOptions, viewport_key: ViewportKey)
Call at the start of each viewport pass with the latest known TextOptions.
Call after painting the previous frame, but before using Fonts for the new frame.
This function will react to changes in TextOptions,
as well as notice when the font atlas is getting full, and handle that.
Sourcepub fn used_since_begin_pass(&self, viewport_key: ViewportKey) -> bool
pub fn used_since_begin_pass(&self, viewport_key: ViewportKey) -> bool
Has any text been laid out in this viewport since its last Self::begin_pass?
While this is false, fonts can still be swapped out for this pass without
leaving anything laid out with the old ones.
Sourcepub fn font_image_delta(&mut self) -> Option<ImageDelta>
pub fn font_image_delta(&mut self) -> Option<ImageDelta>
Call at the end of each frame (before painting) to get the change to the font texture since last call.
pub fn options(&self) -> &TextOptions
pub fn definitions(&self) -> &FontDefinitions
Sourcepub fn texture_atlas(&self) -> &TextureAtlas
pub fn texture_atlas(&self) -> &TextureAtlas
The font atlas.
Pass this to crate::Tessellator.
Sourcepub fn image(&self) -> ColorImage
pub fn image(&self) -> ColorImage
The full font atlas image.
Sourcepub fn font_image_size(&self) -> [usize; 2]
pub fn font_image_size(&self) -> [usize; 2]
Current size of the font image.
Pass this to crate::Tessellator.
Sourcepub fn has_glyph(&mut self, font_id: &FontId, c: char) -> bool
pub fn has_glyph(&mut self, font_id: &FontId, c: char) -> bool
Do the installed fonts have this glyph?
This does not consult the GlyphRasterizers, so it can return false
for a character that would still render via a rasterizer (e.g. the browser on web).
Sourcepub fn has_glyphs(&mut self, font_id: &FontId, s: &str) -> bool
pub fn has_glyphs(&mut self, font_id: &FontId, s: &str) -> bool
Do the installed fonts have all the glyphs in this text?
See Self::has_glyph for the caveat about the GlyphRasterizers.
pub fn num_galleys_in_cache(&self) -> usize
Sourcepub fn retain_galley_caches(&mut self, keep: impl FnMut(ViewportKey) -> bool)
pub fn retain_galley_caches(&mut self, keep: impl FnMut(ViewportKey) -> bool)
Drop cached layouts belonging to viewports that are no longer alive.
Sourcepub fn font_atlas_fill_ratio(&self) -> f32
pub fn font_atlas_fill_ratio(&self) -> f32
How full is the font atlas?
This increases as new fonts and/or glyphs are used,
but can also decrease in a call to Self::begin_pass.
Sourcepub fn layout_uncached(
&mut self,
pixels_per_point: f32,
job: Arc<LayoutJob>,
) -> Galley
pub fn layout_uncached( &mut self, pixels_per_point: f32, job: Arc<LayoutJob>, ) -> Galley
Lay out some text, bypassing the galley cache.
Prefer FontsView::layout_job, which memoizes.
This is mostly useful for benchmarking the layout code.
Sourcepub fn layout_uncached_for_viewport(
&mut self,
pixels_per_point: f32,
viewport_key: ViewportKey,
job: Arc<LayoutJob>,
) -> Galley
pub fn layout_uncached_for_viewport( &mut self, pixels_per_point: f32, viewport_key: ViewportKey, job: Arc<LayoutJob>, ) -> Galley
Lay out text without caching it in the given viewport’s cache.
Sourcepub fn with_pixels_per_point(&mut self, pixels_per_point: f32) -> FontsView<'_>
pub fn with_pixels_per_point(&mut self, pixels_per_point: f32) -> FontsView<'_>
Returns a FontsView with the given pixels_per_point that can be used to do text layout.
This uses the default layout-cache namespace. Integrations that render multiple
independently scheduled viewports must use Self::with_pixels_per_point_for_viewport.
Sourcepub fn with_pixels_per_point_for_viewport(
&mut self,
pixels_per_point: f32,
viewport_key: ViewportKey,
) -> FontsView<'_>
pub fn with_pixels_per_point_for_viewport( &mut self, pixels_per_point: f32, viewport_key: ViewportKey, ) -> FontsView<'_>
Returns a FontsView with the given pixels_per_point for the specified
viewport that can be used to do text layout with a viewport-specific galley cache.
Auto Trait Implementations§
impl !Freeze for Fonts
impl !RefUnwindSafe for Fonts
impl !UnwindSafe for Fonts
impl Forget for Fonts
impl Move for Fonts
impl Send for Fontswhere
Arc<FontDefinitions>: Send,
RawVecInner: Send,
RawTable<(OutlineGlyphKey, GlyphAllocation)>: Send,
RawTable<(RasterGlyphKey, Option<RasterGlyphAllocation>)>: Send,
RawTable<(FontFaceKey, FontFace)>: Send,
RawTable<(String, FontFaceKey)>: Send,
Arc<str>: Send,
RawTable<(char, FontFaceKey)>: Send,
NodeRef<Owned, char, Vec<String>, LeafOrInternal>: Send,
BoxRaw<(char, Vec<String>)>: Send,
RawTable<(FontFamily, FamilyKey)>: Send,
InternalBitFlags: Send,
SmallVec<[u8; 8]>: Send,
Atomic<usize>: Send,
Arc<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Sync + Send>: Send,
Arc<dyn FontProvider>: Send,
Arc<dyn AsRef<[u8]> + Sync + Send>: Send,
SmallVec<[(Tag, f32); 2]>: Send,
NodeRef<Owned, ViewportKey, ViewportGalleyCache, LeafOrInternal>: Send,
BoxRaw<(ViewportKey, ViewportGalleyCache)>: Send,
impl Sync for Fontswhere
Arc<FontDefinitions>: Sync,
RawVecInner: Sync,
RawTable<(OutlineGlyphKey, GlyphAllocation)>: Sync,
RawTable<(RasterGlyphKey, Option<RasterGlyphAllocation>)>: Sync,
RawTable<(FontFaceKey, FontFace)>: Sync,
RawTable<(String, FontFaceKey)>: Sync,
Arc<str>: Sync,
RawTable<(char, FontFaceKey)>: Sync,
NodeRef<Owned, char, Vec<String>, LeafOrInternal>: Sync,
BoxRaw<(char, Vec<String>)>: Sync,
RawTable<(FontFamily, FamilyKey)>: Sync,
InternalBitFlags: Sync,
SmallVecData<[u8; 8]>: Sync,
u8: Sync,
Atomic<usize>: Sync,
Arc<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Sync + Send>: Sync,
Arc<dyn FontProvider>: Sync,
Arc<dyn AsRef<[u8]> + Sync + Send>: Sync,
SmallVecData<[(Tag, f32); 2]>: Sync,
(Tag, f32): Sync,
NodeRef<Owned, ViewportKey, ViewportGalleyCache, LeafOrInternal>: Sync,
BoxRaw<(ViewportKey, ViewportGalleyCache)>: Sync,
impl Unpin for Fontswhere
Arc<FontDefinitions>: Unpin,
*const u8 is !null: Unpin,
Arc<dyn AsRef<[u8]> + Sync + Send>: Unpin,
&'static [u8]: Unpin,
&'static [BigEndian<u16>]: Unpin,
&'static [BigEndian<u32>]: Unpin,
Box<HintInstance>: Unpin,
Arc<GlyphStyleMap>: Unpin,
Arc<RwLock<Vec<Option<UnscaledStyleMetrics>>>>: Unpin,
*const (Tag, f32) is !null: Unpin,
(Tag, f32): Unpin,
Align4<u32>: Unpin,
Box<LookupInfo>: Unpin,
Atomic<u16>: Unpin,
Align8<usize>: Unpin,
Box<hb_cache_core_t<16, 8, 256, Atomic<u16>>>: Unpin,
Atomic<u32>: Unpin,
Arc<str>: Unpin,
*const LeafNode<char, Vec<String>> is !null: Unpin,
Box<(char, Vec<String>)>: Unpin,
InternalBitFlags: Unpin,
u8: Unpin,
Arc<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Sync + Send>: Unpin,
Arc<dyn FontProvider>: Unpin,
*const LeafNode<ViewportKey, ViewportGalleyCache> is !null: Unpin,
Box<(ViewportKey, ViewportGalleyCache)>: Unpin,
impl UnsafeUnpin for Fontswhere
*const ArcInner<FontDefinitions> is !null: UnsafeUnpin,
PhantomData<ArcInner<FontDefinitions>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Color32>: UnsafeUnpin,
PhantomData<PrerasterizedDisc>: UnsafeUnpin,
PhantomData<fn() -> NoHashHasher<OutlineGlyphKey>>: UnsafeUnpin,
PhantomData<(OutlineGlyphKey, GlyphAllocation)>: UnsafeUnpin,
PhantomData<fn() -> NoHashHasher<RasterGlyphKey>>: UnsafeUnpin,
PhantomData<(RasterGlyphKey, Option<RasterGlyphAllocation>)>: UnsafeUnpin,
PhantomData<fn() -> NoHashHasher<FontFaceKey>>: UnsafeUnpin,
PhantomData<(FontFaceKey, FontFace)>: UnsafeUnpin,
PhantomData<(String, FontFaceKey)>: UnsafeUnpin,
PhantomData<Family>: UnsafeUnpin,
PhantomData<(FontFamily, FamilyKey)>: UnsafeUnpin,
InternalBitFlags: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<GlyphInfo>: UnsafeUnpin,
PhantomData<GlyphPosition>: UnsafeUnpin,
PhantomData<BitPage>: UnsafeUnpin,
PhantomData<PageInfo>: UnsafeUnpin,
Align8<usize>: UnsafeUnpin,
PhantomData<GlyphRasterizer>: UnsafeUnpin,
PhantomData<Arc<dyn FontProvider>>: UnsafeUnpin,
PhantomData<FontInsert>: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Sync + Send>>: UnsafeUnpin,
*const LeafNode<ViewportKey, ViewportGalleyCache> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(ViewportKey, ViewportGalleyCache)>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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