diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-21 23:18:56 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-21 23:18:56 +0100 |
| commit | b934a2fd83d63fc115c01f959e888c7bc1aa87e4 (patch) | |
| tree | f99e2e867733a2b37e3df2db24edf61d438adeb5 /cli/src/main.rs | |
| parent | 27bb5e8d22f6fe466cecc80bcbad9aec63b2a8f7 (diff) | |
Embed standard fonts in binaryv23-03-21-2
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 40d1a780..3f41ac78 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -404,6 +404,9 @@ impl SystemWorld { let mut searcher = FontSearcher::new(); searcher.search_system(); + #[cfg(feature = "embed-fonts")] + searcher.add_embedded(); + Self { root, library: Prehashed::new(typst_library::build()), @@ -617,6 +620,32 @@ impl FontSearcher { Self { book: FontBook::new(), fonts: vec![] } } + /// Add fonts that are embedded in the binary. + #[cfg(feature = "embed-fonts")] + fn add_embedded(&mut self) { + let mut add = |bytes: &[u8]| { + let buffer = Buffer::from(bytes); + for (i, font) in Font::iter(buffer).enumerate() { + self.book.push(font.info().clone()); + self.fonts.push(FontSlot { + path: PathBuf::new(), + index: i as u32, + font: OnceCell::from(Some(font)), + }); + } + }; + + // Embed default fonts. + add(include_bytes!("../../assets/fonts/LinLibertine_R.ttf")); + add(include_bytes!("../../assets/fonts/LinLibertine_RB.ttf")); + add(include_bytes!("../../assets/fonts/LinLibertine_RBI.ttf")); + add(include_bytes!("../../assets/fonts/LinLibertine_RI.ttf")); + add(include_bytes!("../../assets/fonts/NewCMMath-Book.otf")); + add(include_bytes!("../../assets/fonts/NewCMMath-Regular.otf")); + add(include_bytes!("../../assets/fonts/DejaVuSansMono.ttf")); + add(include_bytes!("../../assets/fonts/DejaVuSansMono-Bold.ttf")); + } + /// Search for fonts in the linux system font directories. #[cfg(all(unix, not(target_os = "macos")))] fn search_system(&mut self) { |
