//! The face shop bundles, cut at build time by `quasi-type`. //! //! One crate rather than an `include_bytes!` in each caller: the binary and two //! test suites all want the same bytes, and cutting it three times would //! download the base three times and leave three places to state the weight. /// Quasi Mono, the house monospace face. /// /// Variable on `wght` 200-800 in one file. **At rest it is `wght` 200**, since /// a cut keeps its base's default instance and Atkinson Hyperlegible Mono's is /// ExtraLight, so anything rendering it names a weight — see [`WEIGHT`]. pub static FACE: &[u8] = include_bytes!(env!("SHOP_FONT_FACE")); /// The base's licence text. OFL 1.1 requires it to travel with a modified /// build, so it travels inside the binary and `shop --license` prints it. pub static LICENSE: &str = include_str!(env!("SHOP_FONT_LICENSE")); /// The family name the face carries, for a fontconfig query or a log line. pub const FAMILY: &str = env!("SHOP_FONT_FAMILY"); /// The style of the face's default instance, which is what `fc-match` and a /// naive loader both report. `ExtraLight` today. pub const DEFAULT_STYLE: &str = env!("SHOP_FONT_STYLE"); /// The weight the face opens at, which is its base's default instance. /// /// Stated so the trap is a number in the source rather than a sentence in a /// comment: it is 200 today, and nothing should draw at it. pub const DEFAULT_WEIGHT: f32 = { // `parse` is not const, and the value comes from the build script as a // string. Two digits of it are all that is ever needed. match env!("SHOP_FONT_DEFAULT_WEIGHT").as_bytes() { [b'2', b'0', b'0', ..] => 200.0, [b'4', b'0', b'0', ..] => 400.0, _ => f32::NAN, } }; /// The weight a terminal draws body text at. /// /// Named rather than inherited. The face's own default is the light end of its /// axis, and a terminal that took it would draw every prompt in ExtraLight. pub const WEIGHT: f32 = 400.0; #[cfg(test)] mod tests { use super::*; #[test] fn the_face_is_a_truetype_file_carrying_an_axis() { assert_eq!(&FACE[0..4], &[0x00, 0x01, 0x00, 0x00], "not an sfnt"); let tags: Vec<&[u8]> = (0..u16::from_be_bytes([FACE[4], FACE[5]]) as usize) .map(|i| &FACE[12 + 16 * i..16 + 16 * i]) .collect(); for wanted in [b"fvar", b"gvar", b"cmap", b"glyf"] { assert!( tags.contains(&&wanted[..]), "{} is missing, so this is not a cut variable face", String::from_utf8_lossy(wanted) ); } } #[test] fn the_licence_travels_with_it() { assert!(LICENSE.contains("SIL OPEN FONT LICENSE")); } /// The trap this crate exists to make impossible to forget. #[test] fn the_faces_own_default_is_not_the_weight_we_draw_at() { assert_eq!(DEFAULT_STYLE, "ExtraLight"); assert!( (WEIGHT - DEFAULT_WEIGHT).abs() > f32::EPSILON, "the weight shop draws at is the file's own default, so naming it bought nothing" ); } }