Skip to main content

FontManager

Struct FontManager 

Source
pub struct FontManager<T> {
    pub fc_cache: Arc<FcFontCache>,
    pub parsed_fonts: Mutex<HashMap<FontId, T>>,
    pub font_chain_cache: HashMap<FontChainKey, FontFallbackChain>,
    pub embedded_fonts: Mutex<HashMap<u64, FontRef>>,
}

Fields§

§fc_cache: Arc<FcFontCache>

Cache that holds the file paths of the fonts (not any font data itself)

§parsed_fonts: Mutex<HashMap<FontId, T>>

Holds the actual parsed font (usually with the font bytes attached)

§font_chain_cache: HashMap<FontChainKey, FontFallbackChain>§embedded_fonts: Mutex<HashMap<u64, FontRef>>

Cache for direct FontRefs (embedded fonts like Material Icons) These are fonts referenced via FontStack::Ref that bypass fontconfig

Implementations§

Source§

impl<T: ParsedFontTrait> FontManager<T>

Source

pub fn new(fc_cache: FcFontCache) -> Result<Self, LayoutError>

Source

pub fn set_font_chain_cache( &mut self, chains: HashMap<FontChainKey, FontFallbackChain>, )

Set the font chain cache from externally resolved chains

This should be called with the result of resolve_font_chains() or collect_and_resolve_font_chains() from solver3::getters.

Source

pub fn merge_font_chain_cache( &mut self, chains: HashMap<FontChainKey, FontFallbackChain>, )

Merge additional font chains into the existing cache

Useful when processing multiple DOMs that may have different font requirements.

Source

pub fn get_font_chain_cache(&self) -> &HashMap<FontChainKey, FontFallbackChain>

Get a reference to the font chain cache

Source

pub fn get_embedded_font_by_hash(&self, font_hash: u64) -> Option<FontRef>

Get an embedded font by its hash (used for WebRender registration) Returns the FontRef if it exists in the embedded_fonts cache.

Source

pub fn get_font_by_hash(&self, font_hash: u64) -> Option<T>

Get a parsed font by its hash (used for WebRender registration) Returns the parsed font if it exists in the parsed_fonts cache.

Source

pub fn register_embedded_font(&self, font_ref: &FontRef)

Register an embedded FontRef for later lookup by hash This is called when using FontStack::Ref during shaping

Source

pub fn get_loaded_fonts(&self) -> LoadedFonts<T>

Get a snapshot of all currently loaded fonts

This returns a copy of all parsed fonts, which can be passed to the shaper. No locking is required after this call - the returned HashMap is independent.

NOTE: This should be called AFTER loading all required fonts for a layout pass.

Source

pub fn get_loaded_font_ids(&self) -> HashSet<FontId>

Get the set of FontIds that are currently loaded

This is useful for computing which fonts need to be loaded (diff with required fonts).

Source

pub fn insert_font(&self, font_id: FontId, font: T) -> Option<T>

Insert a loaded font into the cache

Returns the old font if one was already present for this FontId.

Source

pub fn insert_fonts(&self, fonts: impl IntoIterator<Item = (FontId, T)>)

Insert multiple loaded fonts into the cache

This is more efficient than calling insert_font multiple times because it only acquires the lock once.

Source

pub fn remove_font(&self, font_id: &FontId) -> Option<T>

Remove a font from the cache

Returns the removed font if it was present.

Source§

impl FontManager<FontRef>

Trait Implementations§

Source§

impl<T: Debug> Debug for FontManager<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for FontManager<T>

§

impl<T> RefUnwindSafe for FontManager<T>

§

impl<T> Send for FontManager<T>
where T: Send,

§

impl<T> Sync for FontManager<T>
where T: Send,

§

impl<T> Unpin for FontManager<T>
where T: Unpin,

§

impl<T> UnwindSafe for FontManager<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool