diff options
Diffstat (limited to 'typst')
| -rw-r--r-- | typst/Cargo.lock | 1 | ||||
| -rw-r--r-- | typst/Cargo.toml | 5 | ||||
| -rw-r--r-- | typst/src/world.rs | 29 |
3 files changed, 16 insertions, 19 deletions
diff --git a/typst/Cargo.lock b/typst/Cargo.lock index db63b22..3ce45b7 100644 --- a/typst/Cargo.lock +++ b/typst/Cargo.lock @@ -2424,6 +2424,7 @@ dependencies = [ "serde", "serde_json", "tar", + "typst-assets", "typst-library", "typst-syntax", "typst-timing", diff --git a/typst/Cargo.toml b/typst/Cargo.toml index 3cdc8a7..dc7eb97 100644 --- a/typst/Cargo.toml +++ b/typst/Cargo.toml @@ -16,3 +16,8 @@ opt-level = 2 codegen-units = 1 lto = true strip = true + +[features] +default = ["embed-fonts"] + +embed-fonts = ["typst-kit/embed-fonts"] 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<FontBook>, /// Metadata about all known fonts. - fonts: Vec<Font>, + fonts: Vec<FontSlot>, } impl MinimalWorld { pub fn new(source: impl Into<String>) -> 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<Font>, 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<Font> { - self.fonts.get(id).cloned() + self.fonts.get(id)?.get() } /// Get the current date. |
