main.rs 986 B

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