|
|
|
@ -7,13 +7,14 @@ use key::*;
|
|
|
|
|
use askama::Template;
|
|
|
|
|
use derive_more::From;
|
|
|
|
|
use std::{fs::OpenOptions, io::Write};
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "document.xml")]
|
|
|
|
|
struct DocumentTemplate<'a> {
|
|
|
|
|
dimensions: &'a DocumentDimensions,
|
|
|
|
|
box_size: SVGMeasure,
|
|
|
|
|
positions: Vec<(&'a Key, (SVGMeasure, SVGMeasure))>,
|
|
|
|
|
positions: Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DocumentDimensions {
|
|
|
|
@ -27,24 +28,25 @@ enum Error {
|
|
|
|
|
Template(askama::Error),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn positions(
|
|
|
|
|
fn positions<'a>(
|
|
|
|
|
keys: &'a Vec<Key>,
|
|
|
|
|
size: SVGMeasure,
|
|
|
|
|
padding: SVGMeasure,
|
|
|
|
|
dimensions: &DocumentDimensions,
|
|
|
|
|
) -> Vec<(&Key, (SVGMeasure, SVGMeasure))> {
|
|
|
|
|
) -> Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))> {
|
|
|
|
|
let grid = size + padding;
|
|
|
|
|
let row_count = ((dimensions.width - padding * 2.0) / grid) as u32;
|
|
|
|
|
OYAYUBI
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.map(|(i, key)| (
|
|
|
|
|
key,
|
|
|
|
|
(
|
|
|
|
|
grid * (i as u32 % row_count).into() + padding,
|
|
|
|
|
grid * (i as u32 / row_count).into() + padding,
|
|
|
|
|
)
|
|
|
|
|
))
|
|
|
|
|
.collect()
|
|
|
|
|
let mut x = padding;
|
|
|
|
|
let mut y = padding;
|
|
|
|
|
let mut positions = Vec::with_capacity(keys.len());
|
|
|
|
|
for key in keys {
|
|
|
|
|
if x + grid > dimensions.width {
|
|
|
|
|
x = padding;
|
|
|
|
|
y = y + grid;
|
|
|
|
|
}
|
|
|
|
|
positions.push((key, (x, y)));
|
|
|
|
|
x = x + size * key.width_mod() + padding;
|
|
|
|
|
}
|
|
|
|
|
positions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
@ -60,10 +62,19 @@ fn main() -> Result<(), Error> {
|
|
|
|
|
let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter);
|
|
|
|
|
let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter);
|
|
|
|
|
let document = DocumentTemplate {
|
|
|
|
|
positions: positions(box_size, padding, &dimensions),
|
|
|
|
|
positions: positions(&KEYS, box_size, padding, &dimensions),
|
|
|
|
|
dimensions: &dimensions,
|
|
|
|
|
box_size,
|
|
|
|
|
};
|
|
|
|
|
write!(file, "{}", document.render()?)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref KEYS: Vec<Key<'static>> = {
|
|
|
|
|
let mut keys = OYAYUBI.to_vec();
|
|
|
|
|
keys.push(single("親指左", 3.0));
|
|
|
|
|
keys.push(single("親指右", 3.0));
|
|
|
|
|
keys
|
|
|
|
|
};
|
|
|
|
|
}
|