Compare commits

...

4 commits

8 changed files with 66 additions and 26 deletions

29
Cargo.lock generated
View file

@ -518,6 +518,7 @@ dependencies = [
"clap", "clap",
"clap_derive", "clap_derive",
"dyesub", "dyesub",
"svg-units",
] ]
[[package]] [[package]]
@ -584,6 +585,20 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "err-derive"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"rustversion",
"syn 1.0.109",
"synstructure",
]
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.2" version = "0.3.2"
@ -1963,7 +1978,7 @@ dependencies = [
name = "svg-units" name = "svg-units"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"derive_more", "err-derive",
"lazy_static", "lazy_static",
"regex", "regex",
"strum", "strum",
@ -2004,6 +2019,18 @@ dependencies = [
"syn 2.0.28", "syn 2.0.28",
] ]
[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"unicode-xid",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.47" version = "1.0.47"

View file

@ -1,3 +1,3 @@
[workspace] [workspace]
members = ["dyesub-tool", "dyesub-cli", "dyesub", "svg-units"] members = ["dyesub-tool", "dyesub-cli", "dyesub", "svg-units"]
resolver = "2" resolver = "2"

View file

@ -9,3 +9,4 @@ edition = "2021"
clap = "4.3.23" clap = "4.3.23"
clap_derive = "4.3.12" clap_derive = "4.3.12"
dyesub = { path = "../dyesub" } dyesub = { path = "../dyesub" }
svg-units = { path = "../svg-units" }

View file

@ -1,10 +1,8 @@
#![feature(path_file_prefix)]
use std::path::PathBuf; use std::path::PathBuf;
use clap::Parser; use clap::Parser;
use clap_derive::Parser; use clap_derive::Parser;
use dyesub::Result; use svg_units::SVGMeasure;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -14,9 +12,15 @@ struct Args {
/// Output SVG path /// Output SVG path
#[arg(short, long)] #[arg(short, long)]
output: Option<PathBuf>, output: Option<PathBuf>,
/// Page width
#[arg(long, default_value="11in")]
width: SVGMeasure,
/// Page height
#[arg(long, default_value="8.5in")]
height: SVGMeasure,
} }
fn main() -> Result<()> { fn main() -> dyesub::Result<()> {
let args = Args::parse(); let args = Args::parse();
let output = args.output.unwrap_or_else(|| { let output = args.output.unwrap_or_else(|| {
let mut path = args.input.clone(); let mut path = args.input.clone();

View file

@ -32,18 +32,14 @@ Updating `cargoHash`:
}; };
# nightly is required for function signal syntax in leptos # nightly is required for function signal syntax in leptos
# https://leptos-rs.github.io/leptos/02_getting_started.html # https://leptos-rs.github.io/leptos/02_getting_started.html
rust-bin = pkgs.rust-bin.nightly.latest.minimal; rust = pkgs.rust-bin.nightly.latest;
rust-binWasm = rust-bin.override { # binary for output binary derivations
targets = [ "wasm32-unknown-unknown" ]; # (doesn't include dev tooling e.g. clippy)
}; rust-bin = rust.minimal;
rustPlatform = pkgs.makeRustPlatform { rustPlatform = pkgs.makeRustPlatform {
cargo = rust-bin; cargo = rust-bin;
rustc = rust-bin; rustc = rust-bin;
}; };
rustPlatformWasm = pkgs.makeRustPlatform {
cargo = rust-binWasm;
rustc = rust-binWasm;
};
rustSettings = with pkgs; { rustSettings = with pkgs; {
src = ./.; src = ./.;
cargoHash = nixpkgs.lib.fakeHash; cargoHash = nixpkgs.lib.fakeHash;
@ -56,8 +52,9 @@ Updating `cargoHash`:
in { in {
devShells.${system}.default = with pkgs; mkShell { devShells.${system}.default = with pkgs; mkShell {
packages = [ packages = [
(rust-binWasm.override { (rust.default.override {
extensions = [ "rust-src" ]; extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
}) })
bacon bacon
]; ];
@ -69,13 +66,13 @@ Updating `cargoHash`:
pname = "dyesub-cli"; pname = "dyesub-cli";
version = "0.1.0"; version = "0.1.0";
buildAndTestSubdir = "dyesub-cli"; buildAndTestSubdir = "dyesub-cli";
cargoHash = "sha256-S4GvLg/B/FxjNyrQyBg25OMTgJVVBwPO+Dy/EFM4WoQ="; cargoHash = "sha256-6nbUjVjroFp2KZEk0wDisCUw2e9GtVxFgsGZm8xEe2A=";
meta = meta // { meta = meta // {
description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift keycaps."; description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift keycaps.";
}; };
}); });
dyesub-tool = let dyesub-tool = let
rustToolchain = pkgs.rust-bin.nightly.latest.minimal.override { rustToolchain = rust.minimal.override {
targets = [ "wasm32-unknown-unknown" ]; targets = [ "wasm32-unknown-unknown" ];
}; };
craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope' (final: prev: { craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope' (final: prev: {

View file

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
derive_more = "0.99.17" err-derive = "0.3.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1.9.3" regex = "1.9.3"
strum = "0.25.0" strum = "0.25.0"

View file

@ -2,7 +2,7 @@ mod unit;
pub use unit::SVGUnit; pub use unit::SVGUnit;
mod measure; mod measure;
pub use measure::SVGMeasure; pub use measure::{SVGMeasure, SVGMeasureParseError};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View file

@ -1,5 +1,5 @@
use super::SVGUnit; use super::SVGUnit;
use derive_more::From; use err_derive::Error;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -35,15 +35,18 @@ impl SVGMeasure {
} }
} }
#[derive(From, Debug)] #[derive(Debug, Error)]
pub enum SVGUnitParseError { pub enum SVGMeasureParseError {
ParseMeasure(ParseFloatError), #[error(display = "Failed to parse measure number")]
ParseUnit(ParseError), ParseMeasure(#[source] ParseFloatError),
#[error(display = "Failed to parse measure unit")]
ParseUnit(#[source] ParseError),
#[error(display = "Invalid measure format")]
Invalid, Invalid,
} }
impl FromStr for SVGMeasure { impl FromStr for SVGMeasure {
type Err = SVGUnitParseError; type Err = SVGMeasureParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
if s == "0" { if s == "0" {
return Ok(SVGMeasure::new(0.0, SVGUnit::Pixel)); return Ok(SVGMeasure::new(0.0, SVGUnit::Pixel));
@ -56,11 +59,19 @@ impl FromStr for SVGMeasure {
let unit = captures[2].parse::<SVGUnit>()?; let unit = captures[2].parse::<SVGUnit>()?;
Ok(SVGMeasure::new(measure, unit)) Ok(SVGMeasure::new(measure, unit))
} else { } else {
Err(SVGUnitParseError::Invalid) Err(SVGMeasureParseError::Invalid)
} }
} }
} }
impl<'s> TryFrom<&'s str> for SVGMeasure {
type Error = SVGMeasureParseError;
fn try_from(value: &'s str) -> Result<Self, Self::Error> {
Self::from_str(value)
}
}
const EQ_TOLERANCE: f64 = 0.00001; const EQ_TOLERANCE: f64 = 0.00001;
impl PartialEq for SVGMeasure { impl PartialEq for SVGMeasure {