From 20e0b8dd084d1e00ed606320a346c73eda70fc03 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 10:11:22 -0700 Subject: [PATCH] Show all letter keys, create Key struct --- dyesub-tool/src/key/mod.rs | 28 ++++++++++++++++++++++++ dyesub-tool/src/key/oyayubi.rs | 34 ++++++++++++++++++++++++++++++ dyesub-tool/src/main.rs | 30 ++++++++++++++------------ dyesub-tool/templates/document.xml | 13 ++++++++++-- 4 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 dyesub-tool/src/key/mod.rs create mode 100644 dyesub-tool/src/key/oyayubi.rs diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs new file mode 100644 index 0000000..52f710f --- /dev/null +++ b/dyesub-tool/src/key/mod.rs @@ -0,0 +1,28 @@ +mod oyayubi; +pub use oyayubi::OYAYUBI; + +use std::fmt::{Display, self}; + +pub struct Key { + pub latin: char, + pub normal: char, + pub shift: char, + pub alt_shift: Option, +} + +impl Display for Key { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.latin) + } +} + +impl Key { + const fn new(latin: char, normal: char, shift: char, alt_shift: Option) -> Self { + Self { + latin, + normal, + shift, + alt_shift, + } + } +} \ No newline at end of file diff --git a/dyesub-tool/src/key/oyayubi.rs b/dyesub-tool/src/key/oyayubi.rs new file mode 100644 index 0000000..d94a77c --- /dev/null +++ b/dyesub-tool/src/key/oyayubi.rs @@ -0,0 +1,34 @@ +use super::Key; + +pub const OYAYUBI: [Key; 30] = [ + Key::new('Q', '。', 'ぁ', None), + Key::new('W', 'か', 'え', None), + Key::new('E', 'た', 'り', None), + Key::new('R', 'こ', 'ゃ', None), + Key::new('T', 'さ', 'れ', None), + Key::new('Y', 'ら', 'よ', Some('ぱ')), + Key::new('U', 'ち', 'に', None), + Key::new('I', 'く', 'る', None), + Key::new('O', 'つ', 'ま', None), + Key::new('P', ',', 'ぇ', Some('ぴ')), + Key::new('A', 'う', 'を', None), + Key::new('S', 'し', 'あ', None), + Key::new('D', 'て', 'な', None), + Key::new('F', 'け', 'ゅ', None), + Key::new('G', 'せ', 'も', None), + Key::new('H', 'は', 'み', None), + Key::new('J', 'と', 'お', None), + Key::new('K', 'き', 'の', None), + Key::new('L', 'い', 'ょ', Some('ぽ')), + Key::new(';', 'ん', 'っ', None), // Missing + + Key::new('Z', '.', 'ぅ', None), + Key::new('X', 'ひ', 'ー', None), + Key::new('C', 'す', 'ろ', None), + Key::new('V', 'ふ', 'や', None), + Key::new('B', 'へ', 'ぃ', None), + Key::new('N', 'め', 'ぬ', Some('ぷ')), + Key::new('M', 'そ', 'ゆ', None), + Key::new(',', 'ね', 'む', Some('ぺ')), // Missing < + Key::new('.', 'ほ', 'わ', None), // Missing > + Key::new('?', '・', 'ぉ', Some('ゎ')) // Missing / +]; \ No newline at end of file diff --git a/dyesub-tool/src/main.rs b/dyesub-tool/src/main.rs index ba9def8..854d8f5 100644 --- a/dyesub-tool/src/main.rs +++ b/dyesub-tool/src/main.rs @@ -1,16 +1,19 @@ pub mod svg; use svg::*; +pub mod key; +use key::*; + use askama::Template; use derive_more::From; use std::{fs::OpenOptions, io::Write}; #[derive(Template)] #[template(path = "document.xml")] -struct DocumentTemplate { - dimensions: DocumentDimensions, +struct DocumentTemplate<'a> { + dimensions: &'a DocumentDimensions, box_size: SVGMeasure, - positions: Vec<(SVGMeasure, SVGMeasure)>, + positions: Vec<(&'a Key, (SVGMeasure, SVGMeasure))>, } struct DocumentDimensions { @@ -28,17 +31,19 @@ fn positions( size: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, - count: u32, -) -> Vec<(SVGMeasure, SVGMeasure)> { +) -> Vec<(&Key, (SVGMeasure, SVGMeasure))> { let grid = size + padding; let row_count = ((dimensions.width - padding * 2.0) / grid) as u32; - (0..count) - .map(|i| { + OYAYUBI + .iter() + .enumerate() + .map(|(i, key)| ( + key, ( - grid * (i % row_count).into() + padding, - grid * (i / row_count).into() + padding, + grid * (i as u32 % row_count).into() + padding, + grid * (i as u32 / row_count).into() + padding, ) - }) + )) .collect() } @@ -53,11 +58,10 @@ fn main() -> Result<(), Error> { height: SVGMeasure::new(11.0, SVGUnit::Inch), }; let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); - let boxes = 54; let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter); let document = DocumentTemplate { - positions: positions(box_size, padding, &dimensions, boxes), - dimensions, + positions: positions(box_size, padding, &dimensions), + dimensions: &dimensions, box_size, }; write!(file, "{}", document.render()?)?; diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index de05c53..7f7d4cb 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -4,10 +4,19 @@ - {% for (x, y) in positions %} + {% for (key, (x, y)) in positions %} - + {% let dy = "0.125em" %} + {% let font_size = "0.45cm" %} + {% let latin_font_size = "0.4cm" %} + {% let alt_shift_font_size = "0.325cm" %} + {{ key.latin }} + {{ key.shift }} + {{ key.normal }} + {% if let Some(alt_shift) = key.alt_shift %} + {{ alt_shift }} + {% endif %} {% endfor %}