summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Ananyin <ananinegor@gmail.com>2021-04-13 20:41:57 +0300
committerAndreas Kling <kling@serenityos.org>2021-04-13 22:04:25 +0200
commitfe544feb17c550803dbf3da6ac5059d0c8d700c3 (patch)
tree30290f96105126b4f6c916294c20839d1e5af19d
parente4b3591ac4463644d5b77cc8eac4336d4ff0d974 (diff)
downloadserenity-fe544feb17c550803dbf3da6ac5059d0c8d700c3.zip
LibWeb: Start parsing font property
-rw-r--r--Userland/Libraries/LibWeb/CSS/Properties.json8
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleResolver.cpp22
2 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json
index 3344ea6538..321be3919f 100644
--- a/Userland/Libraries/LibWeb/CSS/Properties.json
+++ b/Userland/Libraries/LibWeb/CSS/Properties.json
@@ -188,6 +188,14 @@
"inherited": false,
"initial": "none"
},
+ "font": {
+ "longhands": [
+ "font-family",
+ "font-size",
+ "font-variant",
+ "font-weight"
+ ]
+ },
"font-family": {
"inherited": true,
"initial": "sans-serif"
diff --git a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
index c101a1ad40..0d55ec9218 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
@@ -664,6 +664,28 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
return;
}
+ // FIXME: parse other values as well
+ if (property_id == CSS::PropertyID::Font) {
+ auto parts = split_on_whitespace(value.to_string());
+ if (parts.size() < 2)
+ return;
+ auto size_parts = parts[0].split_view('/');
+ if (size_parts.size() == 2) {
+ auto size = parse_css_value(context, size_parts[0]);
+ if (!size)
+ return;
+ style.set_property(CSS::PropertyID::FontSize, size.release_nonnull());
+ } else if (size_parts.size() == 1) {
+ auto size = parse_css_value(context, parts[0]);
+ if (!size)
+ return;
+ style.set_property(CSS::PropertyID::FontSize, size.release_nonnull());
+ }
+ auto family = parse_css_value(context, parts[1]);
+ style.set_property(CSS::PropertyID::FontFamily, family.release_nonnull());
+ return;
+ }
+
style.set_property(property_id, value);
}