use super::{FontMetrics, Glyph};
pub mod application12;
pub mod cairo18;
pub mod chicago12;
pub mod chicago9;
pub mod geneva10;
pub mod geneva12;
pub mod geneva14;
pub mod geneva18;
pub mod geneva24;
pub mod geneva9;
pub mod london18;
pub mod monaco10;
pub mod monaco12;
pub mod monaco9;
pub mod newyork12;
pub mod newyork14;
pub mod newyork18;
pub mod venice14;
pub struct GlyphSrc {
pub advance: u8,
pub origin_x: i8,
pub origin_y: i8,
pub rows: &'static [&'static str],
}
#[macro_export]
macro_rules! g {
($adv:expr, ($ox:expr, $oy:expr), $($row:literal)*) => {
$crate::quickdraw::fonts::pixel_font::GlyphSrc {
advance: $adv,
origin_x: $ox,
origin_y: $oy,
rows: &[$($row),*],
}
};
}
const fn glyph_width(g: &GlyphSrc) -> usize {
if g.rows.is_empty() {
0
} else {
g.rows[0].len()
}
}
pub const fn data_len(src: &[GlyphSrc]) -> usize {
let mut total = 0;
let mut i = 0;
while i < src.len() {
total += glyph_width(&src[i]) * src[i].rows.len();
i += 1;
}
total
}
pub const fn decode_glyphs<const N: usize>(src: &[GlyphSrc]) -> [Glyph; N] {
let mut out = [Glyph {
width: 0,
height: 0,
advance: 0,
origin_x: 0,
origin_y: 0,
data_offset: 0,
}; N];
let mut off = 0;
let mut i = 0;
while i < N {
let g = &src[i];
let w = glyph_width(g);
let h = g.rows.len();
out[i] = Glyph {
width: w as u8,
height: h as u8,
advance: g.advance,
origin_x: g.origin_x,
origin_y: g.origin_y,
data_offset: off,
};
off += w * h;
i += 1;
}
out
}
pub const fn decode_data<const LEN: usize>(src: &[GlyphSrc]) -> [u8; LEN] {
let mut out = [0u8; LEN];
let mut pos = 0;
let mut i = 0;
while i < src.len() {
let g = &src[i];
let w = glyph_width(g);
let mut r = 0;
while r < g.rows.len() {
let bytes = g.rows[r].as_bytes();
let mut c = 0;
while c < w {
out[pos] = if bytes[c] == b'#' { 255 } else { 0 };
pos += 1;
c += 1;
}
r += 1;
}
i += 1;
}
out
}
pub struct DecodedFace {
pub metrics: FontMetrics,
pub glyphs: &'static [Glyph],
pub data: &'static [u8],
}