main.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. mod opts;
  2. use crate::opts::Options;
  3. use clap::Parser;
  4. use thyme::{
  5. data::{Config, Mapping},
  6. draw::Pattern,
  7. file::ThymeFile,
  8. image::Image,
  9. };
  10. fn main() -> Result<(), Box<dyn std::error::Error>> {
  11. // read the command-line options
  12. let opts = Options::parse();
  13. // load the PNG image for the pattern
  14. let image = Image::load(opts.image)?;
  15. // load the color map file
  16. let mapping = Mapping::load(opts.mapping, &image)?;
  17. let thyme = ThymeFile::from_image_and_config(&image, &mapping);
  18. let config = Config {
  19. grid_every: opts.grid,
  20. line_weight: opts.line_weight,
  21. major_line_weight: opts.major_line_weight,
  22. grid_size: opts.size,
  23. font: opts.font.clone(),
  24. };
  25. let surf = cairo::SvgSurface::new(
  26. config.scale(image.width),
  27. config.scale(image.height),
  28. Some(opts.output.unwrap_or_else(|| "output.svg".to_string())),
  29. )?;
  30. Pattern {
  31. thyme,
  32. config,
  33. }
  34. .draw(cairo::Context::new(&surf)?)?;
  35. surf.finish();
  36. Ok(())
  37. }