1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 10:18:15 +09:00

LibWeb: Parse font-weight and font-style inside @font-face rules

This commit is contained in:
Andreas Kling 2023-05-24 15:35:04 +02:00
parent be10360350
commit 74bdbdf43f
Notes: sideshowbarker 2024-07-17 06:24:08 +09:00
3 changed files with 28 additions and 4 deletions

View file

@ -5604,6 +5604,8 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
Optional<FlyString> font_family;
Vector<FontFace::Source> src;
Vector<UnicodeRange> unicode_range;
Optional<int> weight;
Optional<int> slope;
for (auto& declaration_or_at_rule : declarations_and_at_rules) {
if (declaration_or_at_rule.is_at_rule()) {
@ -5612,6 +5614,20 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
}
auto const& declaration = declaration_or_at_rule.declaration();
if (declaration.name().equals_ignoring_ascii_case("font-weight"sv)) {
TokenStream token_stream { declaration.values() };
if (auto value = parse_css_value(CSS::PropertyID::FontWeight, token_stream); !value.is_error()) {
weight = value.value()->to_font_weight();
}
continue;
}
if (declaration.name().equals_ignoring_ascii_case("font-style"sv)) {
TokenStream token_stream { declaration.values() };
if (auto value = parse_css_value(CSS::PropertyID::FontStyle, token_stream); !value.is_error()) {
slope = value.value()->to_font_slope();
}
continue;
}
if (declaration.name().equals_ignoring_ascii_case("font-family"sv)) {
// FIXME: This is very similar to, but different from, the logic in parse_font_family_value().
// Ideally they could share code.
@ -5698,7 +5714,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
unicode_range.empend(0x0u, 0x10FFFFu);
}
return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), move(src), move(unicode_range) }).release_value_but_fixme_should_propagate_errors();
return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range) }).release_value_but_fixme_should_propagate_errors();
}
Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>& component_values)