LibWeb: Handle format(woff-variations) etc in @font-face src values

"format(woff-variations)" and pals are supposed to expand like so:
"format(woff) tech(variations)".

However, since we don't support tech() yet, this patch just adds a small
hack where we still treat "woff-variations" as "woff" so that fonts
load and get used, even if we don't make use of the variations yet.
This commit is contained in:
Andreas Kling 2025-05-23 14:03:40 +02:00 committed by Jelle Raaijmakers
commit 59e2416b61
Notes: github-actions[bot] 2025-05-23 14:37:58 +00:00
2 changed files with 12 additions and 6 deletions

View file

@ -3874,6 +3874,7 @@ RefPtr<StringStyleValue const> Parser::parse_opentype_tag_value(TokenStream<Comp
return string_value;
}
// https://drafts.csswg.org/css-fonts/#font-face-src-parsing
RefPtr<FontSourceStyleValue const> Parser::parse_font_source_value(TokenStream<ComponentValue>& tokens)
{
// <font-src> = <url> [ format(<font-format>)]? [ tech( <font-tech>#)]? | local(<family-name>)
@ -3919,6 +3920,12 @@ RefPtr<FontSourceStyleValue const> Parser::parse_font_source_value(TokenStream<C
return nullptr;
}
// FIXME: Some of the formats support an optional "-variations" suffix that's really supposed to map to tech(variations).
// Once we support tech(*), we should ensure this propagates correctly.
if (format_name.is_one_of("woff2-variations"sv, "woff-variations"sv, "truetype-variations"sv, "opentype-variations"sv)) {
format_name = MUST(format_name.to_string().substring_from_byte_offset(0, format_name.bytes().size() - strlen("-variations")));
}
if (!font_format_is_supported(format_name)) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: font source format({}) not supported; skipping.", format_name);
return nullptr;

View file

@ -2,16 +2,15 @@ Harness status: OK
Found 48 tests
44 Pass
4 Fail
48 Pass
Pass Load Ahem with format woff
Pass Load Ahem with format truetype
Pass Load Ahem with format opentype
Pass Load Ahem with format woff2
Fail Load Ahem with format woff-variations
Fail Load Ahem with format truetype-variations
Fail Load Ahem with format opentype-variations
Fail Load Ahem with format woff2-variations
Pass Load Ahem with format woff-variations
Pass Load Ahem with format truetype-variations
Pass Load Ahem with format opentype-variations
Pass Load Ahem with format woff2-variations
Pass Do not load Ahem with format xyzwoff
Pass Do not load Ahem with format xyztruetype
Pass Do not load Ahem with format xyzopentype