#![cfg_attr(not(test), no_std)]
pub mod char_offset;
pub use char_offset::{CHARS_PER_ROW, char_offset_impl};
#[cfg(feature = "regular8x8")]
pub const IBM437_8X8_REGULAR_DATA: &[u8] = include_bytes!("fonts/ibm437_font_8_8_regular.raw");
#[cfg(feature = "bold8x8")]
pub const IBM437_8X8_BOLD_DATA: &[u8] = include_bytes!("fonts/ibm437_font_8_8_bold.raw");
#[cfg(feature = "regular9x14")]
pub const IBM437_9X14_REGULAR_DATA: &[u8] = include_bytes!("fonts/ibm437_font_9_14_regular.raw");
#[cfg(feature = "embedded-graphics-backend")]
mod eg_backend {
use embedded_graphics::{
geometry::Size,
image::ImageRaw,
mono_font::{DecorationDimensions, MonoFont},
};
use crate::char_offset::{CHARS_PER_ROW, char_offset_impl};
#[cfg(feature = "regular8x8")]
pub const IBM437_8X8_REGULAR: MonoFont = MonoFont {
image: ImageRaw::new(
include_bytes!("fonts/ibm437_font_8_8_regular.raw"),
CHARS_PER_ROW as u32 * 8,
),
glyph_mapping: &char_offset_impl,
character_size: Size::new(8, 8),
character_spacing: 0,
baseline: 6,
underline: DecorationDimensions::new(8, 1),
strikethrough: DecorationDimensions::default_strikethrough(8),
};
#[cfg(feature = "bold8x8")]
pub const IBM437_8X8_BOLD: MonoFont = MonoFont {
image: ImageRaw::new(
include_bytes!("fonts/ibm437_font_8_8_bold.raw"),
CHARS_PER_ROW as u32 * 8,
),
glyph_mapping: &char_offset_impl,
character_size: Size::new(8, 8),
character_spacing: 0,
baseline: 6,
underline: DecorationDimensions::new(8, 1),
strikethrough: DecorationDimensions::default_strikethrough(8),
};
#[cfg(feature = "regular9x14")]
pub const IBM437_9X14_REGULAR: MonoFont = MonoFont {
image: ImageRaw::new(
include_bytes!("fonts/ibm437_font_9_14_regular.raw"),
CHARS_PER_ROW as u32 * 9,
),
glyph_mapping: &char_offset_impl,
character_size: Size::new(9, 14),
character_spacing: 0,
baseline: 10,
underline: DecorationDimensions::new(14, 1),
strikethrough: DecorationDimensions::default_strikethrough(14),
};
}
#[cfg(feature = "embedded-graphics-backend")]
pub use eg_backend::*;
#[cfg(feature = "framebuffer")]
pub mod framebuffer;
#[cfg(all(test, feature = "embedded-graphics-backend"))]
mod test {
use super::*;
use embedded_graphics::{
mock_display::MockDisplay,
mono_font::{MonoTextStyle, MonoTextStyleBuilder},
pixelcolor::BinaryColor,
prelude::*,
text::Text,
};
#[test]
fn test_a() {
let mut display = MockDisplay::new();
assert_eq!(char_offset_impl('a'), 'a' as usize);
let style = MonoTextStyle::new(&IBM437_8X8_REGULAR, BinaryColor::On);
Text::new("a", Point::new(0, 6), style)
.draw(&mut display)
.unwrap();
assert_eq!(
display,
MockDisplay::from_pattern(&[
" ",
" ",
" #### ",
" # ",
" ##### ",
" # # ",
" ###### ",
" ",
])
);
}
#[test]
fn test_nbsp() {
let mut display = MockDisplay::new();
assert_eq!(char_offset_impl('\u{A0}'), '\u{A0}' as usize);
let style = MonoTextStyleBuilder::new()
.font(&IBM437_8X8_REGULAR)
.text_color(BinaryColor::On)
.background_color(BinaryColor::Off)
.build();
Text::new("\u{A0}", Point::new(0, 6), style)
.draw(&mut display)
.unwrap();
assert_eq!(
display,
MockDisplay::from_pattern(&[
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
])
);
}
#[test]
fn test_space() {
let mut display = MockDisplay::new();
assert_eq!(char_offset_impl(' '), ' ' as usize);
let style = MonoTextStyleBuilder::new()
.font(&IBM437_8X8_REGULAR)
.text_color(BinaryColor::On)
.background_color(BinaryColor::Off)
.build();
Text::new(" ", Point::new(0, 6), style)
.draw(&mut display)
.unwrap();
assert_eq!(
display,
MockDisplay::from_pattern(&[
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
"........ ",
])
);
}
}