Skip to main content

Fonts

Struct Fonts 

Source
pub struct Fonts { /* private fields */ }
Available on crate feature 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

Source

pub fn new(options: TextOptions, definitions: FontDefinitions) -> Fonts

Create a new Fonts for text layout.

This call is expensive, so only create one Fonts and then reuse it.

Source

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.

Source

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.

Source

pub fn set_glyph_rasterizers(&mut self, glyph_rasterizers: Vec<GlyphRasterizer>)

Replace all GlyphRasterizers.

Pass an empty list to only use the installed fonts.

Source

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.

Source

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.

Source

pub fn with_missing_glyph_policy(self, policy: MissingGlyphPolicy) -> Fonts

What to do with characters that nothing can draw. See MissingGlyphPolicy.

Source

pub fn set_missing_glyph_policy(&mut self, policy: MissingGlyphPolicy)

What to do with characters that nothing can draw. See MissingGlyphPolicy.

Source

pub fn missing_glyph_policy(&self) -> MissingGlyphPolicy

Source

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.

Source

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.

Source

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.

Source

pub fn options(&self) -> &TextOptions

Source

pub fn definitions(&self) -> &FontDefinitions

Source

pub fn texture_atlas(&self) -> &TextureAtlas

The font atlas. Pass this to crate::Tessellator.

Source

pub fn image(&self) -> ColorImage

The full font atlas image.

Source

pub fn font_image_size(&self) -> [usize; 2]

Current size of the font image. Pass this to crate::Tessellator.

Source

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

Source

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.

Source

pub fn num_galleys_in_cache(&self) -> usize

Source

pub fn retain_galley_caches(&mut self, keep: impl FnMut(ViewportKey) -> bool)

Drop cached layouts belonging to viewports that are no longer alive.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 Fonts
where 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 Fonts
where 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 Fonts
where 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 Fonts
where *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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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