LibWeb/CSS: Only attempt to load valid @font-face fonts

These must have a `font-family` and `src` set to be included in
font-matching. Otherwise they should be ignored, but still exist in the
CSSOM.
This commit is contained in:
Sam Atkins 2025-04-03 12:15:11 +01:00
parent f87b454fa9
commit 9cce791424
Notes: github-actions[bot] 2025-04-04 09:41:32 +00:00
4 changed files with 17 additions and 2 deletions

View file

@ -34,6 +34,15 @@ void CSSFontFaceRule::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSFontFaceRule);
}
bool CSSFontFaceRule::is_valid() const
{
// @font-face rules require a font-family and src descriptor; if either of these are missing, the @font-face rule
// must not be considered when performing the font matching algorithm.
// https://drafts.csswg.org/css-fonts-4/#font-face-rule
return !m_style->descriptor(DescriptorID::FontFamily).is_null()
&& !m_style->descriptor(DescriptorID::Src).is_null();
}
ParsedFontFace CSSFontFaceRule::font_face() const
{
return ParsedFontFace::from_descriptors(m_style);