Skip to content

Commit 58c2ccd

Browse files
committed
0.12.1: Make collection of monospace fallback information optional
1 parent 4f31665 commit 58c2ccd

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.12.1] - 2024-06-31
9+
10+
### Changed
11+
12+
- Make collection of monospace fallback information optional
13+
814
## [0.12.0] - 2024-06-18
915

1016
### Added

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cosmic-text"
33
description = "Pure Rust multi-line text handling"
4-
version = "0.12.0"
4+
version = "0.12.1"
55
authors = ["Jeremy Soller <jeremy@system76.com>"]
66
edition = "2021"
77
license = "MIT OR Apache-2.0"
@@ -38,6 +38,7 @@ features = ["hardcoded-data"]
3838
[features]
3939
default = ["std", "swash", "fontconfig"]
4040
fontconfig = ["fontdb/fontconfig", "std"]
41+
monospace_fallback = []
4142
no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"]
4243
shape-run-cache = []
4344
std = [

src/font/mod.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ self_cell!(
2525
}
2626
);
2727

28+
struct FontMonospaceFallback {
29+
monospace_em_width: Option<f32>,
30+
scripts: Vec<[u8; 4]>,
31+
unicode_codepoints: Vec<u32>,
32+
}
33+
2834
/// A font
2935
pub struct Font {
3036
#[cfg(feature = "swash")]
3137
swash: (u32, swash::CacheKey),
3238
rustybuzz: OwnedFace,
3339
data: Arc<dyn AsRef<[u8]> + Send + Sync>,
3440
id: fontdb::ID,
35-
monospace_em_width: Option<f32>,
36-
scripts: Vec<[u8; 4]>,
37-
unicode_codepoints: Vec<u32>,
41+
monospace_fallback: Option<FontMonospaceFallback>,
3842
}
3943

4044
impl fmt::Debug for Font {
@@ -51,15 +55,19 @@ impl Font {
5155
}
5256

5357
pub fn monospace_em_width(&self) -> Option<f32> {
54-
self.monospace_em_width
58+
self.monospace_fallback
59+
.as_ref()
60+
.and_then(|x| x.monospace_em_width)
5561
}
5662

5763
pub fn scripts(&self) -> &[[u8; 4]] {
58-
&self.scripts
64+
self.monospace_fallback.as_ref().map_or(&[], |x| &x.scripts)
5965
}
6066

6167
pub fn unicode_codepoints(&self) -> &[u32] {
62-
&self.unicode_codepoints
68+
self.monospace_fallback
69+
.as_ref()
70+
.map_or(&[], |x| &x.unicode_codepoints)
6371
}
6472

6573
pub fn data(&self) -> &[u8] {
@@ -85,7 +93,7 @@ impl Font {
8593
pub fn new(db: &fontdb::Database, id: fontdb::ID) -> Option<Self> {
8694
let info = db.face(id)?;
8795

88-
let (monospace_em_width, scripts, unicode_codepoints) = {
96+
let monospace_fallback = if cfg!(feature = "monospace_fallback") {
8997
db.with_face_data(id, |font_data, face_index| {
9098
let face = ttf_parser::Face::parse(font_data, face_index).ok()?;
9199
let monospace_em_width = info
@@ -128,9 +136,15 @@ impl Font {
128136

129137
unicode_codepoints.shrink_to_fit();
130138

131-
Some((monospace_em_width, scripts, unicode_codepoints))
139+
Some(FontMonospaceFallback {
140+
monospace_em_width,
141+
scripts,
142+
unicode_codepoints,
143+
})
132144
})?
133-
}?;
145+
} else {
146+
None
147+
};
134148

135149
let data = match &info.source {
136150
fontdb::Source::Binary(data) => Arc::clone(data),
@@ -145,9 +159,7 @@ impl Font {
145159

146160
Some(Self {
147161
id: info.id,
148-
monospace_em_width,
149-
scripts,
150-
unicode_codepoints,
162+
monospace_fallback,
151163
#[cfg(feature = "swash")]
152164
swash: {
153165
let swash = swash::FontRef::from_index((*data).as_ref(), info.index as usize)?;

0 commit comments

Comments
 (0)