main.rs 995 B

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