diff --git a/Cargo.lock b/Cargo.lock index 4da1e66d2..50bb43472 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2930,8 +2930,6 @@ dependencies = [ "unscanny", "usvg", "wasmi", - "xmlparser", - "xmlwriter", "xmp-writer", ] @@ -2974,6 +2972,7 @@ dependencies = [ "typst", "typst-library", "typst-render", + "typst-svg", "ureq", "xz2", "zip", @@ -3080,6 +3079,21 @@ dependencies = [ "usvg", ] +[[package]] +name = "typst-svg" +version = "0.9.0" +dependencies = [ + "base64", + "comemo", + "ecow", + "flate2", + "tracing", + "ttf-parser", + "typst", + "xmlparser", + "xmlwriter", +] + [[package]] name = "typst-syntax" version = "0.9.0" @@ -3111,6 +3125,7 @@ dependencies = [ "typst", "typst-library", "typst-render", + "typst-svg", "unscanny", "walkdir", ] diff --git a/Cargo.toml b/Cargo.toml index b88d880bc..089874945 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ typst = { path = "crates/typst" } typst-library = { path = "crates/typst-library" } typst-macros = { path = "crates/typst-macros" } typst-render = { path = "crates/typst-render" } +typst-svg = { path = "crates/typst-svg" } typst-syntax = { path = "crates/typst-syntax" } az = "1.2" base64 = "0.21.2" diff --git a/crates/typst-cli/Cargo.toml b/crates/typst-cli/Cargo.toml index 9a96c6b2f..6e270bd8b 100644 --- a/crates/typst-cli/Cargo.toml +++ b/crates/typst-cli/Cargo.toml @@ -23,6 +23,7 @@ doc = false typst = { workspace = true } typst-library = { workspace = true } typst-render = { workspace = true } +typst-svg = { workspace = true } chrono = { workspace = true } clap = { workspace = true } codespan-reporting = { workspace = true } diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 80e19f1b7..9eec36cb4 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -226,7 +226,7 @@ fn export_image( .map_err(|err| eco_format!("failed to write PNG file ({err})"))?; } ImageExportFormat::Svg => { - let svg = typst::export::svg(frame); + let svg = typst_svg::svg(frame); fs::write(path, svg.as_bytes()) .map_err(|err| eco_format!("failed to write SVG file ({err})"))?; } diff --git a/crates/typst-svg/Cargo.toml b/crates/typst-svg/Cargo.toml new file mode 100644 index 000000000..628c34f8d --- /dev/null +++ b/crates/typst-svg/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "typst-svg" +description = "SVG exporter for Typst." +version.workspace = true +rust-version.workspace = true +authors.workspace = true +edition.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +categories.workspace = true +keywords.workspace = true + +[lib] +doctest = false +bench = false + +[dependencies] +typst = { workspace = true } +base64 = { workspace = true } +comemo = { workspace = true } +ecow = { workspace = true} +flate2 = { workspace = true } +tracing = { workspace = true } +ttf-parser = { workspace = true } +xmlparser = { workspace = true } +xmlwriter = { workspace = true } diff --git a/crates/typst/src/export/svg.rs b/crates/typst-svg/src/lib.rs similarity index 99% rename from crates/typst/src/export/svg.rs rename to crates/typst-svg/src/lib.rs index 060664286..c057566d6 100644 --- a/crates/typst/src/export/svg.rs +++ b/crates/typst-svg/src/lib.rs @@ -6,18 +6,17 @@ use std::io::Read; use base64::Engine; use ecow::{eco_format, EcoString}; use ttf_parser::{GlyphId, OutlineBuilder}; -use xmlwriter::XmlWriter; - -use crate::doc::{Frame, FrameItem, FrameKind, GroupItem, TextItem}; -use crate::eval::Repr; -use crate::font::Font; -use crate::geom::{ +use typst::doc::{Frame, FrameItem, FrameKind, GroupItem, TextItem}; +use typst::eval::Repr; +use typst::font::Font; +use typst::geom::{ self, Abs, Angle, Axes, Color, FixedStroke, Geometry, Gradient, LineCap, LineJoin, Paint, PathItem, Point, Quadrant, Ratio, RatioOrAngle, Relative, Shape, Size, Transform, }; -use crate::image::{Image, ImageFormat, RasterFormat, VectorFormat}; -use crate::util::hash128; +use typst::image::{Image, ImageFormat, RasterFormat, VectorFormat}; +use typst::util::hash128; +use xmlwriter::XmlWriter; /// The number of segments in a conic gradient. /// This is a heuristic value that seems to work well. diff --git a/crates/typst/Cargo.toml b/crates/typst/Cargo.toml index 340639797..4a0955096 100644 --- a/crates/typst/Cargo.toml +++ b/crates/typst/Cargo.toml @@ -53,8 +53,6 @@ unicode-segmentation = { workspace = true } unscanny = { workspace = true } usvg = { workspace = true } wasmi = { workspace = true } -xmlparser = { workspace = true } -xmlwriter = { workspace = true } xmp-writer = { workspace = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/typst/src/export/mod.rs b/crates/typst/src/export/mod.rs index ef24c97b0..bdcc9c406 100644 --- a/crates/typst/src/export/mod.rs +++ b/crates/typst/src/export/mod.rs @@ -1,7 +1,5 @@ //! Exporting into external formats. mod pdf; -mod svg; pub use self::pdf::{pdf, PdfPageLabel, PdfPageLabelStyle}; -pub use self::svg::{svg, svg_merged}; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 023776eac..cce7c6af9 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -10,6 +10,7 @@ publish = false typst = { workspace = true } typst-library = { workspace = true } typst-render = { workspace = true } +typst-svg = { workspace = true } clap = { workspace = true } comemo = { workspace = true } ecow = { workspace = true } diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 07dba1778..3cf8aa1c8 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -439,7 +439,7 @@ fn test( fs::create_dir_all(png_path.parent().unwrap()).unwrap(); canvas.save_png(png_path).unwrap(); - let svg = typst::export::svg_merged(&document.pages, Abs::pt(5.0)); + let svg = typst_svg::svg_merged(&document.pages, Abs::pt(5.0)); fs::create_dir_all(svg_path.parent().unwrap()).unwrap(); std::fs::write(svg_path, svg.as_bytes()).unwrap();