From 58c2ccd1fb3daf0abc792f9dd52b5766b7125ccd Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 31 Jul 2024 10:02:11 -0600 Subject: [PATCH] 0.12.1: Make collection of monospace fallback information optional --- CHANGELOG.md | 6 ++++++ Cargo.toml | 3 ++- src/font/mod.rs | 36 ++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a264c977..77ed6edc35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.1] - 2024-06-31 + +### Changed + +- Make collection of monospace fallback information optional + ## [0.12.0] - 2024-06-18 ### Added diff --git a/Cargo.toml b/Cargo.toml index 3ba2401e7c..6b1acddd26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cosmic-text" description = "Pure Rust multi-line text handling" -version = "0.12.0" +version = "0.12.1" authors = ["Jeremy Soller "] edition = "2021" license = "MIT OR Apache-2.0" @@ -38,6 +38,7 @@ features = ["hardcoded-data"] [features] default = ["std", "swash", "fontconfig"] fontconfig = ["fontdb/fontconfig", "std"] +monospace_fallback = [] no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"] shape-run-cache = [] std = [ diff --git a/src/font/mod.rs b/src/font/mod.rs index c554166dc3..252a2a0744 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -25,6 +25,12 @@ self_cell!( } ); +struct FontMonospaceFallback { + monospace_em_width: Option, + scripts: Vec<[u8; 4]>, + unicode_codepoints: Vec, +} + /// A font pub struct Font { #[cfg(feature = "swash")] @@ -32,9 +38,7 @@ pub struct Font { rustybuzz: OwnedFace, data: Arc + Send + Sync>, id: fontdb::ID, - monospace_em_width: Option, - scripts: Vec<[u8; 4]>, - unicode_codepoints: Vec, + monospace_fallback: Option, } impl fmt::Debug for Font { @@ -51,15 +55,19 @@ impl Font { } pub fn monospace_em_width(&self) -> Option { - self.monospace_em_width + self.monospace_fallback + .as_ref() + .and_then(|x| x.monospace_em_width) } pub fn scripts(&self) -> &[[u8; 4]] { - &self.scripts + self.monospace_fallback.as_ref().map_or(&[], |x| &x.scripts) } pub fn unicode_codepoints(&self) -> &[u32] { - &self.unicode_codepoints + self.monospace_fallback + .as_ref() + .map_or(&[], |x| &x.unicode_codepoints) } pub fn data(&self) -> &[u8] { @@ -85,7 +93,7 @@ impl Font { pub fn new(db: &fontdb::Database, id: fontdb::ID) -> Option { let info = db.face(id)?; - let (monospace_em_width, scripts, unicode_codepoints) = { + let monospace_fallback = if cfg!(feature = "monospace_fallback") { db.with_face_data(id, |font_data, face_index| { let face = ttf_parser::Face::parse(font_data, face_index).ok()?; let monospace_em_width = info @@ -128,9 +136,15 @@ impl Font { unicode_codepoints.shrink_to_fit(); - Some((monospace_em_width, scripts, unicode_codepoints)) + Some(FontMonospaceFallback { + monospace_em_width, + scripts, + unicode_codepoints, + }) })? - }?; + } else { + None + }; let data = match &info.source { fontdb::Source::Binary(data) => Arc::clone(data), @@ -145,9 +159,7 @@ impl Font { Some(Self { id: info.id, - monospace_em_width, - scripts, - unicode_codepoints, + monospace_fallback, #[cfg(feature = "swash")] swash: { let swash = swash::FontRef::from_index((*data).as_ref(), info.index as usize)?;