|
|
|
@ -8,6 +8,12 @@ use std::{fs::OpenOptions, io::Write};
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "document.xml")]
|
|
|
|
|
struct DocumentTemplate {
|
|
|
|
|
dimensions: DocumentDimensions,
|
|
|
|
|
box_size: SVGMeasure,
|
|
|
|
|
positions: Vec<(SVGMeasure, SVGMeasure)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DocumentDimensions {
|
|
|
|
|
width: SVGMeasure,
|
|
|
|
|
height: SVGMeasure,
|
|
|
|
|
}
|
|
|
|
@ -18,16 +24,35 @@ enum Error {
|
|
|
|
|
Template(askama::Error),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn positions(size: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, count: u32) -> Vec<(SVGMeasure, SVGMeasure)> {
|
|
|
|
|
let grid = size + padding;
|
|
|
|
|
let row_count = ((dimensions.width - padding * 2.0) / grid) as u32;
|
|
|
|
|
(0..count)
|
|
|
|
|
.map(|i| (
|
|
|
|
|
grid * (i % row_count).into() + padding,
|
|
|
|
|
grid * (i / row_count).into() + padding,
|
|
|
|
|
))
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
|
let mut file = OpenOptions::new()
|
|
|
|
|
.write(true)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.create(true)
|
|
|
|
|
.open("output.svg")?;
|
|
|
|
|
let document = DocumentTemplate {
|
|
|
|
|
let dimensions = DocumentDimensions {
|
|
|
|
|
width: SVGMeasure::new(8.5, SVGUnit::Inch),
|
|
|
|
|
height: SVGMeasure::new(11.0, SVGUnit::Inch),
|
|
|
|
|
};
|
|
|
|
|
let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter);
|
|
|
|
|
let boxes = 54;
|
|
|
|
|
let padding = SVGMeasure::new(5.0, SVGUnit::Millimeter);
|
|
|
|
|
let document = DocumentTemplate {
|
|
|
|
|
positions: positions(box_size, padding, &dimensions, boxes),
|
|
|
|
|
dimensions,
|
|
|
|
|
box_size,
|
|
|
|
|
};
|
|
|
|
|
write!(file, "{}", document.render()?)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|