summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-11-08 13:21:25 +0100
committerLaurenz <laurmaedje@gmail.com>2023-11-08 13:21:47 +0100
commit80b4ca4c04cb5d911947895d9d04c87efb97b0f4 (patch)
tree2de98314a524a0c5663408a51ccb13a5a74ddea4
parentec04c3de2fcc5b31d94dc2be8561e569f28cc0a1 (diff)
Extract `typst-svg` crate
-rw-r--r--Cargo.lock19
-rw-r--r--Cargo.toml1
-rw-r--r--crates/typst-cli/Cargo.toml1
-rw-r--r--crates/typst-cli/src/compile.rs2
-rw-r--r--crates/typst-svg/Cargo.toml27
-rw-r--r--crates/typst-svg/src/lib.rs (renamed from crates/typst/src/export/svg.rs)15
-rw-r--r--crates/typst/Cargo.toml2
-rw-r--r--crates/typst/src/export/mod.rs2
-rw-r--r--tests/Cargo.toml1
-rw-r--r--tests/src/tests.rs2
10 files changed, 56 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4da1e66d..50bb4347 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",
@@ -3081,6 +3080,21 @@ dependencies = [
]
[[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"
dependencies = [
@@ -3111,6 +3125,7 @@ dependencies = [
"typst",
"typst-library",
"typst-render",
+ "typst-svg",
"unscanny",
"walkdir",
]
diff --git a/Cargo.toml b/Cargo.toml
index b88d880b..08987494 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 9a96c6b2..6e270bd8 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 80e19f1b..9eec36cb 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 00000000..628c34f8
--- /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
index 06066428..c057566d 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 34063979..4a095509 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 ef24c97b..bdcc9c40 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 023776ea..cce7c6af 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 07dba177..3cf8aa1c 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();