| ... | @@ -113,10 +113,12 @@ pub(crate) const DEFAULT_FONT: &str = "Arial"; | ... | @@ -113,10 +113,12 @@ pub(crate) const DEFAULT_FONT: &str = "Arial"; |
| 113 | pub(crate) const DEFAULT_FONT_SIZE: f32 = 11.0; | 113 | pub(crate) const DEFAULT_FONT_SIZE: f32 = 11.0; |
| 114 | | 114 | |
| 115 | /// Metric-compatible faces for the fonts OneNote pages use most, under the SIL Open Font | 115 | /// Metric-compatible faces for the fonts OneNote pages use most, under the SIL Open Font |
| 116 | /// Licence files beside them, by the family each stands in for. The browser fetches them | 116 | /// Licence files beside them, by the family each stands in for. Each is left out where the |
| 117 | /// beside the module instead (`register_substitute`), keeping them out of it. | 117 | /// system ships the family it stands in for: Windows ships all four, macOS and iOS all but |
| 118 | #[cfg(not(target_arch = "wasm32"))] | 118 | /// Calibri. The browser fetches them beside the module instead (`register_substitute`), |
| 119 | const BUNDLED: [(&str, &[&[u8]]); 4] = [ | 119 | /// keeping them out of it. |
| | 120 | #[cfg(not(any(windows, target_arch = "wasm32")))] |
| | 121 | const BUNDLED: &[(&str, &[&[u8]])] = &[ |
| 120 | ( | 122 | ( |
| 121 | "Calibri", | 123 | "Calibri", |
| 122 | &[ | 124 | &[ |
| ... | @@ -126,6 +128,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ | ... | @@ -126,6 +128,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ |
| 126 | include_bytes!("../assets/fonts/Carlito-BoldItalic.ttf"), | 128 | include_bytes!("../assets/fonts/Carlito-BoldItalic.ttf"), |
| 127 | ], | 129 | ], |
| 128 | ), | 130 | ), |
| | 131 | #[cfg(not(any(target_os = "macos", target_os = "ios")))] |
| 129 | ( | 132 | ( |
| 130 | "Arial", | 133 | "Arial", |
| 131 | &[ | 134 | &[ |
| ... | @@ -133,6 +136,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ | ... | @@ -133,6 +136,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ |
| 133 | include_bytes!("../assets/fonts/Arimo-Italic.ttf"), | 136 | include_bytes!("../assets/fonts/Arimo-Italic.ttf"), |
| 134 | ], | 137 | ], |
| 135 | ), | 138 | ), |
| | 139 | #[cfg(not(any(target_os = "macos", target_os = "ios")))] |
| 136 | ( | 140 | ( |
| 137 | "Times New Roman", | 141 | "Times New Roman", |
| 138 | &[ | 142 | &[ |
| ... | @@ -142,6 +146,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ | ... | @@ -142,6 +146,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ |
| 142 | include_bytes!("../assets/fonts/Tinos-BoldItalic.ttf"), | 146 | include_bytes!("../assets/fonts/Tinos-BoldItalic.ttf"), |
| 143 | ], | 147 | ], |
| 144 | ), | 148 | ), |
| | 149 | #[cfg(not(any(target_os = "macos", target_os = "ios")))] |
| 145 | ( | 150 | ( |
| 146 | "Courier New", | 151 | "Courier New", |
| 147 | &[ | 152 | &[ |
| ... | @@ -156,7 +161,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ | ... | @@ -156,7 +161,7 @@ const BUNDLED: [(&str, &[&[u8]]); 4] = [ |
| 156 | impl Default for TextEngine { | 161 | impl Default for TextEngine { |
| 157 | /// An engine that lays out each bundled family in its substitute where it is missing. | 162 | /// An engine that lays out each bundled family in its substitute where it is missing. |
| 158 | fn default() -> Self { | 163 | fn default() -> Self { |
| 159 | #[cfg_attr(target_arch = "wasm32", allow(unused_mut))] | 164 | #[cfg_attr(any(windows, target_arch = "wasm32"), allow(unused_mut))] |
| 160 | let mut engine = Self { | 165 | let mut engine = Self { |
| 161 | // Clones share loaded font files, so glyphs one lays out draw from the same cache. | 166 | // Clones share loaded font files, so glyphs one lays out draw from the same cache. |
| 162 | fonts: FontContext { | 167 | fonts: FontContext { |
| ... | @@ -167,8 +172,8 @@ impl Default for TextEngine { | ... | @@ -167,8 +172,8 @@ impl Default for TextEngine { |
| 167 | arial_substitutes: BTreeSet::new(), | 172 | arial_substitutes: BTreeSet::new(), |
| 168 | substitutes: BTreeMap::new(), | 173 | substitutes: BTreeMap::new(), |
| 169 | }; | 174 | }; |
| 170 | #[cfg(not(target_arch = "wasm32"))] | 175 | #[cfg(not(any(windows, target_arch = "wasm32")))] |
| 171 | for (family, faces) in BUNDLED { | 176 | for &(family, faces) in BUNDLED { |
| 172 | if engine.fonts.collection.family_id(family).is_none() { | 177 | if engine.fonts.collection.family_id(family).is_none() { |
| 173 | for face in faces { | 178 | for face in faces { |
| 174 | engine | 179 | engine |
| ... | @@ -706,7 +711,9 @@ mod tests { | ... | @@ -706,7 +711,9 @@ mod tests { |
| 706 | if engine.substitute("Calibri").is_none() { | 711 | if engine.substitute("Calibri").is_none() { |
| 707 | return; | 712 | return; |
| 708 | } | 713 | } |
| 709 | let explicit = Blob::new(Arc::new(BUNDLED[0].1[0].to_vec())); | 714 | let explicit = Blob::new(Arc::new( |
| | 715 | include_bytes!("../assets/fonts/Carlito-Regular.ttf").to_vec(), |
| | 716 | )); |
| 710 | assert_eq!(engine.register_substitute(explicit.clone()), Ok("Calibri")); | 717 | assert_eq!(engine.register_substitute(explicit.clone()), Ok("Calibri")); |
| 711 | let substitute = engine.substitute("Calibri").unwrap(); | 718 | let substitute = engine.substitute("Calibri").unwrap(); |
| 712 | assert_eq!(substitute.faces.len(), 1); | 719 | assert_eq!(substitute.faces.len(), 1); |