From a25246faf8760e29cb9f462c24aac7599393fca9 Mon Sep 17 00:00:00 2001 From: Dominic Date: Tue, 8 Jun 2021 20:46:32 +0200 Subject: [PATCH] use macro for the test code --- codegen/templates/tests.in | 219 +- tests/generated.rs | 13258 +++++++++++++---------------------- 2 files changed, 4961 insertions(+), 8516 deletions(-) diff --git a/codegen/templates/tests.in b/codegen/templates/tests.in index 98e97917..3b85d247 100644 --- a/codegen/templates/tests.in +++ b/codegen/templates/tests.in @@ -1,113 +1,122 @@ // @generated +macro_rules! test_font { + ($mod:ident: { + font: $font:ident, + width: $width:literal, + height: $height:literal, + m_pattern: $m_pattern:expr, + {%- for range in char_ranges %} + char_range_{{ loop.index }}_pattern: $char_range_{{ loop.index }}_pattern:expr, + {%- endfor %} + fallback_pattern: $fallback_pattern:expr + }) => { + mod $mod { + use bitmap_font::*; + use embedded_graphics::{ + drawable::Drawable, + fonts::Text, + geometry::{Dimensions, Point, Size}, + mock_display::MockDisplay, + pixelcolor::BinaryColor, + transform::Transform + }; + + #[test] + fn font_size() { + assert_eq!($font.width(), $width); + assert_eq!($font.height(), $height); + } + + #[test] + fn text_empty_size() { + let size = Text::new("", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::zero()); + } + + #[test] + fn text_a_size() { + let size = Text::new("a", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::new($width, $height)); + } + + #[test] + fn text_multiline_size() { + let size = Text::new("aa\naaa\na", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::new(3 * $width, 3 * $height)); + } + + #[test] + fn text_translate() { + let mut text = Text::new("M", Point::zero()) + .with_font($font, BinaryColor::On); + text.translate_mut(Point::new(2, 2)); + assert_eq!(text.top_left(), Point::new(2, 2)); + assert_eq!(text.bottom_right(), Point::new(2 + $width, 2 + $height)); + + let mut display = MockDisplay::new(); + text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); + assert_eq!(display, MockDisplay::from_pattern($m_pattern)); + } + + {%- for range in char_ranges %} + + #[test] + fn text_char_range_{{ loop.index }}() { + let mut display = MockDisplay::new(); + Text::new("{{ range.start }}{{ range.mid }}{{ range.end }}", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_{{ loop.index }}_pattern)); + } + {%- endfor %} + + #[test] + fn text_fallback() { + let mut display = MockDisplay::new(); + Text::new("€?µ", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display,MockDisplay::from_pattern($fallback_pattern)); + } + } + }; +} + {%- for font in fonts %} -mod font_{{ font.width }}x{{ font.height }}{% if font.bold %}_bold{% endif %} { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_{{ font.width }}x{{ font.height }}{% if font.bold %}_BOLD{% endif %}; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), {{ font.width }}); - assert_eq!(FONT.height(), {{ font.height }}); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new({{ font.width }}, {{ font.height }})); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new({{ 3*font.width }}, {{ 3*font.height }})); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new({{ 2+font.width }}, {{ 2+font.height }})); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "{% for x in 0..font.width+5 %} {% endfor %}", - {%- for y in 0..font.height %} - " {{ font.glyph('M').mock_line(y) }}", - {%- endfor %} - ]) - ); - } - - {%- for range in char_ranges %} - - #[test] - fn text_char_range_{{ loop.index }}() { - let mut display = MockDisplay::new(); - Text::new("{{ range.start }}{{ range.mid }}{{ range.end }}", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - {%- for y in 0..font.height %} - "{{ font.glyph(range.start).mock_line(y) }}{{ font.glyph(range.mid).mock_line(y) }}{{ font.glyph(range.end).mock_line(y) }}", - {%- endfor %} - ]) - ); - } - {%- endfor %} - - {%- if 2*font.height < 64 %} - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - {%- for y in 0..font.height %} - "{{ font.glyph('?').mock_line(y) }}{{ font.glyph('?').mock_line(y) }}", - {%- endfor %} - {%- for y in 0..font.height %} - "{{ font.glyph(' ').mock_line(y) }}{{ font.glyph('?').mock_line(y) }}", - {%- endfor %} - ]) - ); +test_font! { + font_{{ font.width }}x{{ font.height }}{% if font.bold %}_bold{% endif %}: { + font: FONT_{{ font.width }}x{{ font.height }}{% if font.bold %}_BOLD{% endif %}, + width: {{ font.width }}, + height: {{ font.height }}, + m_pattern: &[ + "{% for x in 0..font.width+5 %} {% endfor %}", + {%- for y in 0..font.height %} + " {{ font.glyph('M').mock_line(y) }}", + {%- endfor %} + ], + {%- for range in char_ranges %} + char_range_{{ loop.index }}_pattern: &[ + {%- for y in 0..font.height %} + "{{ font.glyph(range.start).mock_line(y) }}{{ font.glyph(range.mid).mock_line(y) }}{{ font.glyph(range.end).mock_line(y) }}", + {%- endfor %} + ], + {%- endfor %} + fallback_pattern: &[ + {%- for y in 0..font.height %} + "{{ font.glyph('?').mock_line(y) }}{{ font.glyph('?').mock_line(y) }}{{ font.glyph('?').mock_line(y) }}", + {%- endfor %} + ] } - {%- endif %} } {%- endfor %} diff --git a/tests/generated.rs b/tests/generated.rs index c59d20c0..597f1602 100644 --- a/tests/generated.rs +++ b/tests/generated.rs @@ -1,8497 +1,4933 @@ // @generated -mod font_5x9 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform +macro_rules! test_font { + ($mod:ident: { + font: $font:ident, + width: $width:literal, + height: $height:literal, + m_pattern: $m_pattern:expr, + char_range_1_pattern: $char_range_1_pattern:expr, + char_range_2_pattern: $char_range_2_pattern:expr, + char_range_3_pattern: $char_range_3_pattern:expr, + char_range_4_pattern: $char_range_4_pattern:expr, + char_range_5_pattern: $char_range_5_pattern:expr, + fallback_pattern: $fallback_pattern:expr + }) => { + mod $mod { + use bitmap_font::*; + use embedded_graphics::{ + drawable::Drawable, + fonts::Text, + geometry::{Dimensions, Point, Size}, + mock_display::MockDisplay, + pixelcolor::BinaryColor, + transform::Transform + }; + + #[test] + fn font_size() { + assert_eq!($font.width(), $width); + assert_eq!($font.height(), $height); + } + + #[test] + fn text_empty_size() { + let size = Text::new("", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::zero()); + } + + #[test] + fn text_a_size() { + let size = Text::new("a", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::new($width, $height)); + } + + #[test] + fn text_multiline_size() { + let size = Text::new("aa\naaa\na", Point::zero()) + .with_font($font, BinaryColor::On) + .size(); + assert_eq!(size, Size::new(3 * $width, 3 * $height)); + } + + #[test] + fn text_translate() { + let mut text = Text::new("M", Point::zero()) + .with_font($font, BinaryColor::On); + text.translate_mut(Point::new(2, 2)); + assert_eq!(text.top_left(), Point::new(2, 2)); + assert_eq!(text.bottom_right(), Point::new(2 + $width, 2 + $height)); + + let mut display = MockDisplay::new(); + text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); + assert_eq!(display, MockDisplay::from_pattern($m_pattern)); + } + + #[test] + fn text_char_range_1() { + let mut display = MockDisplay::new(); + Text::new(" O~", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_1_pattern)); + } + + #[test] + fn text_char_range_2() { + let mut display = MockDisplay::new(); + Text::new("¡¤¦", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_2_pattern)); + } + + #[test] + fn text_char_range_3() { + let mut display = MockDisplay::new(); + Text::new("°°°", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_3_pattern)); + } + + #[test] + fn text_char_range_4() { + let mut display = MockDisplay::new(); + Text::new("¿ßÿ", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_4_pattern)); + } + + #[test] + fn text_char_range_5() { + let mut display = MockDisplay::new(); + Text::new("", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display, MockDisplay::from_pattern($char_range_5_pattern)); + } + + #[test] + fn text_fallback() { + let mut display = MockDisplay::new(); + Text::new("€?µ", Point::zero()) + .with_font($font, BinaryColor::On) + .draw(&mut display) + .unwrap(); + assert_eq!(display,MockDisplay::from_pattern($fallback_pattern)); + } + } }; - - const FONT: BitmapFont = FONT_5x9; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 5); - assert_eq!(FONT.height(), 9); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(5, 9)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(15, 27)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(7, 11)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # # ", - " #### ", - " # # ", - " # # ", - " # # ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## # ", - " # # # ## ", - " # # ", - " # # ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " # # # ", - " ## # ", - " # # # # ", - " # # ", - " # ## # ", - " # # # # ", - " # # ", - " # ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ## ", - "# # # # # # ", - " ## ## ## ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " # # ", - " ### ", - " # # # # # ", - " # # # # ", - " # # # # # ", - " # # # ### ", - "# # ", - " ### ## ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "########### ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - "### ### ", - " # # ", - " # # ", - " # # ", - " ", - " # # ", - " ", - " ", - " ", - " ### ", - " # ", - " # ", - " # ", - " ", - " # ", - " ", - " ", - ]) - ); - } } -mod font_5x9_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_5x9_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 5); - assert_eq!(FONT.height(), 9); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(5, 9)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(15, 27)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(7, 11)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # # ", - " #### ", - " #### ", - " # # ", - " # # ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " # # ", - " ## #### ", - " ## # # # ", - " ## # ", - " ## # ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ## # ## ", - " ## ## ", - " ## ## # ## ", - " ## # ", - " ## ## ## ", - " ## ## # ## ", - " ## ## ", - " ## ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ## ", - "## # ## # ## # ", - " ## ## ## ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " # # ", - " ### ", - " ## ## # ## # ", - " ### ## # ", - " ## ## # ## # ", - "## ### ### ", - "## # ## ", - " ## ## ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "########### ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ## ## ", - "# ## # ## ", - " ## ## ", - " ## ## ", - " ", - " ## ## ", - " ", - " ", - " ", - " ## ", - " # ## ", - " ## ", - " ## ", - " ", - " ## ", - " ", - " ", - ]) - ); +test_font! { + font_5x9: { + font: FONT_5x9, + width: 5, + height: 9, + m_pattern: &[ + " ", + " ", + " ", + " # # ", + " #### ", + " # # ", + " # # ", + " # # ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ## ## # ", + " # # # ## ", + " # # ", + " # # ", + " ## ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " # # # ", + " ## # ", + " # # # # ", + " # # ", + " # ## # ", + " # # # # ", + " # # ", + " # ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ## ## ## ", + "# # # # # # ", + " ## ## ## ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " # # ", + " ### ", + " # # # # # ", + " # # # # ", + " # # # # # ", + " # # # ### ", + "# # ", + " ### ## ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "########### ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + "### ### ### ", + " # # # ", + " # # # ", + " # # # ", + " ", + " # # # ", + " ", + " ", + ] } } -mod font_6x12 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_6x12; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 6); - assert_eq!(FONT.height(), 12); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(6, 12)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(18, 36)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(8, 14)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # # ", - " ## ## ", - " # # # ", - " # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### # # ", - " # # # # # ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " ### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " # ", - " # ", - " # # # # ", - " ### # ", - " # # ", - " # ### # ", - " # # # # ", - " # # ", - " # # ", - " # ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ## ", - "# # # # # # ", - "# # # # # # ", - " ## ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### # # ", - " # # # ", - " # # # # ", - " # ## # # ", - " # # # # # ", - " # # # # # ", - "# # ## #### ", - "# # # ", - " ### ### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "############# ", - "############# ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ### ### ", - "# # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " # # ", - " ", - " ", - " ", - " ", - " ### ", - " # # ", - " # ", - " # ", - " # ", - " ", - " ", - " # ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_5x9_bold: { + font: FONT_5x9_BOLD, + width: 5, + height: 9, + m_pattern: &[ + " ", + " ", + " ", + " # # ", + " #### ", + " #### ", + " # # ", + " # # ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " # # ", + " ## #### ", + " ## # # # ", + " ## # ", + " ## # ", + " ## ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ## # ## ", + " ## ## ", + " ## ## # ## ", + " ## # ", + " ## ## ## ", + " ## ## # ## ", + " ## ## ", + " ## ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ## ## ## ", + "## # ## # ## # ", + " ## ## ## ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " # # ", + " ### ", + " ## ## # ## # ", + " ### ## # ", + " ## ## # ## # ", + "## ### ### ", + "## # ## ", + " ## ## ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "########### ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ## ## ## ", + "# ## # ## # ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ## ## ## ", + " ", + " ", + ] } } -mod font_6x12_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_6x12_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 6); - assert_eq!(FONT.height(), 12); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(6, 12)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(18, 36)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(8, 14)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # # ", - " ## ## ", - " ##### ", - " ##### ", - " # # # ", - " # # ", - " # # ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### ## # ", - " ## # ##### ", - " ## # # ## ", - " ## # ", - " ## # ", - " ## # ", - " ### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ## ", - " ## # ## ", - " ## ### ## ", - " ## # ## ", - " ## # ", - " ## ### ## ", - " ## ## # ## ", - "#### ## ", - "#### ## ", - " ## ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### ### ### ", - "## # ## # ## # ", - "## # ## # ## # ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ### ## ## ", - " ## # ## ## ", - " ## ## # ", - " ## # ## # ", - " ## # ## # ", - " ## ## # ## # ", - " ## ## # ## # ", - "## ## # #### ", - "## # ## ## ", - " ### ### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "############# ", - "############# ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ### ### ", - "# ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ", - " ", - " ", - " ", - " ### ", - " # ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_6x12: { + font: FONT_6x12, + width: 6, + height: 12, + m_pattern: &[ + " ", + " ", + " ", + " # # ", + " ## ## ", + " # # # ", + " # # # ", + " # # ", + " # # ", + " # # ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ### # # ", + " # # # # # ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " ### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " # ", + " # ", + " # # # # ", + " ### # ", + " # # ", + " # ### # ", + " # # # # ", + " # # ", + " # # ", + " # ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ## ## ## ", + "# # # # # # ", + "# # # # # # ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ### # # ", + " # # # ", + " # # # # ", + " # ## # # ", + " # # # # # ", + " # # # # # ", + "# # ## #### ", + "# # # ", + " ### ### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "############# ", + "############# ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ### ### ### ", + "# # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " # # # ", + " ", + " ", + " ", + ] } } -mod font_7x13 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_7x13; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 7); - assert_eq!(FONT.height(), 13); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(7, 13)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(21, 39)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(9, 15)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " # # ", - " ## ## ", - " # # # ", - " # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### # # ", - " # # # # # ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " ### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " # ", - " # ", - " # # # # ", - " ### # ", - " # # ", - " # ### # ", - " # # # # ", - " # # ", - " # # ", - " # ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ## ## ", - " # # # # # # ", - " # # # # # # ", - " ## ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### # # ", - " # # # ", - " # # # # ", - " # ## # # ", - " # # # # # ", - " # # # # # ", - " # # ## #### ", - " # # # ", - " ### ### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "############### ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### ### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ### ", - " # # ", - " # ", - " # ", - " # ", - " ", - " ", - " # ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_6x12_bold: { + font: FONT_6x12_BOLD, + width: 6, + height: 12, + m_pattern: &[ + " ", + " ", + " ", + " # # ", + " ## ## ", + " ##### ", + " ##### ", + " # # # ", + " # # ", + " # # ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ### ## # ", + " ## # ##### ", + " ## # # ## ", + " ## # ", + " ## # ", + " ## # ", + " ### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ## ", + " ## # ## ", + " ## ### ## ", + " ## # ## ", + " ## # ", + " ## ### ## ", + " ## ## # ## ", + "#### ## ", + "#### ## ", + " ## ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ### ### ### ", + "## # ## # ## # ", + "## # ## # ## # ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ### ## ## ", + " ## # ## ## ", + " ## ## # ", + " ## # ## # ", + " ## # ## # ", + " ## ## # ## # ", + " ## ## # ## # ", + "## ## # #### ", + "## # ## ## ", + " ### ### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "############# ", + "############# ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ### ### ### ", + "# ## # ## # ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ", + " ", + " ", + ] } } -mod font_7x13_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_7x13_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 7); - assert_eq!(FONT.height(), 13); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(7, 13)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(21, 39)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(9, 15)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ## ", - " ###### ", - " ###### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " #### ## # ", - " ## ## ###### ", - " ## ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ", - " ## ", - " ## ## ## ## ", - " #### ## ", - " #### ", - " ## #### ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### ### ### ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " #### ## ## ", - " ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - "## ## ## ##### ", - "## # ## ", - " #### #### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "############### ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### #### ", - "## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_7x13: { + font: FONT_7x13, + width: 7, + height: 13, + m_pattern: &[ + " ", + " ", + " ", + " ", + " # # ", + " ## ## ", + " # # # ", + " # # # ", + " # # ", + " # # ", + " # # ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ### # # ", + " # # # # # ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " ### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " # ", + " # ", + " # # # # ", + " ### # ", + " # # ", + " # ### # ", + " # # # # ", + " # # ", + " # # ", + " # ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ## ## ## ", + " # # # # # # ", + " # # # # # # ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ### # # ", + " # # # ", + " # # # # ", + " # ## # # ", + " # # # # # ", + " # # # # # ", + " # # ## #### ", + " # # # ", + " ### ### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "############### ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ### ### ### ", + " # # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " # # # ", + " ", + " ", + " ", + ] } } -mod font_7x14 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_7x14; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 7); - assert_eq!(FONT.height(), 14); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(7, 14)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(21, 42)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(9, 16)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " # # ", - " ## ## ", - " # # # ", - " # # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### # # ", - " # # # # # ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " ### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # ", - " # # # # ", - " # ### # ", - " # # # ", - " ### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ## ## ", - " # # # # # # ", - " # # # # # # ", - " ## ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### # # ", - " # # # ", - " # # # # # ", - " # ## # # ", - " # # # # ", - " # # # # # ", - " # # # # # ", - " # # ## #### ", - " # # # ", - " ### ### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "############### ", - "############### ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ### ### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " # # ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ### ", - " # # ", - " # ", - " # ", - " # ", - " ", - " ", - " # ", - " # ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_7x13_bold: { + font: FONT_7x13_BOLD, + width: 7, + height: 13, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ## ## ", + " ###### ", + " ###### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " #### ## # ", + " ## ## ###### ", + " ## ## # ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ## ", + " ## ", + " ## ## ## ## ", + " #### ## ", + " #### ", + " ## #### ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ### ### ### ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " #### ## ## ", + " ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + "## ## ## ##### ", + "## # ## ", + " #### #### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "############### ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " #### #### #### ", + "## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ", + " ", + " ", + ] } } -mod font_7x14_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_7x14_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 7); - assert_eq!(FONT.height(), 14); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(7, 14)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(21, 42)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(9, 16)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ## ", - " ###### ", - " ###### ", - " ###### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " #### ## # ", - " ## ## ###### ", - " ## ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ## ## ", - " ## #### ## ", - " ## ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## #### ## ", - " ## ## ## ## ", - " #### ## ", - " #### ## ", - " ## ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### ### ### ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " #### ## ## ", - " ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - "## ## ## ##### ", - "## # ## ", - " #### #### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "############### ", - "############### ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### #### ", - "# ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " # ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_7x14: { + font: FONT_7x14, + width: 7, + height: 14, + m_pattern: &[ + " ", + " ", + " ", + " ", + " # # ", + " ## ## ", + " # # # ", + " # # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ### # # ", + " # # # # # ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " ### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " # ", + " # # # # ", + " # ### # ", + " # # # ", + " ### ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ## ## ## ", + " # # # # # # ", + " # # # # # # ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ### # # ", + " # # # ", + " # # # # # ", + " # ## # # ", + " # # # # ", + " # # # # # ", + " # # # # # ", + " # # ## #### ", + " # # # ", + " ### ### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "############### ", + "############### ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ### ### ### ", + " # # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " # # # ", + " # # # ", + " ", + " ", + " ", + ] } } -mod font_8x15 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_8x15; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 8); - assert_eq!(FONT.height(), 15); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(8, 15)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(24, 45)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(10, 17)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " # #", - " ## ##", - " # # # #", - " # # #", - " # # #", - " # #", - " # #", - " # #", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### ## #", - " # # # # #", - " # # # ## ", - " # # ", - " # # ", - " # # ", - " # # ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " # ", - " # # # ", - " # #### # ", - " # # # # ", - " # # ", - " #### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ### ### ### ", - " # # # # # # ", - " # # # # # # ", - " # # # # # # ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # # ", - " #### # # ", - " # # ", - " # # # # # ", - " # # ## # # ", - " # # # # ", - " # # # # ", - " # # # # # ", - " # # ## ##### ", - " # # ", - " # # # ", - " ### #### ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "################# ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " #### #### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " # # ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " # # ", - " # ", - " # ", - " # ", - " ", - " ", - " # ", - " # ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_7x14_bold: { + font: FONT_7x14_BOLD, + width: 7, + height: 14, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ## ## ", + " ###### ", + " ###### ", + " ###### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " #### ## # ", + " ## ## ###### ", + " ## ## # ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ## ## ## ", + " ## #### ## ", + " ## ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## #### ## ", + " ## ## ## ## ", + " #### ## ", + " #### ## ", + " ## ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ### ### ### ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " #### ## ## ", + " ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + "## ## ## ##### ", + "## # ## ", + " #### #### ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "############### ", + "############### ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " #### #### #### ", + "# ## # ## # ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + ] } } -mod font_8x15_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_8x15_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 8); - assert_eq!(FONT.height(), 15); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(8, 15)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(24, 45)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(10, 17)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ##", - " ### ###", - " #######", - " ## # ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### ### #", - " ## ## #######", - " ## ## # ### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ## ## ", - " ##### ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ##### ## ", - " ## ## ## ## ", - " #### ## ", - " #### ## ", - " ## ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### #### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ## ", - " #### ## ## ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ##### ", - " ## ## ", - " ## # ## ", - " #### #### ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "################# ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " #### #### ", - " # ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " # ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_8x15: { + font: FONT_8x15, + width: 8, + height: 15, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " # #", + " ## ##", + " # # # #", + " # # #", + " # # #", + " # #", + " # #", + " # #", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " #### ## #", + " # # # # #", + " # # # ## ", + " # # ", + " # # ", + " # # ", + " # # ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " # ", + " # # # ", + " # #### # ", + " # # # # ", + " # # ", + " #### ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ### ### ### ", + " # # # # # # ", + " # # # # # # ", + " # # # # # # ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " # # ", + " #### # # ", + " # # ", + " # # # # # ", + " # # ## # # ", + " # # # # ", + " # # # # ", + " # # # # # ", + " # # ## ##### ", + " # # ", + " # # # ", + " ### #### ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "################# ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " #### #### #### ", + " # # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " # # # ", + " # # # ", + " ", + " ", + " ", + ] } } -mod font_8x16 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_8x16; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 8); - assert_eq!(FONT.height(), 16); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(8, 16)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(24, 48)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(10, 18)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " # #", - " ## ##", - " # # # #", - " # # #", - " # # #", - " # #", - " # #", - " # #", - " # #", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## #", - " # # #", - " #### # ## ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # ", - " # # # ", - " # #### # ", - " # # # # ", - " # # ", - " # # ", - " # #### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ### ### ### ", - " # # # # # # ", - " # # # # # # ", - " # # # # # # ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " # # ", - " #### # # ", - " # # ", - " # # # # # ", - " # # ## # # ", - " # # # # ", - " # # # # ", - " # # # # # ", - " # # # # # ", - " # # ## ##### ", - " # # ", - " # # # ", - " #### #### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "################# ", - "################# ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### #### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " # # ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " # # ", - " # ", - " # ", - " # ", - " # ", - " ", - " ", - " # ", - " # ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_8x15_bold: { + font: FONT_8x15_BOLD, + width: 8, + height: 15, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ##", + " ### ###", + " #######", + " ## # ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " #### ### #", + " ## ## #######", + " ## ## # ### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ## ## ## ", + " ##### ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ##### ## ", + " ## ## ## ## ", + " #### ## ", + " #### ## ", + " ## ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### #### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ## ## ", + " #### ## ## ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ##### ", + " ## ## ", + " ## # ## ", + " #### #### ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "################# ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " #### #### #### ", + " # ## # ## # ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + ] } } -mod font_8x16_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_8x16_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 8); - assert_eq!(FONT.height(), 16); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(8, 16)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(24, 48)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(10, 18)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ##", - " ### ###", - " #######", - " ## # ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ##", - " #### ##", - " #### ## ####", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ", - " ## ## ## ", - " ## ##### ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ## ", - " ## ##### ## ", - " #### ## ## ## ", - " #### ## ", - " #### ## ", - " ## ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " #### #### #### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " #### ## ## ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ##### ", - " ## ## ", - " ## # ## ", - " #### #### ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "################# ", - "################# ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### #### ", - " # ## # ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " # ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_8x16: { + font: FONT_8x16, + width: 8, + height: 16, + m_pattern: &[ + " ", + " ", + " ", + " ", + " # #", + " ## ##", + " # # # #", + " # # #", + " # # #", + " # #", + " # #", + " # #", + " # #", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ## #", + " # # #", + " #### # ## ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " # ", + " # # # ", + " # #### # ", + " # # # # ", + " # # ", + " # # ", + " # #### ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ### ### ### ", + " # # # # # # ", + " # # # # # # ", + " # # # # # # ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " # # ", + " #### # # ", + " # # ", + " # # # # # ", + " # # ## # # ", + " # # # # ", + " # # # # ", + " # # # # # ", + " # # # # # ", + " # # ## ##### ", + " # # ", + " # # # ", + " #### #### ", + " ", + ], + char_range_5_pattern: &[ + " ", + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "################# ", + "################# ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + ], + fallback_pattern: &[ + " ", + " ", + " #### #### #### ", + " # # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " # # # ", + " # # # ", + " ", + " ", + " ", + " ", + ] } } -mod font_10x18 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_10x18; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 10); - assert_eq!(FONT.height(), 18); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(10, 18)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(30, 54)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(12, 20)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### ## ", - " #### #### ## ", - " ## ## ## #### ", - " ## ## ## #### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ## ", - " ## ## ## ", - " #### ## ", - " #### ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## #### ## ", - " ## #### ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - " #### #### #### ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " ## ## ", - " ###### ", - " ###### ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ###### ", - " ## ## ## ###### ", - "## ## ", - "## ## ", - " ###### #### ", - " ###### #### ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "###################### ", - "###################### ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - "###### ###### ", - "###### ###### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ###### ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_8x16_bold: { + font: FONT_8x16_BOLD, + width: 8, + height: 16, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ## ##", + " ### ###", + " #######", + " ## # ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ## ##", + " #### ##", + " #### ## ####", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ## ", + " ## ## ## ", + " ## ##### ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ## ", + " ## ##### ## ", + " #### ## ## ## ", + " #### ## ", + " #### ## ", + " ## ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " #### #### #### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " #### ## ## ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ##### ", + " ## ## ", + " ## # ## ", + " #### #### ", + " ", + ], + char_range_5_pattern: &[ + " ", + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "################# ", + "################# ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + ], + fallback_pattern: &[ + " ", + " ", + " #### #### #### ", + " # ## # ## # ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + ] } } -mod font_10x18_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_10x18_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 10); - assert_eq!(FONT.height(), 18); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(10, 18)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(30, 54)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(12, 20)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ######## ", - " ######## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " ## ## ", - " #### ######## ", - " #### ######## ", - " #### ## ## ## ", - " #### ## ## ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### ## #### ", - " #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ## #### ", - " #### #### ## #### ", - " #### ## ", - " #### ## ", - " #### #### #### ", - " #### #### #### ", - " #### #### ## #### ", - " #### #### ## #### ", - " #### #### ", - " #### #### ", - " #### ", - " #### ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - "#### ## #### ## #### ## ", - "#### ## #### ## #### ## ", - " #### #### #### ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " ## ## ", - " ###### ", - " ###### ", - " #### #### ## #### ## ", - " #### #### ## #### ## ", - " ###### #### ## ", - " ###### #### ## ", - " #### #### ## #### ## ", - " #### #### ## #### ## ", - "#### ###### ###### ", - "#### ###### ###### ", - "#### ## #### ", - "#### ## #### ", - " #### #### ", - " #### #### ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "###################### ", - "###################### ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### #### ", - " #### #### ", - "## #### ## #### ", - "## #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " ## #### ", - " ## #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_10x18: { + font: FONT_10x18, + width: 10, + height: 18, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### ## ", + " #### #### ## ", + " ## ## ## #### ", + " ## ## ## #### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " #### ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " #### ## ", + " #### ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## #### ## ", + " ## #### ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " ## ## ", + " ###### ", + " ###### ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ###### ", + " ## ## ## ###### ", + "## ## ", + "## ## ", + " ###### #### ", + " ###### #### ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "###################### ", + "###################### ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + "###### ###### ###### ", + "###### ###### ###### ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + ] } } -mod font_10x20 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_10x20; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 10); - assert_eq!(FONT.height(), 20); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(10, 20)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(30, 60)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(12, 22)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " # # ", - " ## ## ", - " # # # # ", - " # # # ", - " # # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## # ", - " #### # # # ", - " # # # # # ", - " # # # ## ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " # ", - " # # # ", - " # ### # # ", - " # # # # ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # # ### # # ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ### ### ### ", - " # # # # # # ", - " # # # # # # ", - " # # # # # # ", - " ### ### ### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " # # ", - " # # ", - " #### ", - " # # ", - " # # # # # ", - " # # # # # ", - " # ## # # ", - " # # # # ", - " # # # # ", - " # # # # # ", - " # # # # # ", - " # # ## ###### ", - " # # ", - " # # # ", - " ##### # ", - " ##### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "######## ######## # ", - "######### ######### # ", - "##################### ", - "##################### ", - "######### ######### # ", - "######## ######## # ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ##### ##### ", - " # # # # ", - " # # ", - " # # ", - " # # ", - " # # ", - " ", - " ", - " ", - " # # ", - " # # ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ##### ", - " # # ", - " # ", - " # ", - " # ", - " # ", - " ", - " ", - " ", - " # ", - " # ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_10x18_bold: { + font: FONT_10x18_BOLD, + width: 10, + height: 18, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ######## ", + " ######## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ## ## ", + " ## ## ", + " #### ######## ", + " #### ######## ", + " #### ## ## ## ", + " #### ## ## ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " #### ", + " #### ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " #### ## #### ", + " #### ## #### ", + " #### #### ", + " #### #### ", + " #### #### ## #### ", + " #### #### ## #### ", + " #### ## ", + " #### ## ", + " #### #### #### ", + " #### #### #### ", + " #### #### ## #### ", + " #### #### ## #### ", + " #### #### ", + " #### #### ", + " #### ", + " #### ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + "#### ## #### ## #### ## ", + "#### ## #### ## #### ## ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " ## ## ", + " ###### ", + " ###### ", + " #### #### ## #### ## ", + " #### #### ## #### ## ", + " ###### #### ## ", + " ###### #### ## ", + " #### #### ## #### ## ", + " #### #### ## #### ## ", + "#### ###### ###### ", + "#### ###### ###### ", + "#### ## #### ", + "#### ## #### ", + " #### #### ", + " #### #### ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "###################### ", + "###################### ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " #### #### #### ", + " #### #### #### ", + "## #### ## #### ## #### ", + "## #### ## #### ## #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + ] } } -mod font_10x20_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_10x20_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 10); - assert_eq!(FONT.height(), 20); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(10, 20)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(30, 60)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(12, 22)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ### ### ", - " ######## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ## ", - " #### #### ## ", - " ## ## ## #### ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ## ", - " ## ", - " ## ## ## ", - " ## ####### ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ####### ## ", - " ## ## ## ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " ## ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### #### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ## ", - " ## ## ", - " ##### ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ###### ", - " ## ## ", - " ## ## ## ", - " ###### ##### ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "# # #", - "## ## # ", - "### ### # ", - "#### #### # ", - "##### ##### # ", - "###### ###### # ", - "####### ####### # ", - "######## ######## # ", - "######### ######### # ", - "##################### ", - "##################### ", - "######### ######### # ", - "######## ######## # ", - "####### ####### # ", - "###### ###### # ", - "##### ##### # ", - "#### #### # ", - "### ### # ", - "## ## # ", - "# # #", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ###### ###### ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_10x20: { + font: FONT_10x20, + width: 10, + height: 20, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " # # ", + " ## ## ", + " # # # # ", + " # # # ", + " # # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ## # ", + " #### # # # ", + " # # # # # ", + " # # # ## ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " # # ", + " #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " # ", + " # # # ", + " # ### # # ", + " # # # # ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # # ### # # ", + " # # # # ", + " # # ", + " # # ", + " # # ", + " # ", + " ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ### ### ### ", + " # # # # # # ", + " # # # # # # ", + " # # # # # # ", + " ### ### ### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " # # ", + " # # ", + " #### ", + " # # ", + " # # # # # ", + " # # # # # ", + " # ## # # ", + " # # # # ", + " # # # # ", + " # # # # # ", + " # # # # # ", + " # # ## ###### ", + " # # ", + " # # # ", + " ##### # ", + " ##### ", + " ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "######## ######## # ", + "######### ######### # ", + "##################### ", + "##################### ", + "######### ######### # ", + "######## ######## # ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ##### ##### ##### ", + " # # # # # # ", + " # # # ", + " # # # ", + " # # # ", + " # # # ", + " ", + " ", + " ", + " # # # ", + " # # # ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_12x24 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_12x24; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 12); - assert_eq!(FONT.height(), 24); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(12, 24)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(36, 72)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(14, 26)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " #### #### ", - " #### #### ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ###### ", - " ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ###### ## ", - " ###### ## ", - " ## ## ", - " ## ## ", - " ## ###### ## ", - " ## ###### ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - "## ## ## ## ## ## ", - " #### #### #### ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## #### ## ## ", - " ## #### ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - "## ## #### ######## ", - "## ## #### ######## ", - "## ## ## ", - "## ## ## ", - " ###### ###### ", - " ###### ###### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "########################## ", - "########################## ", - "########################## ", - "########################## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ###### ###### ", - " ###### ###### ", - "## ## ## ## ", - "## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ###### ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_10x20_bold: { + font: FONT_10x20_BOLD, + width: 10, + height: 20, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ### ### ", + " ######## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ## ## ", + " #### #### ## ", + " ## ## ## #### ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ## ", + " ## ", + " ## ## ## ", + " ## ####### ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ####### ## ", + " ## ## ## ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " ## ", + " ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### #### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ## ## ", + " ## ## ", + " ##### ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ###### ", + " ## ## ", + " ## ## ## ", + " ###### ##### ", + " ", + " ", + " ", + ], + char_range_5_pattern: &[ + "# # #", + "## ## # ", + "### ### # ", + "#### #### # ", + "##### ##### # ", + "###### ###### # ", + "####### ####### # ", + "######## ######## # ", + "######### ######### # ", + "##################### ", + "##################### ", + "######### ######### # ", + "######## ######## # ", + "####### ####### # ", + "###### ###### # ", + "##### ##### # ", + "#### #### # ", + "### ### # ", + "## ## # ", + "# # #", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_12x24_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_12x24_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 12); - assert_eq!(FONT.height(), 24); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(12, 24)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(36, 72)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(14, 26)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " #### #### ", - " #### #### ", - " ########## ", - " ########## ", - " ########## ", - " ########## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### #### ## ", - " ###### #### ## ", - " #### ## ########## ", - " #### ## ########## ", - " #### ## ## #### ", - " #### ## ## #### ", - " #### ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " #### ## ", - " ###### ", - " ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " #### ", - " #### ", - " #### ## #### ", - " #### ## #### ", - " #### ###### #### ", - " #### ###### #### ", - " #### ## #### ", - " #### ## #### ", - " #### ## ", - " #### ## ", - " #### ###### #### ", - " #### ###### #### ", - " #### #### ## #### ", - " #### #### ## #### ", - "######## #### ", - "######## #### ", - "######## #### ", - "######## #### ", - " #### ", - " #### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - "#### ## #### ## #### ## ", - "#### ## #### ## #### ## ", - "#### ## #### ## #### ## ", - "#### ## #### ## #### ## ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ###### #### #### ", - " ###### #### #### ", - " #### ## #### #### ", - " #### ## #### #### ", - " #### #### ## ", - " #### #### ## ", - " #### ## #### ## ", - " #### ## #### ## ", - " #### ## #### ## ", - " #### ## #### ## ", - " #### #### ## #### ## ", - " #### #### ## #### ## ", - " #### #### ## #### ## ", - " #### #### ## #### ## ", - "#### #### ## ######## ", - "#### #### ## ######## ", - "#### ## #### #### ", - "#### ## #### #### ", - " ###### ###### ", - " ###### ###### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "########################## ", - "########################## ", - "########################## ", - "########################## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ###### ###### ", - " ###### ###### ", - "## #### ## #### ", - "## #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ###### ", - " ## #### ", - " ## #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_12x24: { + font: FONT_12x24, + width: 12, + height: 24, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " #### #### ", + " #### #### ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ###### ", + " ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ## ", + " ## ", + " ## ", + " ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ###### ## ", + " ###### ## ", + " ## ## ", + " ## ## ", + " ## ###### ## ", + " ## ###### ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## #### ## ## ", + " ## #### ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + "## ## #### ######## ", + "## ## #### ######## ", + "## ## ## ", + "## ## ## ", + " ###### ###### ", + " ###### ###### ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "########################## ", + "########################## ", + "########################## ", + "########################## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + "## ## ## ## ## ## ", + "## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_14x26 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_14x26; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 14); - assert_eq!(FONT.height(), 26); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(14, 26)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(42, 78)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(16, 28)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " #### #### ", - " #### #### ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ###### ", - " ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ###### ## ", - " ###### ## ", - " ## ## ", - " ## ## ", - " ## ###### ## ", - " ## ###### ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " #### #### #### ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## #### ## ## ", - " ## #### ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ######## ", - " ## ## #### ######## ", - " ## ## ## ", - " ## ## ## ", - " ###### ###### ", - " ###### ###### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############################## ", - "############################## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### ###### ", - " ###### ###### ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ###### ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_12x24_bold: { + font: FONT_12x24_BOLD, + width: 12, + height: 24, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " #### #### ", + " #### #### ", + " ########## ", + " ########## ", + " ########## ", + " ########## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ###### #### ## ", + " ###### #### ## ", + " #### ## ########## ", + " #### ## ########## ", + " #### ## ## #### ", + " #### ## ## #### ", + " #### ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " #### ## ", + " ###### ", + " ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " #### ", + " #### ", + " #### ## #### ", + " #### ## #### ", + " #### ###### #### ", + " #### ###### #### ", + " #### ## #### ", + " #### ## #### ", + " #### ## ", + " #### ## ", + " #### ###### #### ", + " #### ###### #### ", + " #### #### ## #### ", + " #### #### ## #### ", + "######## #### ", + "######## #### ", + "######## #### ", + "######## #### ", + " #### ", + " #### ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + "#### ## #### ## #### ## ", + "#### ## #### ## #### ## ", + "#### ## #### ## #### ## ", + "#### ## #### ## #### ## ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ###### #### #### ", + " ###### #### #### ", + " #### ## #### #### ", + " #### ## #### #### ", + " #### #### ## ", + " #### #### ## ", + " #### ## #### ## ", + " #### ## #### ## ", + " #### ## #### ## ", + " #### ## #### ## ", + " #### #### ## #### ## ", + " #### #### ## #### ## ", + " #### #### ## #### ## ", + " #### #### ## #### ## ", + "#### #### ## ######## ", + "#### #### ## ######## ", + "#### ## #### #### ", + "#### ## #### #### ", + " ###### ###### ", + " ###### ###### ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "########################## ", + "########################## ", + "########################## ", + "########################## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + "## #### ## #### ## #### ", + "## #### ## #### ## #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_14x26_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_14x26_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 14); - assert_eq!(FONT.height(), 26); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(14, 26)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(42, 78)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(16, 28)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ############ ", - " ############ ", - " ############ ", - " ############ ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ######## #### ## ", - " ######## #### ## ", - " #### #### ############ ", - " #### #### ############ ", - " #### #### ## #### ", - " #### #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " ######## #### ", - " ######## #### ", - " ######## ", - " ######## ", - " #### ######## #### ", - " #### ######## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### ", - " #### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ######## #### #### ", - " ######## #### #### ", - " #### #### #### ", - " #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - "#### #### #### ########## ", - "#### #### #### ########## ", - "#### ## #### ", - "#### ## #### ", - " ######## ######## ", - " ######## ######## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############################## ", - "############################## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ######## ######## ", - " ######## ######## ", - "#### #### #### #### ", - "#### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ", - " ######## ", - " #### #### ", - " #### #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_14x26: { + font: FONT_14x26, + width: 14, + height: 26, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " #### #### ", + " #### #### ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ###### ", + " ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ## ", + " ## ", + " ## ", + " ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ###### ## ", + " ###### ## ", + " ## ## ", + " ## ## ", + " ## ###### ## ", + " ## ###### ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## #### ## ## ", + " ## #### ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ######## ", + " ## ## #### ######## ", + " ## ## ## ", + " ## ## ## ", + " ###### ###### ", + " ###### ###### ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############################## ", + "############################## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_14x28 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_14x28; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 14); - assert_eq!(FONT.height(), 28); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(14, 28)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(42, 84)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(16, 30)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " #### #### ", - " #### #### ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ###### ", - " ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ###### ## ", - " ## ###### ## ", - " ## ## ## ", - " ## ## ## ", - " ###### ", - " ###### ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " #### #### #### ", - " #### #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ## ## ", - " ###### ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## #### ## ## ", - " ## #### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ######## ", - " ## ## #### ######## ", - " ## ## ## ", - " ## ## ## ", - " ###### ###### ", - " ###### ###### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############################## ", - "############################## ", - "############################## ", - "############################## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ###### ###### ", - " ###### ###### ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ", - " ###### ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_14x26_bold: { + font: FONT_14x26_BOLD, + width: 14, + height: 26, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ############ ", + " ############ ", + " ############ ", + " ############ ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ######## #### ## ", + " ######## #### ## ", + " #### #### ############ ", + " #### #### ############ ", + " #### #### ## #### ", + " #### #### ## #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " #### ", + " #### ", + " #### ", + " #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " ######## #### ", + " ######## #### ", + " ######## ", + " ######## ", + " #### ######## #### ", + " #### ######## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### ", + " #### ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ######## #### #### ", + " ######## #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + "#### #### #### ########## ", + "#### #### #### ########## ", + "#### ## #### ", + "#### ## #### ", + " ######## ######## ", + " ######## ######## ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############################## ", + "############################## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_14x28_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_14x28_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 14); - assert_eq!(FONT.height(), 28); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(14, 28)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(42, 84)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(16, 30)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ############ ", - " ############ ", - " ############ ", - " ############ ", - " ############ ", - " ############ ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ######## #### ## ", - " ######## #### ## ", - " #### #### ############ ", - " #### #### ############ ", - " #### #### ## #### ", - " #### #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - " #### ######## #### ", - " #### ######## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### ", - " #### #### #### ", - " #### #### ", - " #### #### ", - " #### ######## #### ", - " #### ######## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " #### ", - " #### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - "#### #### #### #### #### #### ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ######## #### #### ", - " ######## #### #### ", - " #### #### #### ", - " #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - "#### #### #### ########## ", - "#### #### #### ########## ", - "#### ## #### ", - "#### ## #### ", - " ######## ######## ", - " ######## ######## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############################## ", - "############################## ", - "############################## ", - "############################## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ######## ######## ", - " ######## ######## ", - "## #### ## #### ", - "## #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ", - " ######## ", - " ## #### ", - " ## #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_14x28: { + font: FONT_14x28, + width: 14, + height: 28, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " #### #### ", + " #### #### ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ###### ", + " ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ## ", + " ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ###### ## ", + " ## ###### ## ", + " ## ## ## ", + " ## ## ## ", + " ###### ", + " ###### ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ## ## ", + " ###### ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## #### ## ## ", + " ## #### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ######## ", + " ## ## #### ######## ", + " ## ## ## ", + " ## ## ## ", + " ###### ###### ", + " ###### ###### ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############################## ", + "############################## ", + "############################## ", + "############################## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_16x30 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_16x30; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 16); - assert_eq!(FONT.height(), 30); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(16, 30)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(48, 90)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(18, 32)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ##", - " ## ##", - " #### ####", - " #### ####", - " ## ## ## ##", - " ## ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## #### ##", - " ######## #### ##", - " ## ## ## ## ##", - " ## ## ## ## ##", - " ## ## ## #### ", - " ## ## ## #### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ## ## ", - " ## ## ## ", - " ## ######## ## ", - " ## ######## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ######## ## ## ", - " ######## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ## ## ", - " ## ## #### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ########## ", - " ## ## #### ########## ", - " ## ## ", - " ## ## ", - " ## ## ## ", - " ## ## ## ", - " ###### ######## ", - " ###### ######## ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################################## ", - "################################## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ######## ", - " ######## ######## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ", - " ######## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_14x28_bold: { + font: FONT_14x28_BOLD, + width: 14, + height: 28, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ############ ", + " ############ ", + " ############ ", + " ############ ", + " ############ ", + " ############ ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ######## #### ## ", + " ######## #### ## ", + " #### #### ############ ", + " #### #### ############ ", + " #### #### ## #### ", + " #### #### ## #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " #### ######## #### ", + " #### ######## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### ", + " #### #### ", + " #### ######## #### ", + " #### ######## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " #### ", + " #### ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + "#### #### #### #### #### #### ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ######## #### #### ", + " ######## #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + "#### #### #### ########## ", + "#### #### #### ########## ", + "#### ## #### ", + "#### ## #### ", + " ######## ######## ", + " ######## ######## ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############################## ", + "############################## ", + "############################## ", + "############################## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + "## #### ## #### ## #### ", + "## #### ## #### ## #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_16x30_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_16x30_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 16); - assert_eq!(FONT.height(), 30); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(16, 30)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(48, 90)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(18, 32)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ####", - " #### ####", - " ###### ######", - " ###### ######", - " ##############", - " ##############", - " #### ## ####", - " #### ## ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ###### ##", - " ######## ###### ##", - " #### #### ##############", - " #### #### ##############", - " #### #### ## ###### ", - " #### #### ## ###### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### #### ", - " #### #### #### ", - " ########## #### ", - " ########## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### ########## #### ", - " #### ########## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " #### ", - " #### ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ######## #### #### ", - " ######## #### #### ", - " #### #### ", - " #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### ########## ", - " #### #### #### ########## ", - " #### #### ", - " #### #### ", - " #### ## #### ", - " #### ## #### ", - " ######## ######## ", - " ######## ######## ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################################## ", - "################################## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); - } - - #[test] - fn text_fallback() { - let mut display = MockDisplay::new(); - Text::new("§?\n µ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ######## ", - " ######## ######## ", - " ## #### ## #### ", - " ## #### ## #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ", - " ######## ", - " ## #### ", - " ## #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); +test_font! { + font_16x30: { + font: FONT_16x30, + width: 16, + height: 30, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ##", + " ## ##", + " #### ####", + " #### ####", + " ## ## ## ##", + " ## ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ######## #### ##", + " ######## #### ##", + " ## ## ## ## ##", + " ## ## ## ## ##", + " ## ## ## #### ", + " ## ## ## #### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ", + " ## ", + " ## ## ## ", + " ## ## ## ", + " ## ######## ## ", + " ## ######## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " ######## ## ## ", + " ######## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ## ## ", + " ## ## #### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ########## ", + " ## ## #### ########## ", + " ## ## ", + " ## ## ", + " ## ## ## ", + " ## ## ## ", + " ###### ######## ", + " ###### ######## ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################################## ", + "################################## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_16x32 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_16x32; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 16); - assert_eq!(FONT.height(), 32); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(16, 32)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(48, 96)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(18, 34)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ##", - " ## ##", - " #### ####", - " #### ####", - " ## ## ## ##", - " ## ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ## ##", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### ##", - " #### ##", - " ## ## ##", - " ## ## ##", - " ######## ## #### ", - " ######## ## #### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ## ## ", - " ## ## ## ", - " ## ######## ## ", - " ## ######## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ######## ", - " ## ######## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ######## ## ## ", - " ######## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ## ## ", - " ## ## #### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ########## ", - " ## ## #### ########## ", - " ## ## ", - " ## ## ", - " ## ## ## ", - " ## ## ## ", - " ######## ######## ", - " ######## ######## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################################## ", - "################################## ", - "################################## ", - "################################## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - ]) - ); +test_font! { + font_16x30_bold: { + font: FONT_16x30_BOLD, + width: 16, + height: 30, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### ####", + " #### ####", + " ###### ######", + " ###### ######", + " ##############", + " ##############", + " #### ## ####", + " #### ## ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ###### ##", + " ######## ###### ##", + " #### #### ##############", + " #### #### ##############", + " #### #### ## ###### ", + " #### #### ## ###### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " ########## #### ", + " ########## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### ########## #### ", + " #### ########## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " #### ", + " #### ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ######## #### #### ", + " ######## #### #### ", + " #### #### ", + " #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### ########## ", + " #### #### #### ########## ", + " #### #### ", + " #### #### ", + " #### ## #### ", + " #### ## #### ", + " ######## ######## ", + " ######## ######## ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################################## ", + "################################## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ## #### ## #### ## #### ", + " ## #### ## #### ## #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_16x32_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_16x32_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 16); - assert_eq!(FONT.height(), 32); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(16, 32)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(48, 96)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(18, 34)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### ####", - " #### ####", - " ###### ######", - " ###### ######", - " ##############", - " ##############", - " #### ## ####", - " #### ## ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " #### ####", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### ####", - " #### ####", - " ######## ####", - " ######## ####", - " ######## #### ########", - " ######## #### ########", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " #### #### #### ", - " #### #### #### ", - " #### ########## #### ", - " #### ########## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### #### ", - " #### #### #### ", - " #### ########## #### ", - " #### ########## #### ", - " ######## #### #### #### ", - " ######## #### #### #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " #### ", - " #### ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ######## #### #### ", - " ######## #### #### ", - " #### #### ", - " #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### ########## ", - " #### #### #### ########## ", - " #### #### ", - " #### #### ", - " #### ## #### ", - " #### ## #### ", - " ######## ######## ", - " ######## ######## ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################################## ", - "################################## ", - "################################## ", - "################################## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - ]) - ); +test_font! { + font_16x32: { + font: FONT_16x32, + width: 16, + height: 32, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ##", + " ## ##", + " #### ####", + " #### ####", + " ## ## ## ##", + " ## ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ## ##", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " #### ##", + " #### ##", + " ## ## ##", + " ## ## ##", + " ######## ## #### ", + " ######## ## #### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ## ", + " ## ", + " ## ## ## ", + " ## ## ## ", + " ## ######## ## ", + " ## ######## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ######## ", + " ## ######## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " ######## ## ## ", + " ######## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ## ## ", + " ## ## #### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ########## ", + " ## ## #### ########## ", + " ## ## ", + " ## ## ", + " ## ## ## ", + " ## ## ## ", + " ######## ######## ", + " ######## ######## ", + " ", + " ", + ], + char_range_5_pattern: &[ + " ", + " ", + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################################## ", + "################################## ", + "################################## ", + "################################## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_20x40 { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_20x40; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 20); - assert_eq!(FONT.height(), 40); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); - } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(20, 40)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(60, 120)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(22, 42)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " #### #### ", - " #### #### ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### ## ", - " #### ## ", - " ######## ## ## ## ", - " ######## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## #### ", - " ## ## ## #### ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ## ", - " ## ", - " ## ## ## ", - " ## ## ## ", - " ## ###### ## ## ", - " ## ###### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ###### ## ## ", - " ## ## ###### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ", - " ## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ## ## ## ## ## ## ", - " ###### ###### ###### ", - " ###### ###### ###### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ## ## ", - " ## ## ", - " ## ## ", - " ## ## ", - " ######## ", - " ######## ", - " ## ## ", - " ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## #### ## ## ", - " ## #### ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## ## ## ## ", - " ## ## #### ############ ", - " ## ## #### ############ ", - " ## ## ", - " ## ## ", - " ## ## ## ", - " ## ## ## ", - " ########## ## ", - " ########## ## ", - " ########## ", - " ########## ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################ ################ ## ", - "################ ################ ## ", - "################## ################## ## ", - "################## ################## ## ", - "########################################## ", - "########################################## ", - "########################################## ", - "########################################## ", - "################## ################## ## ", - "################## ################## ## ", - "################ ################ ## ", - "################ ################ ## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); +test_font! { + font_16x32_bold: { + font: FONT_16x32_BOLD, + width: 16, + height: 32, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### ####", + " #### ####", + " ###### ######", + " ###### ######", + " ##############", + " ##############", + " #### ## ####", + " #### ## ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " #### ####", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " #### ####", + " #### ####", + " ######## ####", + " ######## ####", + " ######## #### ########", + " ######## #### ########", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### ", + " #### ", + " #### #### #### ", + " #### #### #### ", + " #### ########## #### ", + " #### ########## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### ########## #### ", + " #### ########## #### ", + " ######## #### #### #### ", + " ######## #### #### #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " #### ", + " #### ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ######## #### #### ", + " ######## #### #### ", + " #### #### ", + " #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### ########## ", + " #### #### #### ########## ", + " #### #### ", + " #### #### ", + " #### ## #### ", + " #### ## #### ", + " ######## ######## ", + " ######## ######## ", + " ", + " ", + ], + char_range_5_pattern: &[ + " ", + " ", + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################################## ", + "################################## ", + "################################## ", + "################################## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ## #### ## #### ## #### ", + " ## #### ## #### ## #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } } -mod font_20x40_bold { - use bitmap_font::*; - use embedded_graphics::{ - drawable::Drawable, - fonts::Text, - geometry::{Dimensions, Point, Size}, - mock_display::MockDisplay, - pixelcolor::BinaryColor, - transform::Transform - }; - - const FONT: BitmapFont = FONT_20x40_BOLD; - - #[test] - fn font_size() { - assert_eq!(FONT.width(), 20); - assert_eq!(FONT.height(), 40); - } - - #[test] - fn text_empty_size() { - let size = Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::zero()); +test_font! { + font_20x40: { + font: FONT_20x40, + width: 20, + height: 40, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " #### #### ", + " #### #### ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### ## ", + " #### ## ", + " ######## ## ## ## ", + " ######## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## #### ", + " ## ## ## #### ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ## ", + " ## ", + " ## ## ## ", + " ## ## ## ", + " ## ###### ## ## ", + " ## ###### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ###### ## ## ", + " ## ## ###### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ", + " ## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ###### ###### ###### ", + " ###### ###### ###### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " ## ## ", + " ## ## ", + " ## ## ", + " ## ## ", + " ######## ", + " ######## ", + " ## ## ", + " ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## #### ## ## ", + " ## #### ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## ## ## ## ", + " ## ## #### ############ ", + " ## ## #### ############ ", + " ## ## ", + " ## ## ", + " ## ## ## ", + " ## ## ## ", + " ########## ## ", + " ########## ## ", + " ########## ", + " ########## ", + " ", + " ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################ ################ ## ", + "################ ################ ## ", + "################## ################## ## ", + "################## ################## ## ", + "########################################## ", + "########################################## ", + "########################################## ", + "########################################## ", + "################## ################## ## ", + "################## ################## ## ", + "################ ################ ## ", + "################ ################ ## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ########## ########## ########## ", + " ########## ########## ########## ", + " ## ## ## ## ## ## ", + " ## ## ## ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ## ## ## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } - - #[test] - fn text_a_size() { - let size = Text::new("a", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(20, 40)); - } - - #[test] - fn text_multiline_size() { - let size = Text::new("aa\naaa\na", Point::zero()) - .with_font(FONT, BinaryColor::On) - .size(); - assert_eq!(size, Size::new(60, 120)); - } - - #[test] - fn text_translate() { - let mut text = Text::new("M", Point::zero()) - .with_font(FONT, BinaryColor::On); - text.translate_mut(Point::new(2, 2)); - assert_eq!(text.top_left(), Point::new(2, 2)); - assert_eq!(text.bottom_right(), Point::new(22, 42)); - - let mut display = MockDisplay::new(); - text.translate(Point::new(3, -1)).draw(&mut display).unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ###### ###### ", - " ###### ###### ", - " ################ ", - " ################ ", - " #### #### #### ", - " #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_1() { - let mut display = MockDisplay::new(); - Text::new(" O~", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " ######## ######## #### ", - " ######## ######## #### ", - " #### #### #### ######## ", - " #### #### #### ######## ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ######## ", - " ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_2() { - let mut display = MockDisplay::new(); - Text::new("¡¤¦", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " #### ", - " #### ", - " #### ", - " #### ", - " #### #### #### ", - " #### #### #### ", - " #### ############## #### ", - " #### ############## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### ############## #### ", - " #### ############## #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " ######## #### ", - " #### ", - " #### ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_3() { - let mut display = MockDisplay::new(); - Text::new("°°°", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " #### #### #### #### #### #### ", - " ######## ######## ######## ", - " ######## ######## ######## ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_4() { - let mut display = MockDisplay::new(); - Text::new("¿ßÿ", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - " ", - " ", - " ", - " ", - " #### #### ", - " #### #### ", - " #### #### ", - " #### #### ", - " ########## ", - " ########## ", - " #### #### ", - " #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### ###### #### #### ", - " #### ###### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### #### #### ", - " #### #### #### ############ ", - " #### #### #### ############ ", - " #### #### ", - " #### #### ", - " #### #### #### ", - " #### #### #### ", - " ############ ########## ", - " ############ ########## ", - " ", - " ", - " ", - " ", - " ", - " ", - ]) - ); - } - - #[test] - fn text_char_range_5() { - let mut display = MockDisplay::new(); - Text::new("", Point::zero()) - .with_font(FONT, BinaryColor::On) - .draw(&mut display) - .unwrap(); - assert_eq!( - display, - MockDisplay::from_pattern(&[ - "## ## ##", - "## ## ##", - "#### #### ## ", - "#### #### ## ", - "###### ###### ## ", - "###### ###### ## ", - "######## ######## ## ", - "######## ######## ## ", - "########## ########## ## ", - "########## ########## ## ", - "############ ############ ## ", - "############ ############ ## ", - "############## ############## ## ", - "############## ############## ## ", - "################ ################ ## ", - "################ ################ ## ", - "################## ################## ## ", - "################## ################## ## ", - "########################################## ", - "########################################## ", - "########################################## ", - "########################################## ", - "################## ################## ## ", - "################## ################## ## ", - "################ ################ ## ", - "################ ################ ## ", - "############## ############## ## ", - "############## ############## ## ", - "############ ############ ## ", - "############ ############ ## ", - "########## ########## ## ", - "########## ########## ## ", - "######## ######## ## ", - "######## ######## ## ", - "###### ###### ## ", - "###### ###### ## ", - "#### #### ## ", - "#### #### ## ", - "## ## ##", - "## ## ##", - ]) - ); +} + +test_font! { + font_20x40_bold: { + font: FONT_20x40_BOLD, + width: 20, + height: 40, + m_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ###### ###### ", + " ###### ###### ", + " ################ ", + " ################ ", + " #### #### #### ", + " #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_1_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " ######## ######## #### ", + " ######## ######## #### ", + " #### #### #### ######## ", + " #### #### #### ######## ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ######## ", + " ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_2_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " #### ", + " #### ", + " #### ", + " #### ", + " #### #### #### ", + " #### #### #### ", + " #### ############## #### ", + " #### ############## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### ############## #### ", + " #### ############## #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " ######## #### ", + " #### ", + " #### ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_3_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " ######## ######## ######## ", + " ######## ######## ######## ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_4_pattern: &[ + " ", + " ", + " ", + " ", + " #### #### ", + " #### #### ", + " #### #### ", + " #### #### ", + " ########## ", + " ########## ", + " #### #### ", + " #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### ###### #### #### ", + " #### ###### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### #### #### ", + " #### #### #### ############ ", + " #### #### #### ############ ", + " #### #### ", + " #### #### ", + " #### #### #### ", + " #### #### #### ", + " ############ ########## ", + " ############ ########## ", + " ", + " ", + " ", + " ", + " ", + " ", + ], + char_range_5_pattern: &[ + "## ## ##", + "## ## ##", + "#### #### ## ", + "#### #### ## ", + "###### ###### ## ", + "###### ###### ## ", + "######## ######## ## ", + "######## ######## ## ", + "########## ########## ## ", + "########## ########## ## ", + "############ ############ ## ", + "############ ############ ## ", + "############## ############## ## ", + "############## ############## ## ", + "################ ################ ## ", + "################ ################ ## ", + "################## ################## ## ", + "################## ################## ## ", + "########################################## ", + "########################################## ", + "########################################## ", + "########################################## ", + "################## ################## ## ", + "################## ################## ## ", + "################ ################ ## ", + "################ ################ ## ", + "############## ############## ## ", + "############## ############## ## ", + "############ ############ ## ", + "############ ############ ## ", + "########## ########## ## ", + "########## ########## ## ", + "######## ######## ## ", + "######## ######## ## ", + "###### ###### ## ", + "###### ###### ## ", + "#### #### ## ", + "#### #### ## ", + "## ## ##", + "## ## ##", + ], + fallback_pattern: &[ + " ", + " ", + " ", + " ", + " ", + " ", + " ############ ############ ############ ", + " ############ ############ ############ ", + " #### #### #### #### #### #### ", + " #### #### #### #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " #### #### #### ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ] } }