tinymist_project::world::font

Trait FontResolver

pub trait FontResolver {
    // Required methods
    fn font_book(&self) -> &LazyHash<FontBook>;
    fn slot(&self, index: usize) -> Option<&FontSlot>;
    fn font(&self, index: usize) -> Option<Font>;

    // Provided methods
    fn revision(&self) -> Option<NonZero<usize>> { ... }
    fn get_by_info(&self, info: &FontInfo) -> Option<Font> { ... }
    fn default_get_by_info(&self, info: &FontInfo) -> Option<Font> { ... }
}
Expand description

A FontResolver can resolve a font by index. It also provides FontBook for typst to query fonts.

Required Methods§

fn font_book(&self) -> &LazyHash<FontBook>

The font book interface for typst.

fn slot(&self, index: usize) -> Option<&FontSlot>

Gets the font slot by index. The index parameter is the index of the font in the FontBook.infos.

fn font(&self, index: usize) -> Option<Font>

Gets the font by index. The index parameter is the index of the font in the FontBook.infos.

Provided Methods§

fn revision(&self) -> Option<NonZero<usize>>

An optionally implemented revision function for users, e.g. the World.

A user of FontResolver will differentiate the prev and next revisions to determine if the underlying state of fonts has changed.

  • If either prev or next is None, the world’s revision is always increased.
  • Otherwise, the world’s revision is increased if prev != next.

If the revision of fonts is changed, the world will invalidate all related caches and increase its revision.

fn get_by_info(&self, info: &FontInfo) -> Option<Font>

Gets a font by its info.

fn default_get_by_info(&self, info: &FontInfo) -> Option<Font>

The default implementation of FontResolver::get_by_info.

Implementations on Foreign Types§

§

impl<T> FontResolver for Arc<T>
where T: FontResolver,

§

fn font_book(&self) -> &LazyHash<FontBook>

§

fn slot(&self, index: usize) -> Option<&FontSlot>

§

fn font(&self, index: usize) -> Option<Font>

§

fn get_by_info(&self, info: &FontInfo) -> Option<Font>

Implementors§