Getty Ritter 2 年之前
父节点
当前提交
4f4af17502
共有 3 个文件被更改,包括 119 次插入6 次删除
  1. 103 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 15 6
      src/main.rs

+ 103 - 0
Cargo.lock

@@ -20,6 +20,17 @@ version = "1.0.52"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
 
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.0.1"
@@ -71,6 +82,21 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
+[[package]]
+name = "clap"
+version = "3.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375"
+dependencies = [
+ "atty",
+ "bitflags",
+ "indexmap",
+ "os_str_bytes",
+ "strsim",
+ "termcolor",
+ "textwrap",
+]
+
 [[package]]
 name = "crc32fast"
 version = "1.3.0"
@@ -275,6 +301,15 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
 
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "indexmap"
 version = "1.8.0"
@@ -297,6 +332,12 @@ version = "0.5.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
 
+[[package]]
+name = "memchr"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
+
 [[package]]
 name = "miniz_oxide"
 version = "0.4.4"
@@ -313,6 +354,15 @@ version = "1.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
 
+[[package]]
+name = "os_str_bytes"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
+dependencies = [
+ "memchr",
+]
+
 [[package]]
 name = "pango"
 version = "0.15.2"
@@ -498,6 +548,12 @@ version = "1.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
 
+[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
 [[package]]
 name = "syn"
 version = "1.0.86"
@@ -522,6 +578,21 @@ dependencies = [
  "version-compare",
 ]
 
+[[package]]
+name = "termcolor"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.14.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
+
 [[package]]
 name = "thiserror"
 version = "1.0.30"
@@ -547,6 +618,7 @@ name = "thyme"
 version = "0.1.0"
 dependencies = [
  "cairo-rs",
+ "clap",
  "pango",
  "pangocairo",
  "png",
@@ -587,6 +659,37 @@ version = "0.9.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
 
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
 [[package]]
 name = "yaml-rust"
 version = "0.4.5"

+ 1 - 0
Cargo.toml

@@ -12,3 +12,4 @@ pango = "*"
 pangocairo = "*"
 serde = { version = "*", features = ["derive"] }
 serde_yaml = "*"
+clap = "*"

+ 15 - 6
src/main.rs

@@ -25,7 +25,6 @@ impl Mapping {
     }
 }
 
-
 struct Image {
     width: u32,
     height: u32,
@@ -58,7 +57,7 @@ impl Image {
         Ok(Image {
             width: info.width,
             height: info.height,
-            data
+            data,
         })
     }
 }
@@ -69,6 +68,7 @@ struct Config {
     line_weight: f64,
     major_line_weight: f64,
     grid_size: f64,
+    font: String,
 }
 
 impl Config {
@@ -84,6 +84,7 @@ impl Default for Config {
             line_weight: 1.0,
             major_line_weight: 3.0,
             grid_size: 24.0,
+            font: "Fira Sans 12".to_string(),
         }
     }
 }
@@ -107,7 +108,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
     ctx.paint()?;
 
     let layout = pangocairo::functions::create_layout(&ctx).unwrap();
-    let font = pango::FontDescription::from_string("Fira Sans 12");
+    let font = pango::FontDescription::from_string(&config.font);
     layout.set_width(2880);
     layout.set_font_description(Some(&font));
 
@@ -115,13 +116,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
     for i in 0..=img.width {
         ctx.move_to(config.scale(i), 0.0);
         ctx.line_to(config.scale(i), config.scale(img.height));
-        ctx.set_line_width(if i % config.grid_every == 0 { config.major_line_weight } else { config.line_weight });
+        ctx.set_line_width(if i % config.grid_every == 0 {
+            config.major_line_weight
+        } else {
+            config.line_weight
+        });
         ctx.stroke()?;
     }
     for j in 0..=img.height {
         ctx.move_to(0.0, config.scale(j));
         ctx.line_to(config.scale(img.width), config.scale(j));
-        ctx.set_line_width(if j % config.grid_every == 0 { config.major_line_weight } else { config.line_weight });
+        ctx.set_line_width(if j % config.grid_every == 0 {
+            config.major_line_weight
+        } else {
+            config.line_weight
+        });
         ctx.stroke()?;
     }
 
@@ -136,7 +145,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
             y += 1;
         }
 
-        if l != "" {
+        if !l.is_empty() {
             ctx.move_to(config.scale(x - 1) + 5.0, config.scale(y) + 3.0);
             layout.set_text(l);
             pangocairo::functions::show_layout(&ctx, &layout);