summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml10
-rw-r--r--cli/src/main.rs29
2 files changed, 39 insertions, 0 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 97e2fa02..b91e15a5 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -27,3 +27,13 @@ pico-args = "0.4"
same-file = "1"
siphasher = "0.3"
walkdir = "2"
+
+[features]
+default = ["embed-fonts"]
+
+# Embeds Typst's default fonts for
+# - text (Linux Libertine),
+# - math (New Computer Modern Math), and
+# - code (Deja Vu Sans Mono)
+# into the binary.
+embed-fonts = []
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) {