From 4a85c9584877423a3549fbf1bdf9f4ab3a80ccfa Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Sat, 24 Nov 2018 15:38:41 +1100 Subject: [PATCH] Add 10, 12, 14pt sizes --- src/lib.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4bd4ac0..40f2826 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,81 @@ impl FontBuilderConf for ProFont9PointConf { /// The 9 point size. pub type ProFont9Point<'a, C> = FontBuilder<'a, C, ProFont9PointConf>; +#[derive(Debug, Copy, Clone)] +pub enum ProFont10PointConf {} +impl FontBuilderConf for ProFont10PointConf { + const FONT_IMAGE: &'static [u8] = include_bytes!("../data/ProFont10Point.raw"); + const CHAR_HEIGHT: u32 = 13; + const CHAR_WIDTH: u32 = 7; + const FONT_IMAGE_WIDTH: u32 = Self::CHAR_WIDTH * CHARS_PER_ROW; + fn char_offset(c: char) -> u32 { + let fallback = '?' as u32 - ' ' as u32; + if c < ' ' { + return fallback; + } + if c <= '~' { + return c as u32 - ' ' as u32; + } + if c < '¡' || c > 'ÿ' { + return fallback; + } + c as u32 - ' ' as u32 - 34 + } +} + +/// The 10 point size. +pub type ProFont10Point<'a, C> = FontBuilder<'a, C, ProFont10PointConf>; + +#[derive(Debug, Copy, Clone)] +pub enum ProFont12PointConf {} +impl FontBuilderConf for ProFont12PointConf { + const FONT_IMAGE: &'static [u8] = include_bytes!("../data/ProFont12Point.raw"); + const CHAR_HEIGHT: u32 = 15; + const CHAR_WIDTH: u32 = 8; + const FONT_IMAGE_WIDTH: u32 = Self::CHAR_WIDTH * CHARS_PER_ROW; + fn char_offset(c: char) -> u32 { + let fallback = '?' as u32 - ' ' as u32; + if c < ' ' { + return fallback; + } + if c <= '~' { + return c as u32 - ' ' as u32; + } + if c < '¡' || c > 'ÿ' { + return fallback; + } + c as u32 - ' ' as u32 - 34 + } +} + +/// The 12 point size. +pub type ProFont12Point<'a, C> = FontBuilder<'a, C, ProFont12PointConf>; + +#[derive(Debug, Copy, Clone)] +pub enum ProFont14PointConf {} +impl FontBuilderConf for ProFont14PointConf { + const FONT_IMAGE: &'static [u8] = include_bytes!("../data/ProFont14Point.raw"); + const CHAR_HEIGHT: u32 = 18; + const CHAR_WIDTH: u32 = 10; + const FONT_IMAGE_WIDTH: u32 = Self::CHAR_WIDTH * CHARS_PER_ROW; + fn char_offset(c: char) -> u32 { + let fallback = '?' as u32 - ' ' as u32; + if c < ' ' { + return fallback; + } + if c <= '~' { + return c as u32 - ' ' as u32; + } + if c < '¡' || c > 'ÿ' { + return fallback; + } + c as u32 - ' ' as u32 - 34 + } +} + +/// The 14 point size. +pub type ProFont14Point<'a, C> = FontBuilder<'a, C, ProFont14PointConf>; + #[derive(Debug, Copy, Clone)] pub enum ProFont18PointConf {} impl FontBuilderConf for ProFont18PointConf {