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
parent 2d064116ab
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;