-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(export::svg): reuse reference in a transformed item (#443)
* test: check bug in ieee rendering * fix(export::svg): reuse reference in a transformed item
- Loading branch information
1 parent
fea8842
commit f528532
Showing
5 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "typst-ts-incremental-test" | ||
authors.workspace = true | ||
version.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
typst.workspace = true | ||
typst-syntax.workspace = true | ||
comemo.workspace = true | ||
|
||
sha2.workspace = true | ||
anyhow.workspace = true | ||
tokio.workspace = true | ||
|
||
typst-ts-dev-server.workspace = true | ||
typst-ts-test-common.workspace = true | ||
typst-ts-core.workspace = true | ||
hex.workspace = true | ||
typst-ts-compiler.workspace = true | ||
typst-ts-svg-exporter.workspace = true | ||
|
||
[features] | ||
generate = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use std::path::Path; | ||
|
||
use typst::model::Document; | ||
use typst_ts_compiler::{ | ||
service::{CompileDriver, CompileExporter, Compiler}, | ||
ShadowApi, TypstSystemWorld, | ||
}; | ||
use typst_ts_core::{ | ||
config::CompileOpts, | ||
exporter_builtins::GroupExporter, | ||
vector::{ | ||
incr::{IncrDocClient, IncrDocServer}, | ||
ir::{Abs, Point, Rect}, | ||
stream::BytesModuleStream, | ||
}, | ||
}; | ||
use typst_ts_svg_exporter::IncrSvgDocClient; | ||
|
||
fn get_driver( | ||
workspace_dir: &Path, | ||
entry_file_path: &Path, | ||
exporter: GroupExporter<Document>, | ||
) -> CompileExporter<CompileDriver> { | ||
let project_base = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); | ||
let font_path = project_base.join("assets/fonts"); | ||
let world = TypstSystemWorld::new(CompileOpts { | ||
root_dir: workspace_dir.to_owned(), | ||
no_system_fonts: true, | ||
font_paths: vec![font_path], | ||
..CompileOpts::default() | ||
}) | ||
.unwrap(); | ||
|
||
let driver = CompileDriver { | ||
world, | ||
entry_file: entry_file_path.to_owned(), | ||
}; | ||
|
||
CompileExporter::new(driver).with_exporter(exporter) | ||
} | ||
|
||
pub fn test_compiler( | ||
workspace_dir: &Path, | ||
entry_file_path: &Path, | ||
exporter: GroupExporter<Document>, | ||
) { | ||
let mut driver = get_driver(workspace_dir, entry_file_path, exporter); | ||
let mut content = { std::fs::read_to_string(entry_file_path).expect("Could not read file") }; | ||
|
||
let mut incr_server = IncrDocServer::default(); | ||
let mut incr_client = IncrDocClient::default(); | ||
let mut incr_svg_client = IncrSvgDocClient::default(); | ||
|
||
let window = Rect { | ||
lo: Point::new(Abs::from(0.), Abs::from(0.)), | ||
hi: Point::new(Abs::from(1e33), Abs::from(1e33)), | ||
}; | ||
|
||
let mut diff = vec![]; | ||
|
||
// checkout the entry file | ||
let main_id = driver.main_id(); | ||
|
||
let doc = driver | ||
.with_shadow_file_by_id(main_id, content.as_bytes().into(), |driver| { | ||
driver.compile(&mut Default::default()) | ||
}) | ||
.unwrap(); | ||
let server_delta = incr_server.pack_delta(doc); | ||
let server_delta = BytesModuleStream::from_slice(&server_delta).checkout_owned(); | ||
incr_client.merge_delta(server_delta); | ||
|
||
for i in 0..200 { | ||
println!("Iteration {}", i); | ||
|
||
content = content.replace("@netwok2020", "@netwok2020 x"); | ||
|
||
let doc = driver | ||
.with_shadow_file_by_id(main_id, content.as_bytes().into(), |driver| { | ||
driver.compile(&mut Default::default()) | ||
}) | ||
.unwrap(); | ||
|
||
let server_delta = incr_server.pack_delta(doc); | ||
let sd = server_delta.len(); | ||
let server_delta = BytesModuleStream::from_slice(&server_delta).checkout_owned(); | ||
incr_client.merge_delta(server_delta); | ||
incr_client.set_layout(incr_client.doc.layouts[0].unwrap_single()); | ||
let cd = incr_svg_client.render_in_window(&mut incr_client, window); | ||
// std::fs::write(format!("{}.svg", i), cd.clone()).unwrap(); | ||
diff.push((sd, cd.len())); | ||
|
||
comemo::evict(10); | ||
} | ||
|
||
println!("diff: {:?}", diff); | ||
} | ||
|
||
pub fn main() { | ||
let workspace_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); | ||
let entry_file_path = workspace_dir.join("fuzzers/corpora/typst-templates/ieee/main.typ"); | ||
|
||
let noop_exporter = GroupExporter::new(vec![]); | ||
test_compiler(&workspace_dir, &entry_file_path, noop_exporter); | ||
} |