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/),
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 <jeremy@system76.com>"]
|
||||
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 = [
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ self_cell!(
|
|||
}
|
||||
);
|
||||
|
||||
struct FontMonospaceFallback {
|
||||
monospace_em_width: Option<f32>,
|
||||
scripts: Vec<[u8; 4]>,
|
||||
unicode_codepoints: Vec<u32>,
|
||||
}
|
||||
|
||||
/// A font
|
||||
pub struct Font {
|
||||
#[cfg(feature = "swash")]
|
||||
|
|
@ -32,9 +38,7 @@ pub struct Font {
|
|||
rustybuzz: OwnedFace,
|
||||
data: Arc<dyn AsRef<[u8]> + Send + Sync>,
|
||||
id: fontdb::ID,
|
||||
monospace_em_width: Option<f32>,
|
||||
scripts: Vec<[u8; 4]>,
|
||||
unicode_codepoints: Vec<u32>,
|
||||
monospace_fallback: Option<FontMonospaceFallback>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Font {
|
||||
|
|
@ -51,15 +55,19 @@ impl Font {
|
|||
}
|
||||
|
||||
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]] {
|
||||
&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<Self> {
|
||||
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)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue