From 36add75c8aac03116e2ce66440c25e5c8b9bc2de Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sat, 3 Oct 2026 14:18:06 -0700 Subject: [PATCH] chore: release builds leave out the font clones where the system ships the real families Windows ships Arial, Times New Roman, Courier New and Calibri, and macOS and iOS all but Calibri, so only Linux keeps Arimo, Tinos and Cousine and only Windows drops Carlito. Layout already preferred an installed family to its clone. Release executables after the debug split: macOS aarch64 40.97 to 36.42 MB (-4.56), Windows x86_64 45.88 to 38.62 MB (-7.26), Linux x86_64 unchanged at 52.35 MB. Assisted-by: claude-opus-5.5 --- crates/canvas/src/layout.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/canvas/src/layout.rs b/crates/canvas/src/layout.rs index c8112f6d5c3ff2f8d4a1535320f063bd04e99e2a..8ccc0d142788d356f5b18f759c379513c21571c8 100644 --- a/crates/canvas/src/layout.rs +++ b/crates/canvas/src/layout.rs @@ -113,10 +113,12 @@ pub(crate) const DEFAULT_FONT: &str = "Arial"; pub(crate) const DEFAULT_FONT_SIZE: f32 = 11.0; /// Metric-compatible faces for the fonts OneNote pages use most, under the SIL Open Font -/// Licence files beside them, by the family each stands in for. The browser fetches them -/// beside the module instead (`register_substitute`), keeping them out of it. -#[cfg(not(target_arch = "wasm32"))] -const BUNDLED: [(&str, &[&[u8]]); 4] = [ +/// Licence files beside them, by the family each stands in for. Each is left out where the +/// system ships the family it stands in for: Windows ships all four, macOS and iOS all but +/// Calibri. The browser fetches them beside the module instead (`register_substitute`), +/// keeping them out of it. +#[cfg(not(any(windows, target_arch = "wasm32")))] +const BUNDLED: &[(&str, &[&[u8]])] = &[ ( "Calibri", &[ @@ -126,6 +128,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ include_bytes!("../assets/fonts/Carlito-BoldItalic.ttf"), ], ), + #[cfg(not(any(target_os = "macos", target_os = "ios")))] ( "Arial", &[ @@ -133,6 +136,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ include_bytes!("../assets/fonts/Arimo-Italic.ttf"), ], ), + #[cfg(not(any(target_os = "macos", target_os = "ios")))] ( "Times New Roman", &[ @@ -142,6 +146,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ include_bytes!("../assets/fonts/Tinos-BoldItalic.ttf"), ], ), + #[cfg(not(any(target_os = "macos", target_os = "ios")))] ( "Courier New", &[ @@ -156,7 +161,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ impl Default for TextEngine { /// An engine that lays out each bundled family in its substitute where it is missing. fn default() -> Self { - #[cfg_attr(target_arch = "wasm32", allow(unused_mut))] + #[cfg_attr(any(windows, target_arch = "wasm32"), allow(unused_mut))] let mut engine = Self { // Clones share loaded font files, so glyphs one lays out draw from the same cache. fonts: FontContext { @@ -167,8 +172,8 @@ impl Default for TextEngine { arial_substitutes: BTreeSet::new(), substitutes: BTreeMap::new(), }; - #[cfg(not(target_arch = "wasm32"))] - for (family, faces) in BUNDLED { + #[cfg(not(any(windows, target_arch = "wasm32")))] + for &(family, faces) in BUNDLED { if engine.fonts.collection.family_id(family).is_none() { for face in faces { engine @@ -706,7 +711,9 @@ mod tests { if engine.substitute("Calibri").is_none() { return; } - let explicit = Blob::new(Arc::new(BUNDLED[0].1[0].to_vec())); + let explicit = Blob::new(Arc::new( + include_bytes!("../assets/fonts/Carlito-Regular.ttf").to_vec(), + )); assert_eq!(engine.register_substitute(explicit.clone()), Ok("Calibri")); let substitute = engine.substitute("Calibri").unwrap(); assert_eq!(substitute.faces.len(), 1); -- 2.54.0