0.12.1: Make collection of monospace fallback information optional
This commit is contained in:
parent
4f31665805
commit
58c2ccd1fb
3 changed files with 32 additions and 13 deletions
|
|
@ -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/),
|
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).
|
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
|
## [0.12.0] - 2024-06-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-text"
|
name = "cosmic-text"
|
||||||
description = "Pure Rust multi-line text handling"
|
description = "Pure Rust multi-line text handling"
|
||||||
version = "0.12.0"
|
version = "0.12.1"
|
||||||
authors = ["Jeremy Soller <jeremy@system76.com>"]
|
authors = ["Jeremy Soller <jeremy@system76.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
@ -38,6 +38,7 @@ features = ["hardcoded-data"]
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "swash", "fontconfig"]
|
default = ["std", "swash", "fontconfig"]
|
||||||
fontconfig = ["fontdb/fontconfig", "std"]
|
fontconfig = ["fontdb/fontconfig", "std"]
|
||||||
|
monospace_fallback = []
|
||||||
no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"]
|
no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"]
|
||||||
shape-run-cache = []
|
shape-run-cache = []
|
||||||
std = [
|
std = [
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@ self_cell!(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
struct FontMonospaceFallback {
|
||||||
|
monospace_em_width: Option<f32>,
|
||||||
|
scripts: Vec<[u8; 4]>,
|
||||||
|
unicode_codepoints: Vec<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
/// A font
|
/// A font
|
||||||
pub struct Font {
|
pub struct Font {
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
|
|
@ -32,9 +38,7 @@ pub struct Font {
|
||||||
rustybuzz: OwnedFace,
|
rustybuzz: OwnedFace,
|
||||||
data: Arc<dyn AsRef<[u8]> + Send + Sync>,
|
data: Arc<dyn AsRef<[u8]> + Send + Sync>,
|
||||||
id: fontdb::ID,
|
id: fontdb::ID,
|
||||||
monospace_em_width: Option<f32>,
|
monospace_fallback: Option<FontMonospaceFallback>,
|
||||||
scripts: Vec<[u8; 4]>,
|
|
||||||
unicode_codepoints: Vec<u32>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Font {
|
impl fmt::Debug for Font {
|
||||||
|
|
@ -51,15 +55,19 @@ impl Font {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monospace_em_width(&self) -> Option<f32> {
|
pub fn monospace_em_width(&self) -> Option<f32> {
|
||||||
self.monospace_em_width
|
self.monospace_fallback
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|x| x.monospace_em_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scripts(&self) -> &[[u8; 4]] {
|
pub fn scripts(&self) -> &[[u8; 4]] {
|
||||||
&self.scripts
|
self.monospace_fallback.as_ref().map_or(&[], |x| &x.scripts)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unicode_codepoints(&self) -> &[u32] {
|
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] {
|
pub fn data(&self) -> &[u8] {
|
||||||
|
|
@ -85,7 +93,7 @@ impl Font {
|
||||||
pub fn new(db: &fontdb::Database, id: fontdb::ID) -> Option<Self> {
|
pub fn new(db: &fontdb::Database, id: fontdb::ID) -> Option<Self> {
|
||||||
let info = db.face(id)?;
|
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| {
|
db.with_face_data(id, |font_data, face_index| {
|
||||||
let face = ttf_parser::Face::parse(font_data, face_index).ok()?;
|
let face = ttf_parser::Face::parse(font_data, face_index).ok()?;
|
||||||
let monospace_em_width = info
|
let monospace_em_width = info
|
||||||
|
|
@ -128,9 +136,15 @@ impl Font {
|
||||||
|
|
||||||
unicode_codepoints.shrink_to_fit();
|
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 {
|
let data = match &info.source {
|
||||||
fontdb::Source::Binary(data) => Arc::clone(data),
|
fontdb::Source::Binary(data) => Arc::clone(data),
|
||||||
|
|
@ -145,9 +159,7 @@ impl Font {
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
id: info.id,
|
id: info.id,
|
||||||
monospace_em_width,
|
monospace_fallback,
|
||||||
scripts,
|
|
||||||
unicode_codepoints,
|
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
swash: {
|
swash: {
|
||||||
let swash = swash::FontRef::from_index((*data).as_ref(), info.index as usize)?;
|
let swash = swash::FontRef::from_index((*data).as_ref(), info.index as usize)?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue