summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--assets/fonts/NewCMMath-Book.otfbin0 -> 2161432 bytes
-rw-r--r--cli/Cargo.toml10
-rw-r--r--cli/src/main.rs29
-rw-r--r--src/util/buffer.rs12
-rw-r--r--tests/ref/compiler/content-field.pngbin2444 -> 2502 bytes
-rw-r--r--tests/ref/layout/enum-numbering.pngbin21461 -> 21548 bytes
-rw-r--r--tests/ref/math/accent.pngbin6686 -> 6816 bytes
-rw-r--r--tests/ref/math/attach.pngbin11096 -> 11366 bytes
-rw-r--r--tests/ref/math/cases.pngbin2982 -> 3134 bytes
-rw-r--r--tests/ref/math/content.pngbin8085 -> 8329 bytes
-rw-r--r--tests/ref/math/delimited.pngbin10731 -> 11282 bytes
-rw-r--r--tests/ref/math/frac.pngbin22213 -> 23154 bytes
-rw-r--r--tests/ref/math/matrix.pngbin7154 -> 7376 bytes
-rw-r--r--tests/ref/math/multiline.pngbin7949 -> 8165 bytes
-rw-r--r--tests/ref/math/numbering.pngbin13751 -> 14196 bytes
-rw-r--r--tests/ref/math/op.pngbin6032 -> 6228 bytes
-rw-r--r--tests/ref/math/root.pngbin9508 -> 9754 bytes
-rw-r--r--tests/ref/math/spacing.pngbin11600 -> 11992 bytes
-rw-r--r--tests/ref/math/style.pngbin23028 -> 23494 bytes
-rw-r--r--tests/ref/math/syntax.pngbin4633 -> 4719 bytes
-rw-r--r--tests/ref/math/underover.pngbin4757 -> 4877 bytes
-rw-r--r--tests/ref/math/vec.pngbin1608 -> 1668 bytes
-rw-r--r--tests/ref/meta/state.pngbin52360 -> 52409 bytes
24 files changed, 48 insertions, 8 deletions
diff --git a/README.md b/README.md
index 10ba1c9a..1a824601 100644
--- a/README.md
+++ b/README.md
@@ -113,11 +113,6 @@ typst file.typ
typst path/to/source.typ path/to/output.pdf
```
-To properly use Typst, you should also install the fonts "Linux Libertine" and
-"New Computer Modern Math". They are available as part of this repository in
-`assets/fonts` or you can install them through the package manager of your
-choice.
-
You can also watch source files and automatically recompile on changes. This is
faster than compiling from scratch each time because Typst has incremental
compilation.
diff --git a/assets/fonts/NewCMMath-Book.otf b/assets/fonts/NewCMMath-Book.otf
new file mode 100644
index 00000000..eeca1dde
--- /dev/null
+++ b/assets/fonts/NewCMMath-Book.otf
Binary files differ
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) {
diff --git a/src/util/buffer.rs b/src/util/buffer.rs
index da12b6cb..23fb9802 100644
--- a/src/util/buffer.rs
+++ b/src/util/buffer.rs
@@ -1,3 +1,4 @@
+use std::borrow::Cow;
use std::fmt::{self, Debug, Formatter};
use std::ops::Deref;
use std::sync::Arc;
@@ -6,9 +7,14 @@ use comemo::Prehashed;
/// A shared buffer that is cheap to clone and hash.
#[derive(Clone, Hash, Eq, PartialEq)]
-pub struct Buffer(Arc<Prehashed<Vec<u8>>>);
+pub struct Buffer(Arc<Prehashed<Cow<'static, [u8]>>>);
impl Buffer {
+ /// Create a buffer from a static byte slice.
+ pub fn from_static(slice: &'static [u8]) -> Self {
+ Self(Arc::new(Prehashed::new(Cow::Borrowed(slice))))
+ }
+
/// Return a view into the buffer.
pub fn as_slice(&self) -> &[u8] {
self
@@ -22,13 +28,13 @@ impl Buffer {
impl From<&[u8]> for Buffer {
fn from(slice: &[u8]) -> Self {
- Self(Arc::new(Prehashed::new(slice.to_vec())))
+ Self(Arc::new(Prehashed::new(slice.to_vec().into())))
}
}
impl From<Vec<u8>> for Buffer {
fn from(vec: Vec<u8>) -> Self {
- Self(Arc::new(Prehashed::new(vec)))
+ Self(Arc::new(Prehashed::new(vec.into())))
}
}
diff --git a/tests/ref/compiler/content-field.png b/tests/ref/compiler/content-field.png
index 8ad5566a..d2f696b4 100644
--- a/tests/ref/compiler/content-field.png
+++ b/tests/ref/compiler/content-field.png
Binary files differ
diff --git a/tests/ref/layout/enum-numbering.png b/tests/ref/layout/enum-numbering.png
index 4804d573..7c39da4f 100644
--- a/tests/ref/layout/enum-numbering.png
+++ b/tests/ref/layout/enum-numbering.png
Binary files differ
diff --git a/tests/ref/math/accent.png b/tests/ref/math/accent.png
index bea94cab..a87a684d 100644
--- a/tests/ref/math/accent.png
+++ b/tests/ref/math/accent.png
Binary files differ
diff --git a/tests/ref/math/attach.png b/tests/ref/math/attach.png
index aeab9af8..956199ca 100644
--- a/tests/ref/math/attach.png
+++ b/tests/ref/math/attach.png
Binary files differ
diff --git a/tests/ref/math/cases.png b/tests/ref/math/cases.png
index 87c358da..c9eca24c 100644
--- a/tests/ref/math/cases.png
+++ b/tests/ref/math/cases.png
Binary files differ
diff --git a/tests/ref/math/content.png b/tests/ref/math/content.png
index 92fe9860..433c8ddc 100644
--- a/tests/ref/math/content.png
+++ b/tests/ref/math/content.png
Binary files differ
diff --git a/tests/ref/math/delimited.png b/tests/ref/math/delimited.png
index 34b61a70..0670337f 100644
--- a/tests/ref/math/delimited.png
+++ b/tests/ref/math/delimited.png
Binary files differ
diff --git a/tests/ref/math/frac.png b/tests/ref/math/frac.png
index d0ac9c1a..fc8789b3 100644
--- a/tests/ref/math/frac.png
+++ b/tests/ref/math/frac.png
Binary files differ
diff --git a/tests/ref/math/matrix.png b/tests/ref/math/matrix.png
index fa6e53f3..d97d6ec1 100644
--- a/tests/ref/math/matrix.png
+++ b/tests/ref/math/matrix.png
Binary files differ
diff --git a/tests/ref/math/multiline.png b/tests/ref/math/multiline.png
index 1433ba30..94ef1196 100644
--- a/tests/ref/math/multiline.png
+++ b/tests/ref/math/multiline.png
Binary files differ
diff --git a/tests/ref/math/numbering.png b/tests/ref/math/numbering.png
index 3b9db84f..a06e2b0c 100644
--- a/tests/ref/math/numbering.png
+++ b/tests/ref/math/numbering.png
Binary files differ
diff --git a/tests/ref/math/op.png b/tests/ref/math/op.png
index ac93559c..b4878438 100644
--- a/tests/ref/math/op.png
+++ b/tests/ref/math/op.png
Binary files differ
diff --git a/tests/ref/math/root.png b/tests/ref/math/root.png
index 267249b0..ccd284a6 100644
--- a/tests/ref/math/root.png
+++ b/tests/ref/math/root.png
Binary files differ
diff --git a/tests/ref/math/spacing.png b/tests/ref/math/spacing.png
index 38d21026..921996b0 100644
--- a/tests/ref/math/spacing.png
+++ b/tests/ref/math/spacing.png
Binary files differ
diff --git a/tests/ref/math/style.png b/tests/ref/math/style.png
index 78cfe9b1..46d72662 100644
--- a/tests/ref/math/style.png
+++ b/tests/ref/math/style.png
Binary files differ
diff --git a/tests/ref/math/syntax.png b/tests/ref/math/syntax.png
index 442e8bfe..f223ba5a 100644
--- a/tests/ref/math/syntax.png
+++ b/tests/ref/math/syntax.png
Binary files differ
diff --git a/tests/ref/math/underover.png b/tests/ref/math/underover.png
index a585f59d..d090057d 100644
--- a/tests/ref/math/underover.png
+++ b/tests/ref/math/underover.png
Binary files differ
diff --git a/tests/ref/math/vec.png b/tests/ref/math/vec.png
index 20db1512..a8343d9a 100644
--- a/tests/ref/math/vec.png
+++ b/tests/ref/math/vec.png
Binary files differ
diff --git a/tests/ref/meta/state.png b/tests/ref/meta/state.png
index 86d9da4a..ca77fdc7 100644
--- a/tests/ref/meta/state.png
+++ b/tests/ref/meta/state.png
Binary files differ