Load unifont fonts into typst
This commit is contained in:
parent
428b825e43
commit
49d6a2c022
3 changed files with 23 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2527,6 +2527,7 @@ dependencies = [
|
||||||
"image",
|
"image",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"showbits-assets",
|
||||||
"typst",
|
"typst",
|
||||||
"typst-assets",
|
"typst-assets",
|
||||||
"typst-render",
|
"typst-render",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ anyhow = { workspace = true }
|
||||||
image = { workspace = true }
|
image = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = "1.0.139"
|
serde_json = "1.0.139"
|
||||||
|
showbits-assets = { workspace = true }
|
||||||
typst = { workspace = true }
|
typst = { workspace = true }
|
||||||
typst-assets = { workspace = true }
|
typst-assets = { workspace = true }
|
||||||
typst-render = { workspace = true }
|
typst-render = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,9 @@ impl FontLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_embedded_fonts(&mut self) {
|
fn load_font_file(&mut self, data: &'static [u8]) {
|
||||||
// https://github.com/typst/typst/blob/be12762d942e978ddf2e0ac5c34125264ab483b7/crates/typst-cli/src/fonts.rs#L107-L121
|
// https://github.com/typst/typst/blob/be12762d942e978ddf2e0ac5c34125264ab483b7/crates/typst-cli/src/fonts.rs#L107-L121
|
||||||
for font_file in typst_assets::fonts() {
|
let font_data = Bytes::new(data);
|
||||||
let font_data = Bytes::new(font_file);
|
|
||||||
for (i, font) in Font::iter(font_data).enumerate() {
|
for (i, font) in Font::iter(font_data).enumerate() {
|
||||||
self.book.push(font.info().clone());
|
self.book.push(font.info().clone());
|
||||||
self.fonts.push(FontSlot {
|
self.fonts.push(FontSlot {
|
||||||
|
|
@ -66,6 +65,18 @@ impl FontLoader {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_embedded_fonts(&mut self) {
|
||||||
|
// https://github.com/typst/typst/blob/be12762d942e978ddf2e0ac5c34125264ab483b7/crates/typst-cli/src/fonts.rs#L107-L121
|
||||||
|
for font_file in typst_assets::fonts() {
|
||||||
|
self.load_font_file(font_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_unifonts(&mut self) {
|
||||||
|
self.load_font_file(showbits_assets::UNIFONT);
|
||||||
|
self.load_font_file(showbits_assets::UNIFONT_JP);
|
||||||
|
self.load_font_file(showbits_assets::UNIFONT_UPPER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +93,7 @@ impl Typst {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut loader = FontLoader::new();
|
let mut loader = FontLoader::new();
|
||||||
loader.load_embedded_fonts();
|
loader.load_embedded_fonts();
|
||||||
|
loader.load_unifonts();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
library: LazyHash::new(Library::default()),
|
library: LazyHash::new(Library::default()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue