diff --git a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp index eb7d3046562..8123b7be199 100644 --- a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp +++ b/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp @@ -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); diff --git a/Libraries/LibWeb/CSS/CSSFontFaceRule.h b/Libraries/LibWeb/CSS/CSSFontFaceRule.h index fc6894360a8..69c9308f6df 100644 --- a/Libraries/LibWeb/CSS/CSSFontFaceRule.h +++ b/Libraries/LibWeb/CSS/CSSFontFaceRule.h @@ -22,6 +22,7 @@ public: virtual ~CSSFontFaceRule() override = default; + bool is_valid() const; ParsedFontFace font_face() const; CSSStyleDeclaration* style() { return m_style; } diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index c8a8426f975..e58c0dfa56f 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -3061,8 +3061,10 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet& sheet) for (auto const& rule : sheet.rules()) { if (!is(*rule)) continue; - auto font_loader = load_font_face(static_cast(*rule).font_face()); - if (font_loader.has_value()) { + auto const& font_face_rule = static_cast(*rule); + if (!font_face_rule.is_valid()) + continue; + if (auto font_loader = load_font_face(font_face_rule.font_face()); font_loader.has_value()) { sheet.add_associated_font_loader(font_loader.value()); } } diff --git a/Libraries/LibWeb/Dump.cpp b/Libraries/LibWeb/Dump.cpp index 4625bb8c3f3..2803277488f 100644 --- a/Libraries/LibWeb/Dump.cpp +++ b/Libraries/LibWeb/Dump.cpp @@ -702,6 +702,9 @@ void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_leve void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rule, int indent_levels) { auto const font_face = rule.font_face(); + indent(builder, indent_levels + 1); + builder.appendff("VALID: {}\n", rule.is_valid()); + indent(builder, indent_levels + 1); builder.appendff("font-family: {}\n", font_face.font_family());