mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 12:02:51 +00:00
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:
parent
f87b454fa9
commit
9cce791424
Notes:
github-actions[bot]
2025-04-04 09:41:32 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9cce791424
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4206
4 changed files with 17 additions and 2 deletions
|
@ -34,6 +34,15 @@ void CSSFontFaceRule::initialize(JS::Realm& realm)
|
||||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSFontFaceRule);
|
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
|
ParsedFontFace CSSFontFaceRule::font_face() const
|
||||||
{
|
{
|
||||||
return ParsedFontFace::from_descriptors(m_style);
|
return ParsedFontFace::from_descriptors(m_style);
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
|
|
||||||
virtual ~CSSFontFaceRule() override = default;
|
virtual ~CSSFontFaceRule() override = default;
|
||||||
|
|
||||||
|
bool is_valid() const;
|
||||||
ParsedFontFace font_face() const;
|
ParsedFontFace font_face() const;
|
||||||
CSSStyleDeclaration* style() { return m_style; }
|
CSSStyleDeclaration* style() { return m_style; }
|
||||||
|
|
||||||
|
|
|
@ -3061,8 +3061,10 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet& sheet)
|
||||||
for (auto const& rule : sheet.rules()) {
|
for (auto const& rule : sheet.rules()) {
|
||||||
if (!is<CSSFontFaceRule>(*rule))
|
if (!is<CSSFontFaceRule>(*rule))
|
||||||
continue;
|
continue;
|
||||||
auto font_loader = load_font_face(static_cast<CSSFontFaceRule const&>(*rule).font_face());
|
auto const& font_face_rule = static_cast<CSSFontFaceRule const&>(*rule);
|
||||||
if (font_loader.has_value()) {
|
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());
|
sheet.add_associated_font_loader(font_loader.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rule, int indent_levels)
|
||||||
{
|
{
|
||||||
auto const font_face = rule.font_face();
|
auto const font_face = rule.font_face();
|
||||||
|
indent(builder, indent_levels + 1);
|
||||||
|
builder.appendff("VALID: {}\n", rule.is_valid());
|
||||||
|
|
||||||
indent(builder, indent_levels + 1);
|
indent(builder, indent_levels + 1);
|
||||||
builder.appendff("font-family: {}\n", font_face.font_family());
|
builder.appendff("font-family: {}\n", font_face.font_family());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue