pub struct GlyphRasterizer {
pub key: Arc<str>,
pub rasterize: Arc<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Send + Sync>,
pub priority: FontPriority,
}Expand description
Rasterizes grapheme clusters using something other than the installed fonts, e.g. the browser on web, or your own custom glyphs.
By default (FontPriority::Lowest) a rasterizer is a fallback:
it is only asked about clusters that no installed font can render,
after the FontProviders have been asked for a font for them.
With FontPriority::Highest it is instead asked about every cluster,
before any font. Use this to override how specific glyphs look,
e.g. to always render … your own way.
Return None quickly for everything you do not want to override.
Several rasterizers can be installed. Within a priority tier
they are asked in the order they were added, and the first to return Some wins.
Results (and failures) are cached per cluster, family, and size, so each rasterizer is asked at most once per such combination.
Every rasterizer has a Self::key, which makes installing it idempotent:
adding one when a rasterizer with the same key is already installed is a no-op.
Fields§
§key: Arc<str>Identifies this rasterizer: two rasterizers with the same key are the same rasterizer.
Adding one when a rasterizer with this key is already installed is a no-op,
so it is safe to add it every frame.
To swap out an installed rasterizer, replace them all with
e.g. Context::set_glyph_rasterizers.
rasterize: Arc<dyn for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Send + Sync>Rasterize one grapheme cluster.
Return None if this rasterizer does not handle it.
priority: FontPriorityIs this a fallback (FontPriority::Lowest, the default),
or does it override the installed fonts (FontPriority::Highest)?
Implementations§
Source§impl GlyphRasterizer
impl GlyphRasterizer
Sourcepub fn new(
key: impl Into<Arc<str>>,
rasterize: impl for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Send + Sync + 'static,
) -> GlyphRasterizer
pub fn new( key: impl Into<Arc<str>>, rasterize: impl for<'a> Fn(&GlyphRasterizerRequest<'a>) -> Option<RasterizedGlyph> + Send + Sync + 'static, ) -> GlyphRasterizer
A fallback rasterizer (FontPriority::Lowest).
key identifies the rasterizer (see Self::key).
Pick something unique, e.g. a fully qualified name like "my_crate::MyGlyphs".
See Self::with_priority.
Sourcepub fn with_priority(self, priority: FontPriority) -> GlyphRasterizer
pub fn with_priority(self, priority: FontPriority) -> GlyphRasterizer
Should this rasterizer be asked before (FontPriority::Highest)
or after (FontPriority::Lowest) the installed fonts?
Trait Implementations§
Source§impl Clone for GlyphRasterizer
impl Clone for GlyphRasterizer
Source§fn clone(&self) -> GlyphRasterizer
fn clone(&self) -> GlyphRasterizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for GlyphRasterizer
impl !UnwindSafe for GlyphRasterizer
impl Forget for GlyphRasterizer
impl Freeze for GlyphRasterizer
impl Move for GlyphRasterizer
impl Send for GlyphRasterizer
impl Sync for GlyphRasterizer
impl Unpin for GlyphRasterizer
impl UnsafeUnpin for GlyphRasterizer
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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