Show all letter keys, create Key struct

main
Elnu 1 year ago
parent 31b9a88edb
commit 20e0b8dd08

@ -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<char>,
}
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<char>) -> Self {
Self {
latin,
normal,
shift,
alt_shift,
}
}
}

@ -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 /
];

@ -1,16 +1,19 @@
pub mod svg; pub mod svg;
use svg::*; use svg::*;
pub mod key;
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};
#[derive(Template)] #[derive(Template)]
#[template(path = "document.xml")] #[template(path = "document.xml")]
struct DocumentTemplate { struct DocumentTemplate<'a> {
dimensions: DocumentDimensions, dimensions: &'a DocumentDimensions,
box_size: SVGMeasure, box_size: SVGMeasure,
positions: Vec<(SVGMeasure, SVGMeasure)>, positions: Vec<(&'a Key, (SVGMeasure, SVGMeasure))>,
} }
struct DocumentDimensions { struct DocumentDimensions {
@ -28,17 +31,19 @@ fn positions(
size: SVGMeasure, size: SVGMeasure,
padding: SVGMeasure, padding: SVGMeasure,
dimensions: &DocumentDimensions, dimensions: &DocumentDimensions,
count: u32, ) -> Vec<(&Key, (SVGMeasure, SVGMeasure))> {
) -> Vec<(SVGMeasure, SVGMeasure)> {
let grid = size + padding; let grid = size + padding;
let row_count = ((dimensions.width - padding * 2.0) / grid) as u32; let row_count = ((dimensions.width - padding * 2.0) / grid) as u32;
(0..count) OYAYUBI
.map(|i| { .iter()
.enumerate()
.map(|(i, key)| (
key,
( (
grid * (i % row_count).into() + padding, grid * (i as u32 % row_count).into() + padding,
grid * (i / row_count).into() + padding, grid * (i as u32 / row_count).into() + padding,
) )
}) ))
.collect() .collect()
} }
@ -53,11 +58,10 @@ fn main() -> Result<(), Error> {
height: SVGMeasure::new(11.0, SVGUnit::Inch), height: SVGMeasure::new(11.0, SVGUnit::Inch),
}; };
let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter);
let boxes = 54;
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, boxes), positions: positions(box_size, padding, &dimensions),
dimensions, dimensions: &dimensions,
box_size, box_size,
}; };
write!(file, "{}", document.render()?)?; write!(file, "{}", document.render()?)?;

@ -4,10 +4,19 @@
<defs> <defs>
<style type="text/css"><![CDATA[@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@700&display=swap');]]></style> <style type="text/css"><![CDATA[@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@700&display=swap');]]></style>
</defs> </defs>
{% for (x, y) in positions %} {% for (key, (x, y)) in positions %}
<g x="{{ x }}" y="{{ y }}" transform="translate({{ x.to_user_units() }},{{ y.to_user_units() }})" width="{{ box_size }}" height="{{ box_size }}"> <g x="{{ x }}" y="{{ y }}" transform="translate({{ x.to_user_units() }},{{ y.to_user_units() }})" width="{{ box_size }}" height="{{ box_size }}">
<rect width="{{ box_size }}" height="{{ box_size }}" fill="none" stroke="#cccccc" stroke-width="1pt" rx="2mm" /> <rect width="{{ box_size }}" height="{{ box_size }}" fill="none" stroke="#cccccc" stroke-width="1pt" rx="2mm" />
<text x="{{ box_size / 2.0 }}" y="{{ box_size / 2.0 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="0.5cm"></text> {% let dy = "0.125em" %}
{% let font_size = "0.45cm" %}
{% let latin_font_size = "0.4cm" %}
{% let alt_shift_font_size = "0.325cm" %}
<text x="{{ box_size * 0.25 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ latin_font_size }}" dy="{{ dy }}">{{ key.latin }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ key.shift }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.75 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ key.normal }}</text>
{% if let Some(alt_shift) = key.alt_shift %}
<text x="{{ box_size / 2.0 }}" y="{{ box_size / 2.0 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ alt_shift_font_size }}" dy="{{ dy }}">{{ alt_shift }}</text>
{% endif %}
</g> </g>
{% endfor %} {% endfor %}
</svg> </svg>

Before

Width:  |  Height:  |  Size: 804 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Loading…
Cancel
Save