Update typst and related packages
This commit is contained in:
parent
a5f2efaf7d
commit
ea0cc4c7e3
4 changed files with 404 additions and 261 deletions
619
Cargo.lock
generated
619
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -10,7 +10,6 @@ edition = "2024"
|
||||||
anyhow = "1.0.96"
|
anyhow = "1.0.96"
|
||||||
axum = "0.8.1"
|
axum = "0.8.1"
|
||||||
clap = { version = "4.5.30", features = ["derive", "deprecated"] }
|
clap = { version = "4.5.30", features = ["derive", "deprecated"] }
|
||||||
comemo = "0.4.0"
|
|
||||||
cosmic-text = "0.12.1"
|
cosmic-text = "0.12.1"
|
||||||
escpos = "0.15.0"
|
escpos = "0.15.0"
|
||||||
image = "0.25.5"
|
image = "0.25.5"
|
||||||
|
|
@ -25,9 +24,9 @@ showbits-assets.path = "./showbits-assets"
|
||||||
showbits-common.path = "./showbits-common"
|
showbits-common.path = "./showbits-common"
|
||||||
time = "0.3.37"
|
time = "0.3.37"
|
||||||
tokio = "1.43.0"
|
tokio = "1.43.0"
|
||||||
typst = "0.11.0"
|
typst = "0.13.0"
|
||||||
typst-assets = { version = "0.11.0", features = ["fonts"] }
|
typst-assets = { version = "0.13.0", features = ["fonts"] }
|
||||||
typst-render = "0.11.0"
|
typst-render = "0.13.0"
|
||||||
|
|
||||||
[workspace.dependencies.taffy]
|
[workspace.dependencies.taffy]
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
comemo = { workspace = true }
|
|
||||||
cosmic-text = { workspace = true }
|
cosmic-text = { workspace = true }
|
||||||
image = { workspace = true }
|
image = { workspace = true }
|
||||||
mark = { workspace = true }
|
mark = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{fs, path::PathBuf, sync::OnceLock};
|
use std::{fs, path::PathBuf, sync::OnceLock};
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use comemo::Prehashed;
|
|
||||||
use image::RgbaImage;
|
use image::RgbaImage;
|
||||||
use taffy::{
|
use taffy::{
|
||||||
Layout,
|
Layout,
|
||||||
|
|
@ -10,11 +9,11 @@ use taffy::{
|
||||||
use typst::{
|
use typst::{
|
||||||
Library, World,
|
Library, World,
|
||||||
diag::{FileError, FileResult},
|
diag::{FileError, FileResult},
|
||||||
eval::Tracer,
|
|
||||||
foundations::{Bytes, Datetime},
|
foundations::{Bytes, Datetime},
|
||||||
layout::Abs,
|
layout::Abs,
|
||||||
syntax::{FileId, Source},
|
syntax::{FileId, Source},
|
||||||
text::{Font, FontBook},
|
text::{Font, FontBook},
|
||||||
|
utils::LazyHash,
|
||||||
visualize::Color,
|
visualize::Color,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -34,8 +33,8 @@ impl FontSlot {
|
||||||
pub fn get(&self) -> Option<Font> {
|
pub fn get(&self) -> Option<Font> {
|
||||||
self.font
|
self.font
|
||||||
.get_or_init(|| {
|
.get_or_init(|| {
|
||||||
let data = fs::read(&self.path).ok()?.into();
|
let data = fs::read(&self.path).ok()?;
|
||||||
Font::new(data, self.index)
|
Font::new(Bytes::new(data), self.index)
|
||||||
})
|
})
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +56,7 @@ impl FontLoader {
|
||||||
fn load_embedded_fonts(&mut self) {
|
fn load_embedded_fonts(&mut self) {
|
||||||
// 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() {
|
for font_file in typst_assets::fonts() {
|
||||||
let font_data = Bytes::from_static(font_file);
|
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 {
|
||||||
|
|
@ -71,8 +70,8 @@ impl FontLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DummyWorld {
|
struct DummyWorld {
|
||||||
library: Prehashed<Library>,
|
library: LazyHash<Library>,
|
||||||
book: Prehashed<FontBook>,
|
book: LazyHash<FontBook>,
|
||||||
main: Source,
|
main: Source,
|
||||||
fonts: Vec<FontSlot>,
|
fonts: Vec<FontSlot>,
|
||||||
}
|
}
|
||||||
|
|
@ -83,8 +82,8 @@ impl DummyWorld {
|
||||||
loader.load_embedded_fonts();
|
loader.load_embedded_fonts();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
library: Prehashed::new(Library::builder().build()),
|
library: LazyHash::new(Library::builder().build()),
|
||||||
book: Prehashed::new(loader.book),
|
book: LazyHash::new(loader.book),
|
||||||
main: Source::detached(main),
|
main: Source::detached(main),
|
||||||
fonts: loader.fonts,
|
fonts: loader.fonts,
|
||||||
}
|
}
|
||||||
|
|
@ -92,19 +91,22 @@ impl DummyWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl World for DummyWorld {
|
impl World for DummyWorld {
|
||||||
fn library(&self) -> &Prehashed<Library> {
|
fn library(&self) -> &LazyHash<Library> {
|
||||||
&self.library
|
&self.library
|
||||||
}
|
}
|
||||||
|
|
||||||
fn book(&self) -> &Prehashed<FontBook> {
|
fn book(&self) -> &LazyHash<FontBook> {
|
||||||
&self.book
|
&self.book
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(&self) -> Source {
|
fn main(&self) -> FileId {
|
||||||
self.main.clone()
|
self.main.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source(&self, _id: FileId) -> FileResult<Source> {
|
fn source(&self, id: FileId) -> FileResult<Source> {
|
||||||
|
if id == self.main.id() {
|
||||||
|
return Ok(self.main.clone());
|
||||||
|
}
|
||||||
Err(FileError::AccessDenied)
|
Err(FileError::AccessDenied)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,19 +151,15 @@ impl Typst {
|
||||||
source.push_str(&self.code);
|
source.push_str(&self.code);
|
||||||
|
|
||||||
let world = DummyWorld::new(source);
|
let world = DummyWorld::new(source);
|
||||||
let mut tracer = Tracer::new();
|
|
||||||
|
|
||||||
let document = typst::compile(&world, &mut tracer).map_err(|errs| {
|
let document = typst::compile(&world).output.map_err(|errs| {
|
||||||
errs.into_iter()
|
errs.into_iter()
|
||||||
.map(|sd| sd.message.to_string())
|
.map(|sd| sd.message.to_string())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let pixmap =
|
let pixmap = typst_render::render_merged(&document, SCALE, Abs::zero(), Some(Color::WHITE));
|
||||||
typst_render::render_merged(&document, SCALE, Color::WHITE, Abs::zero(), Color::WHITE);
|
|
||||||
|
|
||||||
let buffer = RgbaImage::from_raw(pixmap.width(), pixmap.height(), pixmap.take()).unwrap();
|
let buffer = RgbaImage::from_raw(pixmap.width(), pixmap.height(), pixmap.take()).unwrap();
|
||||||
|
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue