letters.rs

1.9 kB · rust · 73 lines

1use super::glyphs::{DIGITS, EXTRAS, SPECIALS, UPPERS};2use super::models::Glyph;34/// Blanks the four corner cells of an uppercase bitmap into its rounded lowercase form.5pub fn lower(rows: &[&str]) -> Vec<String> {6    let mut grid: Vec<Vec<char>> = rows.iter().map(|row| row.chars().collect()).collect();7    let last = grid.len() - 1;8    let right = grid[0].len() - 1;9    for &y in &[0, last] {10        grid[y][0] = '0';11        grid[y][right] = '0';12    }13    grid.into_iter()14        .map(|row| row.into_iter().collect())15        .collect()16}1718fn rows_of(rows: &[&str]) -> Vec<String> {19    rows.iter().map(|row| row.to_string()).collect()20}2122/// Builds the twenty-six uppercase glyphs.23pub fn uppers() -> Vec<Glyph> {24    UPPERS25        .iter()26        .map(|&(c, rows)| Glyph::new(c, rows_of(rows)))27        .collect()28}2930/// Builds the twenty-six lowercase glyphs by rounding the uppers' corners.31pub fn lowers() -> Vec<Glyph> {32    UPPERS33        .iter()34        .map(|&(c, rows)| {35            let lowered = c.to_ascii_lowercase();36            Glyph::new(lowered, lower(rows))37        })38        .collect()39}4041/// Builds the ten digit glyphs.42pub fn digits() -> Vec<Glyph> {43    DIGITS44        .iter()45        .map(|&(c, rows)| Glyph::new(c, rows_of(rows)))46        .collect()47}4849/// Builds the punctuation, symbol and arrow glyphs.50pub fn extras() -> Vec<Glyph> {51    EXTRAS52        .iter()53        .map(|&(c, rows)| Glyph::new(c, rows_of(rows)))54        .collect()55}5657/// Builds the four seven-row glyphs: dollar, at, copyright and registered.58pub fn specials() -> Vec<Glyph> {59    SPECIALS60        .iter()61        .map(|&(c, rows)| Glyph::new(c, rows_of(rows)))62        .collect()63}6465/// Builds every glyph in font order: uppers, lowers, digits, extras, specials.66pub fn all() -> Vec<Glyph> {67    let mut glyphs = uppers();68    glyphs.extend(lowers());69    glyphs.extend(digits());70    glyphs.extend(extras());71    glyphs.extend(specials());72    glyphs73}