main.rs 904 B

12345678910111213141516171819202122232425262728293031323334353637
  1. mod opts;
  2. use crate::opts::Options;
  3. use clap::Parser;
  4. use std::fs::File;
  5. use thyme::{data::Config, draw::Pattern, file::ThymeFile};
  6. fn main() -> Result<(), Box<dyn std::error::Error>> {
  7. // read the command-line options
  8. let opts = Options::parse();
  9. // load the thyme file
  10. let thyme = {
  11. let mut f = File::open(opts.file)?;
  12. ThymeFile::from_stream(&mut f)?
  13. };
  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(thyme.width),
  23. config.scale(thyme.height),
  24. Some(opts.output.unwrap_or_else(|| "output.svg".to_string())),
  25. )?;
  26. Pattern { thyme, config }.draw(cairo::Context::new(&surf)?)?;
  27. surf.finish();
  28. Ok(())
  29. }