main.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 { thyme, config }.draw(cairo::Context::new(&surf)?)?;
  31. surf.finish();
  32. Ok(())
  33. }