|
@@ -1,5 +1,6 @@
|
|
|
use std::fs::File;
|
|
|
|
|
|
+use clap::Parser;
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
type Pixel = (u8, u8, u8);
|
|
@@ -126,16 +127,47 @@ impl Default for Config {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[derive(Parser, Debug)]
|
|
|
+#[clap(author, version, about, long_about = None)]
|
|
|
+struct Options {
|
|
|
+ image: String,
|
|
|
+ mapping: String,
|
|
|
+ output: Option<String>,
|
|
|
+
|
|
|
+ #[clap(long, default_value_t = 10)]
|
|
|
+ grid: u32,
|
|
|
+
|
|
|
+ #[clap(long, default_value_t = 1.0)]
|
|
|
+ line_weight: f64,
|
|
|
+
|
|
|
+ #[clap(long, default_value_t = 3.0)]
|
|
|
+ major_line_weight: f64,
|
|
|
+
|
|
|
+ #[clap(long, default_value_t = 24.0)]
|
|
|
+ size: f64,
|
|
|
+
|
|
|
+ #[clap(long, default_value_t = String::from("Fira Sans 12"))]
|
|
|
+ font: String,
|
|
|
+}
|
|
|
+
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
- let img = Image::load("sample.png")?;
|
|
|
- let mapping = Mapping::load("colors.yaml")?;
|
|
|
+ let opts = Options::parse();
|
|
|
+
|
|
|
+ let img = Image::load(opts.image)?;
|
|
|
+ let mapping = Mapping::load(opts.mapping)?;
|
|
|
|
|
|
- let config = Config::default();
|
|
|
+ let config = Config {
|
|
|
+ grid_every: opts.grid,
|
|
|
+ line_weight: opts.line_weight,
|
|
|
+ major_line_weight: opts.major_line_weight,
|
|
|
+ grid_size: opts.size,
|
|
|
+ font: opts.font.clone(),
|
|
|
+ };
|
|
|
|
|
|
let surf = cairo::SvgSurface::new(
|
|
|
config.scale(img.width),
|
|
|
config.scale(img.height),
|
|
|
- Some("output.svg"),
|
|
|
+ Some(opts.output.unwrap_or_else(|| "output.svg".to_string())),
|
|
|
)?;
|
|
|
|
|
|
let ctx = cairo::Context::new(&surf)?;
|