summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-24 15:35:04 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-24 17:19:18 +0200
commit74bdbdf43fb9bf6ae93ee30c37dc3d0ddcba4b3b (patch)
tree57a4b11df52c624fac82a419547476b3118d688c /Userland
parentbe103603508b32936aef12a38b7bb985625efe39 (diff)
downloadserenity-74bdbdf43fb9bf6ae93ee30c37dc3d0ddcba4b3b.zip
LibWeb: Parse font-weight and font-style inside @font-face rules
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CSS/FontFace.cpp5
-rw-r--r--Userland/Libraries/LibWeb/CSS/FontFace.h9
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp18
3 files changed, 28 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp
index 8babc28f5b..1d1eb415a8 100644
--- a/Userland/Libraries/LibWeb/CSS/FontFace.cpp
+++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -8,8 +9,10 @@
namespace Web::CSS {
-FontFace::FontFace(FlyString font_family, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges)
+FontFace::FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges)
: m_font_family(move(font_family))
+ , m_weight(weight)
+ , m_slope(slope)
, m_sources(move(sources))
, m_unicode_ranges(move(unicode_ranges))
{
diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.h b/Userland/Libraries/LibWeb/CSS/FontFace.h
index 9ae577511f..04a112a2d0 100644
--- a/Userland/Libraries/LibWeb/CSS/FontFace.h
+++ b/Userland/Libraries/LibWeb/CSS/FontFace.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -20,16 +21,20 @@ public:
Optional<FlyString> format;
};
- FontFace(FlyString font_family, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges);
+ FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges);
~FontFace() = default;
FlyString font_family() const { return m_font_family; }
+ Optional<int> weight() const { return m_weight; }
+ Optional<int> slope() const { return m_slope; }
Vector<Source> const& sources() const { return m_sources; }
Vector<UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
- // FIXME: font-style, font-weight, font-stretch, font-feature-settings
+ // FIXME: font-stretch, font-feature-settings
private:
FlyString m_font_family;
+ Optional<int> m_weight { 0 };
+ Optional<int> m_slope { 0 };
Vector<Source> m_sources;
Vector<UnicodeRange> m_unicode_ranges;
};
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 719d5512aa..de1a196102 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -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)