Skip to content

Commit

Permalink
build: upgrade typst to v0.9.0 (#384)
Browse files Browse the repository at this point in the history
* build: upgrade typst to v0.9.0-pre

* build: update cargo.lock

* dev: init gradient support

* dev: improve gradient support

* dev: fix gradient support

* dev: bump cargo dependencies

* dev: fix error after bumping

* dev: review image updation

* dev: try fixing #378
+ #378

* dev(compiler): don't print content of FileSnapshot

* build: update cargo.lock

* dev: bump version

* dev: remove debug printing

* dev: apply changes
  • Loading branch information
Myriad-Dreamin authored Oct 31, 2023
1 parent d21c0d2 commit c9f185a
Show file tree
Hide file tree
Showing 230 changed files with 4,764 additions and 1,058 deletions.
914 changes: 480 additions & 434 deletions Cargo.lock

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ strip = true

# typesetting
pixglyph = "0.2"
typst = "0.8.0"
typst-library = "0.8.0"
typst-syntax = "0.8.0"
typst = "0.9.0"
typst-ide = "0.9.0"
typst-library = "0.9.0"
typst-syntax = "0.9.0"
ttf-parser = "0.19.2"

# general
Expand All @@ -86,7 +87,7 @@ bytemuck = "1"
comemo = "0.3"
dissimilar = "1.0"
elsa = "1.8.1"
ecow = "0.1"
ecow = "0.2"
fst = "0.4.7"
indexmap = "2"

Expand All @@ -103,11 +104,12 @@ tokio-tungstenite = "0.20.0"

# system
dirs = "5"
memmap2 = "0.7"
memmap2 = "0.9"
notify = "6"
path-clean = "1.0.1"
pathdiff = "0.2"
walkdir = "2"
instant = { version = "0.1", features = ["wasm-bindgen"] }

# web
js-sys = "^0.3"
Expand All @@ -127,17 +129,17 @@ image = { version = "0.24", default-features = false, features = [
"jpeg",
"gif",
] }
resvg = { version = "0.35", default-features = false, features = [
resvg = { version = "0.36", default-features = false, features = [
"raster-images",
] }
svgtypes = "0.11"
tiny-skia = "0.10.0"
svgtypes = "0.12"
tiny-skia = "0.11"
tiny-skia-path = "0.11"
usvg = { version = "0.35", default-features = false, features = ["text"] }
usvg = { version = "0.36", default-features = false, features = ["text"] }

# cryptography and processing
ansi-to-html = "0.1.3"
base64 = "0.21.0"
base64 = "0.21.2"
base64-serde = "0.7.0"
byteorder = "1.4.3"
data-url = "0.3.0"
Expand All @@ -152,7 +154,7 @@ rustc-hash = "1.1.0"
serde = { version = "1.0.188" }
serde_json = "1.0.106"
serde_with = { version = "3.3", features = ["base64"] }
serde-wasm-bindgen = "^0.5"
serde-wasm-bindgen = "^0.6"
sha2 = "0.10.6"
# todo: typst prevent it, we should notice and bump it later
siphasher = "0.3.10"
Expand Down Expand Up @@ -206,9 +208,14 @@ typst-ts-raster-exporter = { path = "exporter/raster" }
typst-ts-serde-exporter = { path = "exporter/serde" }
typst-ts-svg-exporter = { path = "exporter/svg" }

typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.8.0" }
typst-library = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.8.0" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.8.0" }
typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
typst-library = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
hayagriva = { git = "https://github.com/Myriad-Dreamin/hayagriva.git", branch = "typst.ts-v0.9.0" }

# typst = { path = "../typst/crates/typst" }
# typst-library = { path = "../typst/crates/typst-library" }
# typst-syntax = { path = "../typst/crates/typst-syntax" }
# typst-ide = { path = "../typst/crates/typst-ide" }
# hayagriva = { path = "../hayagriva" }
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true
[dependencies]
typst.workspace = true
typst-library.workspace = true
typst-ide.workspace = true

clap.workspace = true
clap_complete.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fn main() {
if !matches!(&opts.sub, Some(Subcommands::Compile(CompileArgs { trace: _trace @ Some(_), .. }))) {
builder
.filter_module("typst::", log::LevelFilter::Warn)
.filter_module("typst_library::", log::LevelFilter::Warn);
.filter_module("typst_library::", log::LevelFilter::Warn)
.filter_module("tracing::", log::LevelFilter::Off);
}
builder.init();
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/query_repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use typst_ts_core::TakeAs;
use crate::query::serialize;
use crate::CompileOnceArgs;

use typst::ide::autocomplete;
use typst::World;
use typst_ide::autocomplete;

#[derive(Helper, Validator)]
struct ReplContext {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Highlighter for ReplContext {
}
}

fn to_repl_completion_pair(item: typst::ide::Completion) -> Pair {
fn to_repl_completion_pair(item: typst_ide::Completion) -> Pair {
// we does not support code snippet
// let rep = item.apply.as_ref().unwrap_or(&item.label).into();
let rep = item.label.clone().into();
Expand Down
7 changes: 3 additions & 4 deletions compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ parking_lot.workspace = true
hex.workspace = true
sha2.workspace = true
flate2.workspace = true
instant = { version = "0.1", features = ["wasm-bindgen"] }
ecow.workspace = true
instant.workspace = true

serde.workspace = true
serde_json.workspace = true
serde-wasm-bindgen = { workspace = true, optional = true }

same-file = { version = "1", optional = true }

memmap2 = { workspace = true, optional = true }
dirs = { workspace = true, optional = true }
walkdir = { workspace = true, optional = true }
Expand Down Expand Up @@ -92,7 +91,7 @@ system-compile = [
"dep:notify",
"dep:log",
]
system-watch = ["dep:notify", "dep:tokio", "dep:same-file"]
system-watch = ["dep:notify", "dep:tokio"]
system = ["system-compile", "system-watch"]
dynamic-layout = ["dep:typst-ts-svg-exporter"]
__web = [
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub trait ShadowApi {
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T> {
self.map_shadow(file_path, content).at(Span::detached())?;
let res: Result<T, Box<Vec<typst::diag::SourceDiagnostic>>> = f(self);
let res: Result<T, ecow::EcoVec<typst::diag::SourceDiagnostic>> = f(self);
self.unmap_shadow(file_path).at(Span::detached())?;
res
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/service/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn color_stream() -> StandardStream {
/// Print diagnostic messages to the terminal.
pub fn print_diagnostics<'files, W: World + Files<'files, FileId = TypstFileId>>(
world: &'files W,
errors: Vec<SourceDiagnostic>,
errors: ecow::EcoVec<SourceDiagnostic>,
) -> Result<(), codespan_reporting::files::Error> {
let mut w = color_stream();
let config = term::Config {
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub trait DiagObserver {
/// Print diagnostic messages to the terminal.
fn print_diagnostics(
&self,
errors: Vec<SourceDiagnostic>,
errors: ecow::EcoVec<SourceDiagnostic>,
) -> Result<(), codespan_reporting::files::Error>;

/// Print status message to the terminal.
Expand Down Expand Up @@ -329,7 +329,7 @@ where
/// Print diagnostic messages to the terminal.
fn print_diagnostics(
&self,
errors: Vec<SourceDiagnostic>,
errors: ecow::EcoVec<SourceDiagnostic>,
) -> Result<(), codespan_reporting::files::Error> {
diag::print_diagnostics(self.world(), errors)
}
Expand Down Expand Up @@ -367,7 +367,7 @@ where
}
Err(errs) => {
self.print_status::<WITH_STATUS>(DiagStatus::Error(start.elapsed()));
let _err = self.print_diagnostics(*errs);
let _err = self.print_diagnostics(errs);
// todo: log in browser compiler
#[cfg(feature = "system-compile")]
if _err.is_err() {
Expand Down
27 changes: 26 additions & 1 deletion compiler/src/vfs/notify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::{collections::HashMap, path::Path};

use typst::diag::{FileError, FileResult};
Expand All @@ -15,9 +16,27 @@ struct NotifyFileRepr {
/// A file snapshot that is notified by some external source
///
/// Note: The error is boxed to avoid large stack size
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct FileSnapshot(Result<NotifyFileRepr, Box<FileError>>);

impl fmt::Debug for FileSnapshot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0.as_ref() {
Ok(v) => f
.debug_struct("FileSnapshot")
.field("mtime", &v.mtime)
.field(
"content",
&FileContent {
len: v.content.len(),
},
)
.finish(),
Err(e) => f.debug_struct("FileSnapshot").field("error", &e).finish(),
}
}
}

impl FileSnapshot {
/// Access the internal data of the file snapshot
#[inline]
Expand Down Expand Up @@ -245,3 +264,9 @@ impl<M: AccessModel> AccessModel for NotifyAccessModel<M> {
self.inner.content(src)
}
}

#[derive(Debug)]
#[allow(dead_code)]
struct FileContent {
len: usize,
}
17 changes: 9 additions & 8 deletions core/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub mod builtins {
use crate::{exporter_utils::map_err, AsOwnedBytes, AsOwnedString, AsWritable, Transformer};

use super::{utils, DynExporter, Exporter};
use ecow::EcoVec;
use typst::{diag::SourceResult, World};

pub struct GroupExporter<Input> {
Expand All @@ -73,7 +74,7 @@ pub mod builtins {

impl<I> Exporter<I> for GroupExporter<I> {
fn export(&self, world: &dyn World, output: Arc<I>) -> SourceResult<()> {
let mut errors = Vec::new();
let mut errors = EcoVec::new();

for f in &self.exporters {
utils::collect_err(&mut errors, f.export(world, output.clone()))
Expand All @@ -82,7 +83,7 @@ pub mod builtins {
if errors.is_empty() {
Ok(())
} else {
Err(Box::new(errors))
Err(errors)
}
}
}
Expand Down Expand Up @@ -237,21 +238,21 @@ pub mod builtins {

pub mod utils {
use core::fmt::Display;
use ecow::{eco_vec, EcoVec};
use typst::diag::{SourceDiagnostic, SourceResult};

pub fn collect_err(errors: &mut Vec<SourceDiagnostic>, res: SourceResult<()>) {
pub fn collect_err(errors: &mut EcoVec<SourceDiagnostic>, res: SourceResult<()>) {
if let Err(errs) = res {
let mut errs = *errs;
errors.append(&mut errs);
errors.extend(errs);
}
}

/// Convert the given error to a vector of source errors.
// todo: report the component position
pub fn map_err<E: Display>(e: E) -> Box<Vec<SourceDiagnostic>> {
Box::new(vec![SourceDiagnostic::error(
pub fn map_err<E: Display>(e: E) -> EcoVec<SourceDiagnostic> {
eco_vec![SourceDiagnostic::error(
typst::syntax::Span::detached(),
e.to_string(),
)])
)]
}
}
7 changes: 4 additions & 3 deletions core/src/font/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{ops::Deref, sync::Arc};

pub use ttf_parser::GlyphId;
use typst::font::Font;
use typst::geom::Axes;
// use typst::geom::Axes;
use typst::image::{Image as TypstImage, RasterFormat};

use crate::hash::item_hash128;
Expand Down Expand Up @@ -96,10 +96,11 @@ impl IGlyphProvider for FontGlyphProvider {
}

// convert to typst's image format
let glyph_image = TypstImage::new_raw(
// todo: verify result
let glyph_image = TypstImage::new(
raster.data.into(),
RasterFormat::Png.into(),
Axes::new(raster.width as u32, raster.height as u32),
// Axes::new(raster.width as u32, raster.height as u32),
None,
)
.ok()?;
Expand Down
Loading

0 comments on commit c9f185a

Please sign in to comment.