VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Render, SVG: vello_cpu and usvg without their text features: one skrifa, read-fonts and harfrust fewer in the engine
Lucas Leroux1e8f5025c6bf
diff --git a/Cargo.lock b/Cargo.lockindex f85d88263..03217449e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1383,24 +1383,13 @@ dependencies = ["bytemuck",]-[[package]]-name = "fontconfig-parser"-version = "0.5.8"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646"-dependencies = [- "roxmltree 0.20.0",-]-[[package]]name = "fontdb"version = "0.24.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2660c5e9157bf76d2db1294e4a9feba604ef610819a3b591088d0d8392a3290f"dependencies = [- "fontconfig-parser","log",- "memmap2","slotmap","tinyvec",]diff --git a/Cargo.toml b/Cargo.tomlindex 0d3fcb76f..a04729748 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -59,9 +59,14 @@ wasmi = { version = "2.0.0", default-features = false, features = ["std", "validwat = "1.228"# rendering / formats-vello_cpu = { version = "0.2", features = ["f32_pipeline"] }+# Without `text` (glyph runs, through glifo and a second skrifa): the renderer draws the outlines+# vectorcraft-text gives it. The other default features stay.+vello_cpu = { version = "0.2", default-features = false, features = ["std", "png", "u8_pipeline", "f32_pipeline"] }image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] }-usvg = "0.48"+# Without `text` and the system fonts (fontdb, harfrust and skrifa, at other versions than ours):+# SVG import reads `<text>` from the XML itself and never gives usvg a font. A test of the SVG+# crate turns `text` on.+usvg = { version = "0.48", default-features = false, features = ["svgz"] }# Without `simple-text` (its text shaping, the only user of rustybuzz and ttf-parser, which are# unmaintained, #1730): the PDF writer places glyphs itself. A test of the PDF crate turns it on.krilla = { version = "0.8", default-features = false, features = ["raster-images"] }diff --git a/crates/svg/Cargo.toml b/crates/svg/Cargo.tomlindex 1ac02e466..7b679365f 100644--- a/crates/svg/Cargo.toml+++ b/crates/svg/Cargo.toml@@ -33,6 +33,8 @@ skrifa = { workspace = true }# A variable font built in code (no font file is committed).vectorcraft-text = { workspace = true, features = ["test-fonts"] }resvg = { version = "0.45", default-features = false }+# usvg as a reference viewer that lays text out in a font (text_layout.rs).+usvg = { workspace = true, features = ["text"] }vectorcraft-testkit = { workspace = true }proptest = { workspace = true }image = { workspace = true }diff --git a/crates/svg/tests/import_details.rs b/crates/svg/tests/import_details.rsindex abd219723..b38e54648 100644--- a/crates/svg/tests/import_details.rs+++ b/crates/svg/tests/import_details.rs@@ -126,6 +126,27 @@ fn svg_images_import_as_vector_art() {assert!((boxes[1].x0 - 100.0).abs() < 1e-6 && (boxes[1].height() - 20.0).abs() < 1e-6, "{boxes:?}");}+/// usvg unpacks gzipped SVG images itself (its `svgz` feature, which the workspace keeps).+#[test]+fn svgz_images_import_as_vector_art() {+ let dir = folder("svgzimage");+ let inner =+ r##"<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10" viewBox="0 0 20 10"><rect width="10" height="10" fill="#f00"/></svg>"##;+ let gz = vectorcraft_svg::compress(inner);+ std::fs::write(dir.join("img").join("logo.svgz"), &gz).unwrap();+ let data = format!("data:image/svg+xml;base64,{}", vectorcraft_svg::base64_encode(&gz));+ let body =+ format!(r#"<image href="img/logo.svgz" x="10" y="10" width="40" height="20"/><image href="{data}" x="100" y="10" width="40" height="20"/>"#);+ let (d, w) = open_in(&dir, &body);+ assert!(w.is_empty(), "{w:?}");+ assert!(images(&d).is_empty());+ let mut boxes: Vec<Rect> = art(&d).iter().filter(|n| n.path_data().is_some()).filter_map(|n| n.geometric_bounds()).collect();+ boxes.sort_by(|a, b| a.x0.total_cmp(&b.x0));+ assert_eq!(boxes.len(), 2, "{:?}", art(&d));+ assert!((boxes[0].x0 - 10.0).abs() < 1e-6 && (boxes[0].width() - 20.0).abs() < 1e-6, "{boxes:?}");+ assert!((boxes[1].x0 - 100.0).abs() < 1e-6 && (boxes[1].height() - 20.0).abs() < 1e-6, "{boxes:?}");+}+#[test]fn nested_clips_intersect() {let body = r##"<defs><clipPath id="inner"><rect x="60" y="0" width="200" height="200"/></clipPath>