From ce40702a501c3159db89693bd7da713ae1b4c011 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 29 Apr 2026 21:25:40 +0200 Subject: feat(typst): embed fonts --- typst/src/world.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'typst/src/world.rs') diff --git a/typst/src/world.rs b/typst/src/world.rs index 5bbefee..c2fe7c7 100644 --- a/typst/src/world.rs +++ b/typst/src/world.rs @@ -10,7 +10,7 @@ use typst::foundations::{Bytes, Datetime}; use typst::syntax::{FileId, Source}; use typst::text::{Font, FontBook}; use typst::utils::LazyHash; -use typst_kit::fonts::Fonts; +use typst_kit::fonts::{FontSlot, Fonts}; /// Main interface that determines the environment for Typst. pub struct MinimalWorld { @@ -24,33 +24,24 @@ pub struct MinimalWorld { book: LazyHash, /// Metadata about all known fonts. - fonts: Vec, + fonts: Vec, } impl MinimalWorld { pub fn new(source: impl Into) -> Self { - let (fonts, book) = Self::load_fonts(); + let mut searcher = Fonts::searcher(); + searcher.include_system_fonts(true); + #[cfg(feature = "embed-fonts")] + searcher.include_embedded_fonts(true); + let fonts = searcher.search(); Self { library: LazyHash::new(Library::default()), - book: LazyHash::new(book), - fonts: fonts, + book: LazyHash::new(fonts.book), + fonts: fonts.fonts, source: Source::detached(source), } } - - fn load_fonts() -> (Vec, FontBook) { - let mut searcher = Fonts::searcher(); - searcher.include_system_fonts(true); - - let mut fonts = Vec::new(); - let mut book = FontBook::new(); - for font in searcher.search().fonts { - book.push(font.get().unwrap().info().clone()); - fonts.push(font.get().unwrap()); - } - (fonts, book) - } } impl World for MinimalWorld { @@ -85,7 +76,7 @@ impl World for MinimalWorld { /// Accessing a specified font per index of font book. fn font(&self, id: usize) -> Option { - self.fonts.get(id).cloned() + self.fonts.get(id)?.get() } /// Get the current date. -- cgit v1.2.3