main.rs 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. mod opts;
  2. use crate::opts::Options;
  3. use clap::Parser;
  4. use thyme::{
  5. file::ThymeFile,
  6. data::Config,
  7. draw::Pattern,
  8. };
  9. use std::fs::File;
  10. fn main() -> Result<(), Box<dyn std::error::Error>> {
  11. // read the command-line options
  12. let opts = Options::parse();
  13. // load the thyme file
  14. let thyme = {
  15. let mut f = File::open(opts.file)?;
  16. ThymeFile::from_stream(&mut f)?
  17. };
  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(thyme.width),
  27. config.scale(thyme.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. }