-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ members = ["tests"] | |
|
||
[workspace.package] | ||
version = "0.8.0" | ||
authors = ["Martin Haug <[email protected]>", "Laurenz Stampfl <[email protected]>"] | ||
authors = [ | ||
"Martin Haug <[email protected]>", | ||
"Laurenz Stampfl <[email protected]>", | ||
] | ||
edition = "2021" | ||
repository = "https://github.com/typst/svg2pdf" | ||
readme = "README.md" | ||
|
@@ -19,6 +22,7 @@ authors.workspace = true | |
edition.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
build = "build.rs" | ||
|
||
[features] | ||
default = ["image"] | ||
|
@@ -34,14 +38,23 @@ name = "svg2pdf" | |
path = "src/main.rs" | ||
required-features = ["cli"] | ||
|
||
[build-dependencies] | ||
clap = { version = "4.4.2", features = ["derive", "string"] } | ||
clap_complete = "4.4.3" | ||
clap_mangen = "0.2.14" | ||
|
||
[dependencies] | ||
miniz_oxide = "0.7" | ||
pdf-writer = "0.9" | ||
usvg = { version = "0.36", default-features = false } | ||
image = { version = "0.24", default-features = false, features = ["jpeg", "png", "gif"], optional = true } | ||
image = { version = "0.24", default-features = false, features = [ | ||
"jpeg", | ||
"png", | ||
"gif", | ||
], optional = true } | ||
termcolor = { version = "1", optional = true } | ||
clap = { version = "4.4.2", features = ["derive"], optional = true } | ||
fontdb = { version = "0.15", optional= true } | ||
fontdb = { version = "0.15", optional = true } | ||
|
||
[dev-dependencies] | ||
usvg = { version = "0.36.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{env, path::Path}; | ||
|
||
use clap::{CommandFactory, ValueEnum}; | ||
use clap_complete::{generate_to, Shell}; | ||
|
||
mod args { | ||
include!("src/cli.rs"); | ||
} | ||
|
||
fn main() -> Result<(), std::io::Error> { | ||
if !cfg!(feature = "cli") { | ||
return Ok(()); | ||
} | ||
|
||
let outdir_str = match env::var_os("OUT_DIR") { | ||
None => return Ok(()), | ||
Some(outdir) => outdir, | ||
}; | ||
|
||
// Put the files in the same level as the binary (e.g. /target/debug folder) | ||
let outdir_path = &Path::new(&outdir_str).ancestors().nth(3).unwrap(); | ||
|
||
let mut cmd = args::Args::command(); | ||
|
||
let man = clap_mangen::Man::new(cmd.clone()); | ||
let mut manpage_file = std::fs::File::create(outdir_path.join("svg2pdf.1"))?; | ||
man.render(&mut manpage_file)?; | ||
|
||
for shell in Shell::value_variants() { | ||
generate_to(*shell, &mut cmd, "svg2pdf", &outdir_path).unwrap(); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(about, version)] | ||
pub struct Args { | ||
/// Path to read SVG file from. | ||
pub input: PathBuf, | ||
/// Path to write PDF file to. | ||
pub output: Option<PathBuf>, | ||
/// The number of SVG pixels per PDF points. | ||
#[clap(long, default_value = "72.0")] | ||
pub dpi: f32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters