Skip to content

Commit

Permalink
Merge pull request #64 from LaurenzV/text-new
Browse files Browse the repository at this point in the history
Add support for text embedding and refactor crate structure a bit.
  • Loading branch information
LaurenzV committed Mar 30, 2024
2 parents 97274ce + 3a0e597 commit 948c590
Show file tree
Hide file tree
Showing 438 changed files with 4,324 additions and 3,798 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Added support for text embedding.
- The `convert_str` method has been removed. You should now always convert your SVG string into a `usvg`
tree yourself.
- The `convert_tree` method has been renamed into `to_pdf`, and now requires you to provide the fontdb
used for the `usvg` tree.
- `convert_tree_into` has been renamed into `to_chunk` and now returns an independent chunk as well
as the object ID of the SVG.

- TODO: The CLI options have been (temporarily) removed. They will be readded before the next release.
- TODO: Add tests for CLI and svg options
- TODO: Add CLI option to convert text to paths.
- TODO: Add CI test to test builds with different feature
- TODO: Add text feature?

### Changed
- Bumped resvg to v0.40.
Expand Down
26 changes: 20 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ oxipng = { version = "9", default-features = false, features = ["filetime", "par
pdf-writer = "0.9"
pdfium-render = "0.8.6"
termcolor = "1.2"
usvg = { version = "0.40", default-features = false, features = ["text"] }
usvg = { git = "https://github.com/RazrFalcon/resvg", default-features = false, features = ["text"] }
tiny-skia = "0.11.4"
resvg = "0.40"
unicode-properties = "0.1.1"
resvg = {git = "https://github.com/RazrFalcon/resvg"}
subsetter = "0.1.1"
ttf-parser = { version = "0.20.0" }
siphasher = { version = "1.0.1"}

[package]
name = "svg2pdf"
Expand All @@ -49,6 +53,7 @@ image = ["dep:image"]
filters = ["image", "dep:tiny-skia", "dep:resvg"]

[dependencies]
unicode-properties = { workspace = true }
miniz_oxide = { workspace = true }
once_cell = { workspace = true }
pdf-writer = { workspace = true }
Expand All @@ -57,3 +62,7 @@ log = { workspace = true }
image = { workspace = true, optional = true }
tiny-skia = {workspace = true, optional = true }
resvg = {workspace = true, optional = true }
subsetter = { workspace = true }
ttf-parser = { workspace = true }
siphasher = { workspace = true }

10 changes: 3 additions & 7 deletions cli/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ use svg2pdf::Options;

/// Execute a font listing command.
pub fn _convert(command: ConvertCommand) -> Result<(), String> {
convert_(&command.input, command.output, command.dpi)
convert_(&command.input, command.output)
}

pub fn convert_(
input: &PathBuf,
output: Option<PathBuf>,
dpi: f32,
) -> Result<(), String> {
pub fn convert_(input: &PathBuf, output: Option<PathBuf>) -> Result<(), String> {
if let Ok(()) = log::set_logger(&LOGGER) {
log::set_max_level(log::LevelFilter::Warn);
}
Expand All @@ -37,7 +33,7 @@ pub fn convert_(
let tree =
usvg::Tree::from_str(&svg, &options, &fontdb).map_err(|err| err.to_string())?;

let pdf = svg2pdf::convert_tree(&tree, Options { dpi, ..Options::default() });
let pdf = svg2pdf::to_pdf(&tree, Options::default(), &fontdb);

std::fs::write(output, pdf).map_err(|_| "Failed to write PDF file")?;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn run() -> Result<(), String> {

// If an input argument was provided, convert the svg file to pdf.
if let Some(input) = args.input {
return convert::convert_(&input, args.output, args.dpi);
return convert::convert_(&input, args.output);
};

// Otherwise execute the command provided if any.
Expand Down
Loading

0 comments on commit 948c590

Please sign in to comment.