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