Use weight absolute difference in monospace fallback matching
When matching on weights smaller than normal, "equal or smaller" weight restriction may cause monospace fallback to fail, depending on font support at such weights for the text to be shaped. So remove that restriction, and calculate weight differences instead of offsets. In case of no exact weight match, and with all other factors being equal, smaller weights will be picked before bigger ones. So, this should generally not cause any behavioral changes when matching on normal weight or bigger. Should fix pop-os/cosmic-term#104. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
parent
1a18296a67
commit
0cea55630c
3 changed files with 14 additions and 12 deletions
|
|
@ -11,7 +11,8 @@ pub use rustybuzz;
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct FontMatchKey {
|
||||
pub(crate) weight_offset: Option<u16>,
|
||||
pub(crate) font_weight_diff: u16,
|
||||
pub(crate) font_weight: u16,
|
||||
pub(crate) id: fontdb::ID,
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +152,8 @@ impl FontSystem {
|
|||
.faces()
|
||||
.filter(|face| attrs.matches(face))
|
||||
.map(|face| FontMatchKey {
|
||||
weight_offset: attrs.weight.0.checked_sub(face.weight.0),
|
||||
font_weight_diff: attrs.weight.0.abs_diff(face.weight.0),
|
||||
font_weight: face.weight.0,
|
||||
id: face.id,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue