mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Extract typst-svg
crate
This commit is contained in:
parent
ec04c3de2f
commit
80b4ca4c04
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -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",
|
||||
]
|
||||
|
@ -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"
|
||||
|
@ -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 }
|
||||
|
@ -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})"))?;
|
||||
}
|
||||
|
27
crates/typst-svg/Cargo.toml
Normal file
27
crates/typst-svg/Cargo.toml
Normal file
@ -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 }
|
@ -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.
|
@ -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]
|
||||
|
@ -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};
|
||||
|
@ -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 }
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user