| 1 | //! Official KVT wordmark for the title bar. Kept in its own file so the weekly |
| 2 | //! upstream merge does not have to touch the logo bytes. |
| 3 | |
| 4 | use crate::theme::Shade; |
| 5 | |
| 6 | const LOGO: &[u8] = include_bytes!("../../app/assets/brand/kvt-logo.png"); |
| 7 | const LOGO_WIT: &[u8] = include_bytes!("../../app/assets/brand/kvt-logo-wit.png"); |
| 8 | |
| 9 | /// Display size of the wordmark in the title bar, including the clear space |
| 10 | /// baked into the PNG (a quarter of the ink height, per the house style). |
| 11 | pub const TITLE_LOGO_HEIGHT: f32 = 32.; |
| 12 | pub const TITLE_LOGO_WIDTH: f32 = 94.; |
| 13 | |
| 14 | /// Colour logo on light grounds (the original logo belongs on white). White logo |
| 15 | /// on dark and high-contrast grounds, as `logo-kvt-wit.png` in the house style. |
| 16 | pub fn title_logo_png(shade: Shade) -> Option<&'static [u8]> { |
| 17 | Some(if shade.is_dark() { LOGO_WIT } else { LOGO }) |
| 18 | } |
| 19 | |
| 20 | #[cfg(test)] |
| 21 | mod tests { |
| 22 | use super::*; |
| 23 | use crate::theme::Shade; |
| 24 | |
| 25 | #[test] |
| 26 | fn both_wordmarks_are_png() { |
| 27 | for bytes in [LOGO, LOGO_WIT] { |
| 28 | assert!(bytes.starts_with(b"\x89PNG"), "not a png"); |
| 29 | } |
| 30 | assert_ne!(title_logo_png(Shade::Light), title_logo_png(Shade::Dark)); |
| 31 | assert_eq!( |
| 32 | title_logo_png(Shade::Dark), |
| 33 | title_logo_png(Shade::HighContrast) |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | #[test] |
| 38 | fn the_display_size_matches_the_png_aspect() { |
| 39 | // IHDR width and height sit at bytes 16..24 of a PNG. |
| 40 | let width = u32::from_be_bytes(LOGO[16..20].try_into().unwrap()); |
| 41 | let height = u32::from_be_bytes(LOGO[20..24].try_into().unwrap()); |
| 42 | let aspect = (width as f32) / (height as f32); |
| 43 | let display = TITLE_LOGO_WIDTH / TITLE_LOGO_HEIGHT; |
| 44 | assert!( |
| 45 | (aspect - display).abs() < 0.02, |
| 46 | "{width}x{height} aspect {aspect} vs display {display}" |
| 47 | ); |
| 48 | let wit_w = u32::from_be_bytes(LOGO_WIT[16..20].try_into().unwrap()); |
| 49 | let wit_h = u32::from_be_bytes(LOGO_WIT[20..24].try_into().unwrap()); |
| 50 | assert_eq!((width, height), (wit_w, wit_h)); |
| 51 | } |
| 52 | } |