Warn when using variable fonts (#6425)

This commit is contained in:
cAttte 2025-06-11 11:42:57 -03:00 committed by GitHub
parent ada90fdd87
commit 46d57b00b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -196,6 +196,8 @@ bitflags::bitflags! {
const SERIF = 1 << 1;
/// Font face has a MATH table
const MATH = 1 << 2;
/// Font face has an fvar table
const VARIABLE = 1 << 3;
}
}
@ -275,6 +277,7 @@ impl FontInfo {
let mut flags = FontFlags::empty();
flags.set(FontFlags::MONOSPACE, ttf.is_monospaced());
flags.set(FontFlags::MATH, ttf.tables().math.is_some());
flags.set(FontFlags::VARIABLE, ttf.is_variable());
// Determine whether this is a serif or sans-serif font.
if let Some(panose) = ttf

View File

@ -1412,12 +1412,24 @@ pub fn is_default_ignorable(c: char) -> bool {
fn check_font_list(engine: &mut Engine, list: &Spanned<FontList>) {
let book = engine.world.book();
for family in &list.v {
if !book.contains_family(family.as_str()) {
match book.select_family(family.as_str()).next() {
Some(index) => {
if book
.info(index)
.is_some_and(|x| x.flags.contains(FontFlags::VARIABLE))
{
engine.sink.warn(warning!(
list.span,
"variable fonts are not currently supported and may render incorrectly";
hint: "try installing a static version of \"{}\" instead", family.as_str()
))
}
}
None => engine.sink.warn(warning!(
list.span,
"unknown font family: {}",
family.as_str(),
));
)),
}
}
}