Skip to main content

max / shop

3.0 KB · 79 lines History Blame Raw
1 //! The face shop bundles, cut at build time by `quasi-type`.
2 //!
3 //! One crate rather than an `include_bytes!` in each caller: the binary and two
4 //! test suites all want the same bytes, and cutting it three times would
5 //! download the base three times and leave three places to state the weight.
6
7 /// Quasi Mono, the house monospace face.
8 ///
9 /// Variable on `wght` 200-800 in one file. **At rest it is `wght` 200**, since
10 /// a cut keeps its base's default instance and Atkinson Hyperlegible Mono's is
11 /// ExtraLight, so anything rendering it names a weight — see [`WEIGHT`].
12 pub static FACE: &[u8] = include_bytes!(env!("SHOP_FONT_FACE"));
13
14 /// The base's licence text. OFL 1.1 requires it to travel with a modified
15 /// build, so it travels inside the binary and `shop --license` prints it.
16 pub static LICENSE: &str = include_str!(env!("SHOP_FONT_LICENSE"));
17
18 /// The family name the face carries, for a fontconfig query or a log line.
19 pub const FAMILY: &str = env!("SHOP_FONT_FAMILY");
20
21 /// The style of the face's default instance, which is what `fc-match` and a
22 /// naive loader both report. `ExtraLight` today.
23 pub const DEFAULT_STYLE: &str = env!("SHOP_FONT_STYLE");
24
25 /// The weight the face opens at, which is its base's default instance.
26 ///
27 /// Stated so the trap is a number in the source rather than a sentence in a
28 /// comment: it is 200 today, and nothing should draw at it.
29 pub const DEFAULT_WEIGHT: f32 = {
30 // `parse` is not const, and the value comes from the build script as a
31 // string. Two digits of it are all that is ever needed.
32 match env!("SHOP_FONT_DEFAULT_WEIGHT").as_bytes() {
33 [b'2', b'0', b'0', ..] => 200.0,
34 [b'4', b'0', b'0', ..] => 400.0,
35 _ => f32::NAN,
36 }
37 };
38
39 /// The weight a terminal draws body text at.
40 ///
41 /// Named rather than inherited. The face's own default is the light end of its
42 /// axis, and a terminal that took it would draw every prompt in ExtraLight.
43 pub const WEIGHT: f32 = 400.0;
44
45 #[cfg(test)]
46 mod tests {
47 use super::*;
48
49 #[test]
50 fn the_face_is_a_truetype_file_carrying_an_axis() {
51 assert_eq!(&FACE[0..4], &[0x00, 0x01, 0x00, 0x00], "not an sfnt");
52 let tags: Vec<&[u8]> = (0..u16::from_be_bytes([FACE[4], FACE[5]]) as usize)
53 .map(|i| &FACE[12 + 16 * i..16 + 16 * i])
54 .collect();
55 for wanted in [b"fvar", b"gvar", b"cmap", b"glyf"] {
56 assert!(
57 tags.contains(&&wanted[..]),
58 "{} is missing, so this is not a cut variable face",
59 String::from_utf8_lossy(wanted)
60 );
61 }
62 }
63
64 #[test]
65 fn the_licence_travels_with_it() {
66 assert!(LICENSE.contains("SIL OPEN FONT LICENSE"));
67 }
68
69 /// The trap this crate exists to make impossible to forget.
70 #[test]
71 fn the_faces_own_default_is_not_the_weight_we_draw_at() {
72 assert_eq!(DEFAULT_STYLE, "ExtraLight");
73 assert!(
74 (WEIGHT - DEFAULT_WEIGHT).abs() > f32::EPSILON,
75 "the weight shop draws at is the file's own default, so naming it bought nothing"
76 );
77 }
78 }
79