#![no_std]
#![deny(
clippy::all,
clippy::cargo,
clippy::nursery,
// clippy::restriction,
// clippy::pedantic
)]
#![allow(
clippy::suboptimal_flops,
clippy::redundant_pub_crate,
clippy::fallible_impl_from
)]
#![deny(missing_debug_implementations)]
#![deny(rustdoc::all)]
mod bold;
mod light;
mod regular;
#[derive(Debug)]
pub struct RasterizedChar {
raster: &'static [&'static [u8]],
height: usize,
width: usize,
}
impl RasterizedChar {
#[inline]
pub const fn raster(&self) -> &'static [&'static [u8]] {
self.raster
}
#[inline]
pub const fn height(&self) -> usize {
self.height
}
#[inline]
pub const fn width(&self) -> usize {
self.width
}
}
#[derive(Debug, Copy, Clone)]
#[repr(usize)]
pub enum FontWeight {
#[cfg(feature = "light")]
Light,
#[cfg(feature = "regular")]
Regular,
#[cfg(feature = "bold")]
Bold,
}
impl FontWeight {
#[inline]
pub const fn val(self) -> usize {
self as _
}
}
#[derive(Debug, Clone, Copy)]
#[repr(usize)]
pub enum RasterHeight {
#[cfg(feature = "size_16")]
Size16 = 16,
#[cfg(feature = "size_20")]
Size20 = 20,
#[cfg(feature = "size_24")]
Size24 = 24,
#[cfg(feature = "size_32")]
Size32 = 32,
}
impl RasterHeight {
#[inline]
pub const fn val(self) -> usize {
self as _
}
}
#[inline]
pub fn get_raster(c: char, style: FontWeight, size: RasterHeight) -> Option<RasterizedChar> {
let raster = match style {
#[cfg(feature = "light")]
FontWeight::Light => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::light::size_16::get_char(c),
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::light::size_20::get_char(c),
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::light::size_24::get_char(c),
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::light::size_32::get_char(c),
},
#[cfg(feature = "regular")]
FontWeight::Regular => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::regular::size_16::get_char(c),
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::regular::size_20::get_char(c),
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::regular::size_24::get_char(c),
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::regular::size_32::get_char(c),
},
#[cfg(feature = "bold")]
FontWeight::Bold => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::bold::size_16::get_char(c),
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::bold::size_20::get_char(c),
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::bold::size_24::get_char(c),
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::bold::size_32::get_char(c),
},
};
raster.map(|raster| RasterizedChar {
raster,
height: size.val(),
width: get_raster_width(style, size),
})
}
#[inline]
pub const fn get_raster_width(style: FontWeight, size: RasterHeight) -> usize {
match style {
#[cfg(feature = "light")]
FontWeight::Light => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::light::size_16::RASTER_WIDTH,
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::light::size_20::RASTER_WIDTH,
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::light::size_24::RASTER_WIDTH,
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::light::size_32::RASTER_WIDTH,
},
#[cfg(feature = "regular")]
FontWeight::Regular => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::regular::size_16::RASTER_WIDTH,
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::regular::size_20::RASTER_WIDTH,
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::regular::size_24::RASTER_WIDTH,
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::regular::size_32::RASTER_WIDTH,
},
#[cfg(feature = "bold")]
FontWeight::Bold => match size {
#[cfg(feature = "size_16")]
RasterHeight::Size16 => crate::bold::size_16::RASTER_WIDTH,
#[cfg(feature = "size_20")]
RasterHeight::Size20 => crate::bold::size_20::RASTER_WIDTH,
#[cfg(feature = "size_24")]
RasterHeight::Size24 => crate::bold::size_24::RASTER_WIDTH,
#[cfg(feature = "size_32")]
RasterHeight::Size32 => crate::bold::size_32::RASTER_WIDTH,
},
}
}