Only try monospace fonts that support at least one requested script
When font fallback involves monospace fonts, and if word has known scripts, limit the fonts tried for fallback to ones that support at least one requested script. Codepoint support info is still collected for these fonts to guide the fallback order selection process. A map of per-script monospace font-ids is pre-populated in font system to acquire lists of wanted font ids efficiently. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
parent
59ac0b824c
commit
729dc868c2
3 changed files with 70 additions and 5 deletions
|
|
@ -30,6 +30,7 @@ pub struct Font {
|
|||
data: Arc<dyn AsRef<[u8]> + Send + Sync>,
|
||||
id: fontdb::ID,
|
||||
monospace_em_width: Option<f32>,
|
||||
scripts: Vec<[u8; 4]>,
|
||||
unicode_codepoints: Vec<u32>,
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +51,10 @@ impl Font {
|
|||
self.monospace_em_width
|
||||
}
|
||||
|
||||
pub fn scripts(&self) -> &[[u8; 4]] {
|
||||
&self.scripts
|
||||
}
|
||||
|
||||
pub fn unicode_codepoints(&self) -> &[u32] {
|
||||
&self.unicode_codepoints
|
||||
}
|
||||
|
|
@ -77,7 +82,7 @@ impl Font {
|
|||
pub fn new(db: &fontdb::Database, id: fontdb::ID) -> Option<Self> {
|
||||
let info = db.face(id)?;
|
||||
|
||||
let (monospace_em_width, unicode_codepoints) = {
|
||||
let (monospace_em_width, scripts, unicode_codepoints) = {
|
||||
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
|
||||
|
|
@ -93,6 +98,15 @@ impl Font {
|
|||
None?;
|
||||
}
|
||||
|
||||
let scripts = face
|
||||
.tables()
|
||||
.gpos
|
||||
.into_iter()
|
||||
.chain(face.tables().gsub)
|
||||
.flat_map(|table| table.scripts)
|
||||
.map(|script| script.tag.to_bytes())
|
||||
.collect();
|
||||
|
||||
let mut unicode_codepoints = Vec::new();
|
||||
|
||||
face.tables()
|
||||
|
|
@ -111,7 +125,7 @@ impl Font {
|
|||
|
||||
unicode_codepoints.shrink_to_fit();
|
||||
|
||||
Some((monospace_em_width, unicode_codepoints))
|
||||
Some((monospace_em_width, scripts, unicode_codepoints))
|
||||
})?
|
||||
}?;
|
||||
|
||||
|
|
@ -129,6 +143,7 @@ impl Font {
|
|||
Some(Self {
|
||||
id: info.id,
|
||||
monospace_em_width,
|
||||
scripts,
|
||||
unicode_codepoints,
|
||||
#[cfg(feature = "swash")]
|
||||
swash: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue